Install avahi on mesh clients

This commit is contained in:
Bob Mottram 2016-05-28 22:30:06 +01:00
parent 399a463d2f
commit e611870937
1 changed files with 111 additions and 110 deletions

View File

@ -41,11 +41,11 @@ VERSION="1.01"
# get the main project file, so that some values can be extracted # get the main project file, so that some values can be extracted
MAIN_PROJECT_FILE=/usr/local/bin/${PROJECT_NAME} MAIN_PROJECT_FILE=/usr/local/bin/${PROJECT_NAME}
if [ ! -f $MAIN_PROJECT_FILE ]; then if [ ! -f $MAIN_PROJECT_FILE ]; then
MAIN_PROJECT_FILE=/usr/bin/${PROJECT_NAME} MAIN_PROJECT_FILE=/usr/bin/${PROJECT_NAME}
fi fi
if [ ! -f $MAIN_PROJECT_FILE ]; then if [ ! -f $MAIN_PROJECT_FILE ]; then
echo "The main project file $MAIN_PROJECT_FILE was not found" echo "The main project file $MAIN_PROJECT_FILE was not found"
exit 72529 exit 72529
fi fi
# ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html) # ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
@ -58,131 +58,131 @@ SSH_HOST_KEY_ALGORITHMS=$(cat $MAIN_PROJECT_FILE | grep 'SSH_HOST_KEY_ALGORITHMS
REFRESH_GPG_KEYS_HOURS=2 REFRESH_GPG_KEYS_HOURS=2
function refresh_gpg_keys { function refresh_gpg_keys {
if [ ! -f /usr/bin/gpg ]; then if [ ! -f /usr/bin/gpg ]; then
sudo apt-get -y install gnupg sudo apt-get -y install gnupg
fi fi
sudo cp /etc/crontab ~/temp_crontab sudo cp /etc/crontab ~/temp_crontab
sudo chown $CURR_USER:$CURR_USER ~/temp_crontab sudo chown $CURR_USER:$CURR_USER ~/temp_crontab
if ! grep -q "gpg --refresh-keys" ~/temp_crontab; then if ! grep -q "gpg --refresh-keys" ~/temp_crontab; then
echo "0 */$REFRESH_GPG_KEYS_HOURS * * * $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab echo "0 */$REFRESH_GPG_KEYS_HOURS * * * $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab
sudo cp ~/temp_crontab /etc/crontab sudo cp ~/temp_crontab /etc/crontab
sudo chown root:root /etc/crontab sudo chown root:root /etc/crontab
fi fi
rm ~/temp_crontab rm ~/temp_crontab
} }
# see https://stribika.github.io/2015/01/04/secure-secure-shell.html # see https://stribika.github.io/2015/01/04/secure-secure-shell.html
function ssh_remove_small_moduli { function ssh_remove_small_moduli {
sudo awk '$5 > 2000' /etc/ssh/moduli > /home/$CURR_USER/moduli sudo awk '$5 > 2000' /etc/ssh/moduli > /home/$CURR_USER/moduli
sudo mv /home/$CURR_USER/moduli /etc/ssh/moduli sudo mv /home/$CURR_USER/moduli /etc/ssh/moduli
} }
function configure_ssh_client { function configure_ssh_client {
#sudo sed -i 's/# PasswordAuthentication.*/ PasswordAuthentication no/g' /etc/ssh/ssh_config #sudo sed -i 's/# PasswordAuthentication.*/ PasswordAuthentication no/g' /etc/ssh/ssh_config
#sudo sed -i 's/# ChallengeResponseAuthentication.*/ ChallengeResponseAuthentication no/g' /etc/ssh/ssh_config #sudo sed -i 's/# ChallengeResponseAuthentication.*/ ChallengeResponseAuthentication no/g' /etc/ssh/ssh_config
sudo sed -i "s/# HostKeyAlgorithms.*/ HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config sudo sed -i "s/# HostKeyAlgorithms.*/ HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
sudo sed -i "s/# Ciphers.*/ Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config sudo sed -i "s/# Ciphers.*/ Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
sudo sed -i "s/# MACs.*/ MACs $SSH_MACS/g" /etc/ssh/ssh_config sudo sed -i "s/# MACs.*/ MACs $SSH_MACS/g" /etc/ssh/ssh_config
if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
sudo cp /etc/ssh/ssh_config ~/ssh_config sudo cp /etc/ssh/ssh_config ~/ssh_config
sudo chown $CURR_USER:$CURR_USER ~/ssh_config sudo chown $CURR_USER:$CURR_USER ~/ssh_config
echo " HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> ~/ssh_config echo " HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> ~/ssh_config
sudo mv ~/ssh_config /etc/ssh/ssh_config sudo mv ~/ssh_config /etc/ssh/ssh_config
sudo chown root:root /etc/ssh/ssh_config sudo chown root:root /etc/ssh/ssh_config
fi fi
sudo sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config sudo sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
if ! grep -q "Ciphers " /etc/ssh/ssh_config; then if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
sudo cp /etc/ssh/ssh_config ~/ssh_config sudo cp /etc/ssh/ssh_config ~/ssh_config
sudo chown $CURR_USER:$CURR_USER ~/ssh_config sudo chown $CURR_USER:$CURR_USER ~/ssh_config
echo " Ciphers $SSH_CIPHERS" >> ~/ssh_config echo " Ciphers $SSH_CIPHERS" >> ~/ssh_config
sudo mv ~/ssh_config /etc/ssh/ssh_config sudo mv ~/ssh_config /etc/ssh/ssh_config
sudo chown root:root /etc/ssh/ssh_config sudo chown root:root /etc/ssh/ssh_config
fi fi
sudo sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config sudo sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
if ! grep -q "MACs " /etc/ssh/ssh_config; then if ! grep -q "MACs " /etc/ssh/ssh_config; then
sudo cp /etc/ssh/ssh_config ~/ssh_config sudo cp /etc/ssh/ssh_config ~/ssh_config
sudo chown $CURR_USER:$CURR_USER ~/ssh_config sudo chown $CURR_USER:$CURR_USER ~/ssh_config
echo " MACs $SSH_MACS" >> ~/ssh_config echo " MACs $SSH_MACS" >> ~/ssh_config
sudo mv ~/ssh_config /etc/ssh/ssh_config sudo mv ~/ssh_config /etc/ssh/ssh_config
sudo chown root:root /etc/ssh/ssh_config sudo chown root:root /etc/ssh/ssh_config
fi fi
# Create ssh keys # Create ssh keys
if [ ! -f /home/$CURR_USER/.ssh/id_ed25519 ]; then if [ ! -f /home/$CURR_USER/.ssh/id_ed25519 ]; then
ssh-keygen -t ed25519 -o -a 100 ssh-keygen -t ed25519 -o -a 100
fi fi
if [ ! -f /home/$CURR_USER/.ssh/id_rsa ]; then if [ ! -f /home/$CURR_USER/.ssh/id_rsa ]; then
ssh-keygen -t rsa -b 4096 -o -a 100 ssh-keygen -t rsa -b 4096 -o -a 100
fi fi
ssh_remove_small_moduli ssh_remove_small_moduli
if [ ! -d ~/.ssh ]; then if [ ! -d ~/.ssh ]; then
mkdir ~/.ssh mkdir ~/.ssh
fi fi
echo 'Host *.onion' > ~/.ssh/config echo 'Host *.onion' > ~/.ssh/config
echo ' ServerAliveInterval 60' >> ~/.ssh/config echo ' ServerAliveInterval 60' >> ~/.ssh/config
echo ' ServerAliveCountMax 3' >> ~/.ssh/config echo ' ServerAliveCountMax 3' >> ~/.ssh/config
if [[ $ENABLE_MONKEYSPHERE == $'yes' || $ENABLE_MONKEYSPHERE == $'y' ]]; then if [[ $ENABLE_MONKEYSPHERE == $'yes' || $ENABLE_MONKEYSPHERE == $'y' ]]; then
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 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
else else
echo " ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p" >> ~/.ssh/config echo " ProxyCommand connect -R remote -5 -S 127.0.0.1:9050 %h %p" >> ~/.ssh/config
fi fi
echo 'Host *' >> ~/.ssh/config echo 'Host *' >> ~/.ssh/config
echo ' ServerAliveInterval 60' >> ~/.ssh/config echo ' ServerAliveInterval 60' >> ~/.ssh/config
echo ' ServerAliveCountMax 3' >> ~/.ssh/config echo ' ServerAliveCountMax 3' >> ~/.ssh/config
if [[ $ENABLE_MONKEYSPHERE == $'yes' || $ENABLE_MONKEYSPHERE == $'y' ]]; then if [[ $ENABLE_MONKEYSPHERE == $'yes' || $ENABLE_MONKEYSPHERE == $'y' ]]; then
echo ' ProxyCommand monkeysphere ssh-proxycommand %h %p' >> ~/.ssh/config echo ' ProxyCommand monkeysphere ssh-proxycommand %h %p' >> ~/.ssh/config
fi fi
echo '' echo ''
echo $'Copy the following into a file called /home/username/.ssh/authorized_keys on the Freedombone server' echo $'Copy the following into a file called /home/username/.ssh/authorized_keys on the Freedombone server'
echo '' echo ''
echo $(cat /home/$CURR_USER/.ssh/id_rsa.pub) echo $(cat /home/$CURR_USER/.ssh/id_rsa.pub)
echo $(cat /home/$CURR_USER/.ssh/id_ed25519.pub) echo $(cat /home/$CURR_USER/.ssh/id_ed25519.pub)
echo '' echo ''
} }
function configure_monkeysphere { function configure_monkeysphere {
sudo apt-get -y install tor connect-proxy monkeysphere sudo apt-get -y install tor connect-proxy monkeysphere
} }
function show_help { function show_help {
echo '' echo ''
echo $"${PROJECT_NAME}-client --mesh [yes|no] --monkeysphere [yes|no]" echo $"${PROJECT_NAME}-client --mesh [yes|no] --monkeysphere [yes|no]"
echo '' echo ''
exit 0 exit 0
} }
while [[ $# > 1 ]] while [[ $# > 1 ]]
do do
key="$1" key="$1"
case $key in case $key in
-h|--help) -h|--help)
show_help show_help
;; ;;
--essid) --essid)
shift shift
WIFI_SSID="$1" WIFI_SSID="$1"
;; ;;
--channel) --channel)
shift shift
WIFI_CHANNEL=${1} WIFI_CHANNEL=${1}
;; ;;
-m|--mesh) -m|--mesh)
shift shift
MESH_CLIENT_INSTALL=${1} MESH_CLIENT_INSTALL=${1}
;; ;;
--monkeysphere|--ms|--monkey) --monkeysphere|--ms|--monkey)
shift shift
ENABLE_MONKEYSPHERE=${1} ENABLE_MONKEYSPHERE=${1}
;; ;;
*) *)
# unknown option # unknown option
;; ;;
esac esac
shift shift
done done
echo $'Configuring client' echo $'Configuring client'
@ -190,10 +190,11 @@ refresh_gpg_keys
configure_ssh_client configure_ssh_client
configure_monkeysphere configure_monkeysphere
if [[ $MESH_CLIENT_INSTALL == $'yes' || $MESH_CLIENT_INSTALL == $'y' || $MESH_CLIENT_INSTALL == $'on' ]]; then if [[ $MESH_CLIENT_INSTALL == $'yes' || $MESH_CLIENT_INSTALL == $'y' || $MESH_CLIENT_INSTALL == $'on' ]]; then
echo $'Installing mesh packages' echo $'Installing mesh packages'
${PROJECT_NAME}-mesh-install -f toxic sudo apt-get -y install avahi-utils avahi-autoipd avahi-dnsconfd
${PROJECT_NAME}-mesh-install -f qtox ${PROJECT_NAME}-mesh-install -f toxic
${PROJECT_NAME}-mesh-install -f batman_client ${PROJECT_NAME}-mesh-install -f qtox
${PROJECT_NAME}-mesh-install -f batman_client
fi fi
echo $'Configuration complete' echo $'Configuration complete'
exit 0 exit 0