freedombone-app-movim 20KB

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