freedombone-app-etherpad 22KB

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