From 5479d49dc9fc604d9b915520e8e9761aa62cb133 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 27 Feb 2018 14:11:56 +0000 Subject: [PATCH] More tidying --- src/freedombone-app-etherpad | 463 ++++++++++++++-------------- src/freedombone-app-fedwiki | 241 ++++++++------- src/freedombone-app-friendica | 498 +++++++++++++++--------------- src/freedombone-app-ghost | 380 +++++++++++------------ src/freedombone-app-gnusocial | 564 +++++++++++++++++----------------- src/freedombone-app-gogs | 435 +++++++++++++------------- src/freedombone-app-htmly | 545 ++++++++++++++++---------------- src/freedombone-app-hubzilla | 510 +++++++++++++++--------------- src/freedombone-app-icecast | 436 +++++++++++++------------- src/freedombone-app-ipfs | 284 ++++++++--------- src/freedombone-app-irc | 403 ++++++++++++------------ src/freedombone-app-jitsi | 167 +++++----- src/freedombone-app-kanboard | 391 ++++++++++++----------- src/freedombone-app-keyserver | 401 ++++++++++++------------ src/freedombone-app-koel | 493 ++++++++++++++--------------- src/freedombone-app-lychee | 368 +++++++++++----------- src/freedombone-app-mailpile | 172 +++++------ src/freedombone-app-matrix | 324 +++++++++---------- 18 files changed, 3558 insertions(+), 3517 deletions(-) diff --git a/src/freedombone-app-etherpad b/src/freedombone-app-etherpad index 3082e6fd..330de307 100755 --- a/src/freedombone-app-etherpad +++ b/src/freedombone-app-etherpad @@ -41,7 +41,7 @@ ETHERPAD_REPO="https://github.com/ether/etherpad-lite" ETHERPAD_COMMIT='454f539561a8d9de51ed107a29d974eb79198bc6' 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_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=(ONION_ONLY DEFAULT_DOMAIN_NAME @@ -67,109 +67,109 @@ function change_password_etherpad { read_config_param ETHERPAD_DOMAIN_NAME if grep -q "\"$change_username\": {" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json; then - user_line=$(cat /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json | grep "\"$change_username\": {") + user_line=$(grep "\"$change_username\": {" "/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json") if [[ "$user_line" == *"\"is_admin\": true"* ]]; then - sed -i "s|\"$change_username\": {.*|\"$change_username\": { \"password\": "$new_user_password", \"is_admin\": true }|g" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json + sed -i "s|\"$change_username\": {.*|\"$change_username\": { \"password\": \"$new_user_password\", \"is_admin\": true }|g" "/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json" else - sed -i "s|\"$change_username\": {.*|\"$change_username\": { \"password\": "$new_user_password", \"is_admin\": false },|g" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json + sed -i "s|\"$change_username\": {.*|\"$change_username\": { \"password\": \"$new_user_password\", \"is_admin\": false },|g" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json fi - ${PROJECT_NAME}-pass -u $change_username -a etherpad -p "$2" + "${PROJECT_NAME}-pass" -u "$change_username" -a etherpad -p "$2" systemctl restart etherpad fi } function etherpad_create_database { - if [ -f $IMAGE_PASSWORD_FILE ]; then - ETHERPAD_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)" + if [ -f "$IMAGE_PASSWORD_FILE" ]; then + ETHERPAD_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")" else - if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then - ETHERPAD_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})" + if [ ! "$ETHERPAD_ADMIN_PASSWORD" ]; then + ETHERPAD_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")" fi fi - if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then + if [ ! "$ETHERPAD_ADMIN_PASSWORD" ]; then return fi function_check create_database - create_database etherpad "$ETHERPAD_ADMIN_PASSWORD" $MY_USERNAME + create_database etherpad "$ETHERPAD_ADMIN_PASSWORD" "$MY_USERNAME" } function create_etherpad_settings { - settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json - echo '{' > $settings_file - echo " \"title\": \"${ETHERPAD_TITLE}\"," >> $settings_file - echo ' "favicon": "favicon.ico",' >> $settings_file + settings_file="/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json" + { echo '{'; + echo " \"title\": \"${ETHERPAD_TITLE}\","; + echo ' "favicon": "favicon.ico",'; - echo ' "ip": "127.0.0.1",' >> $settings_file - echo " \"port\" : ${ETHERPAD_PORT}," >> $settings_file + echo ' "ip": "127.0.0.1",'; + echo " \"port\" : ${ETHERPAD_PORT},"; - echo ' "showSettingsInAdminPage" : true,' >> $settings_file - echo ' "dbType" : "mysql",' >> $settings_file - echo ' "dbSettings" : {' >> $settings_file - echo ' "user" : "root",' >> $settings_file - echo ' "host" : "localhost",' >> $settings_file - echo " \"password\": \"${MARIADB_PASSWORD}\"," >> $settings_file - echo ' "database": "etherpad",' >> $settings_file - echo ' "charset" : "utf8mb4"' >> $settings_file - echo ' },' >> $settings_file + echo ' "showSettingsInAdminPage" : true,'; + echo ' "dbType" : "mysql",'; + echo ' "dbSettings" : {'; + echo ' "user" : "root",'; + echo ' "host" : "localhost",'; + echo " \"password\": \"${MARIADB_PASSWORD}\","; + echo ' "database": "etherpad",'; + echo ' "charset" : "utf8mb4"'; + echo ' },'; - echo " \"defaultPadText\" : \"${ETHERPAD_WELCOME_MESSAGE}\"," >> $settings_file + echo " \"defaultPadText\" : \"${ETHERPAD_WELCOME_MESSAGE}\","; - echo ' "padOptions": {' >> $settings_file - echo ' "noColors": false,' >> $settings_file - echo ' "showControls": true,' >> $settings_file - echo ' "showChat": true,' >> $settings_file - echo ' "showLineNumbers": false,' >> $settings_file - echo ' "useMonospaceFont": false,' >> $settings_file - echo ' "userName": false,' >> $settings_file - echo ' "userColor": true,' >> $settings_file - echo ' "rtl": false,' >> $settings_file - echo ' "alwaysShowChat": true,' >> $settings_file - echo ' "chatAndUsers": true,' >> $settings_file - echo ' "lang": "en-gb"' >> $settings_file - echo ' },' >> $settings_file + echo ' "padOptions": {'; + echo ' "noColors": false,'; + echo ' "showControls": true,'; + echo ' "showChat": true,'; + echo ' "showLineNumbers": false,'; + echo ' "useMonospaceFont": false,'; + echo ' "userName": false,'; + echo ' "userColor": true,'; + echo ' "rtl": false,'; + echo ' "alwaysShowChat": true,'; + echo ' "chatAndUsers": true,'; + echo ' "lang": "en-gb"'; + echo ' },'; - echo ' "suppressErrorsInPadText" : true,' >> $settings_file - echo ' "requireSession" : false,' >> $settings_file - echo ' "editOnly" : false,' >> $settings_file - echo ' "sessionNoPassword" : false,' >> $settings_file - echo ' "minify" : true,' >> $settings_file - echo ' "maxAge" : 21600, // 60 * 60 * 6 = 6 hours' >> $settings_file - echo ' "abiword" : null,' >> $settings_file - echo ' "soffice" : null,' >> $settings_file - echo ' "tidyHtml" : null,' >> $settings_file - echo ' "allowUnknownFileEnds" : false,' >> $settings_file - echo ' "requireAuthentication" : true,' >> $settings_file - echo ' "requireAuthorization" : true,' >> $settings_file - echo ' "trustProxy" : false,' >> $settings_file - echo ' "disableIPlogging" : true,' >> $settings_file + echo ' "suppressErrorsInPadText" : true,'; + echo ' "requireSession" : false,'; + echo ' "editOnly" : false,'; + echo ' "sessionNoPassword" : false,'; + echo ' "minify" : true,'; + echo ' "maxAge" : 21600, // 60 * 60 * 6 = 6 hours'; + echo ' "abiword" : null,'; + echo ' "soffice" : null,'; + echo ' "tidyHtml" : null,'; + echo ' "allowUnknownFileEnds" : false,'; + echo ' "requireAuthentication" : true,'; + echo ' "requireAuthorization" : true,'; + echo ' "trustProxy" : false,'; + echo ' "disableIPlogging" : true,'; - echo ' "users": {' >> $settings_file - echo " \"${MY_USERNAME}\": { \"password\": \"${ETHERPAD_ADMIN_PASSWORD}\", \"is_admin\": true }" >> $settings_file - echo ' },' >> $settings_file + echo ' "users": {'; + echo " \"${MY_USERNAME}\": { \"password\": \"${ETHERPAD_ADMIN_PASSWORD}\", \"is_admin\": true }"; + echo ' },'; - echo ' "socketTransportProtocols" : ["xhr-polling", "jsonp-polling", "htmlfile"],' >> $settings_file - echo ' "loadTest": false,' >> $settings_file - echo ' "indentationOnNewLine": false,' >> $settings_file + echo ' "socketTransportProtocols" : ["xhr-polling", "jsonp-polling", "htmlfile"],'; + echo ' "loadTest": false,'; + echo ' "indentationOnNewLine": false,'; - echo ' "toolbar": {' >> $settings_file - echo ' "left": [' >> $settings_file - echo ' ["bold", "italic", "underline", "strikethrough"],' >> $settings_file - echo ' ["orderedlist", "unorderedlist", "indent", "outdent"],' >> $settings_file - echo ' ["undo", "redo"],' >> $settings_file - echo ' ["clearauthorship"]' >> $settings_file - echo ' ],' >> $settings_file - echo ' "right": [' >> $settings_file - echo ' ["importexport", "timeslider", "savedrevision"],' >> $settings_file - echo ' ["settings", "embed"],' >> $settings_file - echo ' ["showusers"]' >> $settings_file - echo ' ],' >> $settings_file - echo ' "timeslider": [' >> $settings_file - echo ' ["timeslider_export", "timeslider_returnToPad"]' >> $settings_file - echo ' ]' >> $settings_file - echo ' },' >> $settings_file - echo ' "loglevel": "INFO"' >> $settings_file - echo '}' >> $settings_file + echo ' "toolbar": {'; + echo ' "left": ['; + echo ' ["bold", "italic", "underline", "strikethrough"],'; + echo ' ["orderedlist", "unorderedlist", "indent", "outdent"],'; + echo ' ["undo", "redo"],'; + echo ' ["clearauthorship"]'; + echo ' ],'; + echo ' "right": ['; + echo ' ["importexport", "timeslider", "savedrevision"],'; + echo ' ["settings", "embed"],'; + echo ' ["showusers"]'; + echo ' ],'; + echo ' "timeslider": ['; + echo ' ["timeslider_export", "timeslider_returnToPad"]'; + echo ' ]'; + echo ' },'; + echo ' "loglevel": "INFO"'; + echo '}'; } > $settings_file chmod 600 $settings_file } @@ -177,7 +177,7 @@ function remove_user_etherpad { remove_username="$1" settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json - ${PROJECT_NAME}-pass -u $remove_username --rmapp etherpad + "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp etherpad if grep -q "\"$remove_username\": {" $settings_file; then sed -i "/\"$remove_username\": {/d" $settings_file @@ -191,7 +191,7 @@ function add_user_etherpad { settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json if ! grep -q "\"$new_username\": {" $settings_file; then - ${PROJECT_NAME}-pass -u $new_username -a etherpad -p "$2" + "${PROJECT_NAME}-pass" -u "$new_username" -a etherpad -p "$2" sed -i "/\"users\": {/a \"$new_username\": { \"password\": \"$new_user_password\", \"is_admin\": false }," $settings_file if grep -q "\"$new_username\": {" $settings_file; then systemctl restart etherpad @@ -204,11 +204,11 @@ function add_user_etherpad { } function install_interactive_etherpad { - if [ ! $ONION_ONLY ]; then + if [ ! "$ONION_ONLY" ]; then ONION_ONLY='no' fi - if [[ $ONION_ONLY != "no" ]]; then + if [[ "$ONION_ONLY" != "no" ]]; then ETHERPAD_DOMAIN_NAME='etherpad.local' write_config_param "ETHERPAD_DOMAIN_NAME" "$ETHERPAD_DOMAIN_NAME" else @@ -220,18 +220,17 @@ function install_interactive_etherpad { function etherpad_set_title { read_config_param "ETHERPAD_TITLE" - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 + data=$(mktemp 2>/dev/null) dialog --title $"Etherpad Title" \ --backtitle $"Freedombone Control Panel" \ - --inputbox $'Set a title for your etherpad system' 10 60 "$ETHERPAD_TITLE" 2>$data + --inputbox $'Set a title for your etherpad system' 10 60 "$ETHERPAD_TITLE" 2>"$data" sel=$? case $sel in 0) - temp_title=$(<$data) + temp_title=$(<"$data") if [ ${#temp_title} -gt 0 ]; then ETHERPAD_TITLE="$temp_title" - settings_file=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json + 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 @@ -241,22 +240,22 @@ function etherpad_set_title { fi ;; esac + rm -f "$data" } 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 + data=$(mktemp 2>/dev/null) 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 + --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) + temp_welcome=$(<"$data") if [ ${#temp_welcome} -gt 0 ]; then ETHERPAD_WELCOME_MESSAGE="$temp_welcome" - settings_file=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json + 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 @@ -266,29 +265,33 @@ function etherpad_set_welcome_message { fi ;; esac + rm -f "$data" } function configure_interactive_etherpad { while true do - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 + data=$(mktemp 2>/dev/null) 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 + 3 $"Exit" on 2> "$data" sel=$? case $sel in - 1) return;; - 255) return;; + 1) rm -f "$data" + return;; + 255) rm -f "$data" + return;; esac - case $(cat $data) in + case $(cat "$data") in 1) etherpad_set_title;; 2) etherpad_set_welcome_message;; - 3) break;; + 3) rm -f "$data" + break;; esac + rm -f "$data" done } @@ -311,18 +314,18 @@ function upgrade_etherpad { function backup_local_etherpad { ETHERPAD_DOMAIN_NAME='etherpad' - if grep -q "etherpad domain" $COMPLETION_FILE; then + 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 + if [ -d "$source_directory" ]; then dest_directory=etherpad function_check suspend_site - suspend_site ${ETHERPAD_DOMAIN_NAME} + suspend_site "${ETHERPAD_DOMAIN_NAME}" function_check backup_directory_to_usb - backup_directory_to_usb $source_directory $dest_directory + backup_directory_to_usb "$source_directory" "$dest_directory" function_check backup_database_to_usb backup_database_to_usb etherpad @@ -333,50 +336,50 @@ function backup_local_etherpad { } function restore_local_etherpad { - if ! grep -q "etherpad domain" $COMPLETION_FILE; then + if ! grep -q "etherpad domain" "$COMPLETION_FILE"; then return fi ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain") - if [ $ETHERPAD_DOMAIN_NAME ]; then + if [ "$ETHERPAD_DOMAIN_NAME" ]; then temp_restore_dir=/root/tempetherpad - etherpad_dir=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs + #etherpad_dir="/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs" function_check etherpad_create_database etherpad_create_database - restore_database etherpad ${ETHERPAD_DOMAIN_NAME} + 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 + 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 + if [ -f "/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key" ]; then + chown etherpad: "/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key" fi - MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb) - settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json - sed -i "s|\"password\":.*|\"password\": \"${MARIADB_PASSWORD}\",|g" $settings_file + MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb) + settings_file="/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json" + sed -i "s|\"password\":.*|\"password\": \"${MARIADB_PASSWORD}\",|g" "$settings_file" MARIADB_PASSWORD= fi } function backup_remote_etherpad { - if grep -q "etherpad domain" $COMPLETION_FILE; then + 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 + temp_backup_dir="/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs" + if [ -d "$temp_backup_dir" ]; then function_check suspend_site - suspend_site ${ETHERPAD_DOMAIN_NAME} + 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 + backup_directory_to_friend "$temp_backup_dir" etherpad function_check restart_site restart_site @@ -387,29 +390,29 @@ function backup_remote_etherpad { } function restore_remote_etherpad { - if grep -q "etherpad domain" $COMPLETION_FILE; then + 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} + 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 + 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 + if [ -f "/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key" ]; then + chown etherpad: "/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key" fi - MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb) - settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json - sed -i "s|\"password\":.*|\"password\": \"${MARIADB_PASSWORD}\",|g" $settings_file + MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb) + settings_file="/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json" + sed -i "s|\"password\":.*|\"password\": \"${MARIADB_PASSWORD}\",|g" "$settings_file" MARIADB_PASSWORD= fi } @@ -427,13 +430,13 @@ function remove_etherpad { rm /etc/systemd/system/etherpad.service fi systemctl daemon-reload - 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 + 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 + 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 @@ -441,7 +444,7 @@ function remove_etherpad { 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' "$COMPLETION_FILE" remove_backup_database_local etherpad remove_nodejs etherpad @@ -449,22 +452,22 @@ function remove_etherpad { userdel -r etherpad function_check remove_ddns_domain - remove_ddns_domain $ETHERPAD_DOMAIN_NAME + remove_ddns_domain "$ETHERPAD_DOMAIN_NAME" } function install_etherpad { - if [ ! $ETHERPAD_DOMAIN_NAME ]; then + if [ ! "$ETHERPAD_DOMAIN_NAME" ]; then echo $'No domain name was given for etherpad' exit 7359 fi check_ram_availability 2000 - if [ -f $IMAGE_PASSWORD_FILE ]; then - ETHERPAD_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)" + if [ -f "$IMAGE_PASSWORD_FILE" ]; then + ETHERPAD_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")" else - if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then - ETHERPAD_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})" + if [ ! "$ETHERPAD_ADMIN_PASSWORD" ]; then + ETHERPAD_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")" fi fi @@ -484,133 +487,133 @@ function install_etherpad { function_check install_nodejs install_nodejs etherpad - if [ ! -d /var/www/$ETHERPAD_DOMAIN_NAME ]; then - mkdir /var/www/$ETHERPAD_DOMAIN_NAME + if [ ! -d "/var/www/$ETHERPAD_DOMAIN_NAME" ]; then + mkdir "/var/www/$ETHERPAD_DOMAIN_NAME" fi - if [ ! -d /var/www/$ETHERPAD_DOMAIN_NAME/htdocs ]; then + if [ ! -d "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" ]; then if [ -d /repos/etherpad ]; then - mkdir /var/www/$ETHERPAD_DOMAIN_NAME/htdocs - cp -r -p /repos/etherpad/. /var/www/$ETHERPAD_DOMAIN_NAME/htdocs - cd /var/www/$ETHERPAD_DOMAIN_NAME/htdocs + mkdir "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" + cp -r -p /repos/etherpad/. "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" + cd "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" || exit 32468346 git pull else function_check git_clone - git_clone $ETHERPAD_REPO /var/www/$ETHERPAD_DOMAIN_NAME/htdocs + git_clone "$ETHERPAD_REPO" "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" fi - if [ ! -d /var/www/$ETHERPAD_DOMAIN_NAME/htdocs ]; then + 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 + cd "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" || exit 24654824 + 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 + 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 + add_ddns_domain "$ETHERPAD_DOMAIN_NAME" create_etherpad_settings - adduser --system --home=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/ --group etherpad - chown -R etherpad: /var/www/$ETHERPAD_DOMAIN_NAME/htdocs/ + 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' >> /etc/systemd/system/etherpad.service - echo 'Group=etherpad' >> /etc/systemd/system/etherpad.service - echo "WorkingDirectory=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" >> /etc/systemd/system/etherpad.service - echo "ExecStart=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/bin/run.sh" >> /etc/systemd/system/etherpad.service - echo 'Restart=on-failure' >> /etc/systemd/system/etherpad.service - echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/etherpad.service - echo 'RestartForceExitStatus=3 4' >> /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 + { echo '[Unit]'; + echo 'Description=etherpad-lite (real-time collaborative document editing)'; + echo 'After=syslog.target network.target'; + echo ''; + echo '[Service]'; + echo 'Type=simple'; + echo 'User=etherpad'; + echo 'Group=etherpad'; + echo "WorkingDirectory=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs"; + echo "ExecStart=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/bin/run.sh"; + echo 'Restart=on-failure'; + echo 'SuccessExitStatus=3 4'; + echo 'RestartForceExitStatus=3 4'; + echo ''; + echo '[Install]'; + 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 ' #listen [::]:443 ssl;' >> $etherpad_nginx_site - echo " server_name $ETHERPAD_DOMAIN_NAME;" >> $etherpad_nginx_site - echo '' >> $etherpad_nginx_site - echo ' # Security' >> $etherpad_nginx_site + nginx_http_redirect "$ETHERPAD_DOMAIN_NAME" + { echo 'server {'; + echo ' listen 443 ssl;'; + echo ' #listen [::]:443 ssl;'; + echo " server_name $ETHERPAD_DOMAIN_NAME;"; + echo ''; + echo ' # Security'; } >> "$etherpad_nginx_site" function_check nginx_ssl - nginx_ssl $ETHERPAD_DOMAIN_NAME + nginx_ssl "$ETHERPAD_DOMAIN_NAME" function_check nginx_disable_sniffing - nginx_disable_sniffing $ETHERPAD_DOMAIN_NAME + 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 /dev/null;' >> $etherpad_nginx_site - echo ' error_log /dev/null;' >> $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 + { echo ' add_header Strict-Transport-Security max-age=15768000;'; + echo ''; + echo ' # Logs'; + echo ' access_log /dev/null;'; + echo ' error_log /dev/null;'; + echo ''; + echo ' # Root'; + echo " root /var/www/$ETHERPAD_DOMAIN_NAME/htdocs;"; + echo ''; + echo ' location / {'; } >> "$etherpad_nginx_site" function_check nginx_limits - nginx_limits $ETHERPAD_DOMAIN_NAME '15m' - echo " proxy_pass http://localhost:${ETHERPAD_PORT}/;" >> $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 + nginx_limits "$ETHERPAD_DOMAIN_NAME" '15m' + { echo " proxy_pass http://localhost:${ETHERPAD_PORT}/;"; + echo " proxy_set_header Host \$host;"; + echo ' proxy_buffering off;'; + echo ' }'; + echo '}'; } >> "$etherpad_nginx_site" else - echo -n '' > $etherpad_nginx_site + 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 + { echo 'server {'; + echo " listen 127.0.0.1:$ETHERPAD_ONION_PORT default_server;"; + echo " server_name $ETHERPAD_ONION_HOSTNAME;"; + 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 /dev/null;' >> $etherpad_nginx_site - echo ' error_log /dev/null;' >> $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 + nginx_disable_sniffing "$ETHERPAD_DOMAIN_NAME" + { echo ''; + echo ' # Logs'; + echo ' access_log /dev/null;'; + echo ' error_log /dev/null;'; + echo ''; + echo ' # Root'; + echo " root /var/www/$ETHERPAD_DOMAIN_NAME/htdocs;"; + echo ''; + echo ' location / {'; } >> "$etherpad_nginx_site" function_check nginx_limits - nginx_limits $ETHERPAD_DOMAIN_NAME '15m' - echo " proxy_pass http://localhost:${ETHERPAD_PORT}/;" >> $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 + nginx_limits "$ETHERPAD_DOMAIN_NAME" '15m' + { echo " proxy_pass http://localhost:${ETHERPAD_PORT}/;"; + echo " proxy_set_header Host \$host;"; + echo ' proxy_buffering off;'; + echo ' }'; + echo '}'; } >> "$etherpad_nginx_site" function_check create_site_certificate - create_site_certificate $ETHERPAD_DOMAIN_NAME 'yes' + 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 + 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 + 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 + if [ -f "/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key" ]; then + chown etherpad: "/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key" fi usermod -a -G ssl-cert etherpad @@ -623,14 +626,14 @@ function install_etherpad { backup_database_local etherpad function_check nginx_ensite - nginx_ensite $ETHERPAD_DOMAIN_NAME + nginx_ensite "$ETHERPAD_DOMAIN_NAME" ETHERPAD_ONION_HOSTNAME=$(add_onion_service etherpad 80 ${ETHERPAD_ONION_PORT}) - ${PROJECT_NAME}-pass -u $MY_USERNAME -a etherpad -p "$ETHERPAD_ADMIN_PASSWORD" + "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a etherpad -p "$ETHERPAD_ADMIN_PASSWORD" function_check add_ddns_domain - add_ddns_domain $ETHERPAD_DOMAIN_NAME + add_ddns_domain "$ETHERPAD_DOMAIN_NAME" set_completion_param "etherpad domain" "$ETHERPAD_DOMAIN_NAME" diff --git a/src/freedombone-app-fedwiki b/src/freedombone-app-fedwiki index d8b27591..8197e49a 100755 --- a/src/freedombone-app-fedwiki +++ b/src/freedombone-app-fedwiki @@ -127,7 +127,7 @@ function add_user_fedwiki { } function install_interactive_fedwiki { - if [ ! $ONION_ONLY ]; then + if [ ! "$ONION_ONLY" ]; then ONION_ONLY='no' fi @@ -148,7 +148,7 @@ function change_password_fedwiki { echo $'Fedwiki password is too short' return fi - ${PROJECT_NAME}-pass -u $FEDWIKI_USERNAME -a fedwiki -p "$FEDWIKI_PASSWORD" + "${PROJECT_NAME}-pass" -u "$FEDWIKI_USERNAME" -a fedwiki -p "$FEDWIKI_PASSWORD" sed -i "s|--cookieSecret .*|--cookieSecret '${FEDWIKI_PASSWORD}'|g" /etc/systemd/system/fedwiki.service sed -i "s|\"secret\":.*|\"secret\": \"${FEDWIKI_PASSWORD}\"|g" ${FEDWIKI_DATA}/status/owner.json systemctl daemon-reload @@ -177,12 +177,12 @@ function upgrade_fedwiki { function backup_local_fedwiki { FEDWIKI_DOMAIN_NAME='fedwiki.local' - if grep -q "fedwiki domain" $COMPLETION_FILE; then + if grep -q "fedwiki domain" "$COMPLETION_FILE"; then FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain") fi systemctl stop fedwiki - suspend_site ${FEDWIKI_DOMAIN_NAME} + suspend_site "${FEDWIKI_DOMAIN_NAME}" fedwiki_path=$FEDWIKI_DATA if [ -d $fedwiki_path ]; then @@ -195,11 +195,11 @@ function backup_local_fedwiki { function restore_local_fedwiki { FEDWIKI_DOMAIN_NAME='fedwiki.local' - if grep -q "fedwiki domain" $COMPLETION_FILE; then + if grep -q "fedwiki domain" "$COMPLETION_FILE"; then FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain") fi - if [ $FEDWIKI_DOMAIN_NAME ]; then - suspend_site ${FEDWIKI_DOMAIN_NAME} + if [ "$FEDWIKI_DOMAIN_NAME" ]; then + suspend_site "${FEDWIKI_DOMAIN_NAME}" systemctl stop fedwiki temp_restore_dir=/root/tempfedwiki @@ -215,8 +215,8 @@ function restore_local_fedwiki { rm -rf $temp_restore_dir fi - FEDWIKI_PASSWORD=$(cat ${FEDWIKI_DATA}/status/owner.json | grep secret | awk -F '"' '{print $4}') - ${PROJECT_NAME}-pass -u $FEDWIKI_USERNAME -a fedwiki -p "$FEDWIKI_PASSWORD" + FEDWIKI_PASSWORD=$(grep secret "${FEDWIKI_DATA}/status/owner.json" | awk -F '"' '{print $4}') + "${PROJECT_NAME}-pass" -u "$FEDWIKI_USERNAME" -a fedwiki -p "$FEDWIKI_PASSWORD" sed -i "s|--cookieSecret .*|--cookieSecret '${FEDWIKI_PASSWORD}'|g" /etc/systemd/system/fedwiki.service write_config_param "FEDWIKI_COOKIE" "$FEDWIKI_PASSWORD" systemctl daemon-reload @@ -227,12 +227,12 @@ function restore_local_fedwiki { function backup_remote_fedwiki { FEDWIKI_DOMAIN_NAME='fedwiki.local' - if grep -q "fedwiki domain" $COMPLETION_FILE; then + if grep -q "fedwiki domain" "$COMPLETION_FILE"; then FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain") fi systemctl stop fedwiki - suspend_site ${FEDWIKI_DOMAIN_NAME} + suspend_site "${FEDWIKI_DOMAIN_NAME}" temp_backup_dir=$FEDWIKI_DATA if [ -d $temp_backup_dir ]; then @@ -248,12 +248,12 @@ function backup_remote_fedwiki { function restore_remote_fedwiki { FEDWIKI_DOMAIN_NAME='fedwiki.local' - if grep -q "fedwiki domain" $COMPLETION_FILE; then + if grep -q "fedwiki domain" "$COMPLETION_FILE"; then FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain") fi systemctl stop fedwiki - suspend_site ${FEDWIKI_DOMAIN_NAME} + suspend_site "${FEDWIKI_DOMAIN_NAME}" temp_restore_dir=/root/tempfedwiki function_check restore_directory_from_friend @@ -268,8 +268,8 @@ function restore_remote_fedwiki { rm -rf $temp_restore_dir fi - FEDWIKI_PASSWORD=$(cat ${FEDWIKI_DATA}/status/owner.json | grep secret | awk -F '"' '{print $4}') - ${PROJECT_NAME}-pass -u $FEDWIKI_USERNAME -a fedwiki -p "$FEDWIKI_PASSWORD" + FEDWIKI_PASSWORD=$(grep secret "${FEDWIKI_DATA}/status/owner.json" | awk -F '"' '{print $4}') + "${PROJECT_NAME}-pass" -u "$FEDWIKI_USERNAME" -a fedwiki -p "$FEDWIKI_PASSWORD" sed -i "s|--cookieSecret .*|--cookieSecret '${FEDWIKI_PASSWORD}'|g" /etc/systemd/system/fedwiki.service write_config_param "FEDWIKI_COOKIE" "$FEDWIKI_PASSWORD" systemctl daemon-reload @@ -294,20 +294,20 @@ function remove_fedwiki { remove_nodejs fedwiki read_config_param "FEDWIKI_DOMAIN_NAME" - nginx_dissite $FEDWIKI_DOMAIN_NAME - remove_certs ${FEDWIKI_DOMAIN_NAME} - if [ -f /etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME ]; then - rm -f /etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME + nginx_dissite "$FEDWIKI_DOMAIN_NAME" + remove_certs "${FEDWIKI_DOMAIN_NAME}" + if [ -f "/etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME" ]; then + rm -f "/etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME" fi - if [ -d /var/www/$FEDWIKI_DOMAIN_NAME ]; then - rm -rf /var/www/$FEDWIKI_DOMAIN_NAME + if [ -d "/var/www/$FEDWIKI_DOMAIN_NAME" ]; then + rm -rf "/var/www/$FEDWIKI_DOMAIN_NAME" fi remove_config_param FEDWIKI_DOMAIN_NAME remove_config_param FEDWIKI_CODE function_check remove_onion_service remove_onion_service fedwiki ${FEDWIKI_ONION_PORT} remove_completion_param "install_fedwiki" - sed -i '/fedwiki/d' $COMPLETION_FILE + sed -i '/fedwiki/d' "$COMPLETION_FILE" groupdel -f fedwiki userdel -r fedwiki @@ -317,101 +317,102 @@ function remove_fedwiki { fi function_check remove_ddns_domain - remove_ddns_domain $FEDWIKI_DOMAIN_NAME + remove_ddns_domain "$FEDWIKI_DOMAIN_NAME" } function fedwiki_setup_web { - fedwiki_nginx_file=/etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME + fedwiki_nginx_file="/etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME" - if [[ $ONION_ONLY == "no" ]]; then - echo 'server {' > $fedwiki_nginx_file - echo ' listen 80;' >> $fedwiki_nginx_file - echo ' listen [::]:80;' >> $fedwiki_nginx_file - echo " server_name $FEDWIKI_DOMAIN_NAME;" >> $fedwiki_nginx_file - echo ' rewrite ^ https://$server_name$request_uri? permanent;' >> $fedwiki_nginx_file - echo '}' >> $fedwiki_nginx_file - echo '' >> $fedwiki_nginx_file - echo 'server {' >> $fedwiki_nginx_file - echo ' listen 443 ssl;' >> $fedwiki_nginx_file - echo ' #listen [::]:443 ssl;' >> $fedwiki_nginx_file - echo " server_name $FEDWIKI_DOMAIN_NAME;" >> $fedwiki_nginx_file - echo '' >> $fedwiki_nginx_file + if [[ "$ONION_ONLY" == "no" ]]; then + { echo 'server {'; + echo ' listen 80;'; + echo ' listen [::]:80;'; + echo " server_name $FEDWIKI_DOMAIN_NAME;"; + echo " rewrite ^ https://\$server_name\$request_uri? permanent;"; + echo '}'; + echo ''; + echo 'server {'; + echo ' listen 443 ssl;'; + echo ' #listen [::]:443 ssl;'; + echo " server_name $FEDWIKI_DOMAIN_NAME;"; + echo ''; } > "$fedwiki_nginx_file" function_check nginx_ssl - nginx_ssl $FEDWIKI_DOMAIN_NAME mobile + nginx_ssl "$FEDWIKI_DOMAIN_NAME" mobile - sed -i '/Content-Security-Policy/d' $fedwiki_nginx_file - sed -i '/X-XSS-Protection/d' $fedwiki_nginx_file - sed -i '/X-Robots-Tag/d' $fedwiki_nginx_file - sed -i '/X-Download-Options/d' $fedwiki_nginx_file - sed -i '/X-Permitted-Cross-Domain-Policies/d' $fedwiki_nginx_file + sed -i '/Content-Security-Policy/d' "$fedwiki_nginx_file" + sed -i '/X-XSS-Protection/d' "$fedwiki_nginx_file" + sed -i '/X-Robots-Tag/d' "$fedwiki_nginx_file" + sed -i '/X-Download-Options/d' "$fedwiki_nginx_file" + sed -i '/X-Permitted-Cross-Domain-Policies/d' "$fedwiki_nginx_file" - echo ' add_header X-Robots-Tag none;' >> $fedwiki_nginx_file - echo ' add_header X-Download-Options noopen;' >> $fedwiki_nginx_file - echo ' add_header X-Frame-Options DENY;' >> $fedwiki_nginx_file - echo ' add_header X-Content-Type-Options nosniff;' >> $fedwiki_nginx_file - echo ' add_header Strict-Transport-Security max-age=15768000;' >> $fedwiki_nginx_file - echo '' >> $fedwiki_nginx_file - echo ' location /fonts-font-awesome/ {' >> $fedwiki_nginx_file - echo ' alias /usr/share/fonts-font-awesome/;' >> $fedwiki_nginx_file - echo ' }' >> $fedwiki_nginx_file - echo '' >> $fedwiki_nginx_file - echo ' location / {' >> $fedwiki_nginx_file - echo " proxy_pass http://localhost:${FEDWIKI_PORT};" >> $fedwiki_nginx_file - echo ' proxy_set_header X-Real-IP $remote_addr;' >> $fedwiki_nginx_file - echo ' proxy_set_header Host $host;' >> $fedwiki_nginx_file - echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $fedwiki_nginx_file - echo ' client_max_body_size 1M;' >> $fedwiki_nginx_file - echo ' }' >> $fedwiki_nginx_file - echo '}' >> $fedwiki_nginx_file - echo '' >> $fedwiki_nginx_file + { echo ' add_header X-Robots-Tag none;'; + echo ' add_header X-Download-Options noopen;'; + echo ' add_header X-Frame-Options DENY;'; + echo ' add_header X-Content-Type-Options nosniff;'; + echo ' add_header Strict-Transport-Security max-age=15768000;'; + echo ''; + echo ' location /fonts-font-awesome/ {'; + echo ' alias /usr/share/fonts-font-awesome/;'; + echo ' }'; + echo ''; + echo ' location / {'; + echo " proxy_pass http://localhost:${FEDWIKI_PORT};"; + echo " proxy_set_header X-Real-IP \$remote_addr;"; + echo " proxy_set_header Host \$host;"; + echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;"; + echo ' client_max_body_size 1M;'; + echo ' }'; + echo '}'; + echo ''; } >> "$fedwiki_nginx_file" else - echo -n '' > $fedwiki_nginx_file + echo -n '' > "$fedwiki_nginx_file" fi - echo 'server {' >> $fedwiki_nginx_file - echo " listen 127.0.0.1:$FEDWIKI_ONION_PORT default_server;" >> $fedwiki_nginx_file - echo " server_name $FEDWIKI_ONION_HOSTNAME;" >> $fedwiki_nginx_file - echo '' >> $fedwiki_nginx_file - echo ' add_header X-Robots-Tag none;' >> $fedwiki_nginx_file - echo ' add_header X-Download-Options noopen;' >> $fedwiki_nginx_file - echo ' add_header X-Frame-Options DENY;' >> $fedwiki_nginx_file - echo ' add_header X-Content-Type-Options nosniff;' >> $fedwiki_nginx_file - echo '' >> $fedwiki_nginx_file - echo ' location /fonts-font-awesome/ {' >> $fedwiki_nginx_file - echo ' alias /usr/share/fonts-font-awesome/;' >> $fedwiki_nginx_file - echo ' }' >> $fedwiki_nginx_file - echo '' >> $fedwiki_nginx_file - echo ' location / {' >> $fedwiki_nginx_file - echo " proxy_pass http://localhost:${FEDWIKI_PORT};" >> $fedwiki_nginx_file - echo ' proxy_set_header X-Real-IP $remote_addr;' >> $fedwiki_nginx_file - echo ' proxy_set_header Host $host;' >> $fedwiki_nginx_file - echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $fedwiki_nginx_file - echo ' client_max_body_size 1M;' >> $fedwiki_nginx_file - echo ' }' >> $fedwiki_nginx_file - echo '}' >> $fedwiki_nginx_file + { echo 'server {'; + echo " listen 127.0.0.1:$FEDWIKI_ONION_PORT default_server;"; + echo " server_name $FEDWIKI_ONION_HOSTNAME;"; + echo ''; + echo ' add_header X-Robots-Tag none;'; + echo ' add_header X-Download-Options noopen;'; + echo ' add_header X-Frame-Options DENY;'; + echo ' add_header X-Content-Type-Options nosniff;'; + echo ''; + echo ' location /fonts-font-awesome/ {'; + echo ' alias /usr/share/fonts-font-awesome/;'; + echo ' }'; + echo ''; + echo ' location / {'; + echo " proxy_pass http://localhost:${FEDWIKI_PORT};"; + echo " proxy_set_header X-Real-IP \$remote_addr;"; + echo " proxy_set_header Host \$host;"; + echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;"; + echo ' client_max_body_size 1M;'; + echo ' }'; + echo '}'; } >> "$fedwiki_nginx_file" function_check create_site_certificate - create_site_certificate $FEDWIKI_DOMAIN_NAME 'yes' + create_site_certificate "$FEDWIKI_DOMAIN_NAME" 'yes' function_check nginx_ensite - nginx_ensite $FEDWIKI_DOMAIN_NAME + nginx_ensite "$FEDWIKI_DOMAIN_NAME" } function install_fedwiki { - if [[ $VARIANT == "mesh"* ]]; then + # shellcheck disable=SC2153 + if [[ "$VARIANT" == "mesh"* ]]; then return fi - if [ ! $ONION_ONLY ]; then + if [ ! "$ONION_ONLY" ]; then ONION_ONLY='no' fi - if [ ! $FEDWIKI_DOMAIN_NAME ]; then + if [ ! "$FEDWIKI_DOMAIN_NAME" ]; then echo $'The fedwiki domain name was not specified' exit 893635 fi - if [ ! -d /var/www/$FEDWIKI_DOMAIN_NAME/htdocs ]; then - mkdir -p /var/www/$FEDWIKI_DOMAIN_NAME/htdocs + if [ ! -d "/var/www/$FEDWIKI_DOMAIN_NAME/htdocs" ]; then + mkdir -p "/var/www/$FEDWIKI_DOMAIN_NAME/htdocs" fi if [ ! -d $FEDWIKI_DATA ]; then @@ -429,14 +430,12 @@ function install_fedwiki { apt-get -yq install fonts-font-awesome - npm install -g wiki@$FEDWIKI_VERSION - if [ ! "$?" = "0" ]; then + if ! npm install -g wiki@$FEDWIKI_VERSION; then echo $'Failed to install fedwiki' exit 6293523 fi - npm install -g wiki-security-friends@0.1.0 - if [ ! "$?" = "0" ]; then + if ! npm install -g wiki-security-friends@0.1.0; then echo $'Failed to install wiki-security-friends' exit 783533 fi @@ -457,44 +456,44 @@ function install_fedwiki { FEDWIKI_COOKIE="$(create_password 20)" fi - echo '[Unit]' > /etc/systemd/system/fedwiki.service - echo 'Description=Fedwiki federated wiki' >> /etc/systemd/system/fedwiki.service - echo 'After=syslog.target' >> /etc/systemd/system/fedwiki.service - echo 'After=network.target' >> /etc/systemd/system/fedwiki.service - echo '' >> /etc/systemd/system/fedwiki.service - echo '[Service]' >> /etc/systemd/system/fedwiki.service - echo 'User=fedwiki' >> /etc/systemd/system/fedwiki.service - echo 'Group=fedwiki' >> /etc/systemd/system/fedwiki.service - echo "WorkingDirectory=/usr/local/lib/node_modules/wiki" >> /etc/systemd/system/fedwiki.service - echo "ExecStart=/usr/local/bin/wiki --security_type friends --session_duration 7 --data $FEDWIKI_DATA -p $FEDWIKI_PORT --cookieSecret '${FEDWIKI_COOKIE}'" >> /etc/systemd/system/fedwiki.service - echo 'StandardOutput=syslog' >> /etc/systemd/system/fedwiki.service - echo 'StandardError=syslog' >> /etc/systemd/system/fedwiki.service - echo 'SyslogIdentifier=fedwiki' >> /etc/systemd/system/fedwiki.service - echo 'Restart=always' >> /etc/systemd/system/fedwiki.service - echo "Environment=NODE_ENV=production" >> /etc/systemd/system/fedwiki.service - echo '' >> /etc/systemd/system/fedwiki.service - echo '[Install]' >> /etc/systemd/system/fedwiki.service - echo 'WantedBy=multi-user.target' >> /etc/systemd/system/fedwiki.service + { echo '[Unit]'; + echo 'Description=Fedwiki federated wiki'; + echo 'After=syslog.target'; + echo 'After=network.target'; + echo ''; + echo '[Service]'; + echo 'User=fedwiki'; + echo 'Group=fedwiki'; + echo "WorkingDirectory=/usr/local/lib/node_modules/wiki"; + echo "ExecStart=/usr/local/bin/wiki --security_type friends --session_duration 7 --data $FEDWIKI_DATA -p $FEDWIKI_PORT --cookieSecret '${FEDWIKI_COOKIE}'"; + echo 'StandardOutput=syslog'; + echo 'StandardError=syslog'; + echo 'SyslogIdentifier=fedwiki'; + echo 'Restart=always'; + echo "Environment=NODE_ENV=production"; + echo ''; + echo '[Install]'; + echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/fedwiki.service if [ ! -d ${FEDWIKI_DATA}/status ]; then mkdir -p ${FEDWIKI_DATA}/status fi fedwiki_auth_file=${FEDWIKI_DATA}/status/owner.json - echo '{' > $fedwiki_auth_file - echo " \"name\": \"${MY_USERNAME}\"," >> $fedwiki_auth_file - echo ' "friend": {' >> $fedwiki_auth_file - echo " \"secret\": \"${FEDWIKI_COOKIE}\"" >> $fedwiki_auth_file - echo ' }' >> $fedwiki_auth_file - echo '}' >> $fedwiki_auth_file + { echo '{'; + echo " \"name\": \"${MY_USERNAME}\","; + echo ' "friend": {'; + echo " \"secret\": \"${FEDWIKI_COOKIE}\""; + echo ' }'; + echo '}'; } > $fedwiki_auth_file chown -R fedwiki:fedwiki $FEDWIKI_DATA fedwiki_setup_web - ${PROJECT_NAME}-pass -u $MY_USERNAME -a fedwiki -p "$FEDWIKI_COOKIE" + "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a fedwiki -p "$FEDWIKI_COOKIE" function_check add_ddns_domain - add_ddns_domain $FEDWIKI_DOMAIN_NAME + add_ddns_domain "$FEDWIKI_DOMAIN_NAME" fedwiki_remove_bad_links diff --git a/src/freedombone-app-friendica b/src/freedombone-app-friendica index db1ad7bc..7eee5abe 100755 --- a/src/freedombone-app-friendica +++ b/src/freedombone-app-friendica @@ -60,7 +60,7 @@ function logging_off_friendica { function remove_user_friendica { remove_username="$1" - ${PROJECT_NAME}-pass -u $remove_username --rmapp friendica + "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp friendica } function add_user_friendica { @@ -71,27 +71,26 @@ function add_user_friendica { new_username="$1" new_user_password="$2" - ${PROJECT_NAME}-pass -u $new_username -a friendica -p "$new_user_password" + "${PROJECT_NAME}-pass" -u "$new_username" -a friendica -p "$new_user_password" echo '0' } function friendica_renew_cert { dialog --title $"Renew SSL certificate" \ --backtitle $"Freedombone Control Panel" \ - --yesno $"\nThis will renew a letsencrypt certificate. Select 'yes' to continue" 16 60 + --yesno $"\\nThis will renew a letsencrypt certificate. Select 'yes' to continue" 16 60 sel=$? case $sel in 1) return;; 255) return;; esac FRIENDICA_DOMAIN_NAME=$(get_completion_param "friendica domain") - if [ ! -d /var/www/$FRIENDICA_DOMAIN_NAME/htdocs ]; then + if [ ! -d "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs" ]; then dialog --title $"Renew SSL certificate" \ --msgbox $"Friendica install directory not found" 6 40 return fi - ${PROJECT_NAME}-renew-cert -h $FRIENDICA_DOMAIN_NAME -p 'letsencrypt' - if [ ! "$?" = "0" ]; then + if ! "${PROJECT_NAME}-renew-cert" -h "$FRIENDICA_DOMAIN_NAME" -p 'letsencrypt'; then any_key else dialog --title $"Renew SSL certificate" \ @@ -100,52 +99,54 @@ function friendica_renew_cert { } function friendica_channel_directory_server { - if ! grep -q "friendica domain" $COMPLETION_FILE; then + if ! grep -q "friendica domain" "$COMPLETION_FILE"; then dialog --title $"Friendica channel directory server" \ --msgbox $"Friendica is not installed on this system" 6 40 return fi FRIENDICA_DOMAIN_NAME=$(get_completion_param "friendica domain") - if [ ! -d /var/www/$FRIENDICA_DOMAIN_NAME/htdocs ]; then + if [ ! -d "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs" ]; then dialog --title $"Friendica channel directory server" \ --msgbox $"Friendica install directory not found" 6 40 return fi - CURR_DIR_SERVER=$(cat /var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php | grep directory | awk -F "'" '{print $6}') + CURR_DIR_SERVER=$(grep directory "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php" | awk -F "'" '{print $6}') - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 + data=$(mktemp 2>/dev/null) dialog --title $"Friendica channel directory server" \ --backtitle $"Freedombone Control Panel" \ --inputbox $"When you click on 'channel directory' this is where Friendica will obtain its list from" 8 60 "$CURR_DIR_SERVER" 2>$data sel=$? case $sel in 0) - friendica_domain_server=$(<$data) + friendica_domain_server=$(<"$data") if [[ "$friendica_domain_server" != *"."* ]]; then + rm -f "$data" return fi if [[ "$friendica_domain_server" != "http"* ]]; then dialog --title $"Friendica channel directory server" \ --msgbox $"Invalid domain - include the https://" 6 40 + rm -f "$data" return fi - sed -i "s|\['directory'\] = .*|\['directory'\] = \'$friendica_domain_server\';|g" /var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php + sed -i "s|\['directory'\] = .*|\['directory'\] = \'$friendica_domain_server\';|g" "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php" dialog --title $"Friendica channel directory server" \ --msgbox $"Domain channel directory server changed to $friendica_domain_server" 6 40 ;; esac + rm -f "$data" } function friendica_close_registrations { - sed -i "s|REGISTER_OPEN|REGISTER_CLOSED|g" /var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php + sed -i "s|REGISTER_OPEN|REGISTER_CLOSED|g" "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php" dialog --title $"Friendica Account Registrations" \ --msgbox $"New registrations are now closed" 6 40 } function friendica_allow_registrations { - sed -i "s|REGISTER_CLOSED|REGISTER_OPEN|g" /var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php + sed -i "s|REGISTER_CLOSED|REGISTER_OPEN|g" "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php" dialog --title $"Friendica Account Registrations" \ --msgbox $"New registrations are permitted" 6 40 } @@ -153,8 +154,7 @@ function friendica_allow_registrations { function configure_interactive_friendica { while true do - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 + data=$(mktemp 2>/dev/null) dialog --backtitle $"Freedombone Control Panel" \ --title $"Friendica" \ --radiolist $"Choose an operation:" 15 70 6 \ @@ -162,19 +162,21 @@ function configure_interactive_friendica { 2 $"Renew SSL certificate" off \ 3 $"Close new account registrations" off \ 4 $"Allow new account registrations" off \ - 5 $"Back to main menu" on 2> $data + 5 $"Back to main menu" on 2> "$data" sel=$? case $sel in 1) break;; 255) break;; esac - case $(cat $data) in + case $(cat "$data") in 1) friendica_channel_directory_server;; 2) friendica_renew_cert;; 3) friendica_close_registrations;; 4) friendica_allow_registrations;; - 5) break;; + 5) rm -f "$data" + break;; esac + rm -f "$data" done } @@ -190,7 +192,7 @@ function install_interactive_friendica { } function change_password_friendica { - FRIENDICA_USERNAME="$1" + #FRIENDICA_USERNAME="$1" FRIENDICA_PASSWORD="$2" if [ ${#FRIENDICA_PASSWORD} -lt 8 ]; then echo $'Friendica password is too short' @@ -201,14 +203,14 @@ function change_password_friendica { } function friendica_create_database { - if [ -f $IMAGE_PASSWORD_FILE ]; then - FRIENDICA_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)" + if [ -f "$IMAGE_PASSWORD_FILE" ]; then + FRIENDICA_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")" fi - if [ ! $FRIENDICA_ADMIN_PASSWORD ]; then - FRIENDICA_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})" + if [ ! "$FRIENDICA_ADMIN_PASSWORD" ]; then + FRIENDICA_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")" fi - ${PROJECT_NAME}-pass -u $MY_USERNAME -a friendica -p "$FRIENDICA_ADMIN_PASSWORD" - if [ ! $FRIENDICA_ADMIN_PASSWORD ]; then + "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a friendica -p "$FRIENDICA_ADMIN_PASSWORD" + if [ ! "$FRIENDICA_ADMIN_PASSWORD" ]; then return fi @@ -229,17 +231,17 @@ function upgrade_friendica { FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs function_check set_repo_commit - set_repo_commit $FRIENDICA_PATH "friendica commit" "$FRIENDICA_COMMIT" $FRIENDICA_REPO - set_repo_commit $FRIENDICA_PATH/addon "friendica addons commit" "$FRIENDICA_ADDONS_COMMIT" $FRIENDICA_ADDONS_REPO + set_repo_commit "$FRIENDICA_PATH" "friendica commit" "$FRIENDICA_COMMIT" $FRIENDICA_REPO + set_repo_commit "$FRIENDICA_PATH/addon" "friendica addons commit" "$FRIENDICA_ADDONS_COMMIT" $FRIENDICA_ADDONS_REPO } function backup_local_friendica { - friendica_path=/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs - if [ -d $friendica_path ]; then + friendica_path="/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs" + if [ -d "$friendica_path" ]; then function_check backup_database_to_usb backup_database_to_usb friendica - backup_directory_to_usb $friendica_path friendica + backup_directory_to_usb "$friendica_path" friendica fi } @@ -250,31 +252,31 @@ function restore_local_friendica { function_check friendica_create_database friendica_create_database - restore_database friendica ${FRIENDICA_DOMAIN_NAME} - if [ -d $USB_MOUNT/backup/friendica ]; then - if [ ! -d $friendica_dir/store/[data]/smarty3 ]; then - mkdir -p $friendica_dir/store/[data]/smarty3 + restore_database friendica "${FRIENDICA_DOMAIN_NAME}" + if [ -d "$USB_MOUNT/backup/friendica" ]; then + if [ ! -d "$friendica_dir/store/[data]/smarty3" ]; then + mkdir -p "$friendica_dir/store/[data]/smarty3" fi - chmod 1777 $friendica_dir/store/[data]/smarty3 - chown -R www-data:www-data $friendica_dir/* + chmod 1777 "$friendica_dir/store/[data]/smarty3" + chown -R www-data:www-data "$friendica_dir/*" if [ -d $temp_restore_dir ]; then rm -rf $temp_restore_dir fi - MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb) + MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb) FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs - sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" $FRIENDICA_PATH/.htconfig.php + sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" "$FRIENDICA_PATH/.htconfig.php" MARIADB_PASSWORD= fi } function backup_remote_friendica { - temp_backup_dir=/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs - if [ -d $temp_backup_dir ]; then - suspend_site ${FRIENDICA_DOMAIN_NAME} + temp_backup_dir="/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs" + if [ -d "$temp_backup_dir" ]; then + suspend_site "${FRIENDICA_DOMAIN_NAME}" backup_database_to_friend friendica echo "Backing up Friendica installation" - backup_directory_to_friend $temp_backup_dir friendica + backup_directory_to_friend "$temp_backup_dir" friendica restart_site echo "Backup of Friendica complete" else @@ -289,21 +291,21 @@ function restore_remote_friendica { function_check friendica_create_database friendica_create_database - restore_database_from_friend friendica ${FRIENDICA_DOMAIN_NAME} - if [ -d $SERVER_DIRECTORY/backup/friendica ]; then - if [ ! -d /var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3 ]; then - mkdir -p /var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3 + restore_database_from_friend friendica "${FRIENDICA_DOMAIN_NAME}" + if [ -d "$SERVER_DIRECTORY/backup/friendica" ]; then + if [ ! -d "/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3" ]; then + mkdir -p "/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3" fi - chmod 1777 /var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3 - chown -R www-data:www-data /var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/* + chmod 1777 "/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3" + chown -R www-data:www-data "/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/*" fi if [ -d /root/tempfriendica ]; then rm -rf /root/tempfriendica fi - MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb) - FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs - sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" $FRIENDICA_PATH/.htconfig.php + MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb) + FRIENDICA_PATH="/var/www/$FRIENDICA_DOMAIN_NAME/htdocs" + sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" "$FRIENDICA_PATH/.htconfig.php" MARIADB_PASSWORD= } @@ -311,35 +313,35 @@ function remove_friendica { if [ ${#FRIENDICA_DOMAIN_NAME} -eq 0 ]; then return fi - nginx_dissite $FRIENDICA_DOMAIN_NAME - remove_certs ${FRIENDICA_DOMAIN_NAME} - if [ -d /var/www/$FRIENDICA_DOMAIN_NAME ]; then - rm -rf /var/www/$FRIENDICA_DOMAIN_NAME + nginx_dissite "$FRIENDICA_DOMAIN_NAME" + remove_certs "${FRIENDICA_DOMAIN_NAME}" + if [ -d "/var/www/$FRIENDICA_DOMAIN_NAME" ]; then + rm -rf "/var/www/$FRIENDICA_DOMAIN_NAME" fi - if [ -f /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME ]; then - rm /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME + if [ -f "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME" ]; then + rm "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME" fi function_check drop_database drop_database friendica function_check remove_onion_service remove_onion_service friendica ${FRIENDICA_ONION_PORT} - sed -i '/friendica/d' $COMPLETION_FILE + sed -i '/friendica/d' "$COMPLETION_FILE" sed -i '/poller.php/d' /etc/crontab function_check remove_ddns_domain - remove_ddns_domain $FRIENDICA_DOMAIN_NAME + remove_ddns_domain "$FRIENDICA_DOMAIN_NAME" } function install_friendica { - if [ ! $FRIENDICA_DOMAIN_NAME ]; then + if [ ! "$FRIENDICA_DOMAIN_NAME" ]; then return fi - if [[ $ONION_ONLY != "no" ]]; then + if [[ "$ONION_ONLY" != "no" ]]; then return fi - FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs + FRIENDICA_PATH="/var/www/$FRIENDICA_DOMAIN_NAME/htdocs" function_check install_mariadb install_mariadb @@ -354,38 +356,38 @@ function install_friendica { apt-get -yq install php-dev imagemagick php-imagick libfcgi0ldbl apt-get -yq install php-memcached - if [ ! -d /var/www/$FRIENDICA_DOMAIN_NAME ]; then - mkdir /var/www/$FRIENDICA_DOMAIN_NAME + if [ ! -d "/var/www/$FRIENDICA_DOMAIN_NAME" ]; then + mkdir "/var/www/$FRIENDICA_DOMAIN_NAME" fi - if [ ! -d $FRIENDICA_PATH ]; then - mkdir $FRIENDICA_PATH + if [ ! -d "$FRIENDICA_PATH" ]; then + mkdir "$FRIENDICA_PATH" fi - if [ ! -f $FRIENDICA_PATH/index.php ]; then - cd $INSTALL_DIR + if [ ! -f "$FRIENDICA_PATH/index.php" ]; then + cd "$INSTALL_DIR" || exit 2346824864 if [ -d /repos/friendica ]; then mkdir friendica cp -r -p /repos/friendica/. friendica - cd friendica + cd friendica || exit 24682462 git pull else function_check git_clone - git_clone $FRIENDICA_REPO friendica + git_clone "$FRIENDICA_REPO" friendica fi git checkout $FRIENDICA_COMMIT -b $FRIENDICA_COMMIT set_completion_param "friendica commit" "$FRIENDICA_COMMIT" - rm -rf $FRIENDICA_PATH - mv friendica $FRIENDICA_PATH + rm -rf "$FRIENDICA_PATH" + mv friendica "$FRIENDICA_PATH" - git_clone $FRIENDICA_ADDONS_REPO $FRIENDICA_PATH/addon - cd $FRIENDICA_PATH/addon - git checkout $FRIENDICA_ADDONS_COMMIT -b $FRIENDICA_ADDONS_COMMIT + git_clone "$FRIENDICA_ADDONS_REPO" "$FRIENDICA_PATH/addon" + cd "$FRIENDICA_PATH/addon" || exit 34835685 + git checkout "$FRIENDICA_ADDONS_COMMIT" -b "$FRIENDICA_ADDONS_COMMIT" set_completion_param "friendica addons commit" "$FRIENDICA_ADDONS_COMMIT" - chown -R www-data:www-data $FRIENDICA_PATH + chown -R www-data:www-data "$FRIENDICA_PATH" fi FRIENDICA_ONION_HOSTNAME= @@ -400,158 +402,158 @@ function install_friendica { fi function_check add_ddns_domain - add_ddns_domain $FRIENDICA_DOMAIN_NAME + add_ddns_domain "$FRIENDICA_DOMAIN_NAME" - if [[ $ONION_ONLY == "no" ]]; then + if [[ "$ONION_ONLY" == "no" ]]; then function_check nginx_http_redirect - nginx_http_redirect $FRIENDICA_DOMAIN_NAME - echo 'server {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' listen 443 ssl;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' #listen [::]:443 ssl;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " root $FRIENDICA_PATH;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " server_name $FRIENDICA_DOMAIN_NAME;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " error_log /dev/null;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' index index.php;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' charset utf-8;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' access_log /dev/null;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME + nginx_http_redirect "$FRIENDICA_DOMAIN_NAME" + { echo 'server {'; + echo ' listen 443 ssl;'; + echo ' #listen [::]:443 ssl;'; + echo " root $FRIENDICA_PATH;"; + echo " server_name $FRIENDICA_DOMAIN_NAME;"; + echo " error_log /dev/null;"; + echo ' index index.php;'; + echo ' charset utf-8;'; + echo ' access_log /dev/null;'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME" function_check nginx_ssl - nginx_ssl $FRIENDICA_DOMAIN_NAME + nginx_ssl "$FRIENDICA_DOMAIN_NAME" function_check nginx_disable_sniffing - nginx_disable_sniffing $FRIENDICA_DOMAIN_NAME - echo ' add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' location / {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME + nginx_disable_sniffing "$FRIENDICA_DOMAIN_NAME" + { echo ' add_header Strict-Transport-Security max-age=15768000;'; + echo ''; + echo ' # rewrite to front controller as default rule'; + echo ' location / {'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME" function_check nginx_limits - nginx_limits $FRIENDICA_DOMAIN_NAME - echo ' rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # statically serve these file types when possible' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # otherwise fall back to front controller' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # allow browser to cache them' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' expires 30d;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # block these file types' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' deny all;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # or a unix socket' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' location ~* \.php$ {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME + nginx_limits "$FRIENDICA_DOMAIN_NAME" + { echo " rewrite ^/(.*) /index.php?q=\$uri&\$args last;"; + echo ' }'; + echo ''; + echo ' # statically serve these file types when possible'; + echo ' # otherwise fall back to front controller'; + echo ' # allow browser to cache them'; + echo ' # added .htm for advanced source code editor library'; + echo ' location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {'; + echo ' expires 30d;'; + echo " try_files \$uri /index.php?q=\$uri&\$args;"; + echo ' }'; + echo ''; + echo ' # block these file types'; + echo ' location ~* \.(tpl|md|tgz|log|out)$ {'; + echo ' deny all;'; + echo ' }'; + echo ''; + echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000'; + echo ' # or a unix socket'; + echo ' location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME" function_check nginx_limits - nginx_limits $FRIENDICA_DOMAIN_NAME - echo ' # Zero-day exploit defense.' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # With php-cgi alone:' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # With php-fpm:' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' include fastcgi_params;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' fastcgi_index index.php;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' fastcgi_read_timeout 300;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # deny access to all dot files' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' location ~ /\. {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' deny all;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' location ~ /\.ht {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' deny all;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '}' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME + nginx_limits "$FRIENDICA_DOMAIN_NAME" + { echo ' # Zero-day exploit defense.'; + echo ' # http://forum.nginx.org/read.php?2,88845,page=3'; + echo " # Won't work properly (404 error) if the file is not stored on this"; + echo " # server, which is entirely possible with php-fpm/php-fcgi."; + echo " # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on"; + echo " # another machine. And then cross your fingers that you won't get hacked."; + echo " try_files \$uri \$uri/ /index.php;"; + echo ' # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini'; + echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;'; + echo ' # With php-cgi alone:'; + echo ' # fastcgi_pass 127.0.0.1:9000;'; + echo ' # With php-fpm:'; + echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;'; + echo ' include fastcgi_params;'; + echo ' fastcgi_read_timeout 30;'; + echo ' fastcgi_index index.php;'; + echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;"; + echo ' fastcgi_read_timeout 300;'; + echo ' }'; + echo ''; + echo ' # deny access to all dot files'; + echo ' location ~ /\. {'; + echo ' deny all;'; + echo ' }'; + echo ''; + echo ' location ~ /\.ht {'; + echo ' deny all;'; + echo ' }'; + echo '}'; + echo ''; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME" else - echo 'server {' > /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " listen 127.0.0.1:${FRIENDICA_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " root $FRIENDICA_PATH;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " server_name $FRIENDICA_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " error_log /dev/null;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' index index.php;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' charset utf-8;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' access_log /dev/null;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' location / {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - nginx_limits $FRIENDICA_DOMAIN_NAME - nginx_disable_sniffing $FRIENDICA_DOMAIN_NAME - echo ' rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # statically serve these file types when possible' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # otherwise fall back to front controller' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # allow browser to cache them' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' expires 30d;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # block these file types' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' deny all;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # or a unix socket' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' location ~* \.php$ {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - nginx_limits $FRIENDICA_DOMAIN_NAME - nginx_disable_sniffing $FRIENDICA_DOMAIN_NAME - echo ' # Zero-day exploit defense.' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo " # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # With php-cgi alone:' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # With php-fpm:' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' include fastcgi_params;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' fastcgi_index index.php;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' fastcgi_read_timeout 300;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' # deny access to all dot files' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' location ~ /\. {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' deny all;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' location ~ /\.ht {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' deny all;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo ' }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME - echo '}' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME + { echo 'server {'; + echo " listen 127.0.0.1:${FRIENDICA_ONION_PORT} default_server;"; + echo " root $FRIENDICA_PATH;"; + echo " server_name $FRIENDICA_ONION_HOSTNAME;"; + echo " error_log /dev/null;"; + echo ' index index.php;'; + echo ' charset utf-8;'; + echo ' access_log /dev/null;'; + echo ' add_header Strict-Transport-Security max-age=15768000;'; + echo ''; + echo ' # rewrite to front controller as default rule'; + echo ' location / {'; } > "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME" + nginx_limits "$FRIENDICA_DOMAIN_NAME" + nginx_disable_sniffing "$FRIENDICA_DOMAIN_NAME" + { echo " rewrite ^/(.*) /index.php?q=\$uri&\$args last;"; + echo ' }'; + echo ''; + echo ' # statically serve these file types when possible'; + echo ' # otherwise fall back to front controller'; + echo ' # allow browser to cache them'; + echo ' # added .htm for advanced source code editor library'; + echo ' location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {'; + echo ' expires 30d;'; + echo " try_files \$uri /index.php?q=\$uri&\$args;"; + echo ' }'; + echo ''; + echo ' # block these file types'; + echo ' location ~* \.(tpl|md|tgz|log|out)$ {'; + echo ' deny all;'; + echo ' }'; + echo ''; + echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000'; + echo ' # or a unix socket'; + echo ' location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME" + nginx_limits "$FRIENDICA_DOMAIN_NAME" + nginx_disable_sniffing "$FRIENDICA_DOMAIN_NAME" + { echo ' # Zero-day exploit defense.'; + echo ' # http://forum.nginx.org/read.php?2,88845,page=3'; + echo " # Won't work properly (404 error) if the file is not stored on this"; + echo " # server, which is entirely possible with php-fpm/php-fcgi."; + echo " # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on"; + echo " # another machine. And then cross your fingers that you won't get hacked."; + echo ' try_files $uri $uri/ /index.php;'; + echo ' # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini'; + echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;'; + echo ' # With php-cgi alone:'; + echo ' # fastcgi_pass 127.0.0.1:9000;'; + echo ' # With php-fpm:'; + echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;'; + echo ' include fastcgi_params;'; + echo ' fastcgi_read_timeout 30;'; + echo ' fastcgi_index index.php;'; + echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;"; + echo ' fastcgi_read_timeout 300;'; + echo ' }'; + echo ''; + echo ' # deny access to all dot files'; + echo ' location ~ /\. {'; + echo ' deny all;'; + echo ' }'; + echo ''; + echo ' location ~ /\.ht {'; + echo ' deny all;'; + echo ' }'; + echo '}'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME" fi function_check configure_php configure_php function_check create_site_certificate - create_site_certificate $FRIENDICA_DOMAIN_NAME 'yes' + create_site_certificate "$FRIENDICA_DOMAIN_NAME" 'yes' - if [ ! -d $FRIENDICA_PATH/view/tpl/smarty3 ]; then - mkdir $FRIENDICA_PATH/view/tpl/smarty3 + if [ ! -d "$FRIENDICA_PATH/view/tpl/smarty3" ]; then + mkdir "$FRIENDICA_PATH/view/tpl/smarty3" fi if [ ! -d "$FRIENDICA_PATH/store" ]; then mkdir "$FRIENDICA_PATH/store" @@ -563,9 +565,9 @@ function install_friendica { mkdir "$FRIENDICA_PATH/store/[data]/smarty3" chmod 1777 "$FRIENDICA_PATH/store/[data]/smarty3" fi - chmod 1777 $FRIENDICA_PATH/view/tpl + chmod 1777 "$FRIENDICA_PATH/view/tpl" chown -R www-data:www-data "$FRIENDICA_PATH/store" - chmod 1777 $FRIENDICA_PATH/view/tpl/smarty3 + chmod 1777 "$FRIENDICA_PATH/view/tpl/smarty3" # Ensure that the database gets backed up locally, if remote # backups are not being used @@ -575,55 +577,55 @@ function install_friendica { function_check backup_database_local backup_database_local friendica - chown -R www-data:www-data $FRIENDICA_PATH + chown -R www-data:www-data "$FRIENDICA_PATH" function_check nginx_ensite - nginx_ensite $FRIENDICA_DOMAIN_NAME + nginx_ensite "$FRIENDICA_DOMAIN_NAME" # initialize the database - if [ ! -f $FRIENDICA_PATH/database.sql ]; then + if [ ! -f "$FRIENDICA_PATH/database.sql" ]; then echo $'No database schema found for friendica' exit 252782 fi function_check initialise_database - initialise_database friendica $FRIENDICA_PATH/database.sql + initialise_database friendica "$FRIENDICA_PATH/database.sql" # create the config file - echo ' $FRIENDICA_PATH/.htconfig.php - echo "\$db_host = 'localhost';" >> $FRIENDICA_PATH/.htconfig.php - echo "\$db_user = 'root';" >> $FRIENDICA_PATH/.htconfig.php - echo "\$db_pass = '${MARIADB_PASSWORD}';" >> $FRIENDICA_PATH/.htconfig.php - echo "\$db_data = 'friendica';" >> $FRIENDICA_PATH/.htconfig.php - echo "\$default_timezone = 'Europe/London';" >> $FRIENDICA_PATH/.htconfig.php + { echo ' "$FRIENDICA_PATH/.htconfig.php" if [[ $ONION_ONLY == 'no' ]]; then - echo "\$a->config['system']['baseurl'] = 'https://${FRIENDICA_DOMAIN_NAME}';" >> $FRIENDICA_PATH/.htconfig.php + echo "\$a->config['system']['baseurl'] = 'https://${FRIENDICA_DOMAIN_NAME}';" >> "$FRIENDICA_PATH/.htconfig.php" else - echo "\$a->config['system']['baseurl'] = 'http://${FRIENDICA_ONION_HOSTNAME}';" >> $FRIENDICA_PATH/.htconfig.php + echo "\$a->config['system']['baseurl'] = 'http://${FRIENDICA_ONION_HOSTNAME}';" >> "$FRIENDICA_PATH/.htconfig.php" fi - echo "\$a->config['sitename'] = \"Friendica\";" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['register_policy'] = REGISTER_OPEN;" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['register_text'] = '';" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['admin_email'] = '${MY_EMAIL_ADDRESS}';" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['system']['no_regfullname'] = true;" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['max_import_size'] = 200000;" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['system']['maximagesize'] = 800000;" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['php_path'] = '/usr/bin/php';" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['system']['directory'] = 'http://dir.friendi.ca';" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['system']['allowed_themes'] = 'quattro,vier,duepuntozero,smoothly';" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['system']['theme'] = 'vier';" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['system']['huburl'] = '[internal]';" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['system']['language'] = 'en';" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['system']['rino_encrypt'] = 2;" >> $FRIENDICA_PATH/.htconfig.php - echo "\$a->config['system']['allowed_link_protocols'] = array('mailto', 'cid');" >> $FRIENDICA_PATH/.htconfig.php - chown www-data:www-data $FRIENDICA_PATH/.htconfig.php - chmod 755 $FRIENDICA_PATH/.htconfig.php + { echo "\$a->config['sitename'] = \"Friendica\";"; + echo "\$a->config['register_policy'] = REGISTER_OPEN;"; + echo "\$a->config['register_text'] = '';"; + echo "\$a->config['admin_email'] = '${MY_EMAIL_ADDRESS}';"; + echo "\$a->config['system']['no_regfullname'] = true;"; + echo "\$a->config['max_import_size'] = 200000;"; + echo "\$a->config['system']['maximagesize'] = 800000;"; + echo "\$a->config['php_path'] = '/usr/bin/php';"; + echo "\$a->config['system']['directory'] = 'http://dir.friendi.ca';"; + echo "\$a->config['system']['allowed_themes'] = 'quattro,vier,duepuntozero,smoothly';"; + echo "\$a->config['system']['theme'] = 'vier';"; + echo "\$a->config['system']['huburl'] = '[internal]';"; + echo "\$a->config['system']['language'] = 'en';"; + echo "\$a->config['system']['rino_encrypt'] = 2;"; + echo "\$a->config['system']['allowed_link_protocols'] = array('mailto', 'cid');"; } >> "$FRIENDICA_PATH/.htconfig.php" + chown www-data:www-data "$FRIENDICA_PATH/.htconfig.php" + chmod 755 "$FRIENDICA_PATH/.htconfig.php" systemctl restart mariadb systemctl restart php7.0-fpm systemctl restart nginx systemctl restart cron - ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$FRIENDICA_DOMAIN_NAME" -g friendica --public no + "${PROJECT_NAME}-addemail" -u "$MY_USERNAME" -e "noreply@$FRIENDICA_DOMAIN_NAME" -g friendica --public no set_completion_param "friendica domain" "${FRIENDICA_DOMAIN_NAME}" APP_INSTALLED=1 diff --git a/src/freedombone-app-ghost b/src/freedombone-app-ghost index fa5fb464..e5008d93 100755 --- a/src/freedombone-app-ghost +++ b/src/freedombone-app-ghost @@ -48,14 +48,14 @@ ghost_variables=(GHOST_DOMAIN_NAME function ghost_bust { # kill the started ghost process - kill_pid=$(ps aux | grep "ghost run" | awk -F ' ' '{print $2}' | head -n 1) - kill -9 $kill_pid + kill_pid=$(pgrep "ghost run" | head -n 1) + kill -9 "$kill_pid" - kill_pid=$(ps aux | grep "ghost" | awk -F ' ' '{print $2}' | head -n 1) - kill -9 $kill_pid + kill_pid=$(pgrep "ghost" | head -n 1) + kill -9 "$kill_pid" - kill_pid=$(ps aux | grep "ghost" | awk -F ' ' '{print $2}' | head -n 1) - kill -9 $kill_pid + kill_pid=$(pgrep "ghost" | head -n 1) + kill -9 "$kill_pid" } function logging_on_ghost { @@ -77,9 +77,9 @@ function ghost_replace_jquery { sed -i "s|http://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md sed -i "s|https://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md - cd /var/www/${GHOST_DOMAIN_NAME}/htdocs/current - find ./ -type f -exec sed -i -e 's|https://code.jquery.com|$curr_domain|g' {} \; - find ./ -type f -exec sed -i -e 's|http://code.jquery.com|$curr_domain|g' {} \; + cd "/var/www/${GHOST_DOMAIN_NAME}/htdocs/current" || exit 3468368 + find ./ -type f -exec sed -i -e "s|https://code.jquery.com|$curr_domain|g" {} \; + find ./ -type f -exec sed -i -e "s|http://code.jquery.com|$curr_domain|g" {} \; } function ghost_rss_button { @@ -98,14 +98,14 @@ function ghost_remove_offsite_links { ghost_rss_button # remove google font links - cd /var/www/$GHOST_DOMAIN_NAME/htdocs/current - find ./ -type f -exec sed -i -e 's/fonts.googleapis.com/$curr_domain/g' {} \; + cd "/var/www/$GHOST_DOMAIN_NAME/htdocs/current" || exit 246872424 + find ./ -type f -exec sed -i -e "s/fonts.googleapis.com/$curr_domain/g" {} \; # copy jquery locally previous_jquery_version='1.12.0' jquery_version='1.12.4' if [ ! -f /var/www/$GHOST_DOMAIN_NAME/htdocs/jquery-${jquery_version}.js ]; then - cd /var/www/$GHOST_DOMAIN_NAME/htdocs + cd "/var/www/$GHOST_DOMAIN_NAME/htdocs" || exit 3468746824 wget https://code.jquery.com/jquery-${jquery_version}.js jquery_hash=$(sha256sum jquery-${jquery_version}.js | awk -F ' ' '{print $1}') if [[ "$jquery_hash" != '430f36f9b5f21aae8cc9dca6a81c4d3d84da5175eaedcf2fdc2c226302cb3575' ]]; then @@ -119,27 +119,27 @@ function ghost_remove_offsite_links { } function ghost_replace_proprietary_services { - replace_file=$1 + replace_file="$1" - sed -i 's|Twitter Profile|GNU Social Profile|g' $replace_file - sed -i 's|Twitter profile|GNU Social Profile|g' $replace_file - sed -i 's|Twitter Username|GNU Social Username|g' $replace_file - sed -i 's|twitter.com|quitter.se|g' $replace_file - sed -i 's|Facebook Page|Hubzilla Channel|g' $replace_file - sed -i 's|Facebook Profile|Hubzilla Channel|g' $replace_file - sed -i 's|Facebook profile|Hubzilla Channel|g' $replace_file - sed -i 's|www.facebook.com/username|hubzilladomain/username|g' $replace_file - sed -i 's|www.facebook.com/ghost|hubzilladomain/username|g' $replace_file - sed -i 's|www.facebook.com/testuser|hubzilladomain/username|g' $replace_file - sed -i 's|www.facebook.com/testing|hubzilladomain/username|g' $replace_file - sed -i 's|www.facebook.com/test|hubzilladomain/username|g' $replace_file - sed -i 's|www.facebook.com/yourUsername|hubzilladomain/username|g' $replace_file - sed -i 's|www.facebook.com/yourPage|hubzilladomain/username|g' $replace_file - sed -i 's|Facebook Username|Hubzilla Channel|g' $replace_file - sed -i 's|www.facebook.com|hubzilladomain|g' $replace_file - sed -i 's|facebook value|hubzilla value|g' $replace_file + sed -i 's|Twitter Profile|GNU Social Profile|g' "$replace_file" + sed -i 's|Twitter profile|GNU Social Profile|g' "$replace_file" + sed -i 's|Twitter Username|GNU Social Username|g' "$replace_file" + sed -i 's|twitter.com|quitter.se|g' "$replace_file" + sed -i 's|Facebook Page|Hubzilla Channel|g' "$replace_file" + sed -i 's|Facebook Profile|Hubzilla Channel|g' "$replace_file" + sed -i 's|Facebook profile|Hubzilla Channel|g' "$replace_file" + sed -i 's|www.facebook.com/username|hubzilladomain/username|g' "$replace_file" + sed -i 's|www.facebook.com/ghost|hubzilladomain/username|g' "$replace_file" + sed -i 's|www.facebook.com/testuser|hubzilladomain/username|g' "$replace_file" + sed -i 's|www.facebook.com/testing|hubzilladomain/username|g' "$replace_file" + sed -i 's|www.facebook.com/test|hubzilladomain/username|g' "$replace_file" + sed -i 's|www.facebook.com/yourUsername|hubzilladomain/username|g' "$replace_file" + sed -i 's|www.facebook.com/yourPage|hubzilladomain/username|g' "$replace_file" + sed -i 's|Facebook Username|Hubzilla Channel|g' "$replace_file" + sed -i 's|www.facebook.com|hubzilladomain|g' "$replace_file" + sed -i 's|facebook value|hubzilla value|g' "$replace_file" - sed -i '/
/,/<\/section>/d' $replace_file + sed -i '/