freedombone-app-etherpad 24KB

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