freedombone/src/freedombone-utils-final

165 lines
4.9 KiB
Plaintext
Raw Permalink Normal View History

2016-07-03 17:13:34 +02:00
#!/bin/bash
2018-04-08 14:30:21 +02:00
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
2016-07-03 17:13:34 +02:00
#
2018-04-08 14:30:21 +02:00
# Freedom in the Cloud
2016-07-03 17:13:34 +02:00
#
# Final stage of install
#
# License
# =======
#
2018-02-21 20:32:13 +01:00
# Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
2016-07-03 17:13:34 +02:00
#
# 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 {
2018-02-25 13:50:46 +01:00
if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
2016-09-30 18:30:32 +02:00
return
fi
# unmount any attached usb drive
2018-02-25 23:15:36 +01:00
if [ -d "$USB_MOUNT" ]; then
umount "$USB_MOUNT"
rm -rf "$USB_MOUNT"
2016-09-30 18:30:32 +02:00
fi
function_check split_gpg_key_into_fragments
split_gpg_key_into_fragments
2016-11-30 10:41:56 +01:00
lockdown_permissions
2016-11-18 15:43:19 +01:00
2018-02-25 13:50:46 +01:00
mark_completed "${FUNCNAME[0]}"
2016-09-30 18:30:32 +02:00
clear
echo ''
2016-07-03 17:13:34 +02:00
2017-05-15 16:42:02 +02:00
if [[ $ONION_ONLY == 'no' ]]; then
echo $"
2016-11-23 01:00:06 +01:00
If you wish to verify the server ssh public key at next login it is:
$(get_ssh_server_key)
2017-05-15 16:42:02 +02:00
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.
2016-07-03 17:13:34 +02:00
"
2017-05-15 16:42:02 +02:00
else
echo $"
If you wish to verify the server ssh public key at next login it is:
$(get_ssh_server_key)
"
fi
2016-09-30 18:30:32 +02:00
echo ''
2016-07-03 17:13:34 +02:00
2016-09-30 18:30:32 +02:00
# add user menu on ssh login
2018-02-25 23:15:36 +01:00
if ! grep -q 'controluser' "/home/$MY_USERNAME/.bashrc"; then
echo 'export PS1="\W \$"' >> "/home/$MY_USERNAME/.bashrc"
2018-02-25 23:15:36 +01:00
echo 'controluser' >> "/home/$MY_USERNAME/.bashrc"
2016-09-30 18:30:32 +02:00
fi
2018-02-25 23:15:36 +01:00
if [ ! -f "$IMAGE_PASSWORD_FILE" ]; then
if [ -f "/root/${PROJECT_NAME}-wifi.cfg" ]; then
2016-10-22 16:43:15 +02:00
create_wifi_startup_script
2016-10-22 20:10:12 +02:00
echo ''
2016-10-22 20:11:24 +02:00
echo $'Shutting down the system. Detatch the ethernet cable, attach wifi dongle, then power on again.'
2016-10-22 20:10:12 +02:00
echo ''
2018-02-25 23:15:36 +01:00
"${PROJECT_NAME}-logging" off --restart
2017-06-19 16:27:21 +02:00
systemctl poweroff
2016-10-22 16:43:15 +02:00
return
fi
2017-05-15 16:42:02 +02:00
echo $'Turning off logging'
2018-02-25 23:15:36 +01:00
"${PROJECT_NAME}-logging" off --restart
2017-05-15 16:42:02 +02:00
echo $'Rebooting the system'
2017-06-10 15:26:52 +02:00
systemctl reboot -i
2016-09-30 18:30:32 +02:00
fi
2017-05-15 16:42:02 +02:00
echo $'Turning off logging'
2018-02-25 23:15:36 +01:00
"${PROJECT_NAME}-logging" off --restart
2016-09-30 18:30:32 +02:00
}
function update_installed_apps_list {
2016-09-30 18:49:24 +02:00
# 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
2018-02-25 23:15:36 +01:00
grep "install_" "$COMPLETION_FILE" > "/usr/share/${PROJECT_NAME}/installed.txt"
2016-07-03 17:13:34 +02:00
}
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
2018-02-25 23:15:36 +01:00
{ 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
2018-02-25 23:15:36 +01:00
{ 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 final_set_onion_hostname {
if [[ "$ONION_ONLY" == 'no' ]]; then
return
fi
if [ ! -f /var/lib/tor/hidden_service_email/hostname ]; then
echo $'No onion domain for email was found'
exit 368365
fi
onion_domain=$(cat /var/lib/tor/hidden_service_email/hostname)
2018-04-05 13:33:18 +02:00
echo "$onion_domain" > /etc/hostname
hostname "$onion_domain"
2018-04-05 13:33:18 +02:00
echo "127.0.1.1 $onion_domain" >> /etc/hosts
2018-04-05 18:46:22 +02:00
echo "$onion_domain" > /etc/mailname
}
2016-07-03 17:13:34 +02:00
function setup_final {
2016-09-30 18:30:32 +02:00
function_check update_installed_apps_list
update_installed_apps_list
function_check create_default_user_removal_daemon
create_default_user_removal_daemon
function_check final_set_onion_hostname
final_set_onion_hostname
2016-09-30 18:30:32 +02:00
function_check install_tripwire
install_tripwire
2016-07-03 17:13:34 +02:00
2016-09-30 18:30:32 +02:00
function_check install_final
install_final
2016-10-23 20:38:14 +02:00
export DEBIAN_FRONTEND=
2016-07-03 17:13:34 +02:00
}
# NOTE: deliberately no exit 0