|  | @@ -1,610 +0,0 @@
 | 
	
		
			
			| 1 |  | -#!/bin/bash
 | 
	
		
			
			| 2 |  | -#
 | 
	
		
			
			| 3 |  | -# .---.                  .              .
 | 
	
		
			
			| 4 |  | -# |                      |              |
 | 
	
		
			
			| 5 |  | -# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
 | 
	
		
			
			| 6 |  | -# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
 | 
	
		
			
			| 7 |  | -# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
 | 
	
		
			
			| 8 |  | -#
 | 
	
		
			
			| 9 |  | -#                    Freedom in the Cloud
 | 
	
		
			
			| 10 |  | -#
 | 
	
		
			
			| 11 |  | -# Ghost blog
 | 
	
		
			
			| 12 |  | -#
 | 
	
		
			
			| 13 |  | -# License
 | 
	
		
			
			| 14 |  | -# =======
 | 
	
		
			
			| 15 |  | -#
 | 
	
		
			
			| 16 |  | -# Copyright (C) 2016-2018 Bob Mottram <bob@freedombone.net>
 | 
	
		
			
			| 17 |  | -#
 | 
	
		
			
			| 18 |  | -# This program is free software: you can redistribute it and/or modify
 | 
	
		
			
			| 19 |  | -# it under the terms of the GNU Affero General Public License as published by
 | 
	
		
			
			| 20 |  | -# the Free Software Foundation, either version 3 of the License, or
 | 
	
		
			
			| 21 |  | -# (at your option) any later version.
 | 
	
		
			
			| 22 |  | -#
 | 
	
		
			
			| 23 |  | -# This program is distributed in the hope that it will be useful,
 | 
	
		
			
			| 24 |  | -# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
	
		
			
			| 25 |  | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
	
		
			
			| 26 |  | -# GNU Affero General Public License for more details.
 | 
	
		
			
			| 27 |  | -#
 | 
	
		
			
			| 28 |  | -# You should have received a copy of the GNU Affero General Public License
 | 
	
		
			
			| 29 |  | -# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
	
		
			
			| 30 |  | -
 | 
	
		
			
			| 31 |  | -VARIANTS="full full-vim writer"
 | 
	
		
			
			| 32 |  | -
 | 
	
		
			
			| 33 |  | -IN_DEFAULT_INSTALL=0
 | 
	
		
			
			| 34 |  | -SHOW_ON_ABOUT=1
 | 
	
		
			
			| 35 |  | -
 | 
	
		
			
			| 36 |  | -GHOST_VERSION=1.19.0
 | 
	
		
			
			| 37 |  | -GHOST_DOMAIN_NAME=
 | 
	
		
			
			| 38 |  | -GHOST_CODE=
 | 
	
		
			
			| 39 |  | -GHOST_ONION_PORT=8104
 | 
	
		
			
			| 40 |  | -GHOST_PORT=2368
 | 
	
		
			
			| 41 |  | -
 | 
	
		
			
			| 42 |  | -ghost_variables=(GHOST_DOMAIN_NAME
 | 
	
		
			
			| 43 |  | -                 GHOST_CODE
 | 
	
		
			
			| 44 |  | -                 GHOST_ADMIN_PASSWORD
 | 
	
		
			
			| 45 |  | -                 ONION_ONLY
 | 
	
		
			
			| 46 |  | -                 DDNS_PROVIDER
 | 
	
		
			
			| 47 |  | -                 MY_USERNAME)
 | 
	
		
			
			| 48 |  | -
 | 
	
		
			
			| 49 |  | -function ghost_bust {
 | 
	
		
			
			| 50 |  | -    # kill the started ghost process
 | 
	
		
			
			| 51 |  | -    kill_pid=$(pgrep "ghost run" | head -n 1)
 | 
	
		
			
			| 52 |  | -    kill -9 "$kill_pid"
 | 
	
		
			
			| 53 |  | -
 | 
	
		
			
			| 54 |  | -    kill_pid=$(pgrep "ghost" | head -n 1)
 | 
	
		
			
			| 55 |  | -    kill -9 "$kill_pid"
 | 
	
		
			
			| 56 |  | -
 | 
	
		
			
			| 57 |  | -    kill_pid=$(pgrep "ghost" | head -n 1)
 | 
	
		
			
			| 58 |  | -    kill -9 "$kill_pid"
 | 
	
		
			
			| 59 |  | -}
 | 
	
		
			
			| 60 |  | -
 | 
	
		
			
			| 61 |  | -function logging_on_ghost {
 | 
	
		
			
			| 62 |  | -    echo -n ''
 | 
	
		
			
			| 63 |  | -}
 | 
	
		
			
			| 64 |  | -
 | 
	
		
			
			| 65 |  | -function logging_off_ghost {
 | 
	
		
			
			| 66 |  | -    echo -n ''
 | 
	
		
			
			| 67 |  | -}
 | 
	
		
			
			| 68 |  | -
 | 
	
		
			
			| 69 |  | -function ghost_replace_jquery {
 | 
	
		
			
			| 70 |  | -    curr_domain="https://$GHOST_DOMAIN_NAME"
 | 
	
		
			
			| 71 |  | -    if [[ "$ONION_ONLY" != 'no' ]]; then
 | 
	
		
			
			| 72 |  | -        curr_domain="http://$GHOST_ONION_HOSTNAME"
 | 
	
		
			
			| 73 |  | -    fi
 | 
	
		
			
			| 74 |  | -
 | 
	
		
			
			| 75 |  | -    sed -i "s|src=\"https://code.jquery.com/jquery-.*|src=\"$curr_domain/jquery-${jquery_version}.js\"|g" current/content/themes/casper/default.hbs
 | 
	
		
			
			| 76 |  | -    sed -i "s|src=\"https://code.jquery.com/jquery-.*|src=\"$curr_domain/jquery-${jquery_version}.js\"></script>|g" current/node_modules/gscan/app/tpl/layouts/default.hbs
 | 
	
		
			
			| 77 |  | -    sed -i "s|http://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md
 | 
	
		
			
			| 78 |  | -    sed -i "s|https://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md
 | 
	
		
			
			| 79 |  | -
 | 
	
		
			
			| 80 |  | -    cd "/var/www/${GHOST_DOMAIN_NAME}/htdocs/current" || exit 3468368
 | 
	
		
			
			| 81 |  | -    find ./ -type f -exec sed -i -e "s|https://code.jquery.com|$curr_domain|g" {} \;
 | 
	
		
			
			| 82 |  | -    find ./ -type f -exec sed -i -e "s|http://code.jquery.com|$curr_domain|g" {} \;
 | 
	
		
			
			| 83 |  | -}
 | 
	
		
			
			| 84 |  | -
 | 
	
		
			
			| 85 |  | -function ghost_rss_button {
 | 
	
		
			
			| 86 |  | -    # remove feedly -aaargh!
 | 
	
		
			
			| 87 |  | -    sed -i 's|http://cloud.feedly.com/#subscription/feed/{{@blog.url}}/rss/|{{@blog.url}}/rss/|g' /var/www/$GHOST_DOMAIN_NAME/htdocs/versions/${GHOST_VERSION}/content/themes/casper/partials/site-nav.hbs
 | 
	
		
			
			| 88 |  | -    sed -i 's|http://cloud.feedly.com/#subscription/feed/{{url absolute="true"}}/rss/|{{url absolute="true"}}rss/|g' /var/www/$GHOST_DOMAIN_NAME/htdocs/versions/${GHOST_VERSION}/content/themes/casper/author.hbs
 | 
	
		
			
			| 89 |  | -
 | 
	
		
			
			| 90 |  | -}
 | 
	
		
			
			| 91 |  | -
 | 
	
		
			
			| 92 |  | -function ghost_remove_offsite_links {
 | 
	
		
			
			| 93 |  | -    curr_domain="$GHOST_DOMAIN_NAME"
 | 
	
		
			
			| 94 |  | -    if [[ "$ONION_ONLY" != 'no' ]]; then
 | 
	
		
			
			| 95 |  | -        curr_domain="$GHOST_ONION_HOSTNAME"
 | 
	
		
			
			| 96 |  | -    fi
 | 
	
		
			
			| 97 |  | -
 | 
	
		
			
			| 98 |  | -    ghost_rss_button
 | 
	
		
			
			| 99 |  | -
 | 
	
		
			
			| 100 |  | -    # remove google font links
 | 
	
		
			
			| 101 |  | -    cd "/var/www/$GHOST_DOMAIN_NAME/htdocs/current" || exit 246872424
 | 
	
		
			
			| 102 |  | -    find ./ -type f -exec sed -i -e "s/fonts.googleapis.com/$curr_domain/g" {} \;
 | 
	
		
			
			| 103 |  | -
 | 
	
		
			
			| 104 |  | -    # copy jquery locally
 | 
	
		
			
			| 105 |  | -    previous_jquery_version='1.12.0'
 | 
	
		
			
			| 106 |  | -    jquery_version='1.12.4'
 | 
	
		
			
			| 107 |  | -    if [ ! -f /var/www/$GHOST_DOMAIN_NAME/htdocs/jquery-${jquery_version}.js ]; then
 | 
	
		
			
			| 108 |  | -        cd "/var/www/$GHOST_DOMAIN_NAME/htdocs" || exit 3468746824
 | 
	
		
			
			| 109 |  | -        wget https://code.jquery.com/jquery-${jquery_version}.js
 | 
	
		
			
			| 110 |  | -        jquery_hash=$(sha256sum jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
 | 
	
		
			
			| 111 |  | -        if [[ "$jquery_hash" != '430f36f9b5f21aae8cc9dca6a81c4d3d84da5175eaedcf2fdc2c226302cb3575' ]]; then
 | 
	
		
			
			| 112 |  | -            echo $'Unexpected jquery hash value'
 | 
	
		
			
			| 113 |  | -            exit 258442
 | 
	
		
			
			| 114 |  | -        fi
 | 
	
		
			
			| 115 |  | -    fi
 | 
	
		
			
			| 116 |  | -    ghost_replace_jquery
 | 
	
		
			
			| 117 |  | -    previous_jquery_version='1.11.3'
 | 
	
		
			
			| 118 |  | -    ghost_replace_jquery
 | 
	
		
			
			| 119 |  | -}
 | 
	
		
			
			| 120 |  | -
 | 
	
		
			
			| 121 |  | -function ghost_replace_proprietary_services {
 | 
	
		
			
			| 122 |  | -    replace_file="$1"
 | 
	
		
			
			| 123 |  | -
 | 
	
		
			
			| 124 |  | -    sed -i 's|Twitter Profile|GNU Social Profile|g' "$replace_file"
 | 
	
		
			
			| 125 |  | -    sed -i 's|Twitter profile|GNU Social Profile|g' "$replace_file"
 | 
	
		
			
			| 126 |  | -    sed -i 's|Twitter Username|GNU Social Username|g' "$replace_file"
 | 
	
		
			
			| 127 |  | -    sed -i 's|twitter.com|quitter.se|g' "$replace_file"
 | 
	
		
			
			| 128 |  | -    sed -i 's|Facebook Page|Hubzilla Channel|g' "$replace_file"
 | 
	
		
			
			| 129 |  | -    sed -i 's|Facebook Profile|Hubzilla Channel|g' "$replace_file"
 | 
	
		
			
			| 130 |  | -    sed -i 's|Facebook profile|Hubzilla Channel|g' "$replace_file"
 | 
	
		
			
			| 131 |  | -    sed -i 's|www.facebook.com/username|hubzilladomain/username|g' "$replace_file"
 | 
	
		
			
			| 132 |  | -    sed -i 's|www.facebook.com/ghost|hubzilladomain/username|g' "$replace_file"
 | 
	
		
			
			| 133 |  | -    sed -i 's|www.facebook.com/testuser|hubzilladomain/username|g' "$replace_file"
 | 
	
		
			
			| 134 |  | -    sed -i 's|www.facebook.com/testing|hubzilladomain/username|g' "$replace_file"
 | 
	
		
			
			| 135 |  | -    sed -i 's|www.facebook.com/test|hubzilladomain/username|g' "$replace_file"
 | 
	
		
			
			| 136 |  | -    sed -i 's|www.facebook.com/yourUsername|hubzilladomain/username|g' "$replace_file"
 | 
	
		
			
			| 137 |  | -    sed -i 's|www.facebook.com/yourPage|hubzilladomain/username|g' "$replace_file"
 | 
	
		
			
			| 138 |  | -    sed -i 's|Facebook Username|Hubzilla Channel|g' "$replace_file"
 | 
	
		
			
			| 139 |  | -    sed -i 's|www.facebook.com|hubzilladomain|g' "$replace_file"
 | 
	
		
			
			| 140 |  | -    sed -i 's|facebook value|hubzilla value|g' "$replace_file"
 | 
	
		
			
			| 141 |  | -
 | 
	
		
			
			| 142 |  | -    sed -i '/<section class="share">/,/<\/section>/d' "$replace_file"
 | 
	
		
			
			| 143 |  | -}
 | 
	
		
			
			| 144 |  | -
 | 
	
		
			
			| 145 |  | -function ghost_replace_services {
 | 
	
		
			
			| 146 |  | -    ghost_replace_proprietary_services /var/www/${GHOST_DOMAIN_NAME}/htdocs/content/themes/casper/post.hbs
 | 
	
		
			
			| 147 |  | -}
 | 
	
		
			
			| 148 |  | -
 | 
	
		
			
			| 149 |  | -function remove_user_ghost {
 | 
	
		
			
			| 150 |  | -    remove_username="$1"
 | 
	
		
			
			| 151 |  | -}
 | 
	
		
			
			| 152 |  | -
 | 
	
		
			
			| 153 |  | -function add_user_ghost {
 | 
	
		
			
			| 154 |  | -    if [[ $(app_is_installed ghost) == "0" ]]; then
 | 
	
		
			
			| 155 |  | -        echo '0'
 | 
	
		
			
			| 156 |  | -        return
 | 
	
		
			
			| 157 |  | -    fi
 | 
	
		
			
			| 158 |  | -
 | 
	
		
			
			| 159 |  | -    new_username="$1"
 | 
	
		
			
			| 160 |  | -    new_user_password="$2"
 | 
	
		
			
			| 161 |  | -
 | 
	
		
			
			| 162 |  | -    echo '0'
 | 
	
		
			
			| 163 |  | -}
 | 
	
		
			
			| 164 |  | -
 | 
	
		
			
			| 165 |  | -function install_interactive_ghost {
 | 
	
		
			
			| 166 |  | -    if [ ! "$ONION_ONLY" ]; then
 | 
	
		
			
			| 167 |  | -        ONION_ONLY='no'
 | 
	
		
			
			| 168 |  | -    fi
 | 
	
		
			
			| 169 |  | -
 | 
	
		
			
			| 170 |  | -    if [[ $ONION_ONLY != "no" ]]; then
 | 
	
		
			
			| 171 |  | -        GHOST_DOMAIN_NAME='ghost.local'
 | 
	
		
			
			| 172 |  | -        write_config_param "GHOST_DOMAIN_NAME" "$GHOST_DOMAIN_NAME"
 | 
	
		
			
			| 173 |  | -    else
 | 
	
		
			
			| 174 |  | -        function_check interactive_site_details
 | 
	
		
			
			| 175 |  | -        interactive_site_details "ghost" "GHOST_DOMAIN_NAME" "GHOST_CODE"
 | 
	
		
			
			| 176 |  | -    fi
 | 
	
		
			
			| 177 |  | -    APP_INSTALLED=1
 | 
	
		
			
			| 178 |  | -}
 | 
	
		
			
			| 179 |  | -
 | 
	
		
			
			| 180 |  | -function change_password_ghost {
 | 
	
		
			
			| 181 |  | -    #GHOST_USERNAME="$1"
 | 
	
		
			
			| 182 |  | -    GHOST_PASSWORD="$2"
 | 
	
		
			
			| 183 |  | -    if [ ${#GHOST_PASSWORD} -lt 8 ]; then
 | 
	
		
			
			| 184 |  | -        echo $'Ghost password is too short'
 | 
	
		
			
			| 185 |  | -        return
 | 
	
		
			
			| 186 |  | -    fi
 | 
	
		
			
			| 187 |  | -    #"${PROJECT_NAME}-pass" -u "$GHOST_USERNAME" -a ghost -p "$GHOST_PASSWORD"
 | 
	
		
			
			| 188 |  | -}
 | 
	
		
			
			| 189 |  | -
 | 
	
		
			
			| 190 |  | -function reconfigure_ghost {
 | 
	
		
			
			| 191 |  | -    echo -n ''
 | 
	
		
			
			| 192 |  | -}
 | 
	
		
			
			| 193 |  | -
 | 
	
		
			
			| 194 |  | -function upgrade_ghost {
 | 
	
		
			
			| 195 |  | -    CURR_GHOST_VERSION=$(get_completion_param "ghost version")
 | 
	
		
			
			| 196 |  | -    if [[ "${CURR_GHOST_VERSION}" == "${GHOST_VERSION}" ]]; then
 | 
	
		
			
			| 197 |  | -        return
 | 
	
		
			
			| 198 |  | -    fi
 | 
	
		
			
			| 199 |  | -
 | 
	
		
			
			| 200 |  | -    read_config_param GHOST_DOMAIN_NAME
 | 
	
		
			
			| 201 |  | -
 | 
	
		
			
			| 202 |  | -    if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs ]; then
 | 
	
		
			
			| 203 |  | -        return
 | 
	
		
			
			| 204 |  | -    fi
 | 
	
		
			
			| 205 |  | -
 | 
	
		
			
			| 206 |  | -    systemctl stop ghost
 | 
	
		
			
			| 207 |  | -    ghost_bust
 | 
	
		
			
			| 208 |  | -
 | 
	
		
			
			| 209 |  | -    cd "/var/www/$GHOST_DOMAIN_NAME/htdocs" || exit 3468463
 | 
	
		
			
			| 210 |  | -
 | 
	
		
			
			| 211 |  | -    npm i -g ghost-cli
 | 
	
		
			
			| 212 |  | -    /root/.npm-global/bin/ghost update &
 | 
	
		
			
			| 213 |  | -    sleep 200
 | 
	
		
			
			| 214 |  | -    ghost_bust
 | 
	
		
			
			| 215 |  | -
 | 
	
		
			
			| 216 |  | -    ghost_replace_services
 | 
	
		
			
			| 217 |  | -    ghost_remove_offsite_links
 | 
	
		
			
			| 218 |  | -
 | 
	
		
			
			| 219 |  | -    chown root:root /root/.npm-global/bin/ghost
 | 
	
		
			
			| 220 |  | -    chown -R root:root /usr/local/lib
 | 
	
		
			
			| 221 |  | -    chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
 | 
	
		
			
			| 222 |  | -    systemctl restart ghost
 | 
	
		
			
			| 223 |  | -    sed -i "s|ghost version.*|ghost version:${GHOST_VERSION}|g" "${COMPLETION_FILE}"
 | 
	
		
			
			| 224 |  | -}
 | 
	
		
			
			| 225 |  | -
 | 
	
		
			
			| 226 |  | -function backup_local_ghost {
 | 
	
		
			
			| 227 |  | -    GHOST_DOMAIN_NAME='ghost.local'
 | 
	
		
			
			| 228 |  | -    if grep -q "ghost domain" "$COMPLETION_FILE"; then
 | 
	
		
			
			| 229 |  | -        GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
 | 
	
		
			
			| 230 |  | -    fi
 | 
	
		
			
			| 231 |  | -
 | 
	
		
			
			| 232 |  | -    suspend_site "${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 233 |  | -    systemctl stop ghost
 | 
	
		
			
			| 234 |  | -
 | 
	
		
			
			| 235 |  | -    ghost_path=/var/www/${GHOST_DOMAIN_NAME}/htdocs/content
 | 
	
		
			
			| 236 |  | -    if [ -d "$ghost_path" ]; then
 | 
	
		
			
			| 237 |  | -        backup_directory_to_usb "$ghost_path" ghostcontent
 | 
	
		
			
			| 238 |  | -    fi
 | 
	
		
			
			| 239 |  | -
 | 
	
		
			
			| 240 |  | -    ghost_path=/var/www/${GHOST_DOMAIN_NAME}/htdocs/current/content
 | 
	
		
			
			| 241 |  | -    if [ -d "$ghost_path" ]; then
 | 
	
		
			
			| 242 |  | -        backup_directory_to_usb "$ghost_path" ghostcurrent
 | 
	
		
			
			| 243 |  | -    fi
 | 
	
		
			
			| 244 |  | -
 | 
	
		
			
			| 245 |  | -    systemctl start ghost
 | 
	
		
			
			| 246 |  | -    restart_site
 | 
	
		
			
			| 247 |  | -}
 | 
	
		
			
			| 248 |  | -
 | 
	
		
			
			| 249 |  | -function restore_local_ghost {
 | 
	
		
			
			| 250 |  | -    GHOST_DOMAIN_NAME='ghost.local'
 | 
	
		
			
			| 251 |  | -    if grep -q "ghost domain" "$COMPLETION_FILE"; then
 | 
	
		
			
			| 252 |  | -        GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
 | 
	
		
			
			| 253 |  | -    fi
 | 
	
		
			
			| 254 |  | -    if [ "$GHOST_DOMAIN_NAME" ]; then
 | 
	
		
			
			| 255 |  | -        suspend_site "${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 256 |  | -        systemctl stop ghost
 | 
	
		
			
			| 257 |  | -
 | 
	
		
			
			| 258 |  | -        temp_restore_dir=/root/tempghostcontent
 | 
	
		
			
			| 259 |  | -        function_check restore_directory_from_usb
 | 
	
		
			
			| 260 |  | -        restore_directory_from_usb $temp_restore_dir ghostcontent
 | 
	
		
			
			| 261 |  | -        if [ -d $temp_restore_dir ]; then
 | 
	
		
			
			| 262 |  | -            if [ -d "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content" ]; then
 | 
	
		
			
			| 263 |  | -                cp -r "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content/"* "/var/www/$GHOST_DOMAIN_NAME/htdocs/content/"
 | 
	
		
			
			| 264 |  | -            else
 | 
	
		
			
			| 265 |  | -                if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs/content" ]; then
 | 
	
		
			
			| 266 |  | -                    mkdir "/var/www/$GHOST_DOMAIN_NAME/htdocs/content"
 | 
	
		
			
			| 267 |  | -                fi
 | 
	
		
			
			| 268 |  | -                cp -r $temp_restore_dir/* "/var/www/$GHOST_DOMAIN_NAME/htdocs/content/"
 | 
	
		
			
			| 269 |  | -            fi
 | 
	
		
			
			| 270 |  | -            chown -R ghost:ghost "/var/www/$GHOST_DOMAIN_NAME/htdocs/content"
 | 
	
		
			
			| 271 |  | -            rm -rf $temp_restore_dir
 | 
	
		
			
			| 272 |  | -        fi
 | 
	
		
			
			| 273 |  | -
 | 
	
		
			
			| 274 |  | -        temp_restore_dir=/root/tempghostcurrent
 | 
	
		
			
			| 275 |  | -        function_check restore_directory_from_usb
 | 
	
		
			
			| 276 |  | -        restore_directory_from_usb $temp_restore_dir ghostcurrent
 | 
	
		
			
			| 277 |  | -        if [ -d $temp_restore_dir ]; then
 | 
	
		
			
			| 278 |  | -            if [ -d "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content" ]; then
 | 
	
		
			
			| 279 |  | -                cp -r "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/"* "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/"
 | 
	
		
			
			| 280 |  | -            else
 | 
	
		
			
			| 281 |  | -                if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content" ]; then
 | 
	
		
			
			| 282 |  | -                    mkdir -p "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content"
 | 
	
		
			
			| 283 |  | -                fi
 | 
	
		
			
			| 284 |  | -                cp -r $temp_restore_dir/* "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/"
 | 
	
		
			
			| 285 |  | -            fi
 | 
	
		
			
			| 286 |  | -            chown -R ghost:ghost "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content"
 | 
	
		
			
			| 287 |  | -            rm -rf $temp_restore_dir
 | 
	
		
			
			| 288 |  | -        fi
 | 
	
		
			
			| 289 |  | -
 | 
	
		
			
			| 290 |  | -        systemctl start ghost
 | 
	
		
			
			| 291 |  | -        restart_site
 | 
	
		
			
			| 292 |  | -    fi
 | 
	
		
			
			| 293 |  | -}
 | 
	
		
			
			| 294 |  | -
 | 
	
		
			
			| 295 |  | -function backup_remote_ghost {
 | 
	
		
			
			| 296 |  | -    GHOST_DOMAIN_NAME='ghost.local'
 | 
	
		
			
			| 297 |  | -    if grep -q "ghost domain" "$COMPLETION_FILE"; then
 | 
	
		
			
			| 298 |  | -        GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
 | 
	
		
			
			| 299 |  | -    fi
 | 
	
		
			
			| 300 |  | -
 | 
	
		
			
			| 301 |  | -    suspend_site "${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 302 |  | -
 | 
	
		
			
			| 303 |  | -    temp_backup_dir=/var/www/${GHOST_DOMAIN_NAME}/htdocs/content
 | 
	
		
			
			| 304 |  | -    if [ -d "$temp_backup_dir" ]; then
 | 
	
		
			
			| 305 |  | -        backup_directory_to_friend "$temp_backup_dir" ghostcontent
 | 
	
		
			
			| 306 |  | -    else
 | 
	
		
			
			| 307 |  | -        restart_site
 | 
	
		
			
			| 308 |  | -        echo $"Ghost domain specified but not found in /var/www/${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 309 |  | -        exit 2578
 | 
	
		
			
			| 310 |  | -    fi
 | 
	
		
			
			| 311 |  | -
 | 
	
		
			
			| 312 |  | -    temp_backup_dir=/var/www/${GHOST_DOMAIN_NAME}/htdocs/current/content
 | 
	
		
			
			| 313 |  | -    if [ -d "$temp_backup_dir" ]; then
 | 
	
		
			
			| 314 |  | -        backup_directory_to_friend "$temp_backup_dir" ghostcurrent
 | 
	
		
			
			| 315 |  | -    else
 | 
	
		
			
			| 316 |  | -        restart_site
 | 
	
		
			
			| 317 |  | -        echo $"Ghost domain specified but not found in $temp_backup_dir"
 | 
	
		
			
			| 318 |  | -        exit 78353
 | 
	
		
			
			| 319 |  | -    fi
 | 
	
		
			
			| 320 |  | -
 | 
	
		
			
			| 321 |  | -    restart_site
 | 
	
		
			
			| 322 |  | -}
 | 
	
		
			
			| 323 |  | -
 | 
	
		
			
			| 324 |  | -function restore_remote_ghost {
 | 
	
		
			
			| 325 |  | -    GHOST_DOMAIN_NAME='ghost.local'
 | 
	
		
			
			| 326 |  | -    if grep -q "ghost domain" "$COMPLETION_FILE"; then
 | 
	
		
			
			| 327 |  | -        GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
 | 
	
		
			
			| 328 |  | -    fi
 | 
	
		
			
			| 329 |  | -    suspend_site "${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 330 |  | -
 | 
	
		
			
			| 331 |  | -    systemctl stop ghost
 | 
	
		
			
			| 332 |  | -
 | 
	
		
			
			| 333 |  | -    temp_restore_dir=/root/tempghostcontent
 | 
	
		
			
			| 334 |  | -    function_check restore_directory_from_friend
 | 
	
		
			
			| 335 |  | -    restore_directory_from_friend $temp_restore_dir ghostcontent
 | 
	
		
			
			| 336 |  | -    if [ -d $temp_restore_dir ]; then
 | 
	
		
			
			| 337 |  | -        if [ -d "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content" ]; then
 | 
	
		
			
			| 338 |  | -            cp -r "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content/"* "/var/www/$GHOST_DOMAIN_NAME/htdocs/content/"
 | 
	
		
			
			| 339 |  | -        else
 | 
	
		
			
			| 340 |  | -            if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs/content" ]; then
 | 
	
		
			
			| 341 |  | -                mkdir "/var/www/$GHOST_DOMAIN_NAME/htdocs/content"
 | 
	
		
			
			| 342 |  | -            fi
 | 
	
		
			
			| 343 |  | -            cp -r $temp_restore_dir/* "/var/www/$GHOST_DOMAIN_NAME/htdocs/content/"
 | 
	
		
			
			| 344 |  | -        fi
 | 
	
		
			
			| 345 |  | -        chown -R ghost: "/var/www/$GHOST_DOMAIN_NAME/htdocs"
 | 
	
		
			
			| 346 |  | -        rm -rf $temp_restore_dir
 | 
	
		
			
			| 347 |  | -    fi
 | 
	
		
			
			| 348 |  | -
 | 
	
		
			
			| 349 |  | -    temp_restore_dir=/root/tempghostcurrent
 | 
	
		
			
			| 350 |  | -    function_check restore_directory_from_friend
 | 
	
		
			
			| 351 |  | -    restore_directory_from_friend $temp_restore_dir ghostcurrent
 | 
	
		
			
			| 352 |  | -    if [ -d $temp_restore_dir ]; then
 | 
	
		
			
			| 353 |  | -        if [ -d "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content" ]; then
 | 
	
		
			
			| 354 |  | -            cp -r "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/"* "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/"
 | 
	
		
			
			| 355 |  | -        else
 | 
	
		
			
			| 356 |  | -            if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content" ]; then
 | 
	
		
			
			| 357 |  | -                mkdir -p "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content"
 | 
	
		
			
			| 358 |  | -            fi
 | 
	
		
			
			| 359 |  | -            cp -r $temp_restore_dir/* "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/"
 | 
	
		
			
			| 360 |  | -        fi
 | 
	
		
			
			| 361 |  | -        chown -R ghost: "/var/www/$GHOST_DOMAIN_NAME/htdocs"
 | 
	
		
			
			| 362 |  | -        rm -rf $temp_restore_dir
 | 
	
		
			
			| 363 |  | -    fi
 | 
	
		
			
			| 364 |  | -
 | 
	
		
			
			| 365 |  | -    systemctl start ghost
 | 
	
		
			
			| 366 |  | -    restart_site
 | 
	
		
			
			| 367 |  | -}
 | 
	
		
			
			| 368 |  | -
 | 
	
		
			
			| 369 |  | -function remove_ghost {
 | 
	
		
			
			| 370 |  | -    if [ ${#GHOST_DOMAIN_NAME} -eq 0 ]; then
 | 
	
		
			
			| 371 |  | -        return
 | 
	
		
			
			| 372 |  | -    fi
 | 
	
		
			
			| 373 |  | -
 | 
	
		
			
			| 374 |  | -    systemctl stop ghost
 | 
	
		
			
			| 375 |  | -    systemctl disable ghost
 | 
	
		
			
			| 376 |  | -    rm /etc/systemd/system/ghost.service
 | 
	
		
			
			| 377 |  | -    systemctl daemon-reload
 | 
	
		
			
			| 378 |  | -
 | 
	
		
			
			| 379 |  | -    npm uninstall -g ghost-cli
 | 
	
		
			
			| 380 |  | -
 | 
	
		
			
			| 381 |  | -    function_check remove_nodejs
 | 
	
		
			
			| 382 |  | -    remove_nodejs ghost
 | 
	
		
			
			| 383 |  | -
 | 
	
		
			
			| 384 |  | -    read_config_param "GHOST_DOMAIN_NAME"
 | 
	
		
			
			| 385 |  | -    nginx_dissite "$GHOST_DOMAIN_NAME"
 | 
	
		
			
			| 386 |  | -    remove_certs "${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 387 |  | -    if [ -f "/etc/nginx/sites-available/$GHOST_DOMAIN_NAME" ]; then
 | 
	
		
			
			| 388 |  | -        rm -f "/etc/nginx/sites-available/$GHOST_DOMAIN_NAME"
 | 
	
		
			
			| 389 |  | -    fi
 | 
	
		
			
			| 390 |  | -    if [ -d "/var/www/$GHOST_DOMAIN_NAME" ]; then
 | 
	
		
			
			| 391 |  | -        rm -rf "/var/www/$GHOST_DOMAIN_NAME"
 | 
	
		
			
			| 392 |  | -    fi
 | 
	
		
			
			| 393 |  | -    remove_config_param GHOST_DOMAIN_NAME
 | 
	
		
			
			| 394 |  | -    remove_config_param GHOST_CODE
 | 
	
		
			
			| 395 |  | -    function_check remove_onion_service
 | 
	
		
			
			| 396 |  | -    remove_onion_service ghost ${GHOST_ONION_PORT}
 | 
	
		
			
			| 397 |  | -    remove_completion_param "install_ghost"
 | 
	
		
			
			| 398 |  | -    sed -i '/Ghost/d' "$COMPLETION_FILE"
 | 
	
		
			
			| 399 |  | -    sed -i '/ghost/d' "$COMPLETION_FILE"
 | 
	
		
			
			| 400 |  | -
 | 
	
		
			
			| 401 |  | -    groupdel -f ghost
 | 
	
		
			
			| 402 |  | -    userdel -r ghost
 | 
	
		
			
			| 403 |  | -
 | 
	
		
			
			| 404 |  | -    function_check remove_ddns_domain
 | 
	
		
			
			| 405 |  | -    remove_ddns_domain "$GHOST_DOMAIN_NAME"
 | 
	
		
			
			| 406 |  | -}
 | 
	
		
			
			| 407 |  | -
 | 
	
		
			
			| 408 |  | -function install_ghost {
 | 
	
		
			
			| 409 |  | -    check_ram_availability 900
 | 
	
		
			
			| 410 |  | -
 | 
	
		
			
			| 411 |  | -    if [ ! $ONION_ONLY ]; then
 | 
	
		
			
			| 412 |  | -        ONION_ONLY='no'
 | 
	
		
			
			| 413 |  | -    fi
 | 
	
		
			
			| 414 |  | -
 | 
	
		
			
			| 415 |  | -    if [ ! "$GHOST_DOMAIN_NAME" ]; then
 | 
	
		
			
			| 416 |  | -        echo $'The ghost domain name was not specified'
 | 
	
		
			
			| 417 |  | -        exit 5062
 | 
	
		
			
			| 418 |  | -    fi
 | 
	
		
			
			| 419 |  | -
 | 
	
		
			
			| 420 |  | -    # for the avatar changing command
 | 
	
		
			
			| 421 |  | -    apt-get -yq install unzip wget
 | 
	
		
			
			| 422 |  | -
 | 
	
		
			
			| 423 |  | -    if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs" ]; then
 | 
	
		
			
			| 424 |  | -        mkdir -p "/var/www/$GHOST_DOMAIN_NAME/htdocs"
 | 
	
		
			
			| 425 |  | -    fi
 | 
	
		
			
			| 426 |  | -    cd "/var/www/$GHOST_DOMAIN_NAME/htdocs" || exit 26422842
 | 
	
		
			
			| 427 |  | -
 | 
	
		
			
			| 428 |  | -    function_check install_nodejs
 | 
	
		
			
			| 429 |  | -    install_nodejs ghost
 | 
	
		
			
			| 430 |  | -
 | 
	
		
			
			| 431 |  | -    # now install ghost itself
 | 
	
		
			
			| 432 |  | -    npm install -g ghost-cli@1.6.0
 | 
	
		
			
			| 433 |  | -    if [ ! -f /root/.npm-global/bin/ghost ]; then
 | 
	
		
			
			| 434 |  | -        echo $'ghost was not installed'
 | 
	
		
			
			| 435 |  | -        exit 738539
 | 
	
		
			
			| 436 |  | -    fi
 | 
	
		
			
			| 437 |  | -
 | 
	
		
			
			| 438 |  | -    GHOST_ONION_HOSTNAME=$(add_onion_service ghost 80 ${GHOST_ONION_PORT})
 | 
	
		
			
			| 439 |  | -
 | 
	
		
			
			| 440 |  | -    npm install -g yarn
 | 
	
		
			
			| 441 |  | -    if [ ! -f /root/.npm-global/bin/yarn ]; then
 | 
	
		
			
			| 442 |  | -        echo $'yarn was not installed'
 | 
	
		
			
			| 443 |  | -        exit 2648246
 | 
	
		
			
			| 444 |  | -    fi
 | 
	
		
			
			| 445 |  | -    yarn install --no-emoji --no-progress
 | 
	
		
			
			| 446 |  | -    yarn cache clean
 | 
	
		
			
			| 447 |  | -    adduser --system --home="/var/www/${GHOST_DOMAIN_NAME}/htdocs/" --group ghost
 | 
	
		
			
			| 448 |  | -    rm -rf "/var/www/$GHOST_DOMAIN_NAME/htdocs/"*
 | 
	
		
			
			| 449 |  | -    echo "PATH=$PATH" > setup_ghost
 | 
	
		
			
			| 450 |  | -    echo "ghost install ${GHOST_VERSION} --no-prompt --db=sqlite3 --port ${GHOST_PORT} --verbose" >> setup_ghost
 | 
	
		
			
			| 451 |  | -    chmod +x setup_ghost
 | 
	
		
			
			| 452 |  | -    su -c "setup_ghost" - ghost
 | 
	
		
			
			| 453 |  | -
 | 
	
		
			
			| 454 |  | -    if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs/versions" ]; then
 | 
	
		
			
			| 455 |  | -        echo $'versions directory was not found'
 | 
	
		
			
			| 456 |  | -        exit 782523462
 | 
	
		
			
			| 457 |  | -    fi
 | 
	
		
			
			| 458 |  | -    if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs/content" ]; then
 | 
	
		
			
			| 459 |  | -        echo $'content directory was not found'
 | 
	
		
			
			| 460 |  | -        exit 68352682
 | 
	
		
			
			| 461 |  | -    fi
 | 
	
		
			
			| 462 |  | -
 | 
	
		
			
			| 463 |  | -    npm install -g knex-migrator
 | 
	
		
			
			| 464 |  | -    if [ ! -f "/var/www/$GHOST_DOMAIN_NAME/htdocs/versions/${GHOST_VERSION}/MigratorConfig.js" ]; then
 | 
	
		
			
			| 465 |  | -        echo $'MigratorConfig.js was not found'
 | 
	
		
			
			| 466 |  | -        exit 62783538
 | 
	
		
			
			| 467 |  | -    fi
 | 
	
		
			
			| 468 |  | -    cp "/var/www/$GHOST_DOMAIN_NAME/htdocs/versions/${GHOST_VERSION}/MigratorConfig.js" "/var/www/$GHOST_DOMAIN_NAME/htdocs"
 | 
	
		
			
			| 469 |  | -    chown -R ghost: "/var/www/$GHOST_DOMAIN_NAME/htdocs"
 | 
	
		
			
			| 470 |  | -    cd "/var/www/$GHOST_DOMAIN_NAME/htdocs/current" || exit 783452464
 | 
	
		
			
			| 471 |  | -    knex-migrator init
 | 
	
		
			
			| 472 |  | -
 | 
	
		
			
			| 473 |  | -    ghost_bust
 | 
	
		
			
			| 474 |  | -
 | 
	
		
			
			| 475 |  | -    echo '{' > "/var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json"
 | 
	
		
			
			| 476 |  | -    if [[ "$ONION_ONLY" == 'no' ]]; then
 | 
	
		
			
			| 477 |  | -        # NOTE: url must be http, not https
 | 
	
		
			
			| 478 |  | -        echo "  \"url\": \"http://${GHOST_DOMAIN_NAME}\"," >> "/var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json"
 | 
	
		
			
			| 479 |  | -    else
 | 
	
		
			
			| 480 |  | -        echo "  \"url\": \"http://${GHOST_ONION_HOSTNAME}\"," >> "/var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json"
 | 
	
		
			
			| 481 |  | -    fi
 | 
	
		
			
			| 482 |  | -    { echo '    "paths": {';
 | 
	
		
			
			| 483 |  | -      echo "        \"contentPath\": \"/var/www/${GHOST_DOMAIN_NAME}/htdocs/content\"";
 | 
	
		
			
			| 484 |  | -      echo '    }';
 | 
	
		
			
			| 485 |  | -      echo '}'; } >> "/var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json"
 | 
	
		
			
			| 486 |  | -
 | 
	
		
			
			| 487 |  | -    { echo '[Unit]';
 | 
	
		
			
			| 488 |  | -      echo 'Description=Ghost Blog';
 | 
	
		
			
			| 489 |  | -      echo 'After=syslog.target';
 | 
	
		
			
			| 490 |  | -      echo 'After=network.target';
 | 
	
		
			
			| 491 |  | -      echo '';
 | 
	
		
			
			| 492 |  | -      echo '[Service]';
 | 
	
		
			
			| 493 |  | -      echo 'Type=simple';
 | 
	
		
			
			| 494 |  | -      echo 'User=ghost';
 | 
	
		
			
			| 495 |  | -      echo 'Group=ghost';
 | 
	
		
			
			| 496 |  | -      echo "WorkingDirectory=/var/www/${GHOST_DOMAIN_NAME}/htdocs";
 | 
	
		
			
			| 497 |  | -      echo "ExecStart=/root/.npm-global/bin/ghost run -D";
 | 
	
		
			
			| 498 |  | -      echo "ExecStop=/root/.npm-global/bin/ghost stop";
 | 
	
		
			
			| 499 |  | -      echo "ExecRestart=/root/.npm-global/bin/ghost restart";
 | 
	
		
			
			| 500 |  | -      echo 'Restart=always';
 | 
	
		
			
			| 501 |  | -      echo 'RestartSec=60';
 | 
	
		
			
			| 502 |  | -      echo "Environment=NODE_ENV=development PORT=${GHOST_PORT}";
 | 
	
		
			
			| 503 |  | -      echo '';
 | 
	
		
			
			| 504 |  | -      echo '[Install]';
 | 
	
		
			
			| 505 |  | -      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/ghost.service
 | 
	
		
			
			| 506 |  | -
 | 
	
		
			
			| 507 |  | -    ghost_remove_offsite_links
 | 
	
		
			
			| 508 |  | -
 | 
	
		
			
			| 509 |  | -    chown -R ghost: "/var/www/${GHOST_DOMAIN_NAME}/htdocs"
 | 
	
		
			
			| 510 |  | -
 | 
	
		
			
			| 511 |  | -    systemctl enable ghost
 | 
	
		
			
			| 512 |  | -    systemctl daemon-reload
 | 
	
		
			
			| 513 |  | -    systemctl start ghost
 | 
	
		
			
			| 514 |  | -
 | 
	
		
			
			| 515 |  | -    if [[ ${ONION_ONLY} == "no" ]]; then
 | 
	
		
			
			| 516 |  | -        function_check nginx_http_redirect
 | 
	
		
			
			| 517 |  | -        nginx_http_redirect "${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 518 |  | -        { echo 'server {';
 | 
	
		
			
			| 519 |  | -          echo '    listen 443 ssl;';
 | 
	
		
			
			| 520 |  | -          echo '    #listen [::]:443 ssl;';
 | 
	
		
			
			| 521 |  | -          echo "    root /var/www/${GHOST_DOMAIN_NAME}/htdocs;";
 | 
	
		
			
			| 522 |  | -          echo "    server_name ${GHOST_DOMAIN_NAME};";
 | 
	
		
			
			| 523 |  | -          echo '    access_log /dev/null;';
 | 
	
		
			
			| 524 |  | -          echo "    error_log /dev/null;";
 | 
	
		
			
			| 525 |  | -          echo ''; } >> "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 526 |  | -        function_check nginx_ssl
 | 
	
		
			
			| 527 |  | -        nginx_ssl "${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 528 |  | -        function_check nginx_security_options
 | 
	
		
			
			| 529 |  | -        nginx_security_options "${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 530 |  | -        { echo '    add_header Strict-Transport-Security max-age=0;';
 | 
	
		
			
			| 531 |  | -          echo '';
 | 
	
		
			
			| 532 |  | -          echo '    location / {'; } >> "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 533 |  | -        function_check nginx_limits
 | 
	
		
			
			| 534 |  | -        nginx_limits "${GHOST_DOMAIN_NAME}" '10G'
 | 
	
		
			
			| 535 |  | -        { echo "        proxy_pass http://localhost:${GHOST_PORT};";
 | 
	
		
			
			| 536 |  | -          echo '    }';
 | 
	
		
			
			| 537 |  | -          echo '';
 | 
	
		
			
			| 538 |  | -          echo '    fastcgi_buffers 64 4K;';
 | 
	
		
			
			| 539 |  | -          echo '';
 | 
	
		
			
			| 540 |  | -          echo '    error_page 403 /core/templates/403.php;';
 | 
	
		
			
			| 541 |  | -          echo '    error_page 404 /core/templates/404.php;';
 | 
	
		
			
			| 542 |  | -          echo '';
 | 
	
		
			
			| 543 |  | -          echo '    location = /robots.txt {';
 | 
	
		
			
			| 544 |  | -          echo '        allow all;';
 | 
	
		
			
			| 545 |  | -          echo '        log_not_found off;';
 | 
	
		
			
			| 546 |  | -          echo '        access_log /dev/null;';
 | 
	
		
			
			| 547 |  | -          echo '    }';
 | 
	
		
			
			| 548 |  | -          echo '}';
 | 
	
		
			
			| 549 |  | -          echo ''; } >> "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 550 |  | -    else
 | 
	
		
			
			| 551 |  | -        echo -n '' > "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 552 |  | -    fi
 | 
	
		
			
			| 553 |  | -    { echo 'server {';
 | 
	
		
			
			| 554 |  | -      echo "    listen 127.0.0.1:${GHOST_ONION_PORT} default_server;";
 | 
	
		
			
			| 555 |  | -      echo "    root /var/www/$GHOST_DOMAIN_NAME/htdocs;";
 | 
	
		
			
			| 556 |  | -      echo "    server_name $GHOST_ONION_HOSTNAME;";
 | 
	
		
			
			| 557 |  | -      echo '    access_log /dev/null;';
 | 
	
		
			
			| 558 |  | -      echo "    error_log /dev/null;";
 | 
	
		
			
			| 559 |  | -      echo ''; } >> "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 560 |  | -    function_check nginx_security_options
 | 
	
		
			
			| 561 |  | -    nginx_security_options "${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 562 |  | -    { echo '    add_header Strict-Transport-Security max-age=0;';
 | 
	
		
			
			| 563 |  | -      echo '';
 | 
	
		
			
			| 564 |  | -      echo '    location / {'; } >> "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 565 |  | -    function_check nginx_limits
 | 
	
		
			
			| 566 |  | -    nginx_limits "${GHOST_DOMAIN_NAME}" '10G'
 | 
	
		
			
			| 567 |  | -    { echo "        proxy_pass http://localhost:${GHOST_PORT};";
 | 
	
		
			
			| 568 |  | -      echo '    }';
 | 
	
		
			
			| 569 |  | -      echo '';
 | 
	
		
			
			| 570 |  | -      echo '    fastcgi_buffers 64 4K;';
 | 
	
		
			
			| 571 |  | -      echo '';
 | 
	
		
			
			| 572 |  | -      echo '    error_page 403 /core/templates/403.php;';
 | 
	
		
			
			| 573 |  | -      echo '    error_page 404 /core/templates/404.php;';
 | 
	
		
			
			| 574 |  | -      echo '';
 | 
	
		
			
			| 575 |  | -      echo '    location = /robots.txt {';
 | 
	
		
			
			| 576 |  | -      echo '        allow all;';
 | 
	
		
			
			| 577 |  | -      echo '        log_not_found off;';
 | 
	
		
			
			| 578 |  | -      echo '        access_log /dev/null;';
 | 
	
		
			
			| 579 |  | -      echo '    }';
 | 
	
		
			
			| 580 |  | -      echo '}'; } >> "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
 | 
	
		
			
			| 581 |  | -
 | 
	
		
			
			| 582 |  | -    function_check create_site_certificate
 | 
	
		
			
			| 583 |  | -    create_site_certificate "$GHOST_DOMAIN_NAME" 'yes'
 | 
	
		
			
			| 584 |  | -
 | 
	
		
			
			| 585 |  | -    ghost_replace_services
 | 
	
		
			
			| 586 |  | -
 | 
	
		
			
			| 587 |  | -    function_check nginx_ensite
 | 
	
		
			
			| 588 |  | -    nginx_ensite "$GHOST_DOMAIN_NAME"
 | 
	
		
			
			| 589 |  | -
 | 
	
		
			
			| 590 |  | -    systemctl restart nginx
 | 
	
		
			
			| 591 |  | -
 | 
	
		
			
			| 592 |  | -    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a ghost -p "$GHOST_ADMIN_PASSWORD"
 | 
	
		
			
			| 593 |  | -
 | 
	
		
			
			| 594 |  | -    function_check add_ddns_domain
 | 
	
		
			
			| 595 |  | -    add_ddns_domain "$GHOST_DOMAIN_NAME"
 | 
	
		
			
			| 596 |  | -
 | 
	
		
			
			| 597 |  | -    chown root:root /root/.npm-global/bin/ghost
 | 
	
		
			
			| 598 |  | -    chown -R root:root /usr/local/lib
 | 
	
		
			
			| 599 |  | -    chown -R ghost: "/var/www/${GHOST_DOMAIN_NAME}/htdocs"
 | 
	
		
			
			| 600 |  | -    set_completion_param "ghost domain" "$GHOST_DOMAIN_NAME"
 | 
	
		
			
			| 601 |  | -    if ! grep -q "ghost version:" "${COMPLETION_FILE}"; then
 | 
	
		
			
			| 602 |  | -        echo "ghost version:${GHOST_VERSION}" >> "${COMPLETION_FILE}"
 | 
	
		
			
			| 603 |  | -    else
 | 
	
		
			
			| 604 |  | -        sed -i "s|ghost version.*|ghost version:${GHOST_VERSION}|g" "${COMPLETION_FILE}"
 | 
	
		
			
			| 605 |  | -    fi
 | 
	
		
			
			| 606 |  | -
 | 
	
		
			
			| 607 |  | -    APP_INSTALLED=1
 | 
	
		
			
			| 608 |  | -}
 | 
	
		
			
			| 609 |  | -
 | 
	
		
			
			| 610 |  | -# NOTE: deliberately no exit 0
 |