freedombone-app-etherpad 22KB

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