freedombone-app-etherpad 22KB

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