freedombone-app-etherpad 25KB

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