wifi command
This commit is contained in:
parent
4bacbe64c7
commit
6d3943e23e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# .---. . .
|
||||
# | | |
|
||||
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
||||
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
||||
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
||||
#
|
||||
# Freedom in the Cloud
|
||||
#
|
||||
# Wifi configuration tools
|
||||
|
||||
# License
|
||||
# =======
|
||||
#
|
||||
# Copyright (C) 2016 Bob Mottram <bob@robotics.uk.to>
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
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
|
Loading…
Reference in New Issue