freedombone-app-etherpad 24KB

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