freedombone-client 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
  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. PROJECT_NAME='freedombone'
  29. export TEXTDOMAIN=${PROJECT_NAME}-client
  30. export TEXTDOMAINDIR="/usr/share/locale"
  31. CURR_USER=$USER
  32. MESH_CLIENT_INSTALL=
  33. ENABLE_MONKEYSPHERE=
  34. # Version number of this script
  35. VERSION="1.01"
  36. # get the main project file, so that some values can be extracted
  37. MAIN_PROJECT_FILE=/usr/local/bin/${PROJECT_NAME}
  38. if [ ! -f $MAIN_PROJECT_FILE ]; then
  39. MAIN_PROJECT_FILE=/usr/bin/${PROJECT_NAME}
  40. fi
  41. if [ ! -f $MAIN_PROJECT_FILE ]; then
  42. echo "The main project file $MAIN_PROJECT_FILE was not found"
  43. exit 72529
  44. fi
  45. # ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
  46. SSH_CIPHERS=$(cat $MAIN_PROJECT_FILE | grep 'SSH_CIPHERS=' | head -n 1 | awk -F '"' '{print $2}')
  47. SSH_MACS=$(cat $MAIN_PROJECT_FILE | grep 'SSH_MACS=' | head -n 1 | awk -F '"' '{print $2}')
  48. SSH_KEX=$(cat $MAIN_PROJECT_FILE | grep 'SSH_KEX=' | head -n 1 | awk -F '"' '{print $2}')
  49. SSH_HOST_KEY_ALGORITHMS=$(cat $MAIN_PROJECT_FILE | grep 'SSH_HOST_KEY_ALGORITHMS=' | head -n 1 | awk -F '"' '{print $2}')
  50. # refresh gpg keys every few hours
  51. REFRESH_GPG_KEYS_HOURS=2
  52. function refresh_gpg_keys {
  53. if [ ! -f /usr/bin/gpg ]; then
  54. sudo apt-get -y install gnupg
  55. fi
  56. sudo cp /etc/crontab ~/temp_crontab
  57. sudo chown $CURR_USER:$CURR_USER ~/temp_crontab
  58. if ! grep -q "gpg --refresh-keys" ~/temp_crontab; then
  59. echo "0 */$REFRESH_GPG_KEYS_HOURS * * * $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab
  60. sudo cp ~/temp_crontab /etc/crontab
  61. sudo chown root:root /etc/crontab
  62. fi
  63. rm ~/temp_crontab
  64. }
  65. # see https://stribika.github.io/2015/01/04/secure-secure-shell.html
  66. function ssh_remove_small_moduli {
  67. sudo awk '$5 > 2000' /etc/ssh/moduli > /home/$CURR_USER/moduli
  68. sudo mv /home/$CURR_USER/moduli /etc/ssh/moduli
  69. }
  70. function configure_ssh_client {
  71. #sudo sed -i 's/# PasswordAuthentication.*/ PasswordAuthentication no/g' /etc/ssh/ssh_config
  72. #sudo sed -i 's/# ChallengeResponseAuthentication.*/ ChallengeResponseAuthentication no/g' /etc/ssh/ssh_config
  73. sudo sed -i "s/# HostKeyAlgorithms.*/ HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
  74. sudo sed -i "s/# Ciphers.*/ Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
  75. sudo sed -i "s/# MACs.*/ MACs $SSH_MACS/g" /etc/ssh/ssh_config
  76. if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
  77. sudo cp /etc/ssh/ssh_config ~/ssh_config
  78. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  79. echo " HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> ~/ssh_config
  80. sudo mv ~/ssh_config /etc/ssh/ssh_config
  81. sudo chown root:root /etc/ssh/ssh_config
  82. fi
  83. sudo sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
  84. if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
  85. sudo cp /etc/ssh/ssh_config ~/ssh_config
  86. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  87. echo " Ciphers $SSH_CIPHERS" >> ~/ssh_config
  88. sudo mv ~/ssh_config /etc/ssh/ssh_config
  89. sudo chown root:root /etc/ssh/ssh_config
  90. fi
  91. sudo sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
  92. if ! grep -q "MACs " /etc/ssh/ssh_config; then
  93. sudo cp /etc/ssh/ssh_config ~/ssh_config
  94. sudo chown $CURR_USER:$CURR_USER ~/ssh_config
  95. echo " MACs $SSH_MACS" >> ~/ssh_config
  96. sudo mv ~/ssh_config /etc/ssh/ssh_config
  97. sudo chown root:root /etc/ssh/ssh_config
  98. fi
  99. # Create ssh keys
  100. if [ ! -f /home/$CURR_USER/.ssh/id_ed25519 ]; then
  101. ssh-keygen -t ed25519 -o -a 100
  102. fi
  103. if [ ! -f /home/$CURR_USER/.ssh/id_rsa ]; then
  104. ssh-keygen -t rsa -b 4096 -o -a 100
  105. fi
  106. ssh_remove_small_moduli
  107. if [ ! -d ~/.ssh ]; then
  108. mkdir ~/.ssh
  109. fi
  110. echo 'Host *.onion' > ~/.ssh/config
  111. echo ' ServerAliveInterval 60' >> ~/.ssh/config
  112. echo ' ServerAliveCountMax 3' >> ~/.ssh/config
  113. if [[ $ENABLE_MONKEYSPHERE == $'yes' || $ENABLE_MONKEYSPHERE == $'y' ]]; then
  114. echo " ProxyCommand sh -c 'monkeysphere ssh-proxycommand --no-connect %h %p ; connect -R remote -5 -S 127.0.0.1:9050 %h %p'" >> ~/.ssh/config
  115. else
  116. echo " ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p" >> ~/.ssh/config
  117. fi
  118. echo 'Host *' >> ~/.ssh/config
  119. echo ' ServerAliveInterval 60' >> ~/.ssh/config
  120. echo ' ServerAliveCountMax 3' >> ~/.ssh/config
  121. if [[ $ENABLE_MONKEYSPHERE == $'yes' || $ENABLE_MONKEYSPHERE == $'y' ]]; then
  122. echo ' ProxyCommand monkeysphere ssh-proxycommand %h %p' >> ~/.ssh/config
  123. fi
  124. echo ''
  125. echo $'Copy the following into a file called /home/username/.ssh/authorized_keys on the Freedombone server'
  126. echo ''
  127. echo $(cat /home/$CURR_USER/.ssh/id_rsa.pub)
  128. echo $(cat /home/$CURR_USER/.ssh/id_ed25519.pub)
  129. echo ''
  130. }
  131. function configure_monkeysphere {
  132. sudo apt-get -y install tor connect-proxy monkeysphere
  133. }
  134. function show_help {
  135. echo ''
  136. echo $"${PROJECT_NAME}-client --mesh [yes|no] --monkeysphere [yes|no]"
  137. echo ''
  138. exit 0
  139. }
  140. while [[ $# > 1 ]]
  141. do
  142. key="$1"
  143. case $key in
  144. -h|--help)
  145. show_help
  146. ;;
  147. --essid)
  148. shift
  149. WIFI_SSID="$1"
  150. ;;
  151. --channel)
  152. shift
  153. WIFI_CHANNEL=${1}
  154. ;;
  155. -m|--mesh)
  156. shift
  157. MESH_CLIENT_INSTALL=${1}
  158. ;;
  159. --monkeysphere|--ms|--monkey)
  160. shift
  161. ENABLE_MONKEYSPHERE=${1}
  162. ;;
  163. *)
  164. # unknown option
  165. ;;
  166. esac
  167. shift
  168. done
  169. echo $'Configuring client'
  170. refresh_gpg_keys
  171. configure_ssh_client
  172. configure_monkeysphere
  173. if [[ $MESH_CLIENT_INSTALL == $'yes' || $MESH_CLIENT_INSTALL == $'y' || $MESH_CLIENT_INSTALL == $'on' ]]; then
  174. echo $'Installing mesh packages'
  175. sudo apt-get -y install avahi-utils avahi-autoipd avahi-dnsconfd
  176. sudo ${PROJECT_NAME}-mesh-install -f tox_node
  177. sudo ${PROJECT_NAME}-mesh-install -f toxic
  178. ${PROJECT_NAME}-mesh-install -f qtox
  179. sudo ${PROJECT_NAME}-mesh-install -f zeronet
  180. ${PROJECT_NAME}-mesh-install -f batman_client
  181. fi
  182. echo $'Configuration complete'
  183. exit 0