freedombone-app-etherpad 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Etherpad app
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2016 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 writer"
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=1
  33. ETHERPAD_DOMAIN_NAME=
  34. ETHERPAD_CODE=
  35. ETHERPAD_ONION_PORT=8101
  36. ETHERPAD_PORT=9001
  37. ETHERPAD_REPO="https://github.com/ether/etherpad-lite"
  38. ETHERPAD_COMMIT='223127bf39d2ba431d9c1965a7f2aadadc73d77a'
  39. ETHERPAD_ADMIN_PASSWORD=
  40. ETHERPAD_TITLE=$'Freedombone Docs'
  41. ETHERPAD_WELCOME_MESSAGE=$"Welcome to ${ETHERPAD_TITLE}!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!"
  42. etherpad_variables=(ONION_ONLY
  43. DEFAULT_DOMAIN_NAME
  44. ETHERPAD_DOMAIN_NAME
  45. ETHERPAD_CODE
  46. ETHERPAD_TITLE
  47. ETHERPAD_WELCOME_MESSAGE
  48. DDNS_PROVIDER
  49. MY_USERNAME)
  50. function etherpad_password_hash {
  51. echo $(python -c "from passlib.hash import bcrypt;print(bcrypt.encrypt(\"$1\", rounds=10))")
  52. }
  53. function change_password_etherpad {
  54. change_username="$1"
  55. new_user_password=$(etherpad_password_hash "$2")
  56. read_config_param ETHERPAD_DOMAIN_NAME
  57. if grep "\"$change_username\": {" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json; then
  58. user_line=$(cat /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json | grep "\"$change_username\": {")
  59. if [[ "$user_line" == *"\"is_admin\": true"* ]]; then
  60. sed -i "s|\"$change_username\": {.*|\"$change_username\": { \"hash\": \"$new_user_password\", \"is_admin\": true }|g" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
  61. else
  62. sed -i "s|\"$change_username\": {.*|\"$change_username\": { \"hash\": \"$new_user_password\", \"is_admin\": false },|g" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
  63. fi
  64. ${PROJECT_NAME}-pass -u $change_username -a etherpad -p "$2"
  65. systemctl restart etherpad
  66. fi
  67. }
  68. function etherpad_create_database {
  69. if [ -f $IMAGE_PASSWORD_FILE ]; then
  70. ETHERPAD_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  71. else
  72. if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then
  73. ETHERPAD_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  74. fi
  75. fi
  76. if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then
  77. return
  78. fi
  79. function_check create_database
  80. create_database etherpad "$ETHERPAD_ADMIN_PASSWORD" $MY_USERNAME
  81. }
  82. function create_etherpad_settings {
  83. settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
  84. echo '{' > $settings_file
  85. echo " \"title\": \"${ETHERPAD_TITLE}\"," >> $settings_file
  86. echo ' "favicon": "favicon.ico",' >> $settings_file
  87. echo ' "ip": "0.0.0.0",' >> $settings_file
  88. echo " \"port\" : ${ETHERPAD_PORT}," >> $settings_file
  89. echo ' "showSettingsInAdminPage" : true,' >> $settings_file
  90. if [[ $ONION_ONLY == 'no' ]]; then
  91. echo ' "ssl" : {' >> $settings_file
  92. echo " \"key\" : \"/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key\"," >> $settings_file
  93. echo " \"cert\" : \"/etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem\"," >> $settings_file
  94. echo ' },' >> $settings_file
  95. fi
  96. echo ' "dbType" : "mysql",' >> $settings_file
  97. echo ' "dbSettings" : {' >> $settings_file
  98. echo ' "user" : "root",' >> $settings_file
  99. echo ' "host" : "localhost",' >> $settings_file
  100. echo " \"password\": \"${MARIADB_PASSWORD}\"," >> $settings_file
  101. echo ' "database": "etherpad",' >> $settings_file
  102. echo ' "charset" : "utf8mb4"' >> $settings_file
  103. echo ' },' >> $settings_file
  104. echo " \"defaultPadText\" : \"${ETHERPAD_WELCOME_MESSAGE}\"," >> $settings_file
  105. echo ' "padOptions": {' >> $settings_file
  106. echo ' "noColors": false,' >> $settings_file
  107. echo ' "showControls": true,' >> $settings_file
  108. echo ' "showChat": true,' >> $settings_file
  109. echo ' "showLineNumbers": false,' >> $settings_file
  110. echo ' "useMonospaceFont": false,' >> $settings_file
  111. echo ' "userName": false,' >> $settings_file
  112. echo ' "userColor": true,' >> $settings_file
  113. echo ' "rtl": false,' >> $settings_file
  114. echo ' "alwaysShowChat": true,' >> $settings_file
  115. echo ' "chatAndUsers": true,' >> $settings_file
  116. echo ' "lang": "en-gb"' >> $settings_file
  117. echo ' },' >> $settings_file
  118. echo ' "suppressErrorsInPadText" : true,' >> $settings_file
  119. echo ' "requireSession" : false,' >> $settings_file
  120. echo ' "editOnly" : false,' >> $settings_file
  121. echo ' "sessionNoPassword" : false,' >> $settings_file
  122. echo ' "minify" : true,' >> $settings_file
  123. echo ' "maxAge" : 21600, // 60 * 60 * 6 = 6 hours' >> $settings_file
  124. echo ' "abiword" : null,' >> $settings_file
  125. echo ' "soffice" : null,' >> $settings_file
  126. echo ' "tidyHtml" : null,' >> $settings_file
  127. echo ' "allowUnknownFileEnds" : false,' >> $settings_file
  128. echo ' "requireAuthentication" : true,' >> $settings_file
  129. echo ' "requireAuthorization" : true,' >> $settings_file
  130. echo ' "trustProxy" : false,' >> $settings_file
  131. echo ' "disableIPlogging" : true,' >> $settings_file
  132. echo ' "users": {' >> $settings_file
  133. echo " \"${MY_USERNAME}\": { \"hash\": \"$(etherpad_password_hash "${ETHERPAD_ADMIN_PASSWORD}")\", \"is_admin\": true }" >> $settings_file
  134. echo ' },' >> $settings_file
  135. echo ' "socketTransportProtocols" : ["xhr-polling", "jsonp-polling", "htmlfile"],' >> $settings_file
  136. echo ' "loadTest": false,' >> $settings_file
  137. echo ' "indentationOnNewLine": false,' >> $settings_file
  138. echo ' "toolbar": {' >> $settings_file
  139. echo ' "left": [' >> $settings_file
  140. echo ' ["bold", "italic", "underline", "strikethrough"],' >> $settings_file
  141. echo ' ["orderedlist", "unorderedlist", "indent", "outdent"],' >> $settings_file
  142. echo ' ["undo", "redo"],' >> $settings_file
  143. echo ' ["clearauthorship"]' >> $settings_file
  144. echo ' ],' >> $settings_file
  145. echo ' "right": [' >> $settings_file
  146. echo ' ["importexport", "timeslider", "savedrevision"],' >> $settings_file
  147. echo ' ["settings", "embed"],' >> $settings_file
  148. echo ' ["showusers"]' >> $settings_file
  149. echo ' ],' >> $settings_file
  150. echo ' "timeslider": [' >> $settings_file
  151. echo ' ["timeslider_export", "timeslider_returnToPad"]' >> $settings_file
  152. echo ' ]' >> $settings_file
  153. echo ' },' >> $settings_file
  154. echo ' "loglevel": "INFO"' >> $settings_file
  155. echo '}' >> $settings_file
  156. chmod 600 $settings_file
  157. }
  158. function remove_user_etherpad {
  159. remove_username="$1"
  160. settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
  161. ${PROJECT_NAME}-pass -u $remove_username --rmapp etherpad
  162. if grep -q "\"$remove_username\": {" $settings_file; then
  163. sed -i "/\"$remove_username\": {/d" $settings_file
  164. systemctl restart etherpad
  165. fi
  166. }
  167. function add_user_etherpad {
  168. new_username="$1"
  169. new_user_password=$(etherpad_password_hash "$2")
  170. settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
  171. if ! grep -q "\"$new_username\": {" $settings_file; then
  172. ${PROJECT_NAME}-pass -u $new_username -a etherpad -p "$2"
  173. sed -i "/\"users\": {/a \"$new_username\": { \"hash\": \"$new_user_password\", \"is_admin\": false }," $settings_file
  174. if grep -q "\"$new_username\": {" $settings_file; then
  175. systemctl restart etherpad
  176. else
  177. echo '1'
  178. return
  179. fi
  180. fi
  181. echo '0'
  182. }
  183. function install_interactive_etherpad {
  184. if [ ! $ONION_ONLY ]; then
  185. ONION_ONLY='no'
  186. fi
  187. if [[ $ONION_ONLY != "no" ]]; then
  188. ETHERPAD_DOMAIN_NAME='etherpad.local'
  189. write_config_param "ETHERPAD_DOMAIN_NAME" "$ETHERPAD_DOMAIN_NAME"
  190. else
  191. function_check interactive_site_details
  192. interactive_site_details "etherpad" "ETHERPAD_DOMAIN_NAME" "ETHERPAD_CODE"
  193. fi
  194. APP_INSTALLED=1
  195. }
  196. function etherpad_set_title {
  197. read_config_param "ETHERPAD_TITLE"
  198. data=$(tempfile 2>/dev/null)
  199. trap "rm -f $data" 0 1 2 5 15
  200. dialog --title $"Etherpad Title" \
  201. --backtitle $"Freedombone Control Panel" \
  202. --inputbox $'Set a title for your etherpad system' 10 60 "$ETHERPAD_TITLE" 2>$data
  203. sel=$?
  204. case $sel in
  205. 0)
  206. temp_title=$(<$data)
  207. if [ ${#temp_title} -gt 0 ]; then
  208. ETHERPAD_TITLE="$temp_title"
  209. settings_file=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json
  210. write_config_param "ETHERPAD_TITLE" "$ETHERPAD_TITLE"
  211. sed -i "s|\"title\":.*|\"title\": \"${ETHERPAD_TITLE}\"|g" $settings_file
  212. dialog --title $"Etherpad Title" \
  213. --msgbox $"Title has been set" 6 60
  214. fi
  215. ;;
  216. esac
  217. }
  218. function etherpad_set_welcome_message {
  219. read_config_param "ETHERPAD_WELCOME_MESSAGE"
  220. data=$(tempfile 2>/dev/null)
  221. trap "rm -f $data" 0 1 2 5 15
  222. dialog --title $"Etherpad Welcome Message" \
  223. --backtitle $"Freedombone Control Panel" \
  224. --inputbox $'Set a welcome message, which can include html formatting' 10 60 "$ETHERPAD_WELCOME_MESSAGE" 2>$data
  225. sel=$?
  226. case $sel in
  227. 0)
  228. temp_welcome=$(<$data)
  229. if [ ${#temp_welcome} -gt 0 ]; then
  230. ETHERPAD_WELCOME_MESSAGE="$temp_welcome"
  231. settings_file=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json
  232. write_config_param "ETHERPAD_WELCOME_MESSAGE" "$ETHERPAD_WELCOME_MESSAGE"
  233. sed -i "s|\"defaultPadText\" :.*|\"defaultPadText\" : \"${ETHERPAD_WELCOME_MESSAGE}\"|g" $settings_file
  234. dialog --title $"Etherpad Welcome Message" \
  235. --msgbox $"Welcome message has been set" 6 60
  236. fi
  237. ;;
  238. esac
  239. }
  240. function configure_interactive_etherpad {
  241. while true
  242. do
  243. data=$(tempfile 2>/dev/null)
  244. trap "rm -f $data" 0 1 2 5 15
  245. dialog --backtitle $"Freedombone Control Panel" \
  246. --title $"Etherpad Settings" \
  247. --radiolist $"Choose an operation:" 12 70 3 \
  248. 1 $"Set Title" off \
  249. 2 $"Set a welcome message" off \
  250. 3 $"Exit" on 2> $data
  251. sel=$?
  252. case $sel in
  253. 1) return;;
  254. 255) return;;
  255. esac
  256. case $(cat $data) in
  257. 1) etherpad_set_title;;
  258. 2) etherpad_set_welcome_message;;
  259. 3) break;;
  260. esac
  261. done
  262. }
  263. function reconfigure_etherpad {
  264. create_etherpad_settings
  265. systemctl restart etherpad
  266. }
  267. function upgrade_etherpad {
  268. read_config_param "ETHERPAD_DOMAIN_NAME"
  269. function_check set_repo_commit
  270. set_repo_commit /var/www/$ETHERPAD_DOMAIN_NAME/htdocs "etherpad commit" "$ETHERPAD_COMMIT" $ETHERPAD_REPO
  271. }
  272. function backup_local_etherpad {
  273. ETHERPAD_DOMAIN_NAME='etherpad'
  274. if grep -q "etherpad domain" $COMPLETION_FILE; then
  275. ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
  276. fi
  277. source_directory=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
  278. if [ -d $source_directory ]; then
  279. dest_directory=etherpad
  280. function_check suspend_site
  281. suspend_site ${ETHERPAD_DOMAIN_NAME}
  282. function_check backup_directory_to_usb
  283. backup_directory_to_usb $source_directory $dest_directory
  284. function_check backup_database_to_usb
  285. backup_database_to_usb etherpad
  286. function_check restart_site
  287. restart_site
  288. fi
  289. }
  290. function restore_local_etherpad {
  291. if ! grep -q "etherpad domain" $COMPLETION_FILE; then
  292. return
  293. fi
  294. ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
  295. if [ $ETHERPAD_DOMAIN_NAME ]; then
  296. temp_restore_dir=/root/tempetherpad
  297. etherpad_dir=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
  298. function_check etherpad_create_database
  299. etherpad_create_database
  300. restore_database etherpad ${ETHERPAD_DOMAIN_NAME}
  301. if [ -d $temp_restore_dir ]; then
  302. rm -rf $temp_restore_dir
  303. fi
  304. chown -R etherpad: /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
  305. if [ -f /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem ]; then
  306. chown etherpad: /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem
  307. fi
  308. if [ -f /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key ]; then
  309. chown etherpad: /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key
  310. fi
  311. fi
  312. }
  313. function backup_remote_etherpad {
  314. if grep -q "etherpad domain" $COMPLETION_FILE; then
  315. ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
  316. temp_backup_dir=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
  317. if [ -d $temp_backup_dir ]; then
  318. function_check suspend_site
  319. suspend_site ${ETHERPAD_DOMAIN_NAME}
  320. function_check backup_database_to_friend
  321. backup_database_to_friend etherpad
  322. function_check backup_directory_to_friend
  323. backup_directory_to_friend $temp_backup_dir etherpad
  324. function_check restart_site
  325. restart_site
  326. else
  327. echo $"etherpad domain specified but not found in ${temp_backup_dir}"
  328. fi
  329. fi
  330. }
  331. function restore_remote_etherpad {
  332. if grep -q "etherpad domain" $COMPLETION_FILE; then
  333. ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
  334. function_check etherpad_create_database
  335. etherpad_create_database
  336. function_check restore_database_from_friend
  337. restore_database_from_friend etherpad ${ETHERPAD_DOMAIN_NAME}
  338. if [ -d /root/tempetherpad ]; then
  339. rm -rf /root/tempetherpad
  340. fi
  341. chown -R etherpad: /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
  342. if [ -f /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem ]; then
  343. chown etherpad: /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem
  344. fi
  345. if [ -f /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key ]; then
  346. chown etherpad: /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key
  347. fi
  348. fi
  349. }
  350. function remove_etherpad {
  351. if [ ${#ETHERPAD_DOMAIN_NAME} -eq 0 ]; then
  352. return
  353. fi
  354. read_config_param "ETHERPAD_DOMAIN_NAME"
  355. read_config_param "MY_USERNAME"
  356. echo "Removing $ETHERPAD_DOMAIN_NAME"
  357. if [ -f /etc/systemd/system/etherpad.service ]; then
  358. systemctl stop etherpad
  359. systemctl disable etherpad
  360. rm /etc/systemd/system/etherpad.service
  361. fi
  362. systemctl daemon-reload
  363. nginx_dissite $ETHERPAD_DOMAIN_NAME
  364. remove_certs $ETHERPAD_DOMAIN_NAME
  365. if [ -d /var/www/$ETHERPAD_DOMAIN_NAME ]; then
  366. rm -rf /var/www/$ETHERPAD_DOMAIN_NAME
  367. fi
  368. if [ -f /etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME ]; then
  369. rm /etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME
  370. fi
  371. function_check drop_database
  372. drop_database etherpad
  373. function_check remove_onion_service
  374. remove_onion_service etherpad ${ETHERPAD_ONION_PORT}
  375. remove_app etherpad
  376. remove_completion_param install_etherpad
  377. sed -i '/etherpad/d' $COMPLETION_FILE
  378. remove_backup_database_local etherpad
  379. remove_nodejs etherpad
  380. sync
  381. delgroup etherpad
  382. deluser --remove-all-files etherpad
  383. function_check remove_ddns_domain
  384. remove_ddns_domain $ETHERPAD_DOMAIN_NAME
  385. }
  386. function install_etherpad {
  387. if [ ! $ETHERPAD_DOMAIN_NAME ]; then
  388. echo $'No domain name was given for etherpad'
  389. exit 7359
  390. fi
  391. # Check the amount of RAM
  392. ram_available=$(grep MemTotal /proc/meminfo | awk '{print $2}')
  393. if [ $ram_available -lt 2000000 ]; then
  394. echo $'Need at least 2GB RAM to install etherpad'
  395. exit 783524
  396. fi
  397. if [ -f $IMAGE_PASSWORD_FILE ]; then
  398. ETHERPAD_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  399. else
  400. if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then
  401. ETHERPAD_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  402. fi
  403. fi
  404. function_check install_mariadb
  405. install_mariadb
  406. function_check get_mariadb_password
  407. get_mariadb_password
  408. function_check repair_databases_script
  409. repair_databases_script
  410. apt-get -yq install gzip git curl python libssl-dev pkg-config \
  411. build-essential python g++ make checkinstall \
  412. python-bcrypt python-passlib
  413. function_check install_nodejs
  414. install_nodejs etherpad
  415. if [ ! -d /var/www/$ETHERPAD_DOMAIN_NAME ]; then
  416. mkdir /var/www/$ETHERPAD_DOMAIN_NAME
  417. fi
  418. if [ ! -d /var/www/$ETHERPAD_DOMAIN_NAME/htdocs ]; then
  419. function_check git_clone
  420. git_clone $ETHERPAD_REPO /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
  421. if [ ! -d /var/www/$ETHERPAD_DOMAIN_NAME/htdocs ]; then
  422. echo $'Unable to clone etherpad repo'
  423. exit 56382
  424. fi
  425. fi
  426. cd /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
  427. git checkout $ETHERPAD_COMMIT -b $ETHERPAD_COMMIT
  428. set_completion_param "etherpad commit" "$ETHERPAD_COMMIT"
  429. chmod a+w /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
  430. chown www-data:www-data /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
  431. function_check etherpad_create_database
  432. etherpad_create_database
  433. function_check add_ddns_domain
  434. add_ddns_domain $ETHERPAD_DOMAIN_NAME
  435. create_etherpad_settings
  436. adduser --system --home=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/ --group etherpad
  437. chown -R etherpad: /var/www/$ETHERPAD_DOMAIN_NAME/htdocs/
  438. echo '[Unit]' > /etc/systemd/system/etherpad.service
  439. echo 'Description=etherpad-lite (real-time collaborative document editing)' >> /etc/systemd/system/etherpad.service
  440. echo 'After=syslog.target network.target' >> /etc/systemd/system/etherpad.service
  441. echo '' >> /etc/systemd/system/etherpad.service
  442. echo '[Service]' >> /etc/systemd/system/etherpad.service
  443. echo 'Type=simple' >> /etc/systemd/system/etherpad.service
  444. echo 'User=etherpad' >> /etc/systemd/system/etherpad.service
  445. echo 'Group=etherpad' >> /etc/systemd/system/etherpad.service
  446. echo "WorkingDirectory=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" >> /etc/systemd/system/etherpad.service
  447. echo "ExecStart=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/bin/run.sh" >> /etc/systemd/system/etherpad.service
  448. echo 'Restart=on-failure' >> /etc/systemd/system/etherpad.service
  449. echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/etherpad.service
  450. echo 'RestartForceExitStatus=3 4' >> /etc/systemd/system/etherpad.service
  451. echo '' >> /etc/systemd/system/etherpad.service
  452. echo '[Install]' >> /etc/systemd/system/etherpad.service
  453. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/etherpad.service
  454. chmod +x /etc/systemd/system/etherpad.service
  455. etherpad_nginx_site=/etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME
  456. if [[ $ONION_ONLY == "no" ]]; then
  457. function_check nginx_http_redirect
  458. nginx_http_redirect $ETHERPAD_DOMAIN_NAME
  459. echo 'server {' >> $etherpad_nginx_site
  460. echo ' listen 443 ssl;' >> $etherpad_nginx_site
  461. echo ' listen [::]:443 ssl;' >> $etherpad_nginx_site
  462. echo " server_name $ETHERPAD_DOMAIN_NAME;" >> $etherpad_nginx_site
  463. echo '' >> $etherpad_nginx_site
  464. echo ' # Security' >> $etherpad_nginx_site
  465. function_check nginx_ssl
  466. nginx_ssl $ETHERPAD_DOMAIN_NAME
  467. function_check nginx_disable_sniffing
  468. nginx_disable_sniffing $ETHERPAD_DOMAIN_NAME
  469. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $etherpad_nginx_site
  470. echo '' >> $etherpad_nginx_site
  471. echo ' # Logs' >> $etherpad_nginx_site
  472. echo ' access_log /dev/null;' >> $etherpad_nginx_site
  473. echo ' error_log /dev/null;' >> $etherpad_nginx_site
  474. echo '' >> $etherpad_nginx_site
  475. echo ' # Root' >> $etherpad_nginx_site
  476. echo " root /var/www/$ETHERPAD_DOMAIN_NAME/htdocs;" >> $etherpad_nginx_site
  477. echo '' >> $etherpad_nginx_site
  478. echo ' location / {' >> $etherpad_nginx_site
  479. function_check nginx_limits
  480. nginx_limits $ETHERPAD_DOMAIN_NAME '15m'
  481. echo " proxy_pass http://localhost:${ETHERPAD_PORT}/;" >> $etherpad_nginx_site
  482. echo ' proxy_set_header Host $host;' >> $etherpad_nginx_site
  483. echo ' proxy_buffering off;' >> $etherpad_nginx_site
  484. echo ' }' >> $etherpad_nginx_site
  485. echo '' >> $etherpad_nginx_site
  486. nginx_keybase $ETHERPAD_DOMAIN_NAME
  487. echo '}' >> $etherpad_nginx_site
  488. else
  489. echo -n '' > $etherpad_nginx_site
  490. fi
  491. echo 'server {' >> $etherpad_nginx_site
  492. echo " listen 127.0.0.1:$ETHERPAD_ONION_PORT default_server;" >> $etherpad_nginx_site
  493. echo " server_name $ETHERPAD_DOMAIN_NAME;" >> $etherpad_nginx_site
  494. echo '' >> $etherpad_nginx_site
  495. function_check nginx_disable_sniffing
  496. nginx_disable_sniffing $ETHERPAD_DOMAIN_NAME
  497. echo '' >> $etherpad_nginx_site
  498. echo ' # Logs' >> $etherpad_nginx_site
  499. echo ' access_log /dev/null;' >> $etherpad_nginx_site
  500. echo ' error_log /dev/null;' >> $etherpad_nginx_site
  501. echo '' >> $etherpad_nginx_site
  502. echo ' # Root' >> $etherpad_nginx_site
  503. echo " root /var/www/$ETHERPAD_DOMAIN_NAME/htdocs;" >> $etherpad_nginx_site
  504. echo '' >> $etherpad_nginx_site
  505. echo ' location / {' >> $etherpad_nginx_site
  506. function_check nginx_limits
  507. nginx_limits $ETHERPAD_DOMAIN_NAME '15m'
  508. echo " proxy_pass http://localhost:${ETHERPAD_PORT}/;" >> $etherpad_nginx_site
  509. echo ' proxy_set_header Host $host;' >> $etherpad_nginx_site
  510. echo ' proxy_buffering off;' >> $etherpad_nginx_site
  511. echo ' }' >> $etherpad_nginx_site
  512. echo '' >> $etherpad_nginx_site
  513. nginx_keybase $ETHERPAD_DOMAIN_NAME
  514. echo '}' >> $etherpad_nginx_site
  515. function_check create_site_certificate
  516. create_site_certificate $ETHERPAD_DOMAIN_NAME 'yes'
  517. if [ -f /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.crt ]; then
  518. mv /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.crt /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem
  519. fi
  520. if [ -f /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem ]; then
  521. chown etherpad: /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem
  522. fi
  523. if [ -f /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key ]; then
  524. chown etherpad: /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key
  525. fi
  526. # Ensure that the database gets backed up locally, if remote
  527. # backups are not being used
  528. function_check backup_databases_script_header
  529. backup_databases_script_header
  530. function_check backup_database_local
  531. backup_database_local etherpad
  532. function_check nginx_ensite
  533. nginx_ensite $ETHERPAD_DOMAIN_NAME
  534. ETHERPAD_ONION_HOSTNAME=$(add_onion_service etherpad 80 ${ETHERPAD_ONION_PORT})
  535. ${PROJECT_NAME}-pass -u $MY_USERNAME -a etherpad -p "$ETHERPAD_ADMIN_PASSWORD"
  536. function_check add_ddns_domain
  537. add_ddns_domain $ETHERPAD_DOMAIN_NAME
  538. set_completion_param "etherpad domain" "$ETHERPAD_DOMAIN_NAME"
  539. systemctl restart mariadb
  540. systemctl enable etherpad
  541. systemctl daemon-reload
  542. systemctl start etherpad
  543. systemctl restart nginx
  544. APP_INSTALLED=1
  545. }