freedombone-app-movim 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # movim application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. VARIANTS=''
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=0
  33. MOVIM_DOMAIN_NAME=
  34. MOVIM_CODE=
  35. MOVIM_ONION_PORT=8117
  36. MOVIM_REPO="https://github.com/movim/movim"
  37. MOVIM_COMMIT='6142c2033b7695448516a67690324a3bde048260'
  38. MOVIM_ADMIN_PASSWORD=
  39. MOVIM_DAEMON_PORT=8880
  40. movim_variables=(ONION_ONLY
  41. MOVIM_DOMAIN_NAME
  42. MOVIM_CODE
  43. DDNS_PROVIDER
  44. MY_USERNAME)
  45. function logging_on_movim {
  46. echo -n ''
  47. }
  48. function logging_off_movim {
  49. echo -n ''
  50. }
  51. function remove_user_movim {
  52. remove_username="$1"
  53. ${PROJECT_NAME}-pass -u $remove_username --rmapp movim
  54. }
  55. function add_user_movim {
  56. new_username="$1"
  57. new_user_password="$2"
  58. ${PROJECT_NAME}-pass -u $new_username -a movim -p "$new_user_password"
  59. echo '0'
  60. }
  61. function install_interactive_movim {
  62. if [ ! $ONION_ONLY ]; then
  63. ONION_ONLY='no'
  64. fi
  65. if [[ $ONION_ONLY != "no" ]]; then
  66. MOVIM_DOMAIN_NAME='movim.local'
  67. else
  68. MOVIM_DETAILS_COMPLETE=
  69. while [ ! $MOVIM_DETAILS_COMPLETE ]
  70. do
  71. data=$(tempfile 2>/dev/null)
  72. trap "rm -f $data" 0 1 2 5 15
  73. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  74. dialog --backtitle $"Freedombone Configuration" \
  75. --title $"Movim Configuration" \
  76. --form $"\nPlease enter your Movim details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 12 65 2 \
  77. $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  78. $"Code:" 2 1 "$(grep 'MOVIM_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
  79. 2> $data
  80. else
  81. dialog --backtitle $"Freedombone Configuration" \
  82. --title $"Movim Configuration" \
  83. --form $"\nPlease enter your Movim details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 12 65 2 \
  84. $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  85. 2> $data
  86. fi
  87. sel=$?
  88. case $sel in
  89. 1) exit 1;;
  90. 255) exit 1;;
  91. esac
  92. MOVIM_DOMAIN_NAME=$(cat $data | sed -n 1p)
  93. if [ $MOVIM_DOMAIN_NAME ]; then
  94. TEST_DOMAIN_NAME=$MOVIM_DOMAIN_NAME
  95. validate_domain_name
  96. if [[ $TEST_DOMAIN_NAME != $MOVIM_DOMAIN_NAME ]]; then
  97. MOVIM_DOMAIN_NAME=
  98. dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
  99. else
  100. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  101. MOVIM_CODE=$(cat $data | sed -n 2p)
  102. validate_freedns_code "$MOVIM_CODE"
  103. if [ ! $VALID_CODE ]; then
  104. MOVIM_DOMAIN_NAME=
  105. fi
  106. fi
  107. fi
  108. fi
  109. if [ $MOVIM_DOMAIN_NAME ]; then
  110. MOVIM_DETAILS_COMPLETE="yes"
  111. fi
  112. done
  113. # save the results in the config file
  114. write_config_param "MOVIM_CODE" "$MOVIM_CODE"
  115. fi
  116. write_config_param "MOVIM_DOMAIN_NAME" "$MOVIM_DOMAIN_NAME"
  117. APP_INSTALLED=1
  118. }
  119. function change_password_movim {
  120. curr_username="$1"
  121. new_user_password="$2"
  122. read_config_param 'MOVIM_DOMAIN_NAME'
  123. ${PROJECT_NAME}-pass -u "$curr_username" -a movim -p "$new_user_password"
  124. }
  125. function movim_create_database {
  126. if [ -f $IMAGE_PASSWORD_FILE ]; then
  127. MOVIM_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  128. else
  129. if [ ! $MOVIM_ADMIN_PASSWORD ]; then
  130. MOVIM_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  131. fi
  132. fi
  133. if [ ! $MOVIM_ADMIN_PASSWORD ]; then
  134. return
  135. fi
  136. function_check create_database
  137. create_database movim "$MOVIM_ADMIN_PASSWORD" $MY_USERNAME
  138. }
  139. function reconfigure_movim {
  140. echo -n ''
  141. }
  142. function upgrade_movim {
  143. CURR_MOVIM_COMMIT=$(get_completion_param "movim commit")
  144. if [[ "$CURR_MOVIM_COMMIT" == "$MOVIM_COMMIT" ]]; then
  145. return
  146. fi
  147. if grep -q "movim domain" $COMPLETION_FILE; then
  148. MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
  149. fi
  150. # update to the next commit
  151. function_check set_repo_commit
  152. set_repo_commit /var/www/$MOVIM_DOMAIN_NAME/htdocs "movim commit" "$MOVIM_COMMIT" $MOVIM_REPO
  153. cd /var/www/${MOVIM_DOMAIN_NAME}/htdocs
  154. php composer.phar install
  155. php mud.php db --set
  156. chown -R www-data:www-data /var/www/${MOVIM_DOMAIN_NAME}/htdocs
  157. }
  158. function backup_local_movim {
  159. MOVIM_DOMAIN_NAME='movim'
  160. if grep -q "movim domain" $COMPLETION_FILE; then
  161. MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
  162. fi
  163. source_directory=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
  164. if [ -d $source_directory ]; then
  165. dest_directory=movim
  166. function_check suspend_site
  167. suspend_site ${MOVIM_DOMAIN_NAME}
  168. function_check backup_directory_to_usb
  169. backup_directory_to_usb $source_directory $dest_directory
  170. function_check backup_database_to_usb
  171. backup_database_to_usb movim
  172. function_check restart_site
  173. restart_site
  174. fi
  175. }
  176. function restore_local_movim {
  177. if ! grep -q "movim domain" $COMPLETION_FILE; then
  178. return
  179. fi
  180. MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
  181. if [ $MOVIM_DOMAIN_NAME ]; then
  182. echo $"Restoring movim"
  183. temp_restore_dir=/root/tempmovim
  184. movim_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
  185. # stop the daemons
  186. cd $movim_dir
  187. su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
  188. function_check movim_create_database
  189. movim_create_database
  190. restore_database movim ${MOVIM_DOMAIN_NAME}
  191. if [ -d $temp_restore_dir ]; then
  192. rm -rf $temp_restore_dir
  193. fi
  194. MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
  195. cd /var/www/$MOVIM_DOMAIN_NAME/htdocs/config
  196. sed -i "s|'password'.*|'password' => '$MARIADB_PASSWORD',|g" db.inc.php
  197. MARIADB_PASSWORD=
  198. echo $"Restore of movim complete"
  199. fi
  200. }
  201. function backup_remote_movim {
  202. if grep -q "movim domain" $COMPLETION_FILE; then
  203. MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
  204. temp_backup_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
  205. if [ -d $temp_backup_dir ]; then
  206. function_check suspend_site
  207. suspend_site ${MOVIM_DOMAIN_NAME}
  208. function_check backup_database_to_friend
  209. backup_database_to_friend movim
  210. function_check backup_directory_to_friend
  211. backup_directory_to_friend $temp_backup_dir movim
  212. function_check restart_site
  213. restart_site
  214. else
  215. echo $"movim domain specified but not found in ${temp_backup_dir}"
  216. fi
  217. fi
  218. }
  219. function restore_remote_movim {
  220. if grep -q "movim domain" $COMPLETION_FILE; then
  221. echo $"Restoring movim"
  222. MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
  223. # stop the daemons
  224. cd /var/www/${MOVIM_DOMAIN_NAME}/htdocs
  225. su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
  226. function_check movim_create_database
  227. movim_create_database
  228. function_check restore_database_from_friend
  229. restore_database_from_friend movim ${MOVIM_DOMAIN_NAME}
  230. if [ -d /root/tempmovim ]; then
  231. rm -rf /root/tempmovim
  232. fi
  233. MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
  234. cd /var/www/$MOVIM_DOMAIN_NAME/htdocs/config
  235. sed -i "s|'password'.*|'password' => '$MARIADB_PASSWORD',|g" db.inc.php
  236. MARIADB_PASSWORD=
  237. echo $"Restore of movim complete"
  238. fi
  239. }
  240. function remove_movim {
  241. if [[ $(app_is_installed movim) == "0" ]]; then
  242. return
  243. fi
  244. read_config_param "MOVIM_DOMAIN_NAME"
  245. if [ ${#MOVIM_DOMAIN_NAME} -eq 0 ]; then
  246. return
  247. fi
  248. systemctl stop movim
  249. systemctl disable movim
  250. rm /etc/systemd/system/movim.service
  251. systemctl daemon-reload
  252. read_config_param "MY_USERNAME"
  253. echo "Removing $MOVIM_DOMAIN_NAME"
  254. nginx_dissite $MOVIM_DOMAIN_NAME
  255. remove_certs $MOVIM_DOMAIN_NAME
  256. if [ -d /var/www/$MOVIM_DOMAIN_NAME ]; then
  257. rm -rf /var/www/$MOVIM_DOMAIN_NAME
  258. fi
  259. if [ -f /etc/nginx/sites-available/$MOVIM_DOMAIN_NAME ]; then
  260. rm /etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
  261. fi
  262. function_check drop_database
  263. drop_database movim
  264. function_check remove_onion_service
  265. remove_onion_service movim ${MOVIM_ONION_PORT}
  266. if grep -q "movim" /etc/crontab; then
  267. sed -i "/movim/d" /etc/crontab
  268. fi
  269. remove_app movim
  270. remove_completion_param install_movim
  271. sed -i '/movim/d' $COMPLETION_FILE
  272. remove_backup_database_local movim
  273. function_check remove_ddns_domain
  274. remove_ddns_domain $MOVIM_DOMAIN_NAME
  275. }
  276. function install_movim {
  277. if [ ! $MOVIM_DOMAIN_NAME ]; then
  278. echo $'No domain name was given for movim'
  279. exit 72572
  280. fi
  281. if [[ $(app_is_installed xmpp) == "0" ]]; then
  282. return
  283. fi
  284. movim_hourly_script movim $MOVIM_DOMAIN_NAME
  285. function_check install_mariadb
  286. install_mariadb
  287. function_check get_mariadb_password
  288. get_mariadb_password
  289. function_check repair_databases_script
  290. repair_databases_script
  291. apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
  292. apt-get -yq install php-memcached php-intl exiftool php-imagick libfcgi0ldbl
  293. if [ ! -d /var/www/$MOVIM_DOMAIN_NAME ]; then
  294. mkdir /var/www/$MOVIM_DOMAIN_NAME
  295. fi
  296. if [ ! -d /var/www/$MOVIM_DOMAIN_NAME/htdocs ]; then
  297. if [ -d /repos/movim ]; then
  298. mkdir /var/www/$MOVIM_DOMAIN_NAME/htdocs
  299. cp -r -p /repos/movim/. /var/www/$MOVIM_DOMAIN_NAME/htdocs
  300. cd /var/www/$MOVIM_DOMAIN_NAME/htdocs
  301. git pull
  302. else
  303. function_check git_clone
  304. git_clone $MOVIM_REPO /var/www/$MOVIM_DOMAIN_NAME/htdocs
  305. fi
  306. if [ ! -d /var/www/$MOVIM_DOMAIN_NAME/htdocs ]; then
  307. echo $'Unable to clone movim repo'
  308. exit 76285
  309. fi
  310. fi
  311. cd /var/www/$MOVIM_DOMAIN_NAME/htdocs
  312. git checkout $MOVIM_COMMIT -b $MOVIM_COMMIT
  313. set_completion_param "movim commit" "$MOVIM_COMMIT"
  314. # default login
  315. if [ ! -f /var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php ]; then
  316. echo $'Unable to find Config.php'
  317. exit 72352
  318. fi
  319. sed -i "s|'admin'|'${MY_USERNAME}'|g" /var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php
  320. sed -i "s|'password'|'${MOVIM_ADMIN_PASSWORD}'|g" /var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php
  321. # Fix typo
  322. sed -i 's|weksocket|websocket|g' app/widgets/AdminTest/admintest.js
  323. # curl -sS https://getcomposer.org/installer | php
  324. if [ -f ~/freedombone/image_build/composer_install ]; then
  325. cat ~/freedombone/image_build/composer_install | php
  326. else
  327. if [ -f /home/$MY_USERNAME/freedombone/image_build/composer_install ]; then
  328. cat /home/$MY_USERNAME/freedombone/image_build/composer_install | php
  329. fi
  330. fi
  331. php composer.phar install
  332. cd /var/www/$MOVIM_DOMAIN_NAME/htdocs/config
  333. cp db.example.inc.php db.inc.php
  334. sed -i "s|'username'.*|'username' => 'root',|g" db.inc.php
  335. sed -i "s|'password'.*|'password' => '$MARIADB_PASSWORD',|g" db.inc.php
  336. sed -i "s|'database'.*|'database' => 'movim'|g" db.inc.php
  337. php mud.php db --set
  338. chmod u+rwx /var/www/$MOVIM_DOMAIN_NAME/htdocs
  339. chown -R www-data:www-data /var/www/$MOVIM_DOMAIN_NAME/htdocs
  340. function_check movim_create_database
  341. movim_create_database
  342. function_check add_ddns_domain
  343. add_ddns_domain $MOVIM_DOMAIN_NAME
  344. MOVIM_ONION_HOSTNAME=$(add_onion_service movim 80 ${MOVIM_ONION_PORT})
  345. echo '[Unit]' > /etc/systemd/system/movim.service
  346. echo 'Description=Movim daemon' >> /etc/systemd/system/movim.service
  347. echo 'After=network.target nginx.target' >> /etc/systemd/system/movim.service
  348. echo '' >> /etc/systemd/system/movim.service
  349. echo '[Service]' >> /etc/systemd/system/movim.service
  350. echo 'Type=simple' >> /etc/systemd/system/movim.service
  351. echo 'User=www-data' >> /etc/systemd/system/movim.service
  352. echo "WorkingDirectory=/var/www/$MOVIM_DOMAIN_NAME/htdocs" >> /etc/systemd/system/movim.service
  353. if [[ $ONION_ONLY == 'no' ]]; then
  354. echo "ExecStart=/usr/bin/php /var/www/$MOVIM_DOMAIN_NAME/htdocs/daemon.php start --url=https://$MOVIM_DOMAIN_NAME --port=$MOVIM_DAEMON_PORT" >> /etc/systemd/system/movim.service
  355. else
  356. echo "ExecStart=/usr/bin/php /var/www/$MOVIM_DOMAIN_NAME/htdocs/daemon.php start --url=http://$MOVIM_ONION_HOSTNAME --port=$MOVIM_DAEMON_PORT" >> /etc/systemd/system/movim.service
  357. fi
  358. echo 'StandardOutput=syslog' >> /etc/systemd/system/movim.service
  359. echo 'SyslogIdentifier=movim' >> /etc/systemd/system/movim.service
  360. echo 'PIDFile=/run/movim.pid' >> /etc/systemd/system/movim.service
  361. echo 'Restart=on-failure' >> /etc/systemd/system/movim.service
  362. echo 'RestartSec=10' >> /etc/systemd/system/movim.service
  363. echo '' >> /etc/systemd/system/movim.service
  364. echo '[Install]' >> /etc/systemd/system/movim.service
  365. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/movim.service
  366. systemctl enable movim
  367. systemctl daemon-reload
  368. movim_nginx_site=/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
  369. if [[ $ONION_ONLY == "no" ]]; then
  370. function_check nginx_http_redirect
  371. nginx_http_redirect $MOVIM_DOMAIN_NAME "index index.php"
  372. echo 'server {' >> $movim_nginx_site
  373. echo ' listen 443 ssl;' >> $movim_nginx_site
  374. echo ' listen [::]:443 ssl;' >> $movim_nginx_site
  375. echo " server_name $MOVIM_DOMAIN_NAME;" >> $movim_nginx_site
  376. echo '' >> $movim_nginx_site
  377. function_check nginx_compress
  378. nginx_compress $MOVIM_DOMAIN_NAME
  379. echo '' >> $movim_nginx_site
  380. echo ' # Security' >> $movim_nginx_site
  381. function_check nginx_ssl
  382. nginx_ssl $MOVIM_DOMAIN_NAME
  383. function_check nginx_disable_sniffing
  384. nginx_disable_sniffing $MOVIM_DOMAIN_NAME
  385. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $movim_nginx_site
  386. echo '' >> $movim_nginx_site
  387. echo ' # Logs' >> $movim_nginx_site
  388. echo ' access_log /dev/null;' >> $movim_nginx_site
  389. echo ' error_log /dev/null;' >> $movim_nginx_site
  390. echo '' >> $movim_nginx_site
  391. echo ' # Root' >> $movim_nginx_site
  392. echo " root /var/www/$MOVIM_DOMAIN_NAME/htdocs;" >> $movim_nginx_site
  393. echo '' >> $movim_nginx_site
  394. echo ' # Index' >> $movim_nginx_site
  395. echo ' index index.php;' >> $movim_nginx_site
  396. echo '' >> $movim_nginx_site
  397. echo ' # PHP' >> $movim_nginx_site
  398. echo ' location ~ \.php {' >> $movim_nginx_site
  399. echo ' include snippets/fastcgi-php.conf;' >> $movim_nginx_site
  400. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $movim_nginx_site
  401. echo ' fastcgi_read_timeout 30;' >> $movim_nginx_site
  402. echo ' }' >> $movim_nginx_site
  403. echo '' >> $movim_nginx_site
  404. echo ' # Location' >> $movim_nginx_site
  405. echo ' location / {' >> $movim_nginx_site
  406. function_check nginx_limits
  407. nginx_limits $MOVIM_DOMAIN_NAME '15m'
  408. echo ' try_files $uri $uri/ @movim;' >> $movim_nginx_site
  409. echo ' }' >> $movim_nginx_site
  410. echo '' >> $movim_nginx_site
  411. echo ' location /ws/ {' >> $movim_nginx_site
  412. echo " proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;" >> $movim_nginx_site
  413. echo ' proxy_http_version 1.1;' >> $movim_nginx_site
  414. echo ' proxy_set_header Upgrade $http_upgrade;' >> $movim_nginx_site
  415. echo ' proxy_set_header Connection "Upgrade";' >> $movim_nginx_site
  416. echo ' proxy_set_header Host $host;' >> $movim_nginx_site
  417. echo ' proxy_set_header X-Real-IP $remote_addr;' >> $movim_nginx_site
  418. echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $movim_nginx_site
  419. echo ' proxy_set_header X-Forwarded-Proto https;' >> $movim_nginx_site
  420. echo ' proxy_redirect off;' >> $movim_nginx_site
  421. echo ' }' >> $movim_nginx_site
  422. echo '' >> $movim_nginx_site
  423. echo ' # Fancy URLs' >> $movim_nginx_site
  424. echo ' location @movim {' >> $movim_nginx_site
  425. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $movim_nginx_site
  426. echo ' }' >> $movim_nginx_site
  427. echo '' >> $movim_nginx_site
  428. echo ' # Restrict access that is unnecessary anyway' >> $movim_nginx_site
  429. echo ' location ~ /\.(ht|git) {' >> $movim_nginx_site
  430. echo ' deny all;' >> $movim_nginx_site
  431. echo ' }' >> $movim_nginx_site
  432. echo '' >> $movim_nginx_site
  433. echo '}' >> $movim_nginx_site
  434. else
  435. echo -n '' > $movim_nginx_site
  436. fi
  437. echo 'server {' >> $movim_nginx_site
  438. echo " listen 127.0.0.1:$MOVIM_ONION_PORT default_server;" >> $movim_nginx_site
  439. echo " server_name $MOVIM_DOMAIN_NAME;" >> $movim_nginx_site
  440. echo '' >> $movim_nginx_site
  441. function_check nginx_compress
  442. nginx_compress $MOVIM_DOMAIN_NAME
  443. echo '' >> $movim_nginx_site
  444. function_check nginx_disable_sniffing
  445. nginx_disable_sniffing $MOVIM_DOMAIN_NAME
  446. echo '' >> $movim_nginx_site
  447. echo ' # Logs' >> $movim_nginx_site
  448. echo ' access_log /dev/null;' >> $movim_nginx_site
  449. echo ' error_log /dev/null;' >> $movim_nginx_site
  450. echo '' >> $movim_nginx_site
  451. echo ' # Root' >> $movim_nginx_site
  452. echo " root /var/www/$MOVIM_DOMAIN_NAME/htdocs;" >> $movim_nginx_site
  453. echo '' >> $movim_nginx_site
  454. echo ' # Index' >> $movim_nginx_site
  455. echo ' index index.php;' >> $movim_nginx_site
  456. echo '' >> $movim_nginx_site
  457. echo ' # PHP' >> $movim_nginx_site
  458. echo ' location ~ \.php {' >> $movim_nginx_site
  459. echo ' include snippets/fastcgi-php.conf;' >> $movim_nginx_site
  460. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $movim_nginx_site
  461. echo ' fastcgi_read_timeout 30;' >> $movim_nginx_site
  462. echo ' }' >> $movim_nginx_site
  463. echo '' >> $movim_nginx_site
  464. echo ' # Location' >> $movim_nginx_site
  465. echo ' location / {' >> $movim_nginx_site
  466. function_check nginx_limits
  467. nginx_limits $MOVIM_DOMAIN_NAME '15m'
  468. echo ' try_files $uri $uri/ @movim;' >> $movim_nginx_site
  469. echo ' }' >> $movim_nginx_site
  470. echo '' >> $movim_nginx_site
  471. echo ' location /ws/ {' >> $movim_nginx_site
  472. echo " proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;" >> $movim_nginx_site
  473. echo ' proxy_http_version 1.1;' >> $movim_nginx_site
  474. echo ' proxy_set_header Upgrade $http_upgrade;' >> $movim_nginx_site
  475. echo ' proxy_set_header Connection "Upgrade";' >> $movim_nginx_site
  476. echo ' proxy_set_header Host $host;' >> $movim_nginx_site
  477. echo ' proxy_set_header X-Real-IP $remote_addr;' >> $movim_nginx_site
  478. echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $movim_nginx_site
  479. echo ' proxy_set_header X-Forwarded-Proto https;' >> $movim_nginx_site
  480. echo ' proxy_redirect off;' >> $movim_nginx_site
  481. echo ' }' >> $movim_nginx_site
  482. echo '' >> $movim_nginx_site
  483. echo ' # Fancy URLs' >> $movim_nginx_site
  484. echo ' location @movim {' >> $movim_nginx_site
  485. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $movim_nginx_site
  486. echo ' }' >> $movim_nginx_site
  487. echo '' >> $movim_nginx_site
  488. echo ' # Restrict access that is unnecessary anyway' >> $movim_nginx_site
  489. echo ' location ~ /\.(ht|git) {' >> $movim_nginx_site
  490. echo ' deny all;' >> $movim_nginx_site
  491. echo ' }' >> $movim_nginx_site
  492. echo '' >> $movim_nginx_site
  493. echo '}' >> $movim_nginx_site
  494. function_check configure_php
  495. configure_php
  496. function_check create_site_certificate
  497. create_site_certificate $MOVIM_DOMAIN_NAME 'yes'
  498. # Ensure that the database gets backed up locally, if remote
  499. # backups are not being used
  500. function_check backup_databases_script_header
  501. backup_databases_script_header
  502. function_check backup_database_local
  503. backup_database_local movim
  504. function_check nginx_ensite
  505. nginx_ensite $MOVIM_DOMAIN_NAME
  506. ${PROJECT_NAME}-pass -u $MY_USERNAME -a movim -p "$MOVIM_ADMIN_PASSWORD"
  507. set_completion_param "movim domain" "$MOVIM_DOMAIN_NAME"
  508. systemctl restart mariadb
  509. systemctl start movim
  510. systemctl restart php7.0-fpm
  511. systemctl restart nginx
  512. APP_INSTALLED=1
  513. }
  514. # NOTE: deliberately there is no "exit 0"