freedombone-utils-final 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Final stage of install
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. function install_final {
  29. if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
  30. return
  31. fi
  32. # unmount any attached usb drive
  33. if [ -d "$USB_MOUNT" ]; then
  34. umount "$USB_MOUNT"
  35. rm -rf "$USB_MOUNT"
  36. fi
  37. function_check split_gpg_key_into_fragments
  38. split_gpg_key_into_fragments
  39. lockdown_permissions
  40. mark_completed "${FUNCNAME[0]}"
  41. clear
  42. echo ''
  43. if [[ $ONION_ONLY == 'no' ]]; then
  44. echo $"
  45. If you wish to verify the server ssh public key at next login it is:
  46. $(get_ssh_server_key)
  47. Ensure that ports are forwarded from your internet router.
  48. You can find the list of ports within the firewall section of
  49. the administrator control panel.
  50. "
  51. else
  52. echo $"
  53. If you wish to verify the server ssh public key at next login it is:
  54. $(get_ssh_server_key)
  55. "
  56. fi
  57. echo ''
  58. # add user menu on ssh login
  59. if ! grep -q 'controluser' "/home/$MY_USERNAME/.bashrc"; then
  60. echo 'export PS1="\W \$"' >> "/home/$MY_USERNAME/.bashrc"
  61. echo 'controluser' >> "/home/$MY_USERNAME/.bashrc"
  62. fi
  63. if [ ! -f "$IMAGE_PASSWORD_FILE" ]; then
  64. if [ -f "/root/${PROJECT_NAME}-wifi.cfg" ]; then
  65. create_wifi_startup_script
  66. echo ''
  67. echo $'Shutting down the system. Detatch the ethernet cable, attach wifi dongle, then power on again.'
  68. echo ''
  69. "${PROJECT_NAME}-logging" off --restart
  70. systemctl poweroff
  71. return
  72. fi
  73. echo $'Turning off logging'
  74. "${PROJECT_NAME}-logging" off --restart
  75. echo $'Rebooting the system'
  76. systemctl reboot -i
  77. fi
  78. echo $'Turning off logging'
  79. "${PROJECT_NAME}-logging" off --restart
  80. }
  81. function update_installed_apps_list {
  82. # Why does this secondary file exist, apart from COMPLETION_FILE ?
  83. # It's so that it is visible to unprivileged users from the user control panel
  84. grep "install_" "$COMPLETION_FILE" > "/usr/share/${PROJECT_NAME}/installed.txt"
  85. }
  86. function create_default_user_removal_daemon {
  87. # This daemon runs on first boot and removes the default fbone user
  88. first_start_daemon_filename=/etc/systemd/system/firststart.service
  89. first_start_script=/usr/local/bin/firststart
  90. { echo '#!/bin/bash';
  91. echo 'if [ -d /home/fbone]; then';
  92. echo ' userdel -r fbone';
  93. echo ' if [ -d /home/fbone]; then';
  94. echo ' rm -rf /home/fbone';
  95. echo ' fi';
  96. echo 'fi';
  97. echo 'systemctl disable firststart';
  98. echo "rm $first_start_daemon_filename"; } > $first_start_script
  99. chmod +x $first_start_script
  100. { echo '[Unit]';
  101. echo 'Description=Daemon run on first boot';
  102. echo 'After=syslog.target';
  103. echo 'After=network.target';
  104. echo '';
  105. echo '[Service]';
  106. echo 'User=root';
  107. echo 'Group=root';
  108. echo "ExecStart=$first_start_script";
  109. echo 'StandardOutput=syslog';
  110. echo 'StandardError=syslog';
  111. echo '';
  112. echo '[Install]';
  113. echo 'WantedBy=multi-user.target'; } > $first_start_daemon_filename
  114. systemctl enable firststart
  115. }
  116. function final_set_onion_hostname {
  117. if [[ "$ONION_ONLY" == 'no' ]]; then
  118. return
  119. fi
  120. if [ ! -f /var/lib/tor/hidden_service_email/hostname ]; then
  121. echo $'No onion domain for email was found'
  122. exit 368365
  123. fi
  124. onion_domain=$(cat /var/lib/tor/hidden_service_email/hostname)
  125. echo "$onion_domain" > /etc/hostname
  126. hostname "$onion_domain"
  127. echo "127.0.1.1 $onion_domain" >> /etc/hosts
  128. echo "$onion_domain" > /etc/mailname
  129. }
  130. function setup_final {
  131. function_check update_installed_apps_list
  132. update_installed_apps_list
  133. function_check create_default_user_removal_daemon
  134. create_default_user_removal_daemon
  135. function_check final_set_onion_hostname
  136. final_set_onion_hostname
  137. function_check install_tripwire
  138. install_tripwire
  139. function_check install_final
  140. install_final
  141. export DEBIAN_FRONTEND=
  142. }
  143. # NOTE: deliberately no exit 0