freedombone-app-etherpad 22KB

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