From 6d3943e23e541dc4f57b11017836760b5b34c843 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 20 Apr 2016 12:17:44 +0100 Subject: [PATCH] wifi command --- src/freedombone | 24 +- src/freedombone-client | 10 +- src/freedombone-config | 1056 +++++++++++++++++----------------- src/freedombone-mesh-batman | 22 +- src/freedombone-mesh-install | 12 +- src/freedombone-wifi | 141 +++++ 6 files changed, 719 insertions(+), 546 deletions(-) create mode 100755 src/freedombone-wifi diff --git a/src/freedombone b/src/freedombone index a165517e..1f73ae6d 100755 --- a/src/freedombone +++ b/src/freedombone @@ -441,6 +441,9 @@ EXTERNAL_IP_SERVICES=( \ WIFI_CHANNEL=2 WIFI_INTERFACE=wlan0 +WIFI_TYPE='wpa2-psk' +WIFI_SSID= +WIFI_PASSPHRASE= # cjdns settings ENABLE_CJDNS="no" @@ -457,7 +460,6 @@ CJDCMD_COMMIT='973cca6ed0eecf9041c3403a40193c0b1291b808' # B.A.T.M.A.N settings ENABLE_BATMAN="no" BATMAN_CELLID='any' -ESSID='mesh' # Babel mesh ENABLE_BABEL="no" @@ -1061,6 +1063,18 @@ function read_configuration { if [[ $CONFIGURATION_FILE != "/root/${PROJECT_NAME}.cfg" ]]; then cp $CONFIGURATION_FILE /root/${PROJECT_NAME}.cfg fi + if grep -q "WIFI_INTERFACE" $CONFIGURATION_FILE; then + WIFI_INTERFACE=$(grep "WIFI_INTERFACE" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "WIFI_SSID" $CONFIGURATION_FILE; then + WIFI_SSID=$(grep "WIFI_SSID" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "WIFI_TYPE" $CONFIGURATION_FILE; then + WIFI_TYPE=$(grep "WIFI_TYPE" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "WIFI_PASSPHRASE" $CONFIGURATION_FILE; then + WIFI_PASSPHRASE=$(grep "WIFI_PASSPHRASE" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi if grep -q "SYNCTHING_ID" $CONFIGURATION_FILE; then SYNCTHING_ID=$(grep "SYNCTHING_ID" $CONFIGURATION_FILE | awk -F '=' '{print $2}') fi @@ -1223,9 +1237,6 @@ function read_configuration { if grep -q "DH_KEYLENGTH" $CONFIGURATION_FILE; then DH_KEYLENGTH=$(grep "DH_KEYLENGTH" $CONFIGURATION_FILE | awk -F '=' '{print $2}') fi - if grep -q "WIFI_INTERFACE" $CONFIGURATION_FILE; then - WIFI_INTERFACE=$(grep "WIFI_INTERFACE" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi if grep -q "IRC_PORT" $CONFIGURATION_FILE; then IRC_PORT=$(grep "IRC_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}') fi @@ -1235,9 +1246,6 @@ function read_configuration { if grep -q "BATMAN_CELLID" $CONFIGURATION_FILE; then BATMAN_CELLID=$(grep "BATMAN_CELLID" $CONFIGURATION_FILE | awk -F '=' '{print $2}') fi - if grep -q "ESSID" $CONFIGURATION_FILE; then - ESSID=$(grep "ESSID" $CONFIGURATION_FILE | awk -F '=' '{print $2}') - fi if grep -q "TOX_PORT" $CONFIGURATION_FILE; then TOX_PORT=$(grep "TOX_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}') fi @@ -3097,7 +3105,7 @@ function mesh_batman { echo '' >> /home/$MY_USERNAME/README echo 'Mesh Networking (B.A.T.M.A.N)' >> /home/$MY_USERNAME/README echo '=============================' >> /home/$MY_USERNAME/README - echo "Mesh ESSID: $ESSID" >> /home/$MY_USERNAME/README + echo "Mesh ESSID: $WIFI_SSID" >> /home/$MY_USERNAME/README echo "Mesh cell ID: $BATMAN_CELLID" >> /home/$MY_USERNAME/README echo "Mesh wifi channel: $WIFI_CHANNEL" >> /home/$MY_USERNAME/README chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README diff --git a/src/freedombone-client b/src/freedombone-client index b451efe8..5cdf3f4c 100755 --- a/src/freedombone-client +++ b/src/freedombone-client @@ -41,7 +41,7 @@ WIFI_INTERFACE=wlan0 # B.A.T.M.A.N settings BATMAN_CELLID='02:BA:00:00:03:01' -ESSID='mesh' +WIFI_SSID='mesh' # Babel BABEL_PORT=6696 @@ -155,7 +155,7 @@ function mesh_batman { echo 'fi' >> $BATMAN_SCRIPT echo '' >> $BATMAN_SCRIPT echo '# Mesh definition' >> $BATMAN_SCRIPT - echo "ESSID=$ESSID" >> $BATMAN_SCRIPT + echo "WIFI_SSID=$WIFI_SSID" >> $BATMAN_SCRIPT echo "CELLID=$BATMAN_CELLID" >> $BATMAN_SCRIPT echo "CHANNEL=$WIFI_CHANNEL" >> $BATMAN_SCRIPT echo '' >> $BATMAN_SCRIPT @@ -193,7 +193,7 @@ function mesh_batman { echo ' echo "error: unable to find wifi interface, not enabling batman-adv mesh"' >> $BATMAN_SCRIPT echo ' return' >> $BATMAN_SCRIPT echo ' fi' >> $BATMAN_SCRIPT - echo ' echo "info: enabling batman-adv mesh network $ESSID on $IFACE"' >> $BATMAN_SCRIPT + echo ' echo "info: enabling batman-adv mesh network $WIFI_SSID on $IFACE"' >> $BATMAN_SCRIPT echo ' if [ -f /bin/systemctl ]; then' >> $BATMAN_SCRIPT echo ' systemctl stop network-manager' >> $BATMAN_SCRIPT @@ -213,7 +213,7 @@ function mesh_batman { echo ' ifconfig $IFACE down' >> $BATMAN_SCRIPT echo ' ifconfig $IFACE mtu 1532' >> $BATMAN_SCRIPT echo ' iwconfig $IFACE enc off' >> $BATMAN_SCRIPT - echo ' iwconfig $IFACE mode ad-hoc essid $ESSID channel $CHANNEL' >> $BATMAN_SCRIPT + echo ' iwconfig $IFACE mode ad-hoc essid $WIFI_SSID channel $CHANNEL' >> $BATMAN_SCRIPT echo ' sleep 1' >> $BATMAN_SCRIPT echo ' iwconfig $IFACE ap $CELLID' >> $BATMAN_SCRIPT echo '' >> $BATMAN_SCRIPT @@ -397,7 +397,7 @@ do ;; --essid) shift - ESSID="$1" + WIFI_SSID="$1" ;; --channel) shift diff --git a/src/freedombone-config b/src/freedombone-config index e3fe385d..d619af92 100755 --- a/src/freedombone-config +++ b/src/freedombone-config @@ -102,7 +102,10 @@ MEDIAGOBLIN_CODE= USB_DRIVE=/dev/sdb1 HWRNG_TYPE= ENABLE_SOCIAL_KEY_MANAGEMENT= -ESSID='mesh' +WIFI_INTERFACE=wlan0 +WIFI_TYPE='wpa2-psk' +WIFI_SSID= +WIFI_PASSPHRASE= BATMAN_CELLID='any' WIFI_CHANNEL= CONFIGURATION_FILE= @@ -288,8 +291,17 @@ function save_configuration_file { if [ $ENABLE_SOCIAL_KEY_MANAGEMENT ]; then echo "ENABLE_SOCIAL_KEY_MANAGEMENT=$ENABLE_SOCIAL_KEY_MANAGEMENT" >> $CONFIGURATION_FILE fi - if [ $ESSID ]; then - echo "ESSID=$ESSID" >> $CONFIGURATION_FILE + if [ $WIFI_SSID ]; then + echo "WIFI_SSID=$WIFI_SSID" >> $CONFIGURATION_FILE + fi + if [ $WIFI_INTERFACE ]; then + echo "WIFI_INTERFACE=$WIFI_INTERFACE" >> $CONFIGURATION_FILE + fi + if [ $WIFI_TYPE ]; then + echo "WIFI_TYPE=$WIFI_TYPE" >> $CONFIGURATION_FILE + fi + if [ ${#WIFI_PASSPHRASE} -gt 1 ]; then + echo "WIFI_PASSPHRASE=$WIFI_PASSPHRASE" >> $CONFIGURATION_FILE fi if [ $BATMAN_CELLID ]; then echo "BATMAN_CELLID=$BATMAN_CELLID" >> $CONFIGURATION_FILE @@ -829,327 +841,330 @@ function interactive_configuration { ENABLE_BATMAN="yes" ENABLE_CJDNS="no" ENABLE_BABEL="no" + if [ ! $WIFI_SSID ]; then + WIFI_SSID='mesh' + fi + + #data=$(tempfile 2>/dev/null) + #trap "rm -f $data" 0 1 2 5 15 + #dialog --backtitle "Freedombone Configuration" \ + # --radiolist "Select your type of mesh network:" 10 40 3 \ + # 1 "Babel" off \ + # 2 "B.A.T.M.A.N. Advanced" on \ + # 3 "cjdns" off 2> $data + #sel=$? + #case $sel in + # 1) exit 1;; + # 255) exit 1;; + #esac + #case $(cat $data) in + # 1) ENABLE_BABEL="yes";; + # 2) ENABLE_BATMAN="yes";; + # 3) ENABLE_CJDNS="yes";; + #esac + save_configuration_file - #data=$(tempfile 2>/dev/null) - #trap "rm -f $data" 0 1 2 5 15 - #dialog --backtitle "Freedombone Configuration" \ - # --radiolist "Select your type of mesh network:" 10 40 3 \ - # 1 "Babel" off \ - # 2 "B.A.T.M.A.N. Advanced" on \ - # 3 "cjdns" off 2> $data - #sel=$? - #case $sel in - # 1) exit 1;; - # 255) exit 1;; - #esac - #case $(cat $data) in - # 1) ENABLE_BABEL="yes";; - # 2) ENABLE_BATMAN="yes";; - # 3) ENABLE_CJDNS="yes";; - #esac - save_configuration_file + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone Configuration" \ + --inputbox $"Wireless Mesh ESSID\n\nIf you press enter the default will be '$WIFI_SSID'" 10 40 "$(grep 'WIFI_SSID' temp.cfg | awk -F '=' '{print $2}')" 2> $data + sel=$? + case $sel in + 0) WIFI_SSID=$(cat $data);; + 1) exit 1;; + 255) exit 1;; + esac + save_configuration_file - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone Configuration" \ - --inputbox $"Wireless Mesh ESSID\n\nIf you press enter the default will be '$ESSID'" 10 40 "$(grep 'ESSID' temp.cfg | awk -F '=' '{print $2}')" 2> $data - sel=$? - case $sel in - 0) ESSID=$(cat $data);; - 1) exit 1;; - 255) exit 1;; - esac - save_configuration_file + if [[ $SYSTEM_TYPE != "$VARIANT_MESH_USER" ]]; then + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone Configuration" \ + --inputbox $"Give your mesh peer a name" 10 40 "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data + sel=$? + case $sel in + 0) DEFAULT_DOMAIN_NAME=$(cat $data);; + 1) exit 1;; + 255) exit 1;; + esac + else + DEFAULT_DOMAIN_NAME=$(hostname) + fi + save_configuration_file - if [[ $SYSTEM_TYPE != "$VARIANT_MESH_USER" ]]; then - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone Configuration" \ - --inputbox $"Give your mesh peer a name" 10 40 "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data - sel=$? - case $sel in - 0) DEFAULT_DOMAIN_NAME=$(cat $data);; - 1) exit 1;; - 255) exit 1;; - esac - else - DEFAULT_DOMAIN_NAME=$(hostname) - fi - save_configuration_file + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone Configuration" \ + --radiolist $"Wifi Channel (spaced to be non-overlapping):" 11 50 4 \ + 1 "1" on \ + 2 "5" off \ + 3 "9" off \ + 4 "13" off 2> $data + sel=$? + case $sel in + 1) exit 1;; + 255) exit 1;; + esac + case $(cat $data) in + 1) WIFI_CHANNEL=1;; + 2) WIFI_CHANNEL=5;; + 3) WIFI_CHANNEL=9;; + 4) WIFI_CHANNEL=13;; + esac + save_configuration_file + fi - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone Configuration" \ - --radiolist $"Wifi Channel (spaced to be non-overlapping):" 11 50 4 \ - 1 "1" on \ - 2 "5" off \ - 3 "9" off \ - 4 "13" off 2> $data - sel=$? - case $sel in - 1) exit 1;; - 255) exit 1;; - esac - case $(cat $data) in - 1) WIFI_CHANNEL=1;; - 2) WIFI_CHANNEL=5;; - 3) WIFI_CHANNEL=9;; - 4) WIFI_CHANNEL=13;; - esac - save_configuration_file - fi + #if [[ $ENABLE_BATMAN == "yes" ]]; then + # data=$(tempfile 2>/dev/null) + # trap "rm -f $data" 0 1 2 5 15 + # dialog --backtitle "Freedombone Configuration" \ + # --inputbox "Optionally register with an Access Point" 10 40 "$(grep 'BATMAN_CELLID' temp.cfg | awk -F '=' '{print $2}')" 2> $data + # sel=$? + # case $sel in + # 0) BATMAN_CELLID=$(cat $data);; + # 1) exit 1;; + # 255) exit 1;; + # esac + # save_configuration_file + #fi - #if [[ $ENABLE_BATMAN == "yes" ]]; then - # data=$(tempfile 2>/dev/null) - # trap "rm -f $data" 0 1 2 5 15 - # dialog --backtitle "Freedombone Configuration" \ - # --inputbox "Optionally register with an Access Point" 10 40 "$(grep 'BATMAN_CELLID' temp.cfg | awk -F '=' '{print $2}')" 2> $data - # sel=$? - # case $sel in - # 0) BATMAN_CELLID=$(cat $data);; - # 1) exit 1;; - # 255) exit 1;; - # esac - # save_configuration_file - #fi + if [[ $SYSTEM_TYPE == "$VARIANT_MESH_USER" ]]; then + ${PROJECT_NAME}-client --essid $WIFI_SSID --channel $WIFI_CHANNEL + if [ "$?" = "0" ]; then + clear + echo ".---. . . " + echo "| | | " + echo "|--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. " + echo "| | (.-' (.-' ( | ( )| | | | )( )| | (.-' " + echo "' ' --' --' -' - -' ' ' -' -' -' ' - --'" + echo '' + echo $'Your system is now ready for connection to the mesh network' + echo '' + echo $'To connect to the network open a terminal and type:' + echo '' + echo ' meshweb' + echo '' + echo $'To disconnect from the mesh and return to the internet type:' + echo '' + echo ' sudo batman stop' + echo '' + echo $'To turn your system into a dedicated mesh peer you could add' + echo $'the meshweb command to your startup applications' + echo '' + touch /tmp/meshuserdevice + exit 0 + else + echo $'Failed to fully install the mesh networking system' + exit 74589 + fi + fi - if [[ $SYSTEM_TYPE == "$VARIANT_MESH_USER" ]]; then - ${PROJECT_NAME}-client --essid $ESSID --channel $WIFI_CHANNEL - if [ "$?" = "0" ]; then - clear - echo ".---. . . " - echo "| | | " - echo "|--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. " - echo "| | (.-' (.-' ( | ( )| | | | )( )| | (.-' " - echo "' ' --' --' -' - -' ' ' -' -' -' ' - --'" - echo '' - echo $'Your system is now ready for connection to the mesh network' - echo '' - echo $'To connect to the network open a terminal and type:' - echo '' - echo ' meshweb' - echo '' - echo $'To disconnect from the mesh and return to the internet type:' - echo '' - echo ' sudo batman stop' - echo '' - echo $'To turn your system into a dedicated mesh peer you could add' - echo $'the meshweb command to your startup applications' - echo '' - touch /tmp/meshuserdevice - exit 0 - else - echo $'Failed to fully install the mesh networking system' - exit 74589 - fi - fi + if [ -d /home/$GENERIC_IMAGE_USERNAME ]; then + if [ ! -f $IMAGE_PASSWORD_FILE ]; then + echo 'Cannot find the password file for the admin user' + exit 62753 + fi + # when installing from an image which comes with a known default user account + SELECTED_USERNAME= + while [ ! $SELECTED_USERNAME ] + do + if [ ! $SELECTED_USERNAME ]; then + SELECTED_USERNAME=$(grep 'MY_USERNAME' temp.cfg | awk -F '=' '{print $2}') + fi + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone Configuration" \ + --title $"Username" \ + --inputbox $"Set your username for the system\n\nYour username should not contain any spaces" 12 60 "$SELECTED_USERNAME" 2> $data + sel=$? + case $sel in + 0) possible_username=$(cat $data) + SELECTED_USERNAME= + if [[ $possible_username != *' '* && $possible_username != *'/'* && $possible_username != *'\'* && $possible_username != *'*'* ]]; then + if [ $possible_username ]; then + if [ ${#possible_username} -gt 1 ]; then + if [[ $possible_username != $GENERIC_IMAGE_USERNAME ]]; then + MY_USERNAME=$(cat $data) + useradd -m -s /bin/bash $MY_USERNAME + if [ -d /home/$MY_USERNAME ]; then + echo "${MY_USERNAME}:$(printf `cat $IMAGE_PASSWORD_FILE`)" | chpasswd + # Add the user as a sudoer - they will be the new admin user + if ! grep -q "$MY_USERNAME ALL=(ALL) ALL" /etc/sudoers; then + echo "$MY_USERNAME ALL=(ALL) ALL" >> /etc/sudoers + # remove the generic image admin user from sudoers + sed -i "s|${GENERIC_IMAGE_USERNAME}.*||g" /etc/sudoers + fi + break + fi + fi + fi + fi + fi + ;; + 1) exit 1;; + 255) exit 1;; + esac + done + else + no_of_users=$(find /home/* -maxdepth 0 -type d | wc -l) + if [ $no_of_users -eq 1 ]; then + # only a single user on the system + MY_USERNAME=$(ls /home) + else + # select one from a number of users + if [[ $SYSTEM_TYPE == "$VARIANT_MESH" && $DEFAULT_DOMAIN_NAME && -d /home/$DEFAULT_DOMAIN_NAME ]]; then + MY_USERNAME=$DEFAULT_DOMAIN_NAME + else + select_user + if [ ! $SELECTED_USERNAME ]; then + echo $'No username selected' + exit 72589 + fi + MY_USERNAME="$SELECTED_USERNAME" + fi + fi + fi - if [ -d /home/$GENERIC_IMAGE_USERNAME ]; then - if [ ! -f $IMAGE_PASSWORD_FILE ]; then - echo 'Cannot find the password file for the admin user' - exit 62753 - fi - # when installing from an image which comes with a known default user account - SELECTED_USERNAME= - while [ ! $SELECTED_USERNAME ] - do - if [ ! $SELECTED_USERNAME ]; then - SELECTED_USERNAME=$(grep 'MY_USERNAME' temp.cfg | awk -F '=' '{print $2}') - fi - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone Configuration" \ - --title $"Username" \ - --inputbox $"Set your username for the system\n\nYour username should not contain any spaces" 12 60 "$SELECTED_USERNAME" 2> $data - sel=$? - case $sel in - 0) possible_username=$(cat $data) - SELECTED_USERNAME= - if [[ $possible_username != *' '* && $possible_username != *'/'* && $possible_username != *'\'* && $possible_username != *'*'* ]]; then - if [ $possible_username ]; then - if [ ${#possible_username} -gt 1 ]; then - if [[ $possible_username != $GENERIC_IMAGE_USERNAME ]]; then - MY_USERNAME=$(cat $data) - useradd -m -s /bin/bash $MY_USERNAME - if [ -d /home/$MY_USERNAME ]; then - echo "${MY_USERNAME}:$(printf `cat $IMAGE_PASSWORD_FILE`)" | chpasswd - # Add the user as a sudoer - they will be the new admin user - if ! grep -q "$MY_USERNAME ALL=(ALL) ALL" /etc/sudoers; then - echo "$MY_USERNAME ALL=(ALL) ALL" >> /etc/sudoers - # remove the generic image admin user from sudoers - sed -i "s|${GENERIC_IMAGE_USERNAME}.*||g" /etc/sudoers - fi - break - fi - fi - fi - fi - fi - ;; - 1) exit 1;; - 255) exit 1;; - esac - done - else - no_of_users=$(find /home/* -maxdepth 0 -type d | wc -l) - if [ $no_of_users -eq 1 ]; then - # only a single user on the system - MY_USERNAME=$(ls /home) - else - # select one from a number of users - if [[ $SYSTEM_TYPE == "$VARIANT_MESH" && $DEFAULT_DOMAIN_NAME && -d /home/$DEFAULT_DOMAIN_NAME ]]; then - MY_USERNAME=$DEFAULT_DOMAIN_NAME - else - select_user - if [ ! $SELECTED_USERNAME ]; then - echo $'No username selected' - exit 72589 - fi - MY_USERNAME="$SELECTED_USERNAME" - fi - fi - fi + if [ ! $MY_USERNAME ]; then + echo $'No user account was selected' + exit 64398 + fi + if [[ $MY_USERNAME == '-f' ]]; then + echo $'No user account was selected' + exit 8347 + fi + if [[ $MY_USERNAME == 'debian' || $MY_USERNAME == 'fbone' ]]; then + echo $"Don't use the default user account" + exit 9341 + fi + if [ ! -d /home/$MY_USERNAME ]; then + echo $"The directory /home/$MY_USERNAME does not exist" + exit 6437 + fi + save_configuration_file - if [ ! $MY_USERNAME ]; then - echo $'No user account was selected' - exit 64398 - fi - if [[ $MY_USERNAME == '-f' ]]; then - echo $'No user account was selected' - exit 8347 - fi - if [[ $MY_USERNAME == 'debian' || $MY_USERNAME == 'fbone' ]]; then - echo $"Don't use the default user account" - exit 9341 - fi - if [ ! -d /home/$MY_USERNAME ]; then - echo $"The directory /home/$MY_USERNAME does not exist" - exit 6437 - fi - save_configuration_file + if [[ $MINIMAL_INSTALL == "no" ]]; then + if [[ $(grep "INSTALLING_ON_BBB" temp.cfg | awk -F '=' '{print $2}') == "yes" ]]; then + dialog --title $"Install Target" \ + --backtitle $"Freedombone Configuration" \ + --yesno $"\nAre you installing onto a Beaglebone Black?" 7 60 + else + dialog --title $"Install Target" \ + --backtitle $"Freedombone Configuration" \ + --defaultno \ + --yesno $"\nAre you installing onto a Beaglebone Black?" 7 60 + fi + sel=$? + case $sel in + 0) INSTALLING_ON_BBB="yes";; + 1) INSTALLING_ON_BBB="no";; + 255) exit 1;; + esac + if [[ $INSTALLING_ON_BBB == "yes" ]]; then + USB_DRIVE=/dev/sda1 + fi + save_configuration_file + fi - if [[ $MINIMAL_INSTALL == "no" ]]; then - if [[ $(grep "INSTALLING_ON_BBB" temp.cfg | awk -F '=' '{print $2}') == "yes" ]]; then - dialog --title $"Install Target" \ - --backtitle $"Freedombone Configuration" \ - --yesno $"\nAre you installing onto a Beaglebone Black?" 7 60 - else - dialog --title $"Install Target" \ - --backtitle $"Freedombone Configuration" \ - --defaultno \ - --yesno $"\nAre you installing onto a Beaglebone Black?" 7 60 - fi - sel=$? - case $sel in - 0) INSTALLING_ON_BBB="yes";; - 1) INSTALLING_ON_BBB="no";; - 255) exit 1;; - esac - if [[ $INSTALLING_ON_BBB == "yes" ]]; then - USB_DRIVE=/dev/sda1 - fi - save_configuration_file - fi + if [[ $MINIMAL_INSTALL == "no" ]]; then + if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then + interactive_gpg - if [[ $MINIMAL_INSTALL == "no" ]]; then - if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then - interactive_gpg + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + SOCIAL_KEY_STR=$"\nDo you wish to enable social key management, otherwise known as \"the unforgettable key\"?\n\nThis means that fragments of your GPG key will be included with any remote backups so that if you later lose your key then it can be reconstructed from your friends servers. If you select \"no\" then you can still do social key management, but offline using physical USB thumb drives, which is more secure but less convenient." + if [[ $(grep "ENABLE_SOCIAL_KEY_MANAGEMENT" temp.cfg | awk -F '=' '{print $2}') == "yes" ]]; then + dialog --title $"Social Key Management" \ + --backtitle $"Freedombone Configuration" \ + --yesno "$SOCIAL_KEY_STR" 15 60 + else + dialog --title $"Social Key Management" \ + --backtitle $"Freedombone Configuration" \ + --defaultno \ + --yesno "$SOCIAL_KEY_STR" 15 60 + fi + sel=$? + case $sel in + 0) ENABLE_SOCIAL_KEY_MANAGEMENT="yes";; + 255) exit 1;; + esac + save_configuration_file + fi + else + # enable for the minimal case + ENABLE_SOCIAL_KEY_MANAGEMENT="yes" + fi - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - SOCIAL_KEY_STR=$"\nDo you wish to enable social key management, otherwise known as \"the unforgettable key\"?\n\nThis means that fragments of your GPG key will be included with any remote backups so that if you later lose your key then it can be reconstructed from your friends servers. If you select \"no\" then you can still do social key management, but offline using physical USB thumb drives, which is more secure but less convenient." - if [[ $(grep "ENABLE_SOCIAL_KEY_MANAGEMENT" temp.cfg | awk -F '=' '{print $2}') == "yes" ]]; then - dialog --title $"Social Key Management" \ - --backtitle $"Freedombone Configuration" \ - --yesno "$SOCIAL_KEY_STR" 15 60 - else - dialog --title $"Social Key Management" \ - --backtitle $"Freedombone Configuration" \ - --defaultno \ - --yesno "$SOCIAL_KEY_STR" 15 60 - fi - sel=$? - case $sel in - 0) ENABLE_SOCIAL_KEY_MANAGEMENT="yes";; - 255) exit 1;; - esac - save_configuration_file - fi - else - # enable for the minimal case - ENABLE_SOCIAL_KEY_MANAGEMENT="yes" - fi + if [[ $MINIMAL_INSTALL == "no" ]]; then + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + if [[ $INSTALLING_ON_BBB != "yes" ]]; then + dialog --backtitle $"Freedombone Configuration" \ + --radiolist $"Type of Random Number Generator:" 10 40 2 \ + 1 Haveged on \ + 2 OneRNG off 2> $data + sel=$? + case $sel in + 1) exit 1;; + 255) exit 1;; + esac + case $(cat $data) in + 2) HWRNG_TYPE="onerng" + dialog --title $"OneRNG Device" \ + --msgbox $"Please ensure that the OneRNG device is disconnected. You can reconnect it later during the installation" 8 60 + ;; + 255) exit 1;; + esac + else + HWRNG_TYPE="beaglebone" + fi + save_configuration_file + fi - if [[ $MINIMAL_INSTALL == "no" ]]; then - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - if [[ $INSTALLING_ON_BBB != "yes" ]]; then - dialog --backtitle $"Freedombone Configuration" \ - --radiolist $"Type of Random Number Generator:" 10 40 2 \ - 1 Haveged on \ - 2 OneRNG off 2> $data - sel=$? - case $sel in - 1) exit 1;; - 255) exit 1;; - esac - case $(cat $data) in - 2) HWRNG_TYPE="onerng" - dialog --title $"OneRNG Device" \ - --msgbox $"Please ensure that the OneRNG device is disconnected. You can reconnect it later during the installation" 8 60 - ;; - 255) exit 1;; - esac - else - HWRNG_TYPE="beaglebone" - fi - save_configuration_file - fi - - if [[ $MINIMAL_INSTALL == "no" ]]; then - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone Configuration" \ - --radiolist $"Where to download Debian packages from:" 25 45 49 \ - 1 $"Australia" off \ - 2 $"Austria" off \ - 3 $"Belarus" off \ - 4 $"Belgium" off \ - 5 $"Bosnia and Herzegovina" off \ - 6 $"Brazil" off \ - 7 $"Bulgaria" off \ - 8 $"Canada" off \ - 9 $"Chile" off \ - 10 $"China" off \ - 11 $"Croatia" off \ - 12 $"Czech Republic" off \ - 13 $"Denmark" off \ - 14 $"El Salvador" off \ - 15 $"Estonia" off \ - 16 $"Finland" off \ - 17 $"France 1" off \ - 18 $"France 2" off \ - 19 $"Germany 1" off \ - 20 $"Germany 2" off \ - 21 $"Greece" off \ - 22 $"Hungary" off \ - 23 $"Iceland" off \ - 24 $"Iran" off \ - 25 $"Ireland" off \ - 26 $"Italy" off \ - 27 $"Japan" off \ - 28 $"Korea" off \ - 29 $"Lithuania" off \ - 30 $"Mexico" off \ - 31 $"Netherlands" off \ - 32 $"New Caledonia" off \ - 33 $"New Zealand" off \ - 34 $"Norway" off \ - 35 $"Poland" off \ - 36 $"Portugal" off \ - 37 $"Romania" off \ - 38 $"Russia" off \ - 39 $"Slovakia" off \ + if [[ $MINIMAL_INSTALL == "no" ]]; then + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone Configuration" \ + --radiolist $"Where to download Debian packages from:" 25 45 49 \ + 1 $"Australia" off \ + 2 $"Austria" off \ + 3 $"Belarus" off \ + 4 $"Belgium" off \ + 5 $"Bosnia and Herzegovina" off \ + 6 $"Brazil" off \ + 7 $"Bulgaria" off \ + 8 $"Canada" off \ + 9 $"Chile" off \ + 10 $"China" off \ + 11 $"Croatia" off \ + 12 $"Czech Republic" off \ + 13 $"Denmark" off \ + 14 $"El Salvador" off \ + 15 $"Estonia" off \ + 16 $"Finland" off \ + 17 $"France 1" off \ + 18 $"France 2" off \ + 19 $"Germany 1" off \ + 20 $"Germany 2" off \ + 21 $"Greece" off \ + 22 $"Hungary" off \ + 23 $"Iceland" off \ + 24 $"Iran" off \ + 25 $"Ireland" off \ + 26 $"Italy" off \ + 27 $"Japan" off \ + 28 $"Korea" off \ + 29 $"Lithuania" off \ + 30 $"Mexico" off \ + 31 $"Netherlands" off \ + 32 $"New Caledonia" off \ + 33 $"New Zealand" off \ + 34 $"Norway" off \ + 35 $"Poland" off \ + 36 $"Portugal" off \ + 37 $"Romania" off \ + 38 $"Russia" off \ + 39 $"Slovakia" off \ 40 $"Slovenia" off \ 41 $"Spain" off \ 42 $"Sweden" off \ @@ -1160,83 +1175,83 @@ function interactive_configuration { 47 $"Ukraine" off \ 48 $"United Kingdom" off \ 49 $"United States" on 2> $data - sel=$? - case $sel in - 1) exit 1;; - 255) exit 1;; - esac - case $(cat $data) in - 1) DEBIAN_REPO='ftp.au.debian.org';; - 2) DEBIAN_REPO='ftp.at.debian.org';; - 3) DEBIAN_REPO='ftp.by.debian.org';; + sel=$? + case $sel in + 1) exit 1;; + 255) exit 1;; + esac + case $(cat $data) in + 1) DEBIAN_REPO='ftp.au.debian.org';; + 2) DEBIAN_REPO='ftp.at.debian.org';; + 3) DEBIAN_REPO='ftp.by.debian.org';; 4) DEBIAN_REPO='ftp.be.debian.org';; - 5) DEBIAN_REPO='ftp.ba.debian.org';; - 6) DEBIAN_REPO='ftp.br.debian.org';; - 7) DEBIAN_REPO='ftp.bg.debian.org';; - 8) DEBIAN_REPO='ftp.ca.debian.org';; - 9) DEBIAN_REPO='ftp.cl.debian.org';; - 10) DEBIAN_REPO='ftp.cn.debian.org';; - 11) DEBIAN_REPO='ftp.hr.debian.org';; - 12) DEBIAN_REPO='ftp.cz.debian.org';; - 13) DEBIAN_REPO='ftp.dk.debian.org';; - 14) DEBIAN_REPO='ftp.sv.debian.org';; - 15) DEBIAN_REPO='ftp.ee.debian.org';; - 16) DEBIAN_REPO='ftp.fi.debian.org';; - 17) DEBIAN_REPO='ftp2.fr.debian.org';; - 18) DEBIAN_REPO='ftp.fr.debian.org';; - 19) DEBIAN_REPO='ftp2.de.debian.org';; - 20) DEBIAN_REPO='ftp.de.debian.org';; - 21) DEBIAN_REPO='ftp.gr.debian.org';; - 22) DEBIAN_REPO='ftp.hu.debian.org';; - 23) DEBIAN_REPO='ftp.is.debian.org';; - 24) DEBIAN_REPO='ftp.ir.debian.org';; - 25) DEBIAN_REPO='ftp.ie.debian.org';; - 26) DEBIAN_REPO='ftp.it.debian.org';; - 27) DEBIAN_REPO='ftp.jp.debian.org';; - 28) DEBIAN_REPO='ftp.kr.debian.org';; - 29) DEBIAN_REPO='ftp.lt.debian.org';; - 30) DEBIAN_REPO='ftp.mx.debian.org';; - 31) DEBIAN_REPO='ftp.nl.debian.org';; - 32) DEBIAN_REPO='ftp.nc.debian.org';; - 33) DEBIAN_REPO='ftp.nz.debian.org';; - 34) DEBIAN_REPO='ftp.no.debian.org';; - 35) DEBIAN_REPO='ftp.pl.debian.org';; - 36) DEBIAN_REPO='ftp.pt.debian.org';; - 37) DEBIAN_REPO='ftp.ro.debian.org';; - 38) DEBIAN_REPO='ftp.ru.debian.org';; - 39) DEBIAN_REPO='ftp.sk.debian.org';; - 40) DEBIAN_REPO='ftp.si.debian.org';; - 41) DEBIAN_REPO='ftp.es.debian.org';; - 42) DEBIAN_REPO='ftp.se.debian.org';; - 43) DEBIAN_REPO='ftp.ch.debian.org';; - 44) DEBIAN_REPO='ftp.tw.debian.org';; - 45) DEBIAN_REPO='ftp.th.debian.org';; - 46) DEBIAN_REPO='ftp.tr.debian.org';; - 47) DEBIAN_REPO='ftp.ua.debian.org';; - 48) DEBIAN_REPO='ftp.uk.debian.org';; - 49) DEBIAN_REPO='ftp.us.debian.org';; - 255) exit 1;; - esac - save_configuration_file - else - DEBIAN_REPO='ftp.de.debian.org' - fi + 5) DEBIAN_REPO='ftp.ba.debian.org';; + 6) DEBIAN_REPO='ftp.br.debian.org';; + 7) DEBIAN_REPO='ftp.bg.debian.org';; + 8) DEBIAN_REPO='ftp.ca.debian.org';; + 9) DEBIAN_REPO='ftp.cl.debian.org';; + 10) DEBIAN_REPO='ftp.cn.debian.org';; + 11) DEBIAN_REPO='ftp.hr.debian.org';; + 12) DEBIAN_REPO='ftp.cz.debian.org';; + 13) DEBIAN_REPO='ftp.dk.debian.org';; + 14) DEBIAN_REPO='ftp.sv.debian.org';; + 15) DEBIAN_REPO='ftp.ee.debian.org';; + 16) DEBIAN_REPO='ftp.fi.debian.org';; + 17) DEBIAN_REPO='ftp2.fr.debian.org';; + 18) DEBIAN_REPO='ftp.fr.debian.org';; + 19) DEBIAN_REPO='ftp2.de.debian.org';; + 20) DEBIAN_REPO='ftp.de.debian.org';; + 21) DEBIAN_REPO='ftp.gr.debian.org';; + 22) DEBIAN_REPO='ftp.hu.debian.org';; + 23) DEBIAN_REPO='ftp.is.debian.org';; + 24) DEBIAN_REPO='ftp.ir.debian.org';; + 25) DEBIAN_REPO='ftp.ie.debian.org';; + 26) DEBIAN_REPO='ftp.it.debian.org';; + 27) DEBIAN_REPO='ftp.jp.debian.org';; + 28) DEBIAN_REPO='ftp.kr.debian.org';; + 29) DEBIAN_REPO='ftp.lt.debian.org';; + 30) DEBIAN_REPO='ftp.mx.debian.org';; + 31) DEBIAN_REPO='ftp.nl.debian.org';; + 32) DEBIAN_REPO='ftp.nc.debian.org';; + 33) DEBIAN_REPO='ftp.nz.debian.org';; + 34) DEBIAN_REPO='ftp.no.debian.org';; + 35) DEBIAN_REPO='ftp.pl.debian.org';; + 36) DEBIAN_REPO='ftp.pt.debian.org';; + 37) DEBIAN_REPO='ftp.ro.debian.org';; + 38) DEBIAN_REPO='ftp.ru.debian.org';; + 39) DEBIAN_REPO='ftp.sk.debian.org';; + 40) DEBIAN_REPO='ftp.si.debian.org';; + 41) DEBIAN_REPO='ftp.es.debian.org';; + 42) DEBIAN_REPO='ftp.se.debian.org';; + 43) DEBIAN_REPO='ftp.ch.debian.org';; + 44) DEBIAN_REPO='ftp.tw.debian.org';; + 45) DEBIAN_REPO='ftp.th.debian.org';; + 46) DEBIAN_REPO='ftp.tr.debian.org';; +47) DEBIAN_REPO='ftp.ua.debian.org';; +48) DEBIAN_REPO='ftp.uk.debian.org';; +49) DEBIAN_REPO='ftp.us.debian.org';; +255) exit 1;; +esac + save_configuration_file + else + DEBIAN_REPO='ftp.de.debian.org' + fi - if [[ $MINIMAL_INSTALL == "no" && $ONION_ONLY == "no" ]]; then - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone Configuration" \ - --radiolist $"Pick a domain name service (DNS):" 25 50 16 \ - 1 $"Digital Courage" on \ - 2 $"German Privacy Foundation 1" off \ - 3 $"German Privacy Foundation 2" off \ - 4 $"Chaos Computer Club" off \ - 5 $"ClaraNet" off \ - 6 $"OpenNIC 1" off \ - 7 $"OpenNIC 2" off \ - 8 $"OpenNIC 3" off \ - 9 $"OpenNIC 4" off \ - 10 $"OpenNIC 5" off \ + if [[ $MINIMAL_INSTALL == "no" && $ONION_ONLY == "no" ]]; then + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone Configuration" \ + --radiolist $"Pick a domain name service (DNS):" 25 50 16 \ + 1 $"Digital Courage" on \ + 2 $"German Privacy Foundation 1" off \ + 3 $"German Privacy Foundation 2" off \ + 4 $"Chaos Computer Club" off \ + 5 $"ClaraNet" off \ + 6 $"OpenNIC 1" off \ + 7 $"OpenNIC 2" off \ + 8 $"OpenNIC 3" off \ + 9 $"OpenNIC 4" off \ + 10 $"OpenNIC 5" off \ 11 $"OpenNIC 6" off \ 12 $"OpenNIC 7" off \ 13 $"PowerNS" off \ @@ -1298,138 +1313,138 @@ function interactive_configuration { NAMESERVER2='4.4.4.4' ;; 255) exit 1;; - esac - save_configuration_file - else - # as defaults for a minimal install process these settings are debatable - NAMESERVER1='85.214.73.63' - NAMESERVER2='213.73.91.35' - fi + esac + save_configuration_file + else + # as defaults for a minimal install process these settings are debatable + NAMESERVER1='85.214.73.63' + NAMESERVER2='213.73.91.35' + fi - if [[ $SYSTEM_TYPE != "$VARIANT_MESH" && $ONION_ONLY == "no" ]]; then + if [[ $SYSTEM_TYPE != "$VARIANT_MESH" && $ONION_ONLY == "no" ]]; then - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone Configuration" \ - --radiolist $"Choose Dynamic DNS provider:" 15 40 14 \ - 1 dyndns off \ - 2 freedns on \ - 3 zoneedit off \ - 4 no-ip off \ - 5 easydns off \ - 6 tzo off \ - 7 3322 off \ - 8 dnsomatic off \ - 9 tunnelbroker off \ - 10 dns.he.net off \ - 11 dynsip off \ - 12 sitelutions off \ - 13 dnsexit off \ - 14 changeip off 2> $data - sel=$? - case $sel in - 1) exit 1;; - 255) exit 1;; - esac - case $(cat $data) in - 1) DDNS_PROVIDER="default@dyndns.org";; - 2) DDNS_PROVIDER="default@freedns.afraid.org";; - 3) DDNS_PROVIDER="default@zoneedit.com";; - 4) DDNS_PROVIDER="default@no-ip.com";; - 5) DDNS_PROVIDER="default@easydns.com";; - 6) DDNS_PROVIDER="default@tzo.com";; - 7) DDNS_PROVIDER="dyndns@3322.org";; - 8) DDNS_PROVIDER="default@dnsomatic.com";; - 9) DDNS_PROVIDER="ipv6tb@he.net";; - 10) DDNS_PROVIDER="dyndns@he.net";; - 11) DDNS_PROVIDER="default@dynsip.org";; - 12) DDNS_PROVIDER="default@sitelutions.com";; - 13) DDNS_PROVIDER="default@dnsexit.com";; - 14) DDNS_PROVIDER="default@changeip.com";; - 255) exit 1;; - esac - save_configuration_file + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone Configuration" \ + --radiolist $"Choose Dynamic DNS provider:" 15 40 14 \ + 1 dyndns off \ + 2 freedns on \ + 3 zoneedit off \ + 4 no-ip off \ + 5 easydns off \ + 6 tzo off \ + 7 3322 off \ + 8 dnsomatic off \ + 9 tunnelbroker off \ + 10 dns.he.net off \ + 11 dynsip off \ + 12 sitelutions off \ + 13 dnsexit off \ + 14 changeip off 2> $data + sel=$? + case $sel in + 1) exit 1;; + 255) exit 1;; + esac + case $(cat $data) in + 1) DDNS_PROVIDER="default@dyndns.org";; + 2) DDNS_PROVIDER="default@freedns.afraid.org";; + 3) DDNS_PROVIDER="default@zoneedit.com";; + 4) DDNS_PROVIDER="default@no-ip.com";; + 5) DDNS_PROVIDER="default@easydns.com";; + 6) DDNS_PROVIDER="default@tzo.com";; + 7) DDNS_PROVIDER="dyndns@3322.org";; + 8) DDNS_PROVIDER="default@dnsomatic.com";; + 9) DDNS_PROVIDER="ipv6tb@he.net";; + 10) DDNS_PROVIDER="dyndns@he.net";; + 11) DDNS_PROVIDER="default@dynsip.org";; + 12) DDNS_PROVIDER="default@sitelutions.com";; + 13) DDNS_PROVIDER="default@dnsexit.com";; + 14) DDNS_PROVIDER="default@changeip.com";; + 255) exit 1;; + esac + save_configuration_file - valid_ddns_username= - while [ ! $valid_ddns_username ] - do - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone Configuration" \ - --inputbox $"Dynamic DNS provider username" 10 30 "$(grep 'DDNS_USERNAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data - sel=$? - case $sel in - 0) possible_username=$(cat $data) - if [ "$possible_username" ]; then - if [ ${#possible_username} -gt 1 ]; then - valid_ddns_username=$(cat $data) - DDNS_USERNAME=$valid_ddns_username - break; - fi - fi - ;; - 1) exit 1;; - 255) exit 1;; - esac - done - save_configuration_file + valid_ddns_username= + while [ ! $valid_ddns_username ] + do + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone Configuration" \ + --inputbox $"Dynamic DNS provider username" 10 30 "$(grep 'DDNS_USERNAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data + sel=$? + case $sel in + 0) possible_username=$(cat $data) + if [ "$possible_username" ]; then + if [ ${#possible_username} -gt 1 ]; then + valid_ddns_username=$(cat $data) + DDNS_USERNAME=$valid_ddns_username + break; + fi + fi + ;; + 1) exit 1;; + 255) exit 1;; + esac + done + save_configuration_file - valid_ddns_password= - while [ ! $valid_ddns_password ] - do - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone Configuration" \ - --clear \ - --insecure \ - --passwordbox $"Dynamic DNS provider password" 10 30 "$(grep 'DDNS_PASSWORD' temp.cfg | awk -F '=' '{print $2}')" 2> $data - sel=$? - case $sel in - 0) possible_password=$(cat $data) - if [ "$possible_password" ]; then - if [ ${#possible_password} -gt 1 ]; then - valid_ddns_password=$(cat $data) - DDNS_PASSWORD=$valid_ddns_password - break; - fi - fi - ;; - 1) exit 1;; - 255) exit 1;; - esac - if [ ${#DDNS_PASSWORD} -lt $MINIMUM_PASSWORD_LENGTH ]; then - dialog --title $"Password quality check" --msgbox $"The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters. You may need to change your password on the dynamic DNS provider's web site." 10 40 - DDNS_PASSWORD="" - fi - done - save_configuration_file - fi + valid_ddns_password= + while [ ! $valid_ddns_password ] + do + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone Configuration" \ + --clear \ + --insecure \ + --passwordbox $"Dynamic DNS provider password" 10 30 "$(grep 'DDNS_PASSWORD' temp.cfg | awk -F '=' '{print $2}')" 2> $data + sel=$? + case $sel in + 0) possible_password=$(cat $data) + if [ "$possible_password" ]; then + if [ ${#possible_password} -gt 1 ]; then + valid_ddns_password=$(cat $data) + DDNS_PASSWORD=$valid_ddns_password + break; + fi + fi + ;; + 1) exit 1;; + 255) exit 1;; + esac + if [ ${#DDNS_PASSWORD} -lt $MINIMUM_PASSWORD_LENGTH ]; then + dialog --title $"Password quality check" --msgbox $"The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters. You may need to change your password on the dynamic DNS provider's web site." 10 40 + DDNS_PASSWORD="" + fi + done + save_configuration_file + fi - if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then - valid_name= - while [ ! $valid_name ] - do - data=$(tempfile 2>/dev/null) - trap "rm -f $data" 0 1 2 5 15 - dialog --backtitle $"Freedombone Configuration" \ - --inputbox $"Your full name (or nick)" 10 30 "$(grep 'MY_NAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data - sel=$? - case $sel in - 0) possible_name=$(cat $data) - if [ "$possible_name" ]; then - if [ ${#possible_name} -gt 1 ]; then - valid_name="$possible_name" - MY_NAME="$possible_name" - break; - fi - fi - ;; - 1) exit 1;; - 255) exit 1;; - esac - done - save_configuration_file - fi + if [[ $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then + valid_name= + while [ ! $valid_name ] + do + data=$(tempfile 2>/dev/null) + trap "rm -f $data" 0 1 2 5 15 + dialog --backtitle $"Freedombone Configuration" \ + --inputbox $"Your full name (or nick)" 10 30 "$(grep 'MY_NAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data + sel=$? + case $sel in + 0) possible_name=$(cat $data) + if [ "$possible_name" ]; then + if [ ${#possible_name} -gt 1 ]; then + valid_name="$possible_name" + MY_NAME="$possible_name" + break; + fi + fi + ;; + 1) exit 1;; + 255) exit 1;; + esac + done + save_configuration_file + fi if [[ $MINIMAL_INSTALL == "no" && $ONION_ONLY == "no" ]]; then SET_STATIC_IP="no" @@ -2067,8 +2082,17 @@ function read_configuration { if grep -q "MEDIAGOBLIN_CODE" $CONFIGURATION_FILE; then MEDIAGOBLIN_CODE=$(grep "MEDIAGOBLIN_CODE" $CONFIGURATION_FILE | awk -F '=' '{print $2}') fi - if grep -q "ESSID" $CONFIGURATION_FILE; then - ESSID=$(grep "ESSID" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + if grep -q "WIFI_SSID" $CONFIGURATION_FILE; then + WIFI_SSID=$(grep "WIFI_SSID" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "WIFI_INTERFACE" $CONFIGURATION_FILE; then + WIFI_INTERFACE=$(grep "WIFI_INTERFACE" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "WIFI_TYPE" $CONFIGURATION_FILE; then + WIFI_TYPE=$(grep "WIFI_TYPE" $CONFIGURATION_FILE | awk -F '=' '{print $2}') + fi + if grep -q "WIFI_PASSPHRASE" $CONFIGURATION_FILE; then + WIFI_PASSPHRASE=$(grep "WIFI_PASSPHRASE" $CONFIGURATION_FILE | awk -F '=' '{print $2}') fi if grep -q "BATMAN_CELLID" $CONFIGURATION_FILE; then BATMAN_CELLID=$(grep "BATMAN_CELLID" $CONFIGURATION_FILE | awk -F '=' '{print $2}') diff --git a/src/freedombone-mesh-batman b/src/freedombone-mesh-batman index 623607eb..b5b4b009 100755 --- a/src/freedombone-mesh-batman +++ b/src/freedombone-mesh-batman @@ -42,13 +42,13 @@ if [[ $1 == "start" ]]; then fi # Mesh definition -ESSID= -if ! grep -q "ESSID:" $COMPLETION_FILE; then - ESSID='mesh' +WIFI_SSID= +if ! grep -q "WIFI_SSID:" $COMPLETION_FILE; then + WIFI_SSID='mesh' else - ESSID=$(cat $COMPLETION_FILE | grep "ESSID:" | awk -F ':' '{print $2}') + WIFI_SSID=$(cat $COMPLETION_FILE | grep "WIFI_SSID:" | awk -F ':' '{print $2}') fi -sed -i "s|ESSID:.*|ESSID:${ESSID}|g" $COMPLETION_FILE +sed -i "s|WIFI_SSID:.*|WIFI_SSID:${WIFI_SSID}|g" $COMPLETION_FILE CELLID='any' @@ -93,7 +93,7 @@ start() { echo 'error: unable to find wifi interface, not enabling batman-adv mesh' return fi - echo 'info: enabling batman-adv mesh network $ESSID on $IFACE' + echo 'info: enabling batman-adv mesh network $WIFI_SSID on $IFACE' systemctl stop network-manager sleep 5 @@ -109,7 +109,7 @@ start() { ifconfig $IFACE down ifconfig $IFACE mtu 1532 iwconfig $IFACE enc off - iwconfig $IFACE mode ad-hoc essid $ESSID channel $CHANNEL + iwconfig $IFACE mode ad-hoc essid $WIFI_SSID channel $CHANNEL sleep 1 iwconfig $IFACE ap $CELLID @@ -214,9 +214,9 @@ case "$1" in avahi-browse -atl ;; *) - echo "error: invalid parameter $1" - echo 'usage: $0 {start|stop|restart|status|ping|ls|list}' - exit 2 - ;; + echo "error: invalid parameter $1" + echo 'usage: $0 {start|stop|restart|status|ping|ls|list}' + exit 2 + ;; esac exit 0 diff --git a/src/freedombone-mesh-install b/src/freedombone-mesh-install index c92336c8..f8da5977 100755 --- a/src/freedombone-mesh-install +++ b/src/freedombone-mesh-install @@ -42,7 +42,7 @@ WIFI_INTERFACE='wlan0' # B.A.T.M.A.N settings BATMAN_CELLID='02:BA:00:00:03:01' -ESSID='mesh' +WIFI_SSID='mesh' # Babel BABEL_PORT=6696 @@ -160,7 +160,7 @@ function mesh_babel { echo 'systemctl stop network-manager' >> $babel_script echo 'ifconfig $IFACE down' >> $babel_script echo -n 'iwconfig $IFACE mode ad-hoc channel ' >> $babel_script - echo "$WIFI_CHANNEL essid \"$ESSID\"" >> $babel_script + echo "$WIFI_CHANNEL essid \"$WIFI_SSID\"" >> $babel_script echo 'ifconfig $IFACE up' >> $babel_script echo -n 'ifconfig $IFACE:avahi ' >> $babel_script echo -n "$LOCAL_NETWORK_STATIC_IP_ADDRESS netmask " >> $babel_script @@ -325,7 +325,7 @@ function mesh_babel_client { echo 'fi' >> $babel_script echo 'ifconfig $IFACE down' >> $babel_script echo -n 'iwconfig $IFACE mode ad-hoc channel ' >> $babel_script - echo "$WIFI_CHANNEL essid \"$ESSID\"" >> $babel_script + echo "$WIFI_CHANNEL essid \"$WIFI_SSID\"" >> $babel_script echo 'ifconfig $IFACE up' >> $babel_script echo -n 'ifconfig $IFACE:avahi ' >> $babel_script echo -n "$LOCAL_NETWORK_STATIC_IP_ADDRESS netmask " >> $babel_script @@ -774,7 +774,7 @@ function mesh_batman_client { echo 'fi' >> $BATMAN_SCRIPT echo '' >> $BATMAN_SCRIPT echo '# Mesh definition' >> $BATMAN_SCRIPT - echo "ESSID=$ESSID" >> $BATMAN_SCRIPT + echo "WIFI_SSID=$WIFI_SSID" >> $BATMAN_SCRIPT echo "CELLID=$BATMAN_CELLID" >> $BATMAN_SCRIPT echo "CHANNEL=$WIFI_CHANNEL" >> $BATMAN_SCRIPT echo '' >> $BATMAN_SCRIPT @@ -812,7 +812,7 @@ function mesh_batman_client { echo ' echo "error: unable to find wifi interface, not enabling batman-adv mesh"' >> $BATMAN_SCRIPT echo ' return' >> $BATMAN_SCRIPT echo ' fi' >> $BATMAN_SCRIPT - echo ' echo "info: enabling batman-adv mesh network $ESSID on $IFACE"' >> $BATMAN_SCRIPT + echo ' echo "info: enabling batman-adv mesh network $WIFI_SSID on $IFACE"' >> $BATMAN_SCRIPT echo ' if [ -f /bin/systemctl ]; then' >> $BATMAN_SCRIPT echo ' systemctl stop network-manager' >> $BATMAN_SCRIPT @@ -832,7 +832,7 @@ function mesh_batman_client { echo ' ifconfig $IFACE down' >> $BATMAN_SCRIPT echo ' ifconfig $IFACE mtu 1532' >> $BATMAN_SCRIPT echo ' iwconfig $IFACE enc off' >> $BATMAN_SCRIPT - echo ' iwconfig $IFACE mode ad-hoc essid $ESSID channel $CHANNEL' >> $BATMAN_SCRIPT + echo ' iwconfig $IFACE mode ad-hoc essid $WIFI_SSID channel $CHANNEL' >> $BATMAN_SCRIPT echo ' sleep 1' >> $BATMAN_SCRIPT echo ' iwconfig $IFACE ap $CELLID' >> $BATMAN_SCRIPT echo '' >> $BATMAN_SCRIPT diff --git a/src/freedombone-wifi b/src/freedombone-wifi new file mode 100755 index 00000000..c143f82b --- /dev/null +++ b/src/freedombone-wifi @@ -0,0 +1,141 @@ +#!/bin/bash +# +# .---. . . +# | | | +# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. +# | | (.-' (.-' ( | ( )| | | | )( )| | (.-' +# ' ' --' --' -' - -' ' ' -' -' -' ' - --' +# +# Freedom in the Cloud +# +# Wifi configuration tools + +# License +# ======= +# +# Copyright (C) 2016 Bob Mottram +# +# 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 . + +PROJECT_NAME='freedombone' + +export TEXTDOMAIN=${PROJECT_NAME}-wifi +export TEXTDOMAINDIR="/usr/share/locale" + +CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg +COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt + +WIFI_DEVICE=wlan0 +WIFI_TYPE='wpa2-psk' +WIFI_SSID= +WIFI_PASSPHRASE= + +function wifi_get_psk { + ssid=$1 + passphrase=$2 + + psk=$(wpa_passphrase "$ssid" "$passphrase" | grep 'psk=' | sed -n 2p | awk -F '=' '{print $2}') + echo $psk +} + +function wifi_wpa2_psk { + ssid=$1 + passphrase=$2 + psk=$(wifi_get_psk "$ssid" "$passphrase") + echo "auto $WIFI_DEVICE" > /etc/network/interfaces.d/wifi + echo 'iface $WIFI_DEVICE inet dhcp' >> /etc/network/interfaces.d/wifi + echo " wpa-ssid $ssid" >> /etc/network/interfaces.d/wifi + echo " wpa-psk $psk" >> /etc/network/interfaces.d/wifi +} + +function wifi_none { + ssid=$1 + echo "auto $WIFI_DEVICE" > /etc/network/interfaces.d/wifi + echo 'iface $WIFI_DEVICE inet dhcp' >> /etc/network/interfaces.d/wifi + echo " wireless-essid $ssid" >> /etc/network/interfaces.d/wifi +} + +function show_help { + echo '' + echo $"${PROJECT_NAME}-wifi -d [device] -t [type] -s [ssid] -p [passphrase]" + echo '' + echo $'Wifi configuration tool' + echo '' + echo $' --help Show help' + echo $' -d --device [name] Device name' + echo $' -t --type [wpa2-psk|none] Security type' + echo $' -s --ssid [id] Set SSID' + echo $' -p --passphrase [text] Set passphrase' + echo '' + exit 0 +} + +while [[ $# > 1 ]] +do + key="$1" + + case $key in + --help) + show_help + ;; + -d|--device) + shift + WIFI_DEVICE=${1} + ;; + -t|--type) + shift + WIFI_TYPE=${1} + ;; + -s|--ssid) + shift + WIFI_SSID=${1} + ;; + -p|--pass|--passphrase) + shift + WIFI_PASSPHRASE=${1} + ;; + *) + # unknown option + ;; + esac + shift +done + +if [ ! $WIFI_SSID ]; then + echo $'No SSID given' + exit 1 +fi + +if [[ $WIFI_TYPE != 'none' ]]; then + if [ ! $WIFI_PASSPHRASE ]; then + echo $'No wifi passphrase was given' + exit 2 + fi +fi + +if [[ $WIFI_TYPE == 'wpa2-psk' ]]; then + if [ ! -d /etc/wpa_supplicant ]; then + echo $'wpasupplicant package is not installed' + exit 3 + fi + wifi_wpa2_psk "$WIFI_SSID" "$WIFI_PASSPHRASE" + exit 0 +fi + +if [[ $WIFI_TYPE == 'none' ]]; then + wifi_none "$WIFI_SSID" + exit 0 +fi + +exit 0