install_zotero.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. #!/bin/bash
  2. echo "######################################################"
  3. echo "######################################################"
  4. echo "######################################################"
  5. echo "### SCRIPT TO INSTALL ZOTERO WITH MINIMUM EFFORTS ####"
  6. echo "### AUTHOR: PATRICK HÖHN #############################"
  7. echo "### RELEASED UNDER GPLv2 OR LATER ####################"
  8. echo "######################################################"
  9. echo "######################################################"
  10. echo "######################################################"
  11. echo "install required packages"
  12. echo "add key for elasticsearch repository"
  13. wget -qO - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add -
  14. echo "add debian wheezy backports repository"
  15. # removed for the time being, potentially not required anymore
  16. # sed -i '$s,$,\ndeb http://ftp.acc.umu.se./debian wheezy-backports main,' /etc/apt/sources.list
  17. sed -i '$s,$,\ndeb http://packages.elasticsearch.org/elasticsearch/1.4/debian stable main,' /etc/apt/sources.list
  18. echo "update package cache"
  19. apt-get update
  20. echo "dependencies for dataserver"
  21. apt-get install -y apache2 libapache2-mod-php5 mysql-server memcached zendframework php5-cli php5-memcache php5-mysql php5-curl php5-memcached
  22. echo "general dependencies"
  23. apt-get install -y git gnutls-bin runit libapache2-modsecurity curl elasticsearch openjdk-7-jre
  24. echo "created required directories"
  25. mkdir -p /srv/zotero/dataserver
  26. # fuck DEBIAN
  27. #mkdir -p /srv/zotero/log/{download,upload,error}
  28. mkdir -p /srv/zotero/log/download
  29. mkdir -p /srv/zotero/log/upload
  30. mkdir -p /srv/zotero/log/error
  31. # save current directory
  32. cur_dir=$(pwd)
  33. echo "setting elasticsearch to be started during booting"
  34. update-rc.d elasticsearch defaults 95 10
  35. echo "starting elasticsearch"
  36. /etc/init.d/elasticsearch start
  37. echo "download source code of dataserver"
  38. git clone git://github.com/zotero/dataserver.git /srv/zotero/dataserver
  39. echo "download source code of Elastica"
  40. git clone git://github.com/ruflin/Elastica.git /srv/zotero/dataserver/include/Elastica
  41. cd /srv/zotero/dataserver/include/Elastica
  42. git checkout fc607170ab2ca751097648d48a5d38e15e9d5f6a
  43. echo "install composer"
  44. cd /srv/zotero/dataserver
  45. curl -sS https://getcomposer.org/installer | php
  46. echo "install dependencies"
  47. php composer.phar install
  48. echo "remove composer"
  49. rm composer.phar
  50. echo "install add_user script"
  51. cp "$cur_dir/add_user" /srv/zotero/dataserver/admin
  52. echo "install change_password script"
  53. cp "$cur_dir/change_password" /srv/zotero/dataserver/admin
  54. echo "patch master.sql"
  55. cp "$cur_dir/master.sql" /srv/zotero/dataserver/misc
  56. echo "prepare directory rights"
  57. chown www-data:www-data /srv/zotero/dataserver/tmp
  58. echo "replace zend by native installation"
  59. cd /srv/zotero/dataserver/include
  60. rm -r Zend
  61. ln -s /usr/share/php/Zend/
  62. read -p "Do you want to use SSL certificates for Zotero server? (y/n)" SSL
  63. if [ $SSL=y ] ;
  64. then
  65. read -p "Do you want to generate SSL certificates now? (y/n)" gen_SSL
  66. if [ $gen_SSL=y ];
  67. then
  68. echo "generate SSL key and cert"
  69. certtool -p --sec-param high --outfile /etc/apache2/zotero.key
  70. certtool -s --load-privkey /etc/apache2/zotero.key --outfile /etc/apache2/zotero.cert
  71. else
  72. cp "$cur_dir/zotero.key" /etc/apache2/zotero.key
  73. cp "$cur_dir/zotero.cert" /etc/apache2/zotero.cert
  74. fi
  75. fi
  76. read -p "Do you want to use SSL certificates for LibreS3? (y/n)" SSL_LibreS3
  77. if [ $SSL_LibreS3=y ] ;
  78. then
  79. cat "$cur_dir/sx.cert" >> /srv/zotero/dataserver/vendor/guzzle/guzzle/src/Guzzle/Http/Resources/cacert.pem
  80. fi
  81. echo "enable rewrite support for apache2 server"
  82. a2enmod rewrite
  83. if [ $SSL=y ] ;
  84. then
  85. echo "enable ssl support for apache2 server"
  86. a2enmod ssl
  87. echo "create available site for zotero"
  88. echo "<VirtualHost *:443>
  89. DocumentRoot /srv/zotero/dataserver/htdocs
  90. SSLEngine on
  91. SSLCertificateFile /etc/apache2/zotero.cert
  92. SSLCertificateKeyFile /etc/apache2/zotero.key
  93. <Directory "/srv/zotero/dataserver/htdocs/">
  94. Options FollowSymLinks MultiViews
  95. AllowOverride All
  96. Order allow,deny
  97. Allow from all
  98. </Directory>
  99. ErrorLog /srv/zotero/error.log
  100. CustomLog /srv/zotero/access.log common
  101. </VirtualHost>" > /etc/apache2/sites-available/zotero
  102. else
  103. echo "create available site for zotero"
  104. echo "<VirtualHost *:80>
  105. DocumentRoot /srv/zotero/dataserver/htdocs
  106. <Directory "/srv/zotero/dataserver/htdocs/">
  107. Options FollowSymLinks MultiViews
  108. AllowOverride All
  109. Order allow,deny
  110. Allow from all
  111. </Directory>
  112. ErrorLog /srv/zotero/error.log
  113. CustomLog /srv/zotero/access.log common
  114. </VirtualHost>" > /etc/apache2/sites-available/zotero
  115. fi
  116. echo "activate site for zotero"
  117. a2ensite zotero
  118. echo "change .htaccess"
  119. sed -i '3i RewriteCond %{REQUEST_URI} !^/zotero' /srv/zotero/dataserver/htdocs/.htaccess
  120. echo "restart apache2"[5~
  121. service apache2 reload
  122. echo "###############"
  123. echo "configure MySQL"
  124. echo "###############"
  125. echo " [mysqld]
  126. character-set-server = utf8
  127. collation-server = utf8_general_ci
  128. event-scheduler = ON
  129. sql-mode = STRICT_ALL_TABLES
  130. default-time-zone = '+0:00'" > /etc/mysql/conf.d/zotero.cnf
  131. /etc/init.d/mysql restart
  132. echo -n "root Password for MySQL: "
  133. read password
  134. echo -n "password for zotero database user: "
  135. read zotero_password
  136. cd /srv/zotero/dataserver/misc
  137. DB="mysql -h 127.0.0.1 -P 3306 -u root -p${password}"
  138. echo "DROP DATABASE IF EXISTS zotero_master" | $DB
  139. echo "DROP DATABASE IF EXISTS zotero_shards" | $DB
  140. echo "DROP DATABASE IF EXISTS zotero_ids" | $DB
  141. echo "DROP DATABASE IF EXISTS zotero_www" | $DB
  142. echo "CREATE DATABASE zotero_master" | $DB
  143. echo "CREATE DATABASE zotero_shards" | $DB
  144. echo "CREATE DATABASE zotero_ids" | $DB
  145. echo "CREATE DATABASE zotero_www" | $DB
  146. echo "DROP USER IF EXISTS zotero@localhost;" | $DB
  147. echo "CREATE USER zotero@localhost IDENTIFIED BY '${zotero_password}';" | $DB
  148. echo "GRANT SELECT, INSERT, UPDATE, DELETE ON zotero_master.* TO zotero@localhost;" | $DB
  149. echo "GRANT SELECT, INSERT, UPDATE, DELETE ON zotero_shards.* TO zotero@localhost;" | $DB
  150. echo "GRANT SELECT,INSERT,DELETE ON zotero_ids.* TO zotero@localhost;" | $DB
  151. echo "GRANT SELECT,INSERT,DELETE ON zotero_www.* TO zotero@localhost;" | $DB
  152. echo "Load in master schema"
  153. $DB zotero_master < master.sql
  154. $DB zotero_master < coredata.sql
  155. $DB zotero_master < fulltext.sql
  156. echo "Set up shard info"
  157. echo "INSERT INTO shardHosts VALUES (1, '127.0.0.1', 3306, 'up');" | $DB zotero_master
  158. echo "INSERT INTO shards VALUES (1, 1, 'zotero_shards', 'up', 0);" | $DB zotero_master
  159. echo Load in shard schema
  160. cat shard.sql | $DB zotero_shards
  161. cat triggers.sql | $DB zotero_shards
  162. echo "Load in schema on id server"
  163. cat ids.sql | $DB zotero_ids
  164. echo "Load in www schema"
  165. $DB zotero_www < $(cur_dir)www.sql
  166. echo "Setup roleIDs"
  167. echo "INSERT INTO LUM_ROLE VALUES ('Deleted', 1);" | $DB zotero_www
  168. echo "INSERT INTO LUM_ROLE VALUES ('Invalid', 2);" | $DB zotero_www
  169. echo "INSERT INTO LUM_ROLE VALUES ('Valid', 3);" | $DB zotero_www
  170. echo "#################################"
  171. echo "Configuration database connection"
  172. echo "#################################"
  173. # add code to also configure other databases
  174. cp /srv/zotero/dataserver/include/config/dbconnect.inc.php-sample /srv/zotero/dataserver/include/config/dbconnect.inc.php
  175. echo -n "hostname for database: "
  176. read hostname
  177. sed -i "s/host\ =\ ''/host\ =\ '${hostname}'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  178. sed -i "s/host\ =\ false/host\ =\ '${hostname}'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  179. sed -i "s/port\ =\ ''/port\ =\ 3306/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  180. sed -i "s/port\ =\ false/port\ =\ 3306/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  181. sed -i "s/user\ =\ ''/user\ =\ 'zotero'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  182. sed -i "s/user\ =\ false/user\ =\ 'zotero'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  183. sed -i "s/pass\ =\ ''/pass\ =\ '${zotero_password}'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  184. sed -i "s/pass\ =\ false/pass\ =\ '${zotero_password}'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  185. sed -i "8s/db\ =\ ''/db\ =\ 'zotero_master'/" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  186. sed -i "15s/db\ =\ false/db\ =\ 'zotero_shards'/" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  187. sed -i "22s/db\ =\ false/db\ =\ 'zotero_master'/" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  188. sed -i "s/ids/zotero_ids/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  189. sed -i "s/'www'/'zotero_www'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
  190. echo "###################################"
  191. echo "General configuration of dataserver"
  192. echo "###################################"
  193. cp /srv/zotero/dataserver/include/config/config.inc.php-sample /srv/zotero/dataserver/include/config/config.inc.php
  194. sed -i "s/TESTING_SITE\ =\ true/TESTING_SITE\ =\ false/" /srv/zotero/dataserver/include/config/config.inc.php
  195. sed -i "s/DEV_SITE\ =\ true/DEV_SITE\ =\ false/" /srv/zotero/dataserver/include/config/config.inc.php
  196. echo -n "base-uri for zotero api: "
  197. read API_URI
  198. sed -i "s,API_BASE_URI\ =\ '',API_BASE_URI = '${API_URI}'," /srv/zotero/dataserver/include/config/config.inc.php
  199. echo -n "sync domain for zotero: "
  200. read SYNC_DOMAIN
  201. sed -i "s/SYNC_DOMAIN\ =\ ''/SYNC_DOMAIN\ =\ '${SYNC_DOMAIN}'/" /srv/zotero/dataserver/include/config/config.inc.php
  202. echo -n "Salt for passwords: "
  203. read AUTH_SALT
  204. sed -i "s/AUTH_SALT\ =\ ''/AUTH_SALT\ =\ '${AUTH_SALT}'/" /srv/zotero/dataserver/include/config/config.inc.php
  205. echo -n "api super username: "
  206. read API_SUPER_USERNAME
  207. sed -i "s/API_SUPER_USERNAME\ =\ ''/API_SUPER_USERNAME\ =\ '${API_SUPER_USERNAME}'/" /srv/zotero/dataserver/include/config/config.inc.php
  208. echo -n "api super password: "
  209. read API_SUPER_PASSWORD
  210. sed -i "s/API_SUPER_PASSWORD\ =\ ''/API_SUPER_PASSWORD\ =\ '${API_SUPER_PASSWORD}'/" /srv/zotero/dataserver/include/config/config.inc.php
  211. echo -n "aws access key: "
  212. read AWS_ACCESS_KEY
  213. sed -i "s/AWS_ACCESS_KEY\ =\ ''/AWS_ACCESS_KEY\ =\ '${AWS_ACCESS_KEY}'/" /srv/zotero/dataserver/include/config/config.inc.php
  214. echo -n "aws secret key: "
  215. read AWS_SECRET_KEY
  216. sed -i "s/AWS_SECRET_KEY\ =\ ''/AWS_SECRET_KEY\ =\ '${AWS_SECRET_KEY}'/" /srv/zotero/dataserver/include/config/config.inc.php
  217. echo -n "s3_bucket: "
  218. read S3_BUCKET
  219. sed -i "s/S3_BUCKET\ =\ ''/S3_BUCKET\ =\ '${S3_BUCKET}'/" /srv/zotero/dataserver/include/config/config.inc.php
  220. sed -i "s/us-east-1/custom/" /srv/zotero/dataserver/include/config/config.inc.php
  221. echo -n "s3 endpoint url: "
  222. read S3_ENDPOINT
  223. sed -i "s/S3_ENDPOINT\ =\ 's3.amazonaws.com'/S3_ENDPOINT\ =\ '${S3_ENDPOINT}'/" /srv/zotero/dataserver/include/config/config.inc.php
  224. read AWS_HOST
  225. sed -i "27a\ \ \ \ \ \ \ \ public static \$AWS_HOST\ =\ '${AWS_HOST};'" /srv/zotero/dataserver/include/config/config.inc.php
  226. sed -i "30i\ \ \ \ \ \ \ \ public static \$URI_PREFIX_DOMAIN_MAP = array(" /srv/zotero/dataserver/include/config/config.inc.php
  227. sed -i "31i\ \ \ \ \ \ \ \ \ \ '\/sync\/' => 'sync'" /srv/zotero/dataserver/include/config/config.inc.php
  228. sed -i "32i\ \ \ \ \ \ \ \ );" /srv/zotero/dataserver/include/config/config.inc.php
  229. sed -i "33i \ " /srv/zotero/dataserver/include/config/config.inc.php
  230. echo -n "memcached servers: "
  231. read MEMCACHED_SERVERS
  232. sed -i "s/'memcached1.localdomain:11211:2',\ 'memcached2.localdomain:11211:1'/'${MEMCACHED_SERVERS}'/" /srv/zotero/dataserver/include/config/config.inc.php
  233. echo "Configure document root folder"
  234. sed -i "s/var\/www\/dataserver/srv\/zotero\/dataserver/" /srv/zotero/dataserver/include/config/config.inc.php
  235. echo "##############################################################"
  236. echo "patch header.inc.php for including host name for using own AWS"
  237. echo "##############################################################"
  238. sed -i "225a \$awsconfig['base_url']\ =\ \"http://\" . ZCONFIG::\$AWS_HOST;" /srv/zotero/dataserver/include/header.inc.php
  239. echo "###############################################################################"
  240. echo "patch Storage.inc.php for using custom host name for generating base Upload URL"
  241. echo "###############################################################################"
  242. sed -i "s,\".s3.amazonaws.com/\",\ \".\" . Z_CONFIG::$AWS_HOST" /srv/zotero/dataserver/model/Storage.inc.php
  243. echo "#####################################"
  244. echo "patch AWS-SDK to use custom S3 server"
  245. echo "#####################################"
  246. sed -i "s,{service}.{region}.amazonaws.com,s3.drossenhausen.de.vu" /srv/zotero/dataserver/vendor/aws/aws-sdk-php/src/Aws/Common/Resources/public-endpoints.php
  247. echo "###############"
  248. echo "Configure runit"
  249. echo "###############"
  250. # because of damned debian split in three commands
  251. # mkdir -p /etc/sv/{zotero-download,zotero-error,zotero-upload}/log
  252. mkdir -p /etc/sv/zotero-download/log
  253. mkdir -p /etc/sv/zotero-error/log
  254. mkdir -p /etc/sv/zotero-upload/log
  255. echo "#!/bin/sh
  256. cd /srv/zotero/dataserver/processor/download
  257. exec 2>&1
  258. exec chpst -u www-data:www-data php5 daemon.php" > /etc/sv/zotero-download/run
  259. echo "#!/bin/sh
  260. cd /srv/zotero/dataserver/processor/error
  261. exec 2>&1
  262. exec chpst -u www-data:www-data php5 daemon.php" > /etc/sv/zotero-error/run
  263. echo "#!/bin/sh
  264. cd /srv/zotero/dataserver/processor/upload
  265. exec 2>&1
  266. exec chpst -u www-data:www-data php5 daemon.php" > /etc/sv/zotero-upload/run
  267. echo "#!/bin/sh
  268. exec svlogd /srv/zotero/log/download" > /etc/sv/zotero-download/log/run
  269. echo "#!/bin/sh
  270. exec svlogd /srv/zotero/log/error" > /etc/sv/zotero-error/log/run
  271. echo "#!/bin/sh
  272. exec svlogd /srv/zotero/log/upload" > /etc/sv/zotero-upload/log/run
  273. chmod +x /etc/sv/zotero-download/run
  274. chmod +x /etc/sv/zotero-error/run
  275. chmod +x /etc/sv/zotero-upload/run
  276. chmod +x /etc/sv/zotero-download/log/run
  277. chmod +x /etc/sv/zotero-error/log/run
  278. chmod +x /etc/sv/zotero-upload/log/run
  279. cd /etc/service
  280. ln -s ../sv/zotero-download /etc/service/
  281. ln -s ../sv/zotero-upload /etc/service/
  282. ln -s ../sv/zotero-error /etc/service/