Skip to content
Snippets Groups Projects
freedombone-app-scuttlebot 18.2 KiB
Newer Older
Bob Mottram's avatar
Bob Mottram committed
#!/bin/bash
Bob Mottram's avatar
Bob Mottram committed
#  _____               _           _
# |   __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# |   __|  _| -_| -_| . | . |     | . | . |   | -_|
# |__|  |_| |___|___|___|___|_|_|_|___|___|_|_|___|
Bob Mottram's avatar
Bob Mottram committed
#
Bob Mottram's avatar
Bob Mottram committed
#                              Freedom in the Cloud
Bob Mottram's avatar
Bob Mottram committed
#
Bob Mottram's avatar
Bob Mottram committed
# scuttlebot pub application. Enables nat traversal for SSB.
Bob Mottram's avatar
Bob Mottram committed
# https://scuttlebot.io
#
# License
# =======
#
Bob Mottram's avatar
Bob Mottram committed
# Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
Bob Mottram's avatar
Bob Mottram committed
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

VARIANTS='full full-vim social'
Bob Mottram's avatar
Bob Mottram committed

IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=0
SHOW_CLEARNET_ADDRESS_ON_ABOUT=0
Bob Mottram's avatar
Bob Mottram committed

SCUTTLEBOT_DOMAIN_NAME=
SCUTTLEBOT_CODE=
Bob Mottram's avatar
Bob Mottram committed
SCUTTLEBOT_VERSION='11.2.0'
SCUTTLEBOT_PORT=8010
SCUTTLEBOT_ONION_PORT=8623
GIT_SSB_PORT=7718
NGINX_GIT_SSB_PORT=7719
Bob Mottram's avatar
Bob Mottram committed

scuttlebot_variables=(MY_USERNAME
                      SCUTTLEBOT_DOMAIN_NAME
                      SCUTTLEBOT_CODE
Bob Mottram's avatar
Bob Mottram committed
                      DEFAULT_DOMAIN_NAME
Bob Mottram's avatar
Bob Mottram committed
                      SYSTEM_TYPE)

function logging_on_scuttlebot {
    echo -n ''
}

function logging_off_scuttlebot {
    echo -n ''
}

Bob Mottram's avatar
Bob Mottram committed
function scuttlebot_create_invite {
    invite_string=$(su -c "/etc/scuttlebot/node_modules/.bin/sbot invite.create 1" - scuttlebot | sed 's/"//g')
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    clear
Bob Mottram's avatar
Bob Mottram committed
    echo -e "\\n\\nYour Scuttlebot invite code is:\\n\\n${invite_string}\\n\\n"
    # shellcheck disable=SC2034
Bob Mottram's avatar
Bob Mottram committed
    read -n1 -r -p $"Press any key to continue..." key
}

function configure_interactive_scuttlebot {
    W=(1 $"Create an invite")

Bob Mottram's avatar
Bob Mottram committed
    while true
    do
        # shellcheck disable=SC2068
        selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Scuttlebot" --menu $"Choose an operation, or ESC to exit:" 10 60 2 "${W[@]}" 3>&2 2>&1 1>&3)

        if [ ! "$selection" ]; then
            break
        fi

        case $selection in
Bob Mottram's avatar
Bob Mottram committed
            1) scuttlebot_create_invite;;
        esac
    done
}
Bob Mottram's avatar
Bob Mottram committed

function remove_user_scuttlebot {
Bob Mottram's avatar
Bob Mottram committed
    echo -n ''
#    remove_username="$1"
Bob Mottram's avatar
Bob Mottram committed
}

function add_user_scuttlebot {
Bob Mottram's avatar
Bob Mottram committed
#    new_username="$1"
#    new_user_password="$2"
Bob Mottram's avatar
Bob Mottram committed
    echo '0'
}

function install_interactive_scuttlebot {
    if [[ $ONION_ONLY != "no" ]]; then
        SCUTTLEBOT_DOMAIN_NAME='scuttlebot.local'
        write_config_param "SCUTTLEBOT_DOMAIN_NAME" "$SCUTTLEBOT_DOMAIN_NAME"
    else
        function_check interactive_site_details
        interactive_site_details scuttlebot
    fi
Bob Mottram's avatar
Bob Mottram committed
    APP_INSTALLED=1
}

function change_password_scuttlebot {
Bob Mottram's avatar
Bob Mottram committed
#    new_username="$1"
#    new_user_password="$2"
Bob Mottram's avatar
Bob Mottram committed
    echo '0'
}

function reconfigure_scuttlebot {
    if [ -d /etc/scuttlebot/.ssb ]; then
        systemctl stop scuttlebot
        rm -rf /etc/scuttlebot/.ssb
        systemctl start scuttlebot
    fi
}

function upgrade_scuttlebot {
Bob Mottram's avatar
Bob Mottram committed
    if ! grep -q 'scuttlebot version:' $"COMPLETION_FILE"; then
Bob Mottram's avatar
Bob Mottram committed
        return
    fi

    CURR_SCUTTLEBOT_VERSION=$(get_completion_param "scuttlebot version")
    echo "scuttlebot current version: ${CURR_SCUTTLEBOT_VERSION}"
    echo "scuttlebot app version: ${SCUTTLEBOT_VERSION}"
    if [[ "${CURR_SCUTTLEBOT_VERSION}" == "${SCUTTLEBOT_VERSION}" ]]; then
        return
    fi

Bob Mottram's avatar
Bob Mottram committed
    if ! npm upgrade -g scuttlebot@${SCUTTLEBOT_VERSION} --save; then
Bob Mottram's avatar
Bob Mottram committed
        return
    fi
Bob Mottram's avatar
Bob Mottram committed
    sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" "${COMPLETION_FILE}"
Bob Mottram's avatar
Bob Mottram committed
}

function backup_local_scuttlebot {
    if [ -d /etc/scuttlebot/.ssb ]; then
        systemctl stop scuttlebot
        function_check backup_directory_to_usb
        backup_directory_to_usb /etc/scuttlebot/.ssb scuttlebot
        systemctl start scuttlebot
    fi
}

function restore_local_scuttlebot {
    if [ -d /etc/scuttlebot ]; then
        systemctl stop scuttlebot
        temp_restore_dir=/root/tempscuttlebot
        function_check restore_directory_from_usb
        restore_directory_from_usb $temp_restore_dir scuttlebot
        if [ -d $temp_restore_dir/etc/scuttlebot/.ssb ]; then
            cp -r $temp_restore_dir/etc/scuttlebot/.ssb /etc/scuttlebot/
        else
            cp -r $temp_restore_dir/* /etc/scuttlebot/.ssb/*
        fi
Bob Mottram's avatar
Bob Mottram committed
        systemctl start scuttlebot
        rm -rf $temp_restore_dir
Bob Mottram's avatar
Bob Mottram committed
    fi
}

function backup_remote_scuttlebot {
    if [ -d /etc/scuttlebot/.ssb ]; then
        systemctl stop scuttlebot
        function_check backup_directory_to_friend
        backup_directory_to_friend /etc/scuttlebot/.ssb scuttlebot
        systemctl start scuttlebot
    fi
}

function restore_remote_scuttlebot {
    if [ -d /etc/scuttlebot ]; then
        systemctl stop scuttlebot
        temp_restore_dir=/root/tempscuttlebot
        function_check restore_directory_from_friend
        restore_directory_from_friend $temp_restore_dir scuttlebot
        if [ -d $temp_restore_dir/etc/scuttlebot/.ssb ]; then
            cp -r $temp_restore_dir/etc/scuttlebot/.ssb /etc/scuttlebot/
        else
            cp -r $temp_restore_dir/* /etc/scuttlebot/.ssb/*
        fi
Bob Mottram's avatar
Bob Mottram committed
        systemctl start scuttlebot
        rm -rf $temp_restore_dir
Bob Mottram's avatar
Bob Mottram committed
    fi
}

function remove_scuttlebot {
Bob Mottram's avatar
Bob Mottram committed
    firewall_remove ${SCUTTLEBOT_PORT}
    firewall_remove ${GIT_SSB_PORT}

    if [ $SCUTTLEBOT_DOMAIN_NAME ]; then
        nginx_dissite ${SCUTTLEBOT_DOMAIN_NAME}
        rm /etc/nginx/sites-available/${SCUTTLEBOT_DOMAIN_NAME}
    fi
    systemctl stop git_ssb
Bob Mottram's avatar
Bob Mottram committed
    systemctl stop scuttlebot
    systemctl disable git_ssb
Bob Mottram's avatar
Bob Mottram committed
    systemctl disable scuttlebot
    rm /etc/systemd/system/git_ssb.service
Bob Mottram's avatar
Bob Mottram committed
    rm /etc/systemd/system/scuttlebot.service
Bob Mottram's avatar
Bob Mottram committed
    systemctl daemon-reload
Bob Mottram's avatar
Bob Mottram committed

    userdel -r scuttlebot

    if [ -d /etc/scuttlebot ]; then
        rm -rf /etc/scuttlebot
    fi
    if [ -f /usr/bin/git-ssb-create ]; then
        rm /usr/bin/git-ssb-create
    fi
Bob Mottram's avatar
Bob Mottram committed

    remove_completion_param install_scuttlebot
Bob Mottram's avatar
Bob Mottram committed
    sed -i '/scuttlebot /d' "$COMPLETION_FILE"
Bob Mottram's avatar
Bob Mottram committed
}

function git_ssb_script {
    if [[ "$1" == "mesh" ]]; then
Bob Mottram's avatar
Bob Mottram committed
        # shellcheck disable=SC2154
        git_ssb_script_name=$rootdir/usr/bin/git-ssb-create
        git_ssb_daemon_filename=$rootdir/etc/systemd/system/git_ssb.service
    else
        git_ssb_script_name=/usr/bin/git-ssb-create
        git_ssb_daemon_filename=/etc/systemd/system/git_ssb.service
Bob Mottram's avatar
Bob Mottram committed
    { echo '#!/bin/bash';
      echo "reponame=\"\$1\"";
      echo '';
      echo "if [[ \"\$reponame\" != \"\" ]]; then";
      echo "  mkdir \$reponame";
      echo "  cd \$reponame";
      echo '  git init';
      echo "  git ssb create ssb \$reponame";
      echo '  git push --tags ssb master';
      echo 'fi';
      echo 'exit 0'; } > $git_ssb_script_name
    chmod +x $git_ssb_script_name
Bob Mottram's avatar
Bob Mottram committed
    { echo '[Unit]';
      echo 'Description=Git SSB (SSB git web interface)';
      echo 'After=syslog.target';
      echo 'After=network.target';
      echo 'After=scuttlebot.target';
      echo '';
      echo '[Service]';
      echo 'Type=simple';
      echo 'User=scuttlebot';
      echo 'Group=scuttlebot';
      echo "WorkingDirectory=/etc/scuttlebot";
      echo "ExecStart=/usr/bin/git ssb web --public localhost:$GIT_SSB_PORT";
      echo 'Restart=always';
      echo 'Environment="USER=scuttlebot"';
      echo '';
      echo '[Install]';
      echo 'WantedBy=multi-user.target'; } > $git_ssb_daemon_filename
function scuttlebot_git_setup {
    if [[ "$1" == "mesh" ]]; then

        if [ ! -d "$rootdir/root/.npm-global/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight" ]; then
            mkdir "$rootdir/root/.npm-global/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight"
        if [ ! -f "$rootdir/root/.npm-global/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css" ]; then
            echo $'Could not find foundation.css'
            exit 347687245
        fi
        cp "$rootdir/root/.npm-global/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css" "$rootdir/root/.npm-global/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight/foundation.css"
        git_ssb_nginx_site=$rootdir/etc/nginx/sites-available/git_ssb
Bob Mottram's avatar
Bob Mottram committed
        { echo 'server {';
          echo "  listen $NGINX_GIT_SSB_PORT default_server;";
          echo "  server_name P${PEER_ID}.local;";
          echo '';
          echo '  access_log /dev/null;';
          echo '  error_log /dev/null;';
          echo '';
          echo '  add_header X-XSS-Protection "1; mode=block";';
          echo '  add_header X-Content-Type-Options nosniff;';
          echo '  add_header X-Frame-Options SAMEORIGIN;'; } > "$git_ssb_nginx_site"
        if [ ! $SCUTTLEBOT_DOMAIN_NAME ]; then
            exit 7357225
        fi
        if [ ! -d /root/.npm-global/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight ]; then
            mkdir /root/.npm-global/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight
        if [ ! -f /root/.npm-global/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css ]; then
            echo $'Could not find foundation.css'
            exit 347687245
        fi
        cp /root/.npm-global/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css /root/.npm-global/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight/foundation.css
        git_ssb_nginx_site=/etc/nginx/sites-available/${SCUTTLEBOT_DOMAIN_NAME}
        function_check nginx_http_redirect
        nginx_http_redirect $SCUTTLEBOT_DOMAIN_NAME "index index.html"
Bob Mottram's avatar
Bob Mottram committed
        { echo 'server {';
          echo '  listen 443 ssl;';
          echo '  #listen [::]:443 ssl;';
          echo "  server_name $SCUTTLEBOT_DOMAIN_NAME;";
          echo ''; } >> $git_ssb_nginx_site
        function_check nginx_compress
        nginx_compress $SCUTTLEBOT_DOMAIN_NAME
Bob Mottram's avatar
Bob Mottram committed
        echo '' >> "$git_ssb_nginx_site"
        echo '  # Security' >> "$git_ssb_nginx_site"
        function_check nginx_ssl
        nginx_ssl $SCUTTLEBOT_DOMAIN_NAME

Bob Mottram's avatar
Bob Mottram committed
        function_check nginx_security_options
        nginx_security_options $SCUTTLEBOT_DOMAIN_NAME
Bob Mottram's avatar
Bob Mottram committed
    { echo '';
      echo '  root /root/.npm-global/lib/node_modules/git-ssb/node_modules/git-ssb-web;';
Bob Mottram's avatar
Bob Mottram committed
      echo '';
      echo '  location = / {';
      echo "    proxy_pass http://localhost:${GIT_SSB_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 '    proxy_http_version 1.1;';
      echo "    proxy_set_header Upgrade \$http_upgrade;";
      echo '    proxy_set_header Connection upgrade;';
      echo '  }';
      echo '}'; } >> $git_ssb_nginx_site

    if [ "$SCUTTLEBOT_ONION_HOSTNAME" ]; then
        { echo '';
          echo 'server {';
          echo "  listen 127.0.0.1:${SCUTTLEBOT_ONION_PORT} default_server;";
          echo '  port_in_redirect off;';
Bob Mottram's avatar
Bob Mottram committed
          echo "  server_name ${SCUTTLEBOT_ONION_HOSTNAME};";
          echo '';
          echo '  access_log /dev/null;';
          echo '  error_log /dev/null;';
          echo '';
          echo '  add_header X-XSS-Protection "1; mode=block";';
          echo '  add_header X-Content-Type-Options nosniff;';
          echo '  add_header X-Frame-Options SAMEORIGIN;';
          echo '';
          echo '  root /root/.npm-global/lib/node_modules/git-ssb/node_modules/git-ssb-web;';
Bob Mottram's avatar
Bob Mottram committed
          echo '';
          echo '  location = / {';
          echo "    proxy_pass http://localhost:${GIT_SSB_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 '    proxy_http_version 1.1;';
          echo "    proxy_set_header Upgrade \$http_upgrade;";
          echo '    proxy_set_header Connection upgrade;';
          echo '  }';
          echo '}'; } >> $git_ssb_nginx_site
    if [[ "$1" != "mesh" ]]; then
        nginx_ensite git_ssb
    fi
Bob Mottram's avatar
Bob Mottram committed
function mesh_install_dat {
    get_npm_arch
Bob Mottram's avatar
Bob Mottram committed
    mesh_setup_npm
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    cat <<EOF > "$rootdir/usr/bin/install_dat"
Bob Mottram's avatar
Bob Mottram committed
#!/bin/bash
npm install --arch=$NPM_ARCH -g dat
EOF
    chroot "$rootdir" /bin/chmod +x /usr/bin/install_dat
    chroot "$rootdir" /usr/bin/install_dat
Bob Mottram's avatar
Bob Mottram committed
    rm "$rootdir/usr/bin/install_dat"
function install_dat {
    npm install -g dat
}

Bob Mottram's avatar
Bob Mottram committed
function mesh_install_scuttlebot {
Bob Mottram's avatar
Bob Mottram committed
    #shellcheck disable=SC2153
    if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" ]]; then
        return
    fi

Bob Mottram's avatar
Bob Mottram committed
    mesh_install_dat

    get_npm_arch
Bob Mottram's avatar
Bob Mottram committed
    mesh_setup_npm
    if [ ! -d "$rootdir/etc/scuttlebot" ]; then
        mkdir -p "$rootdir/etc/scuttlebot"
    fi

    # an unprivileged user to install and run as
    chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
    chroot "$rootdir" chown -R scuttlebot:scuttlebot /etc/scuttlebot
Bob Mottram's avatar
Bob Mottram committed
    cat <<EOF > "$rootdir/usr/bin/install_scuttlebot"
Bob Mottram's avatar
Bob Mottram committed
#!/bin/bash
cd /etc/scuttlebot || exit 1
if ! npm install --arch=$NPM_ARCH scuttlebot@${SCUTTLEBOT_VERSION}; then
    exit 2
Bob Mottram's avatar
Bob Mottram committed
fi
Bob Mottram's avatar
Bob Mottram committed
exit 0
Bob Mottram's avatar
Bob Mottram committed
EOF
    chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
    chroot "$rootdir" sudo -u scuttlebot /usr/bin/install_scuttlebot
Bob Mottram's avatar
Bob Mottram committed
    rm "$rootdir/usr/bin/install_scuttlebot"
    if [ ! -f "$rootdir/etc/scuttlebot/node_modules/.bin/sbot" ]; then
Bob Mottram's avatar
Bob Mottram committed
        echo $'Scuttlebot was not installed'
        exit 528253
    fi

    cat <<EOF > "$rootdir/usr/bin/install_git_ssb"
#!/bin/bash
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
export NPM_CONFIG_PREFIX=~/.npm-global
source ~/.profile
if ! npm install --arch=$NPM_ARCH -g git-ssb; then
    exit 1
fi
if ! npm install --arch=$NPM_ARCH -g git-remote-ssb; then
    exit 2
fi
exit 0
EOF
    chroot "$rootdir" /bin/chmod +x /usr/bin/install_git_ssb
    chroot "$rootdir" /usr/bin/install_git_ssb
    rm "$rootdir/usr/bin/install_git_ssb"

Bob Mottram's avatar
Bob Mottram committed
    # daemon
Bob Mottram's avatar
Bob Mottram committed
    { echo '[Unit]';
      echo 'Description=Scuttlebot (messaging system)';
      echo 'After=syslog.target';
      echo 'After=network.target';
      echo '';
      echo '[Service]';
      echo 'Type=simple';
      echo 'User=scuttlebot';
      echo 'Group=scuttlebot';
      echo "WorkingDirectory=/etc/scuttlebot";
      echo 'ExecStart=/etc/scuttlebot/node_modules/.bin/sbot server';
Bob Mottram's avatar
Bob Mottram committed
      echo 'Restart=always';
      echo 'Environment="USER=scuttlebot"';
      echo '';
      echo '[Install]';
      echo 'WantedBy=multi-user.target'; } > "$rootdir/etc/systemd/system/scuttlebot.service"
    scuttlebot_git_setup mesh
    git_ssb_script mesh
Bob Mottram's avatar
Bob Mottram committed
function install_scuttlebot {
    function_check install_nodejs
    install_nodejs scuttlebot

    if [ ! -d /etc/scuttlebot ]; then
        mkdir -p /etc/scuttlebot
    fi

    # an unprivileged user to install and run as
    useradd -d /etc/scuttlebot/ scuttlebot
    chown -R scuttlebot:scuttlebot /etc/scuttlebot

    cat <<EOF > /usr/bin/install_scuttlebot
#!/bin/bash
cd /etc/scuttlebot || exit 1
if ! npm install scuttlebot@${SCUTTLEBOT_VERSION}; then
    exit 2
fi
exit 0
EOF
    chmod +x /usr/bin/install_scuttlebot
    su -c '/usr/bin/install_scuttlebot' - scuttlebot
    rm /usr/bin/install_scuttlebot

    if [ ! -f /etc/scuttlebot/node_modules/.bin/sbot ]; then
        echo $'Scuttlebot was not installed'
Bob Mottram's avatar
Bob Mottram committed
        exit 528253
    fi

    npm install -g git-ssb
    npm install -g git-remote-ssb

Bob Mottram's avatar
Bob Mottram committed
    # daemon
Bob Mottram's avatar
Bob Mottram committed
    { echo '[Unit]';
      echo 'Description=Scuttlebot (messaging system)';
      echo 'After=syslog.target';
      echo 'After=network.target';
      echo '';
      echo '[Service]';
      echo 'Type=simple';
      echo 'User=scuttlebot';
      echo 'Group=scuttlebot';
      echo "WorkingDirectory=/etc/scuttlebot";
      echo 'ExecStart=/etc/scuttlebot/node_modules/.bin/sbot server';
Bob Mottram's avatar
Bob Mottram committed
      echo 'Restart=always';
      echo 'Environment="USER=scuttlebot"';
      echo '';
      echo '[Install]';
      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/scuttlebot.service
Bob Mottram's avatar
Bob Mottram committed

    chown -R scuttlebot:scuttlebot /etc/scuttlebot

    # files gw_name myhostname mdns4_minimal [NOTFOUND=return] dns
    sed -i "s|hosts:.*|hosts:          files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf

    # start the daemon
    systemctl enable scuttlebot.service
    systemctl daemon-reload
    systemctl start scuttlebot.service

Bob Mottram's avatar
Bob Mottram committed
    sleep 3

    if [ ! -d /etc/scuttlebot/.ssb ]; then
        echo $'Scuttlebot config not generated'
        exit 73528
    fi

Bob Mottram's avatar
Bob Mottram committed
    SCUTTLEBOT_ONION_HOSTNAME=$(add_onion_service scuttlebot 80 ${SCUTTLEBOT_ONION_PORT})

    if [[ "$ONION_ONLY" == 'no' ]]; then
        { echo '{';
          echo "  \"host\": \"${DEFAULT_DOMAIN_NAME}\",";
          echo '  "tor-only": false,'; } > /etc/scuttlebot/.ssb/config
    else
        { echo '{';
          echo "  \"host\": \"${SCUTTLEBOT_ONION_HOSTNAME}\",";
          echo '  "tor-only": true,'; } > /etc/scuttlebot/.ssb/config
    fi

    { echo "  \"port\": ${SCUTTLEBOT_PORT},";
Bob Mottram's avatar
Bob Mottram committed
      echo '  "timeout": 30000,';
      echo '  "pub": true,';
      echo '  "local": true,';
      echo '  "friends": {';
      echo '    "dunbar": 150,';
      echo '    "hops": 3';
      echo '  },';
      echo '  "gossip": {';
      echo '    "connections": 2';
      echo '  },';
      echo '  "master": [],';
      echo '  "logging": {';
      echo '    "level": "error"';
      echo '  }';
Bob Mottram's avatar
Bob Mottram committed
      echo '}'; } >> /etc/scuttlebot/.ssb/config
Bob Mottram's avatar
Bob Mottram committed
    chown scuttlebot:scuttlebot /etc/scuttlebot/.ssb/config
    systemctl restart scuttlebot.service

Bob Mottram's avatar
Bob Mottram committed
    firewall_add scuttlebot ${SCUTTLEBOT_PORT}
    firewall_add git_ssb ${GIT_SSB_PORT}

    scuttlebot_git_setup
    git_ssb_script
Bob Mottram's avatar
Bob Mottram committed
    systemctl enable git_ssb.service
    systemctl daemon-reload
    systemctl start git_ssb.service

    function_check create_site_certificate
    create_site_certificate ${SCUTTLEBOT_DOMAIN_NAME} 'yes'

Bob Mottram's avatar
Bob Mottram committed
    if ! grep -q "scuttlebot version:" "${COMPLETION_FILE}"; then
        echo "scuttlebot version:${SCUTTLEBOT_VERSION}" >> "${COMPLETION_FILE}"
Bob Mottram's avatar
Bob Mottram committed
    else
Bob Mottram's avatar
Bob Mottram committed
        sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" "${COMPLETION_FILE}"
Bob Mottram's avatar
Bob Mottram committed
    fi

    APP_INSTALLED=1
}

# NOTE: deliberately no exit 0