freedombone-app-movim 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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='full full-vim social'
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=1
  33. MOVIM_DOMAIN_NAME=
  34. MOVIM_CODE=
  35. MOVIM_ONION_PORT=8117
  36. MOVIM_REPO="https://github.com/movim/movim"
  37. MOVIM_COMMIT='add1a247804eb0e34fc28a74c2eeea16792ffa8e'
  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. chown -R www-data:www-data /var/www/${MOVIM_DOMAIN_NAME}/htdocs
  146. }
  147. function backup_local_movim {
  148. MOVIM_DOMAIN_NAME='movim'
  149. if grep -q "movim domain" $COMPLETION_FILE; then
  150. MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
  151. fi
  152. source_directory=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
  153. if [ -d $source_directory ]; then
  154. dest_directory=movim
  155. function_check suspend_site
  156. suspend_site ${MOVIM_DOMAIN_NAME}
  157. function_check backup_directory_to_usb
  158. backup_directory_to_usb $source_directory $dest_directory
  159. function_check backup_database_to_usb
  160. backup_database_to_usb movim
  161. function_check restart_site
  162. restart_site
  163. fi
  164. }
  165. function restore_local_movim {
  166. if ! grep -q "movim domain" $COMPLETION_FILE; then
  167. return
  168. fi
  169. MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
  170. if [ $MOVIM_DOMAIN_NAME ]; then
  171. echo $"Restoring movim"
  172. temp_restore_dir=/root/tempmovim
  173. movim_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
  174. # stop the daemons
  175. cd $movim_dir
  176. su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
  177. function_check movim_create_database
  178. movim_create_database
  179. restore_database movim ${MOVIM_DOMAIN_NAME}
  180. if [ -d $temp_restore_dir ]; then
  181. rm -rf $temp_restore_dir
  182. fi
  183. echo $"Restore of movim complete"
  184. fi
  185. }
  186. function backup_remote_movim {
  187. if grep -q "movim domain" $COMPLETION_FILE; then
  188. MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
  189. temp_backup_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
  190. if [ -d $temp_backup_dir ]; then
  191. function_check suspend_site
  192. suspend_site ${MOVIM_DOMAIN_NAME}
  193. function_check backup_database_to_friend
  194. backup_database_to_friend movim
  195. function_check backup_directory_to_friend
  196. backup_directory_to_friend $temp_backup_dir movim
  197. function_check restart_site
  198. restart_site
  199. else
  200. echo $"movim domain specified but not found in ${temp_backup_dir}"
  201. fi
  202. fi
  203. }
  204. function restore_remote_movim {
  205. if grep -q "movim domain" $COMPLETION_FILE; then
  206. echo $"Restoring movim"
  207. MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
  208. # stop the daemons
  209. cd /var/www/${MOVIM_DOMAIN_NAME}/htdocs
  210. su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
  211. function_check movim_create_database
  212. movim_create_database
  213. function_check restore_database_from_friend
  214. restore_database_from_friend movim ${MOVIM_DOMAIN_NAME}
  215. if [ -d /root/tempmovim ]; then
  216. rm -rf /root/tempmovim
  217. fi
  218. echo $"Restore of movim complete"
  219. fi
  220. }
  221. function remove_movim {
  222. if [[ $(app_is_installed movim) == "0" ]]; then
  223. return
  224. fi
  225. read_config_param "MOVIM_DOMAIN_NAME"
  226. if [ ${#MOVIM_DOMAIN_NAME} -eq 0 ]; then
  227. return
  228. fi
  229. systemctl stop movim
  230. systemctl disable movim
  231. rm /etc/systemd/system/movim.service
  232. read_config_param "MY_USERNAME"
  233. echo "Removing $MOVIM_DOMAIN_NAME"
  234. nginx_dissite $MOVIM_DOMAIN_NAME
  235. remove_certs $MOVIM_DOMAIN_NAME
  236. if [ -d /var/www/$MOVIM_DOMAIN_NAME ]; then
  237. rm -rf /var/www/$MOVIM_DOMAIN_NAME
  238. fi
  239. if [ -f /etc/nginx/sites-available/$MOVIM_DOMAIN_NAME ]; then
  240. rm /etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
  241. fi
  242. function_check drop_database
  243. drop_database movim
  244. function_check remove_onion_service
  245. remove_onion_service movim ${MOVIM_ONION_PORT}
  246. if grep -q "movim" /etc/crontab; then
  247. sed -i "/movim/d" /etc/crontab
  248. fi
  249. remove_app movim
  250. remove_completion_param install_movim
  251. sed -i '/movim/d' $COMPLETION_FILE
  252. remove_backup_database_local movim
  253. function_check remove_ddns_domain
  254. remove_ddns_domain $MOVIM_DOMAIN_NAME
  255. }
  256. function install_movim {
  257. if [ ! $MOVIM_DOMAIN_NAME ]; then
  258. echo $'No domain name was given for movim'
  259. exit 72572
  260. fi
  261. if [[ $(app_is_installed xmpp) == "0" ]]; then
  262. return
  263. fi
  264. movim_hourly_script movim $MOVIM_DOMAIN_NAME
  265. function_check install_mariadb
  266. install_mariadb
  267. function_check get_mariadb_password
  268. get_mariadb_password
  269. function_check repair_databases_script
  270. repair_databases_script
  271. apt-get -yq install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
  272. apt-get -yq install php5-memcached php5-intl exiftool php5-imagick
  273. if [ ! -d /var/www/$MOVIM_DOMAIN_NAME ]; then
  274. mkdir /var/www/$MOVIM_DOMAIN_NAME
  275. fi
  276. if [ ! -d /var/www/$MOVIM_DOMAIN_NAME/htdocs ]; then
  277. function_check git_clone
  278. git_clone $MOVIM_REPO /var/www/$MOVIM_DOMAIN_NAME/htdocs
  279. if [ ! -d /var/www/$MOVIM_DOMAIN_NAME/htdocs ]; then
  280. echo $'Unable to clone movim repo'
  281. exit 76285
  282. fi
  283. fi
  284. cd /var/www/$MOVIM_DOMAIN_NAME/htdocs
  285. git checkout $MOVIM_COMMIT -b $MOVIM_COMMIT
  286. set_completion_param "movim commit" "$MOVIM_COMMIT"
  287. # default login
  288. if [ ! -f /var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php ]; then
  289. echo $'Unable to find Config.php'
  290. exit 72352
  291. fi
  292. sed -i "s|'admin'|'${MY_USERNAME}'|g" /var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php
  293. sed -i "s|'password'|'${MOVIM_ADMIN_PASSWORD}'|g" /var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php
  294. # curl -sS https://getcomposer.org/installer | php
  295. if [ -f ~/freedombone/image_build/composer_install ]; then
  296. cat ~/freedombone/image_build/composer_install | php
  297. else
  298. if [ -f /home/$MY_USERNAME/freedombone/image_build/composer_install ]; then
  299. cat /home/$MY_USERNAME/freedombone/image_build/composer_install | php
  300. fi
  301. fi
  302. php composer.phar install
  303. cd /var/www/$MOVIM_DOMAIN_NAME/htdocs/config
  304. cp db.example.inc.php db.inc.php
  305. sed -i "s|'username'.*|'username' => 'root',|g" db.inc.php
  306. sed -i "s|'password'.*|'password' => '$MARIADB_PASSWORD',|g" db.inc.php
  307. sed -i "s|'database'.*|'database' => 'movim'|g" db.inc.php
  308. php mud.php db --set
  309. chmod u+rwx /var/www/$MOVIM_DOMAIN_NAME/htdocs
  310. chown -R www-data:www-data /var/www/$MOVIM_DOMAIN_NAME/htdocs
  311. function_check movim_create_database
  312. movim_create_database
  313. function_check add_ddns_domain
  314. add_ddns_domain $MOVIM_DOMAIN_NAME
  315. MOVIM_ONION_HOSTNAME=$(add_onion_service movim 80 ${MOVIM_ONION_PORT})
  316. echo '[Unit]' > /etc/systemd/system/movim.service
  317. echo 'Description=Movim daemon' >> /etc/systemd/system/movim.service
  318. echo 'After=network.target nginx.target' >> /etc/systemd/system/movim.service
  319. echo '' >> /etc/systemd/system/movim.service
  320. echo '[Service]' >> /etc/systemd/system/movim.service
  321. echo 'Type=simple' >> /etc/systemd/system/movim.service
  322. echo 'User=www-data' >> /etc/systemd/system/movim.service
  323. echo "WorkingDirectory=/var/www/$MOVIM_DOMAIN_NAME/htdocs" >> /etc/systemd/system/movim.service
  324. if [[ $ONION_ONLY == 'no' ]]; then
  325. 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
  326. else
  327. 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
  328. fi
  329. echo 'StandardOutput=syslog' >> /etc/systemd/system/movim.service
  330. echo 'SyslogIdentifier=movim' >> /etc/systemd/system/movim.service
  331. echo 'PIDFile=/run/movim.pid' >> /etc/systemd/system/movim.service
  332. echo 'Restart=on-failure' >> /etc/systemd/system/movim.service
  333. echo 'RestartSec=10' >> /etc/systemd/system/movim.service
  334. echo '' >> /etc/systemd/system/movim.service
  335. echo '[Install]' >> /etc/systemd/system/movim.service
  336. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/movim.service
  337. systemctl enable movim
  338. systemctl daemon-reload
  339. movim_nginx_site=/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
  340. if [[ $ONION_ONLY == "no" ]]; then
  341. function_check nginx_http_redirect
  342. nginx_http_redirect $MOVIM_DOMAIN_NAME "index index.php"
  343. echo 'server {' >> $movim_nginx_site
  344. echo ' listen 443 ssl;' >> $movim_nginx_site
  345. echo ' listen [::]:443 ssl;' >> $movim_nginx_site
  346. echo " server_name $MOVIM_DOMAIN_NAME;" >> $movim_nginx_site
  347. echo '' >> $movim_nginx_site
  348. function_check nginx_compress
  349. nginx_compress $MOVIM_DOMAIN_NAME
  350. echo '' >> $movim_nginx_site
  351. echo ' # Security' >> $movim_nginx_site
  352. function_check nginx_ssl
  353. nginx_ssl $MOVIM_DOMAIN_NAME
  354. function_check nginx_disable_sniffing
  355. nginx_disable_sniffing $MOVIM_DOMAIN_NAME
  356. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $movim_nginx_site
  357. echo '' >> $movim_nginx_site
  358. echo ' # Logs' >> $movim_nginx_site
  359. echo ' access_log /dev/null;' >> $movim_nginx_site
  360. echo ' error_log /dev/null;' >> $movim_nginx_site
  361. echo '' >> $movim_nginx_site
  362. echo ' # Root' >> $movim_nginx_site
  363. echo " root /var/www/$MOVIM_DOMAIN_NAME/htdocs;" >> $movim_nginx_site
  364. echo '' >> $movim_nginx_site
  365. echo ' # Index' >> $movim_nginx_site
  366. echo ' index index.php;' >> $movim_nginx_site
  367. echo '' >> $movim_nginx_site
  368. echo ' # PHP' >> $movim_nginx_site
  369. echo ' location ~ \.php {' >> $movim_nginx_site
  370. echo ' include snippets/fastcgi-php.conf;' >> $movim_nginx_site
  371. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $movim_nginx_site
  372. echo ' }' >> $movim_nginx_site
  373. echo '' >> $movim_nginx_site
  374. echo ' # Location' >> $movim_nginx_site
  375. echo ' location / {' >> $movim_nginx_site
  376. function_check nginx_limits
  377. nginx_limits $MOVIM_DOMAIN_NAME '15m'
  378. echo ' try_files $uri $uri/ @movim;' >> $movim_nginx_site
  379. echo ' }' >> $movim_nginx_site
  380. echo '' >> $movim_nginx_site
  381. echo ' location /ws/ {' >> $movim_nginx_site
  382. echo " proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;" >> $movim_nginx_site
  383. echo ' proxy_http_version 1.1;' >> $movim_nginx_site
  384. echo ' proxy_set_header Upgrade $http_upgrade;' >> $movim_nginx_site
  385. echo ' proxy_set_header Connection "Upgrade";' >> $movim_nginx_site
  386. echo ' proxy_set_header Host $host;' >> $movim_nginx_site
  387. echo ' proxy_set_header X-Real-IP $remote_addr;' >> $movim_nginx_site
  388. echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $movim_nginx_site
  389. echo ' proxy_set_header X-Forwarded-Proto https;' >> $movim_nginx_site
  390. echo ' proxy_redirect off;' >> $movim_nginx_site
  391. echo ' }' >> $movim_nginx_site
  392. echo '' >> $movim_nginx_site
  393. echo ' # Fancy URLs' >> $movim_nginx_site
  394. echo ' location @movim {' >> $movim_nginx_site
  395. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $movim_nginx_site
  396. echo ' }' >> $movim_nginx_site
  397. echo '' >> $movim_nginx_site
  398. echo ' # Restrict access that is unnecessary anyway' >> $movim_nginx_site
  399. echo ' location ~ /\.(ht|git) {' >> $movim_nginx_site
  400. echo ' deny all;' >> $movim_nginx_site
  401. echo ' }' >> $movim_nginx_site
  402. echo '' >> $movim_nginx_site
  403. echo '}' >> $movim_nginx_site
  404. else
  405. echo -n '' > $movim_nginx_site
  406. fi
  407. echo 'server {' >> $movim_nginx_site
  408. echo " listen 127.0.0.1:$MOVIM_ONION_PORT default_server;" >> $movim_nginx_site
  409. echo " server_name $MOVIM_DOMAIN_NAME;" >> $movim_nginx_site
  410. echo '' >> $movim_nginx_site
  411. function_check nginx_compress
  412. nginx_compress $MOVIM_DOMAIN_NAME
  413. echo '' >> $movim_nginx_site
  414. function_check nginx_disable_sniffing
  415. nginx_disable_sniffing $MOVIM_DOMAIN_NAME
  416. echo '' >> $movim_nginx_site
  417. echo ' # Logs' >> $movim_nginx_site
  418. echo ' access_log /dev/null;' >> $movim_nginx_site
  419. echo ' error_log /dev/null;' >> $movim_nginx_site
  420. echo '' >> $movim_nginx_site
  421. echo ' # Root' >> $movim_nginx_site
  422. echo " root /var/www/$MOVIM_DOMAIN_NAME/htdocs;" >> $movim_nginx_site
  423. echo '' >> $movim_nginx_site
  424. echo ' # Index' >> $movim_nginx_site
  425. echo ' index index.php;' >> $movim_nginx_site
  426. echo '' >> $movim_nginx_site
  427. echo ' # PHP' >> $movim_nginx_site
  428. echo ' location ~ \.php {' >> $movim_nginx_site
  429. echo ' include snippets/fastcgi-php.conf;' >> $movim_nginx_site
  430. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $movim_nginx_site
  431. echo ' }' >> $movim_nginx_site
  432. echo '' >> $movim_nginx_site
  433. echo ' # Location' >> $movim_nginx_site
  434. echo ' location / {' >> $movim_nginx_site
  435. function_check nginx_limits
  436. nginx_limits $MOVIM_DOMAIN_NAME '15m'
  437. echo ' try_files $uri $uri/ @movim;' >> $movim_nginx_site
  438. echo ' }' >> $movim_nginx_site
  439. echo '' >> $movim_nginx_site
  440. echo ' location /ws/ {' >> $movim_nginx_site
  441. echo " proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;" >> $movim_nginx_site
  442. echo ' proxy_http_version 1.1;' >> $movim_nginx_site
  443. echo ' proxy_set_header Upgrade $http_upgrade;' >> $movim_nginx_site
  444. echo ' proxy_set_header Connection "Upgrade";' >> $movim_nginx_site
  445. echo ' proxy_set_header Host $host;' >> $movim_nginx_site
  446. echo ' proxy_set_header X-Real-IP $remote_addr;' >> $movim_nginx_site
  447. echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $movim_nginx_site
  448. echo ' proxy_set_header X-Forwarded-Proto https;' >> $movim_nginx_site
  449. echo ' proxy_redirect off;' >> $movim_nginx_site
  450. echo ' }' >> $movim_nginx_site
  451. echo '' >> $movim_nginx_site
  452. echo ' # Fancy URLs' >> $movim_nginx_site
  453. echo ' location @movim {' >> $movim_nginx_site
  454. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $movim_nginx_site
  455. echo ' }' >> $movim_nginx_site
  456. echo '' >> $movim_nginx_site
  457. echo ' # Restrict access that is unnecessary anyway' >> $movim_nginx_site
  458. echo ' location ~ /\.(ht|git) {' >> $movim_nginx_site
  459. echo ' deny all;' >> $movim_nginx_site
  460. echo ' }' >> $movim_nginx_site
  461. echo '' >> $movim_nginx_site
  462. echo '}' >> $movim_nginx_site
  463. function_check configure_php
  464. configure_php
  465. function_check create_site_certificate
  466. create_site_certificate $MOVIM_DOMAIN_NAME 'yes'
  467. # Ensure that the database gets backed up locally, if remote
  468. # backups are not being used
  469. function_check backup_databases_script_header
  470. backup_databases_script_header
  471. function_check backup_database_local
  472. backup_database_local movim
  473. function_check nginx_ensite
  474. nginx_ensite $MOVIM_DOMAIN_NAME
  475. ${PROJECT_NAME}-pass -u $MY_USERNAME -a movim -p "$MOVIM_ADMIN_PASSWORD"
  476. set_completion_param "movim domain" "$MOVIM_DOMAIN_NAME"
  477. systemctl start movim
  478. systemctl restart php5-fpm
  479. systemctl restart nginx
  480. APP_INSTALLED=1
  481. }
  482. # NOTE: deliberately there is no "exit 0"