| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 | #!/bin/bash
#
# .---.                  .              .
# |                      |              |
# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
#
#                    Freedom in the Cloud
#
# Final stage of install
#
# License
# =======
#
# Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
function install_final {
    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
        return
    fi
    # unmount any attached usb drive
    if [ -d "$USB_MOUNT" ]; then
        umount "$USB_MOUNT"
        rm -rf "$USB_MOUNT"
    fi
    function_check split_gpg_key_into_fragments
    split_gpg_key_into_fragments
    lockdown_permissions
    mark_completed "${FUNCNAME[0]}"
    clear
    echo ''
    if [[ $ONION_ONLY == 'no' ]]; then
        echo $"
If you wish to verify the server ssh public key at next login it is:
$(get_ssh_server_key)
Ensure that ports are forwarded from your internet router.
You can find the list of ports within the firewall section of
the administrator control panel.
"
    else
        echo $"
If you wish to verify the server ssh public key at next login it is:
$(get_ssh_server_key)
"
    fi
    echo ''
    # add user menu on ssh login
    if ! grep -q 'controluser' "/home/$MY_USERNAME/.bashrc"; then
        echo 'controluser' >> "/home/$MY_USERNAME/.bashrc"
    fi
    if [ ! -f "$IMAGE_PASSWORD_FILE" ]; then
        if [ -f "/root/${PROJECT_NAME}-wifi.cfg" ]; then
            create_wifi_startup_script
            echo ''
            echo $'Shutting down the system. Detatch the ethernet cable, attach wifi dongle, then power on again.'
            echo ''
            "${PROJECT_NAME}-logging" off --restart
            systemctl poweroff
            return
        fi
        echo $'Turning off logging'
        "${PROJECT_NAME}-logging" off --restart
        echo $'Rebooting the system'
        systemctl reboot -i
    fi
    echo $'Turning off logging'
    "${PROJECT_NAME}-logging" off --restart
}
function update_installed_apps_list {
    # Why does this secondary file exist, apart from COMPLETION_FILE ?
    # It's so that it is visible to unprivileged users from the user control panel
    grep "install_" "$COMPLETION_FILE" > "/usr/share/${PROJECT_NAME}/installed.txt"
}
function create_default_user_removal_daemon {
    # This daemon runs on first boot and removes the default fbone user
    first_start_daemon_filename=/etc/systemd/system/firststart.service
    first_start_script=/usr/local/bin/firststart
    { echo '#!/bin/bash';
      echo 'if [ -d /home/fbone]; then';
      echo '    userdel -r fbone';
      echo '    if [ -d /home/fbone]; then';
      echo '        rm -rf /home/fbone';
      echo '    fi';
      echo 'fi';
      echo 'systemctl disable firststart';
      echo "rm $first_start_daemon_filename"; } > $first_start_script
    chmod +x $first_start_script
    { echo '[Unit]';
      echo 'Description=Daemon run on first boot';
      echo 'After=syslog.target';
      echo 'After=network.target';
      echo '';
      echo '[Service]';
      echo 'User=root';
      echo 'Group=root';
      echo "ExecStart=$first_start_script";
      echo 'StandardOutput=syslog';
      echo 'StandardError=syslog';
      echo '';
      echo '[Install]';
      echo 'WantedBy=multi-user.target'; } > $first_start_daemon_filename
    systemctl enable firststart
}
function setup_final {
    function_check update_installed_apps_list
    update_installed_apps_list
    function_check create_default_user_removal_daemon
    create_default_user_removal_daemon
    function_check install_tripwire
    install_tripwire
    function_check install_final
    install_final
    export DEBIAN_FRONTEND=
}
# NOTE: deliberately no exit 0
 |