freedombone/src/freedombone-app-etherpad

647 lines
28 KiB
Plaintext
Raw Normal View History

2016-11-04 15:09:53 +01:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Etherpad app
#
# License
# =======
#
# Copyright (C) 2016 Bob Mottram <bob@freedombone.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
VARIANTS="full full-vim writer"
IN_DEFAULT_INSTALL=1
SHOW_ON_ABOUT=1
ETHERPAD_DOMAIN_NAME=
ETHERPAD_CODE=
ETHERPAD_ONION_PORT=8101
ETHERPAD_REPO="https://github.com/ether/etherpad-lite"
ETHERPAD_COMMIT='223127bf39d2ba431d9c1965a7f2aadadc73d77a'
ETHERPAD_ADMIN_PASSWORD=
ETHERPAD_TITLE=$'Freedombone Docs'
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!"
etherpad_variables=(ETHERPAD_COMMIT
ONION_ONLY
DEFAULT_DOMAIN_NAME
ETHERPAD_DOMAIN_NAME
ETHERPAD_CODE
ETHERPAD_TITLE
ETHERPAD_WELCOME_MESSAGE
DDNS_PROVIDER
MY_USERNAME)
2016-11-04 15:24:28 +01:00
function get_mariadb_etherpad_admin_password {
if [ -f /home/$MY_USERNAME/README ]; then
if grep -q "MariaDB etherpad admin password" /home/$MY_USERNAME/README; then
ETHERPAD_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "MariaDB etherpad admin password" | awk -F ':' '{print $2}' | sed 's/^ *//')
fi
if grep -q "etherpad administrator password" /home/$MY_USERNAME/README; then
ETHERPAD_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "etherpad administrator password" | awk -F ':' '{print $2}' | sed 's/^ *//')
fi
fi
}
function etherpad_create_database {
function_check get_mariadb_etherpad_admin_password
get_mariadb_etherpad_admin_password
if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then
if [ -f $IMAGE_PASSWORD_FILE ]; then
ETHERPAD_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
else
ETHERPAD_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
fi
fi
if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then
return
fi
function_check create_database
create_database etherpad "$ETHERPAD_ADMIN_PASSWORD" $MY_USERNAME
}
2016-11-04 15:09:53 +01:00
function create_etherpad_settings {
echo '{' > /var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json
echo " \"title\": \"${ETHERPAD_TITLE}\"," >> /var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json
echo ' "favicon": "favicon.ico",' >> /var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json
echo ' "ip": "0.0.0.0",' >> /var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json
echo ' "port" : 9001,' >> /var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json
echo ' "showSettingsInAdminPage" : true,' >> /var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json
if [[ $ONION_ONLY == 'no' ]]; then
echo ' "ssl" : {' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo " \"key\" : \"/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key\"," >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo " \"cert\" : \"/etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem\"," >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' },' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
fi
echo ' "dbType" : "mysql",' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "dbSettings" : {' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "user" : "root",' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "host" : "localhost",' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo " \"password\": \"${MARIADB_PASSWORD}\"," >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "database": "etherpad",' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "charset" : "utf8mb4"' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' },' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo " \"defaultPadText\" : \"${ETHERPAD_WELCOME_MESSAGE}\"," >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "padOptions": {' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "noColors": false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "showControls": true,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "showChat": true,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "showLineNumbers": true,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "useMonospaceFont": false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "userName": false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "userColor": false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "rtl": false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "alwaysShowChat": false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "chatAndUsers": false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "lang": "en-gb"' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' },' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "suppressErrorsInPadText" : true,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "requireSession" : false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "editOnly" : false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "sessionNoPassword" : false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "minify" : true,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "maxAge" : 21600, // 60 * 60 * 6 = 6 hours' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "abiword" : null,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "soffice" : null,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "tidyHtml" : null,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "allowUnknownFileEnds" : false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "requireAuthentication" : true,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "requireAuthorization" : true,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "trustProxy" : false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "disableIPlogging" : true,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "users": {' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo " \"${MY_USERNAME}\": {" >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo " \"password\": \"${ETHERPAD_ADMIN_PASSWORD}\"," >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "is_admin": true' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' }' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' },' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "socketTransportProtocols" : ["xhr-polling", "jsonp-polling", "htmlfile"],' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "loadTest": false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "indentationOnNewLine": false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "toolbar": {' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "left": [' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' ["bold", "italic", "underline", "strikethrough"],' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' ["orderedlist", "unorderedlist", "indent", "outdent"],' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' ["undo", "redo"],' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' ["clearauthorship"]' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' ],' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "right": [' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' ["importexport", "timeslider", "savedrevision"],' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' ["settings", "embed"],' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' ["showusers"]' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' ],' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "timeslider": [' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' ["timeslider_export", "timeslider_returnToPad"]' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' ]' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' },' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "loglevel": "INFO",' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "logconfig" :' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' { "appenders": [' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' { "type": "console"' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' //, "category": "access"// only logs pad access' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' }' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' , { "type": "logLevelFilter"' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' , "level": "error" // filters out all log messages that have a lower level than "error"' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' , "appender":' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' { "type": "smtp"' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' , "subject": "[Admin] An error occured in your Etherpad instance!"' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo " , \"recipients\": \"admin@${DEFAULT_DOMAIN_NAME}\"" >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' , "sendInterval": 300 // 60 * 5 = 5 minutes -- will buffer log messages; set to 0 to send a mail for every message' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' , "transport": "SMTP", "SMTP": { // see https://github.com/andris9/Nodemailer#possible-transport-methods' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "host": "localhost", "port": 25,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' "secureConnection": false,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' }' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' }' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' ]' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo ' }' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
echo '}' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
}
function remove_user_etherpad {
remove_username="$1"
read_config_param ETHERPAD_DOMAIN_NAME
if ! grep -q "\"${remove_username}\": {" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json; then
sed -i "/\"${remove_username}\": {/,/},/d" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
fi
}
function add_user_etherpad {
new_username="$1"
new_user_password="$2"
read_config_param ETHERPAD_DOMAIN_NAME
if ! grep -q "\"${new_username}\": {" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json; then
sed -i "/\"users\": {/a \"${new_username}\": {
\"password\": \"${new_user_password}\",
\"is_admin\": false
}," /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
fi
}
function install_interactive_etherpad {
if [ ! $ONION_ONLY ]; then
ONION_ONLY='no'
fi
if [[ $ONION_ONLY != "no" ]]; then
ETHERPAD_DOMAIN_NAME='etherpad.local'
write_config_param "ETHERPAD_DOMAIN_NAME" "$ETHERPAD_DOMAIN_NAME"
else
function_check interactive_site_details
interactive_site_details "etherpad" "ETHERPAD_DOMAIN_NAME" "ETHERPAD_CODE"
fi
APP_INSTALLED=1
}
function etherpad_set_title {
read_config_param "ETHERPAD_TITLE"
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --title $"Etherpad Title" \
--backtitle $"Freedombone Control Panel" \
--inputbox $'Set a title for your etherpad system' 10 60 "$ETHERPAD_TITLE" 2>$data
sel=$?
case $sel in
0)
temp_title=$(<$data)
if [ ${#temp_title} -gt 0 ]; then
ETHERPAD_TITLE="$temp_title"
settings_file=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json
write_config_param "ETHERPAD_TITLE" "$ETHERPAD_TITLE"
sed -i "s|\"title\":.*|\"title\": \"${ETHERPAD_TITLE}\"|g" $settings_file
dialog --title $"Etherpad Title" \
--msgbox $"Title has been set" 6 60
fi
;;
esac
}
function etherpad_set_welcome_message {
read_config_param "ETHERPAD_WELCOME_MESSAGE"
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --title $"Etherpad Welcome Message" \
--backtitle $"Freedombone Control Panel" \
--inputbox $'Set a welcome message, which can include html formatting' 10 60 "$ETHERPAD_WELCOME_MESSAGE" 2>$data
sel=$?
case $sel in
0)
temp_welcome=$(<$data)
if [ ${#temp_welcome} -gt 0 ]; then
ETHERPAD_WELCOME_MESSAGE="$temp_welcome"
settings_file=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json
write_config_param "ETHERPAD_WELCOME_MESSAGE" "$ETHERPAD_WELCOME_MESSAGE"
sed -i "s|\"defaultPadText\" :.*|\"defaultPadText\" : \"${ETHERPAD_WELCOME_MESSAGE}\"|g" $settings_file
dialog --title $"Etherpad Welcome Message" \
--msgbox $"Welcome message has been set" 6 60
fi
;;
esac
}
function configure_interactive_etherpad {
while true
do
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title $"Etherpad Settings" \
--radiolist $"Choose an operation:" 12 70 3 \
1 $"Set Title" off \
2 $"Set a welcome message" off \
3 $"Exit" on 2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
case $(cat $data) in
1) etherpad_set_title;;
2) etherpad_set_welcome_message;;
3) break;;
esac
done
}
function reconfigure_etherpad {
create_etherpad_settings
systemctl restart etherpad
}
function upgrade_etherpad {
read_config_param "ETHERPAD_DOMAIN_NAME"
function_check set_repo_commit
set_repo_commit /var/www/$ETHERPAD_DOMAIN_NAME/htdocs "etherpad commit" "$ETHERPAD_COMMIT" $ETHERPAD_REPO
}
function backup_local_etherpad {
ETHERPAD_DOMAIN_NAME='etherpad'
if grep -q "etherpad domain" $COMPLETION_FILE; then
ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
fi
source_directory=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
if [ -d $source_directory ]; then
dest_directory=etherpad
function_check suspend_site
suspend_site ${ETHERPAD_DOMAIN_NAME}
function_check backup_directory_to_usb
backup_directory_to_usb $source_directory $dest_directory
function_check backup_database_to_usb
backup_database_to_usb etherpad
function_check restart_site
restart_site
fi
}
function restore_local_etherpad {
if ! grep -q "etherpad domain" $COMPLETION_FILE; then
return
fi
ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
if [ $ETHERPAD_DOMAIN_NAME ]; then
temp_restore_dir=/root/tempetherpad
etherpad_dir=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
function_check etherpad_create_database
etherpad_create_database
restore_database etherpad ${ETHERPAD_DOMAIN_NAME}
if [ -d $temp_restore_dir ]; then
rm -rf $temp_restore_dir
fi
chown -R etherpad: /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
if [ -f /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem ]; then
chown etherpad: /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem
fi
if [ -f /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key ]; then
chown etherpad: /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key
fi
fi
}
function backup_remote_etherpad {
if grep -q "etherpad domain" $COMPLETION_FILE; then
ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
temp_backup_dir=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
if [ -d $temp_backup_dir ]; then
function_check suspend_site
suspend_site ${ETHERPAD_DOMAIN_NAME}
function_check backup_database_to_friend
backup_database_to_friend etherpad
function_check backup_directory_to_friend
backup_directory_to_friend $temp_backup_dir etherpad
function_check restart_site
restart_site
else
echo $"etherpad domain specified but not found in ${temp_backup_dir}"
fi
fi
}
function restore_remote_etherpad {
if grep -q "etherpad domain" $COMPLETION_FILE; then
ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
function_check etherpad_create_database
etherpad_create_database
function_check restore_database_from_friend
restore_database_from_friend etherpad ${ETHERPAD_DOMAIN_NAME}
if [ -d /root/tempetherpad ]; then
rm -rf /root/tempetherpad
fi
chown -R etherpad: /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
if [ -f /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem ]; then
chown etherpad: /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem
fi
if [ -f /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key ]; then
chown etherpad: /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key
fi
fi
}
function remove_etherpad {
if [ ${#ETHERPAD_DOMAIN_NAME} -eq 0 ]; then
return
fi
read_config_param "ETHERPAD_DOMAIN_NAME"
read_config_param "MY_USERNAME"
echo "Removing $ETHERPAD_DOMAIN_NAME"
if [ -f /etc/systemd/system/etherpad.service ]; then
systemctl stop etherpad
systemctl disable etherpad
rm /etc/systemd/system/etherpad.service
fi
nginx_dissite $ETHERPAD_DOMAIN_NAME
remove_certs $ETHERPAD_DOMAIN_NAME
if [ -d /var/www/$ETHERPAD_DOMAIN_NAME ]; then
rm -rf /var/www/$ETHERPAD_DOMAIN_NAME
fi
if [ -f /etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME ]; then
rm /etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME
fi
function_check drop_database
drop_database etherpad
function_check remove_onion_service
remove_onion_service etherpad ${ETHERPAD_ONION_PORT}
remove_app etherpad
remove_completion_param install_etherpad
sed -i '/etherpad/d' $COMPLETION_FILE
sed -i '/Etherpad/d' /home/$MY_USERNAME/README
remove_backup_database_local etherpad
deluser --remove-all-files etherpad
remove_nodejs etherpad
}
function install_etherpad {
if [ ! $ETHERPAD_DOMAIN_NAME ]; then
echo $'No domain name was given for etherpad'
exit 7359
fi
function_check install_mariadb
install_mariadb
function_check get_mariadb_password
get_mariadb_password
function_check repair_databases_script
repair_databases_script
apt-get -yq install gzip git curl python libssl-dev pkg-config \
build-essential python g++ make checkinstall
function_check install_nodejs
install_nodejs etherpad
if [ ! -d /var/www/$ETHERPAD_DOMAIN_NAME ]; then
mkdir /var/www/$ETHERPAD_DOMAIN_NAME
fi
if [ ! -d /var/www/$ETHERPAD_DOMAIN_NAME/htdocs ]; then
function_check git_clone
git_clone $ETHERPAD_REPO /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
if [ ! -d /var/www/$ETHERPAD_DOMAIN_NAME/htdocs ]; then
echo $'Unable to clone etherpad repo'
exit 56382
fi
fi
cd /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
git checkout $ETHERPAD_COMMIT -b $ETHERPAD_COMMIT
set_completion_param "etherpad commit" "$ETHERPAD_COMMIT"
chmod a+w /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
chown www-data:www-data /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
function_check etherpad_create_database
etherpad_create_database
function_check add_ddns_domain
add_ddns_domain $ETHERPAD_DOMAIN_NAME
if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then
if [ -f $IMAGE_PASSWORD_FILE ]; then
ETHERPAD_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
else
ETHERPAD_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
fi
fi
create_etherpad_settings
adduser --system --home=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/ --group etherpad
chown -R etherpad: /var/www/$ETHERPAD_DOMAIN_NAME/htdocs/
echo '[Unit]' > /etc/systemd/system/etherpad.service
echo 'Description=etherpad-lite (real-time collaborative document editing)' >> /etc/systemd/system/etherpad.service
echo 'After=syslog.target network.target' >> /etc/systemd/system/etherpad.service
echo '' >> /etc/systemd/system/etherpad.service
echo '[Service]' >> /etc/systemd/system/etherpad.service
echo 'Type=simple' >> /etc/systemd/system/etherpad.service
echo 'User=etherpad-lite' >> /etc/systemd/system/etherpad.service
echo 'Group=etherpad-lite' >> /etc/systemd/system/etherpad.service
echo "ExecStart=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs//bin/run.sh" >> /etc/systemd/system/etherpad.service
echo '' >> /etc/systemd/system/etherpad.service
echo '[Install]' >> /etc/systemd/system/etherpad.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/etherpad.service
chmod +x /etc/systemd/system/etherpad.service
etherpad_nginx_site=/etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME
if [[ $ONION_ONLY == "no" ]]; then
function_check nginx_http_redirect
nginx_http_redirect $ETHERPAD_DOMAIN_NAME
echo 'server {' >> $etherpad_nginx_site
echo ' listen 443 ssl;' >> $etherpad_nginx_site
echo " server_name $ETHERPAD_DOMAIN_NAME;" >> $etherpad_nginx_site
echo '' >> $etherpad_nginx_site
echo ' # Security' >> $etherpad_nginx_site
function_check nginx_ssl
nginx_ssl $ETHERPAD_DOMAIN_NAME
function_check nginx_disable_sniffing
nginx_disable_sniffing $ETHERPAD_DOMAIN_NAME
echo ' add_header Strict-Transport-Security max-age=15768000;' >> $etherpad_nginx_site
echo '' >> $etherpad_nginx_site
echo ' # Logs' >> $etherpad_nginx_site
echo ' access_log off;' >> $etherpad_nginx_site
echo ' error_log off;' >> $etherpad_nginx_site
echo '' >> $etherpad_nginx_site
echo ' # Root' >> $etherpad_nginx_site
echo " root /var/www/$ETHERPAD_DOMAIN_NAME/htdocs;" >> $etherpad_nginx_site
echo '' >> $etherpad_nginx_site
echo ' location / {' >> $etherpad_nginx_site
function_check nginx_limits
nginx_limits $ETHERPAD_DOMAIN_NAME '15m'
echo ' proxy_pass http://localhost:9001/;' >> $etherpad_nginx_site
echo ' proxy_set_header Host $host;' >> $etherpad_nginx_site
echo ' proxy_buffering off;' >> $etherpad_nginx_site
echo ' }' >> $etherpad_nginx_site
echo '}' >> $etherpad_nginx_site
else
echo -n '' > $etherpad_nginx_site
fi
echo 'server {' >> $etherpad_nginx_site
echo " listen 127.0.0.1:$ETHERPAD_ONION_PORT default_server;" >> $etherpad_nginx_site
echo " server_name $ETHERPAD_DOMAIN_NAME;" >> $etherpad_nginx_site
echo '' >> $etherpad_nginx_site
function_check nginx_disable_sniffing
nginx_disable_sniffing $ETHERPAD_DOMAIN_NAME
echo '' >> $etherpad_nginx_site
echo ' # Logs' >> $etherpad_nginx_site
echo ' access_log off;' >> $etherpad_nginx_site
echo ' error_log off;' >> $etherpad_nginx_site
echo '' >> $etherpad_nginx_site
echo ' # Root' >> $etherpad_nginx_site
echo " root /var/www/$ETHERPAD_DOMAIN_NAME/htdocs;" >> $etherpad_nginx_site
echo '' >> $etherpad_nginx_site
echo ' location / {' >> $etherpad_nginx_site
function_check nginx_limits
nginx_limits $ETHERPAD_DOMAIN_NAME '15m'
echo ' proxy_pass http://localhost:9001/;' >> $etherpad_nginx_site
echo ' proxy_set_header Host $host;' >> $etherpad_nginx_site
echo ' proxy_buffering off;' >> $etherpad_nginx_site
echo ' }' >> $etherpad_nginx_site
echo '}' >> $etherpad_nginx_site
function_check create_site_certificate
create_site_certificate $ETHERPAD_DOMAIN_NAME 'yes'
if [ -f /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.crt ]; then
mv /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.crt /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem
fi
if [ -f /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem ]; then
chown etherpad: /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem
fi
if [ -f /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key ]; then
chown etherpad: /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key
fi
# Ensure that the database gets backed up locally, if remote
# backups are not being used
function_check backup_databases_script_header
backup_databases_script_header
function_check backup_database_local
backup_database_local etherpad
function_check nginx_ensite
nginx_ensite $ETHERPAD_DOMAIN_NAME
ETHERPAD_ONION_HOSTNAME=$(add_onion_service etherpad 80 ${ETHERPAD_ONION_PORT})
# some post-install instructions for the user
if ! grep -q $"Etherpad administrator" /home/$MY_USERNAME/README; then
echo '' >> /home/$MY_USERNAME/README
echo $'# Etherpad' >> /home/$MY_USERNAME/README
echo $"Etherpad administrator nickname: $MY_USERNAME" >> /home/$MY_USERNAME/README
echo $"Etherpad administrator password: $ETHERPAD_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
chmod 600 /home/$MY_USERNAME/README
else
if [ -f /home/$MY_USERNAME/README ]; then
sed -i "s|Etherpad administrator password.*|Etherpad administrator password: $ETHERPAD_ADMIN_PASSWORD|g" /home/$MY_USERNAME/README
fi
fi
if ! grep -q "Etherpad onion domain" /home/$MY_USERNAME/README; then
echo $"Etherpad onion domain: ${ETHERPAD_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
echo '' >> /home/$MY_USERNAME/README
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
chmod 600 /home/$MY_USERNAME/README
else
if [ -f /home/$MY_USERNAME/README ]; then
sed -i "s|Etherpad onion domain.*|Etherpad onion domain: ${ETHERPAD_ONION_HOSTNAME}|g" /home/$MY_USERNAME/README
fi
fi
set_completion_param "etherpad domain" "$ETHERPAD_DOMAIN_NAME"
systemctl enable etherpad
systemctl daemon-reload
systemctl start etherpad
systemctl restart nginx
APP_INSTALLED=1
}