kopia lustrzana https://github.com/cyoung/stratux
commit
dc074454c6
|
@ -15,39 +15,3 @@ if [ -e /root/update*stratux*v*.sh ] ; then
|
|||
fi
|
||||
fi
|
||||
|
||||
##### Script for setting up new file structure for hostapd settings
|
||||
##### Look for hostapd.user and if found do nothing.
|
||||
##### If not assume because of previous version and convert to new file structure
|
||||
DAEMON_USER_PREF=/etc/hostapd/hostapd.user
|
||||
if [ ! -f $DAEMON_USER_PREF ]; then
|
||||
DAEMON_CONF=/etc/hostapd/hostapd.conf
|
||||
DAEMON_CONF_EDIMAX=/etc/hostapd/hostapd-edimax.conf
|
||||
HOSTAPD_VALUES=('ssid=' 'channel=' 'auth_algs=' 'wpa=' 'wpa_passphrase=' 'wpa_key_mgmt=' 'wpa_pairwise=' 'rsn_pairwise=')
|
||||
HOSTAPD_VALUES_RM=('#auth_algs=' '#wpa=' '#wpa_passphrase=' '#wpa_key_mgmt=' '#wpa_pairwise=' '#rsn_pairwise=')
|
||||
|
||||
for i in "${HOSTAPD_VALUES[@]}"
|
||||
do
|
||||
if grep -q "^$i" $DAEMON_CONF
|
||||
then
|
||||
grep "^$i" $DAEMON_CONF >> $DAEMON_USER_PREF
|
||||
sed -i '/^'"$i"'/d' $DAEMON_CONF
|
||||
sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX
|
||||
fi
|
||||
done
|
||||
for i in "${HOSTAPD_VALUES_RM[@]}"
|
||||
do
|
||||
if grep -q "^$i" $DAEMON_CONF
|
||||
then
|
||||
sed -i '/^'"$i"'/d' $DAEMON_CONF
|
||||
sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX
|
||||
fi
|
||||
done
|
||||
sleep 1 #make sure there is time to get the file written before checking for it again
|
||||
# If once the code above runs and there is still no hostapd.user file then something is wrong and we will just create the file with basic settings.
|
||||
# Any more then this they somebody was messing with things and its not our fault things are this bad
|
||||
if [ ! -f $DAEMON_USER_PREF ]; then
|
||||
echo "ssid=stratux" >> $DAEMON_USER_PREF
|
||||
echo "channel=1" >> $DAEMON_USER_PREF
|
||||
fi
|
||||
fi
|
||||
##### End hostapd settings structure script
|
||||
|
|
|
@ -13,7 +13,7 @@ OPT_C=false
|
|||
OPT_E=false
|
||||
OPT_O=false
|
||||
|
||||
defaultPass="Squawk1200"
|
||||
#defaultPass="Squawk1200"
|
||||
|
||||
parm="*"
|
||||
err="####"
|
||||
|
@ -39,11 +39,11 @@ function HELP {
|
|||
echo "Command line switches are optional. The following switches are recognized."
|
||||
echo "${REV}-s${NORM} --Sets the SSID to ${BOLD}ssid${NORM}. \"-s stratux\""
|
||||
echo "${REV}-c${NORM} --Sets the channel to ${BOLD}chan${NORM}. \"-c 1\""
|
||||
echo "${REV}-e${NORM} --Turns on encryption with passphrase ${BOLD}pass${NORM}. 8-63 Printable Characters(ascii 32-126). Cannot be used with -o. \"-e password!\""
|
||||
echo "${REV}-o${NORM} --Turns off encryption and sets network to open. Cannot be used with -e."
|
||||
# echo "${REV}-e${NORM} --Turns on encryption with passphrase ${BOLD}pass${NORM}. 8-63 Printable Characters(ascii 32-126). Cannot be used with -o. \"-e password!\""
|
||||
# echo "${REV}-o${NORM} --Turns off encryption and sets network to open. Cannot be used with -e."
|
||||
# echo "${REV}-q${NORM} --Run silently."
|
||||
echo -e "${REV}-h${NORM} --Displays this help message. No further functions are performed."\\n
|
||||
echo -e "Example: ${BOLD}$SCRIPT -s stratux -c 1 -e N3558D${NORM}"\\n
|
||||
echo -e "Example: ${BOLD}$SCRIPT -s Stratux-N3558D -c 5${NORM}"\\n
|
||||
exit 1
|
||||
}
|
||||
clear
|
||||
|
@ -69,7 +69,8 @@ fi
|
|||
#If an option should be followed by an argument, it should be followed by a ":".
|
||||
#Notice there is no ":" after "oqh". The leading ":" suppresses error messages from
|
||||
#getopts. This is required to get my unrecognized option code to work.
|
||||
options=':s:c:eoqh'
|
||||
#options=':s:c:e:oqh'
|
||||
options=':s:c:h'
|
||||
while getopts $options option; do
|
||||
case $option in
|
||||
s) #set option "s"
|
||||
|
@ -97,21 +98,21 @@ while getopts $options option; do
|
|||
fi
|
||||
fi
|
||||
;;
|
||||
e) #set option "e"
|
||||
if [[ -z "${OPTARG}" || "${OPTARG}" == *[[:space:]]* || "${OPTARG}" == -* ]]; then
|
||||
echo "${BOLD}${RED}$err Encryption option(-e) used without passphrase, Passphrase will be set to ${BOLD}$defaultPass${NORMAL}...${WHITE}${NORMAL}"
|
||||
OPT_E=$defaultPass
|
||||
else
|
||||
OPT_E=$OPTARG
|
||||
echo "$parm Encryption option -e used:"
|
||||
if [ -z `echo $OPT_E | tr -d "[:print:]"` ] && [ ${#OPT_E} -ge 8 ] && [ ${#OPT_E} -le 63 ]; then
|
||||
echo "${GREEN} Passphrase will now be ${BOLD}${UNDR}$OPT_E${NORMAL}.${WHITE}${NORMAL}"
|
||||
else
|
||||
echo "${BOLD}${RED}$err Invalid PASSWORD: 8 - 63 printable characters, exiting...${WHITE}${NORMAL}"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
# e) #set option "e"
|
||||
# if [[ -z "${OPTARG}" || "${OPTARG}" == *[[:space:]]* || "${OPTARG}" == -* ]]; then
|
||||
# echo "${BOLD}${RED}$err Encryption option(-e) used without passphrase!${WHITE}${NORMAL}"
|
||||
# OPT_E=$defaultPass
|
||||
# else
|
||||
# OPT_E=$OPTARG
|
||||
# echo "$parm Encryption option -e used:"
|
||||
# if [ -z `echo $OPT_E | tr -d "[:print:]"` ] && [ ${#OPT_E} -ge 8 ] && [ ${#OPT_E} -le 63 ]; then
|
||||
# echo "${GREEN} Passphrase will now be ${BOLD}${UNDR}$OPT_E${NORMAL}.${WHITE}${NORMAL}"
|
||||
# else
|
||||
# echo "${BOLD}${RED}$err Invalid PASSWORD: 8 - 63 printable characters, exiting...${WHITE}${NORMAL}"
|
||||
# exit
|
||||
# fi
|
||||
# fi
|
||||
# ;;
|
||||
o) #set option "o"
|
||||
if [[ -z "${OPTARG}" || "${OPTARG}" == *[[:space:]]* || "${OPTARG}" == -* ]]; then
|
||||
echo "$parm Open WiFI Option -o used."
|
||||
|
@ -188,66 +189,66 @@ do
|
|||
fi
|
||||
fi
|
||||
|
||||
if [ $OPT_E != false ]; then
|
||||
echo "${MAGENTA}Adding WPA encryption with passphrase: ${YELLOW}$OPT_E ${MAGENTA}to $i...${WHITE}"
|
||||
if grep -q "^#auth_algs=" ${i}; then
|
||||
#echo "uncomenting wpa"
|
||||
sed -i "s/^#auth_algs=.*/auth_algs=1/" ${i}
|
||||
sed -i "s/^#wpa=.*/wpa=3/" ${i}
|
||||
sed -i "s/^#wpa_passphrase=.*/wpa_passphrase=$OPT_E/" ${i}
|
||||
sed -i "s/^#wpa_key_mgmt=.*/wpa_key_mgmt=WPA-PSK/" ${i}
|
||||
sed -i "s/^#wpa_pairwise=.*/wpa_pairwise=TKIP/" ${i}
|
||||
sed -i "s/^#rsn_pairwise=.*/rsn_pairwise=CCMP/" ${i}
|
||||
elif grep -q "^auth_algs=" ${i}; then
|
||||
#echo "rewriting existing wpa"
|
||||
sed -i "s/^auth_algs=.*/auth_algs=1/" ${i}
|
||||
sed -i "s/^wpa=.*/wpa=3/" ${i}
|
||||
sed -i "s/^wpa_passphrase=.*/wpa_passphrase=$OPT_E/" ${i}
|
||||
sed -i "s/^wpa_key_mgmt=.*/wpa_key_mgmt=WPA-PSK/" ${i}
|
||||
sed -i "s/^wpa_pairwise=.*/wpa_pairwise=TKIP/" ${i}
|
||||
sed -i "s/^rsn_pairwise=.*/rsn_pairwise=CCMP/" ${i}
|
||||
else
|
||||
#echo "adding wpa"
|
||||
echo "" >> ${i}
|
||||
echo "auth_algs=1" >> ${i}
|
||||
echo "wpa=3" >> ${i}
|
||||
echo "wpa_passphrase=$OPT_E" >> ${i}
|
||||
echo "wpa_key_mgmt=WPA-PSK" >> ${i}
|
||||
echo "wpa_pairwise=TKIP" >> ${i}
|
||||
echo "rsn_pairwise=CCMP" >> ${i}
|
||||
fi
|
||||
fi
|
||||
if [ $OPT_O != false ]; then
|
||||
echo "${MAGENTA}Removing WPA encryption in $i...${WHITE}"
|
||||
if grep -q "^auth_algs=" ${i}; then
|
||||
#echo "comenting out wpa"
|
||||
sed -i "s/^auth_algs=.*/#auth_algs=1/" ${i}
|
||||
sed -i "s/^wpa=.*/#wpa=3/" ${i}
|
||||
sed -i "s/^wpa_passphrase=.*/#wpa_passphrase=$defaultPass/" ${i}
|
||||
sed -i "s/^wpa_key_mgmt=.*/#wpa_key_mgmt=WPA-PSK/" ${i}
|
||||
sed -i "s/^wpa_pairwise=.*/#wpa_pairwise=TKIP/" ${i}
|
||||
sed -i "s/^rsn_pairwise=.*/#rsn_pairwise=CCMP/" ${i}
|
||||
elif grep -q "^#auth_algs=" ${i}; then
|
||||
#echo "rewriting comentied out wpa"
|
||||
sed -i "s/^#auth_algs=.*/#auth_algs=1/" ${i}
|
||||
sed -i "s/^#wpa=.*/#wpa=3/" ${i}
|
||||
sed -i "s/^#wpa_passphrase=.*/#wpa_passphrase=$defaultPass/" ${i}
|
||||
sed -i "s/^#wpa_key_mgmt=.*/#wpa_key_mgmt=WPA-PSK/" ${i}
|
||||
sed -i "s/^#wpa_pairwise=.*/#wpa_pairwise=TKIP/" ${i}
|
||||
sed -i "s/^#rsn_pairwise=.*/#rsn_pairwise=CCMP/" ${i}
|
||||
else
|
||||
#echo "adding commented out WPA"
|
||||
echo "" >> ${i}
|
||||
echo "#auth_algs=1" >> ${i}
|
||||
echo "#wpa=3" >> ${i}
|
||||
echo "#wpa_passphrase=$defaultPass" >> ${i}
|
||||
echo "#wpa_key_mgmt=WPA-PSK" >> ${i}
|
||||
echo "#wpa_pairwise=TKIP" >> ${i}
|
||||
echo "#rsn_pairwise=CCMP" >> ${i}
|
||||
fi
|
||||
|
||||
fi
|
||||
echo "${GREEN}Modified ${i}...done${WHITE}"
|
||||
# if [ $OPT_E != false ]; then
|
||||
# echo "${MAGENTA}Adding WPA encryption with passphrase: ${YELLOW}$OPT_E ${MAGENTA}to $i...${WHITE}"
|
||||
# if grep -q "^#auth_algs=" ${i}; then
|
||||
# #echo "uncomenting wpa"
|
||||
# sed -i "s/^#auth_algs=.*/auth_algs=1/" ${i}
|
||||
# sed -i "s/^#wpa=.*/wpa=3/" ${i}
|
||||
# sed -i "s/^#wpa_passphrase=.*/wpa_passphrase=$OPT_E/" ${i}
|
||||
# sed -i "s/^#wpa_key_mgmt=.*/wpa_key_mgmt=WPA-PSK/" ${i}
|
||||
# sed -i "s/^#wpa_pairwise=.*/wpa_pairwise=TKIP/" ${i}
|
||||
# sed -i "s/^#rsn_pairwise=.*/rsn_pairwise=CCMP/" ${i}
|
||||
# elif grep -q "^auth_algs=" ${i}; then
|
||||
# #echo "rewriting existing wpa"
|
||||
# sed -i "s/^auth_algs=.*/auth_algs=1/" ${i}
|
||||
# sed -i "s/^wpa=.*/wpa=3/" ${i}
|
||||
# sed -i "s/^wpa_passphrase=.*/wpa_passphrase=$OPT_E/" ${i}
|
||||
# sed -i "s/^wpa_key_mgmt=.*/wpa_key_mgmt=WPA-PSK/" ${i}
|
||||
# sed -i "s/^wpa_pairwise=.*/wpa_pairwise=TKIP/" ${i}
|
||||
# sed -i "s/^rsn_pairwise=.*/rsn_pairwise=CCMP/" ${i}
|
||||
# else
|
||||
# #echo "adding wpa"
|
||||
# echo "" >> ${i}
|
||||
# echo "auth_algs=1" >> ${i}
|
||||
# echo "wpa=3" >> ${i}
|
||||
# echo "wpa_passphrase=$OPT_E" >> ${i}
|
||||
# echo "wpa_key_mgmt=WPA-PSK" >> ${i}
|
||||
# echo "wpa_pairwise=TKIP" >> ${i}
|
||||
# echo "rsn_pairwise=CCMP" >> ${i}
|
||||
# fi
|
||||
# fi
|
||||
# if [ $OPT_O != false ]; then
|
||||
# echo "${MAGENTA}Removing WPA encryption in $i...${WHITE}"
|
||||
# if grep -q "^auth_algs=" ${i}; then
|
||||
# #echo "comenting out wpa"
|
||||
# sed -i "s/^auth_algs=.*/#auth_algs=1/" ${i}
|
||||
# sed -i "s/^wpa=.*/#wpa=3/" ${i}
|
||||
# sed -i "s/^wpa_passphrase=.*/#wpa_passphrase=$defaultPass/" ${i}
|
||||
# sed -i "s/^wpa_key_mgmt=.*/#wpa_key_mgmt=WPA-PSK/" ${i}
|
||||
# sed -i "s/^wpa_pairwise=.*/#wpa_pairwise=TKIP/" ${i}
|
||||
# sed -i "s/^rsn_pairwise=.*/#rsn_pairwise=CCMP/" ${i}
|
||||
# elif grep -q "^#auth_algs=" ${i}; then
|
||||
# #echo "rewriting comentied out wpa"
|
||||
# sed -i "s/^#auth_algs=.*/#auth_algs=1/" ${i}
|
||||
# sed -i "s/^#wpa=.*/#wpa=3/" ${i}
|
||||
# sed -i "s/^#wpa_passphrase=.*/#wpa_passphrase=$defaultPass/" ${i}
|
||||
# sed -i "s/^#wpa_key_mgmt=.*/#wpa_key_mgmt=WPA-PSK/" ${i}
|
||||
# sed -i "s/^#wpa_pairwise=.*/#wpa_pairwise=TKIP/" ${i}
|
||||
# sed -i "s/^#rsn_pairwise=.*/#rsn_pairwise=CCMP/" ${i}
|
||||
# else
|
||||
# #echo "adding commented out WPA"
|
||||
# echo "" >> ${i}
|
||||
# echo "#auth_algs=1" >> ${i}
|
||||
# echo "#wpa=3" >> ${i}
|
||||
# echo "#wpa_passphrase=$defaultPass" >> ${i}
|
||||
# echo "#wpa_key_mgmt=WPA-PSK" >> ${i}
|
||||
# echo "#wpa_pairwise=TKIP" >> ${i}
|
||||
# echo "#rsn_pairwise=CCMP" >> ${i}
|
||||
# fi
|
||||
# fi
|
||||
|
||||
echo "${GREEN}Modified ${i}...done${WHITE}"
|
||||
echo ""
|
||||
else
|
||||
echo "${MAGENTA}No ${i} file found...${WHITE}${NORMAL}"
|
||||
|
|
|
@ -1,36 +1,98 @@
|
|||
#!/bin/bash
|
||||
#####
|
||||
##### Wifi/AP control file
|
||||
#####
|
||||
##### Description: All the scripting related to the AP and wireless functions for Stratux should be placed in this file
|
||||
##### This file is called when wlan0 is started i.e. "ifup wlan0"
|
||||
##### This script is called from /etc/network/interfaces by the line "post-up /usr/sbin/stratux-wifi.sh" under the wlan0 configuration
|
||||
#####
|
||||
|
||||
# Preliminaries. Kill off old services.
|
||||
/usr/bin/killall -9 hostapd hostapd-edimax
|
||||
/usr/sbin/service isc-dhcp-server stop
|
||||
|
||||
#Assume PI3 settings
|
||||
DAEMON_CONF=/etc/hostapd/hostapd.conf
|
||||
DAEMON_SBIN=/usr/sbin/hostapd
|
||||
|
||||
#User settings for hostapd.conf and hostapd-edimax.conf
|
||||
# common variables
|
||||
DAEMON_USER_PREF=/etc/hostapd/hostapd.user
|
||||
|
||||
# Temporary hostapd.conf built by combining
|
||||
# non-editable /etc/hostapd/hostapd.conf or hostapd-edimax.conf
|
||||
# and the user configurable /etc/hostapd/hostapd.conf
|
||||
DAEMON_TMP=/tmp/hostapd.conf
|
||||
|
||||
# Detect RPi version.
|
||||
# Per http://elinux.org/RPi_HardwareHistory
|
||||
EW7811Un=$(lsusb | grep EW-7811Un)
|
||||
RPI_REV=`cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^1000//'`
|
||||
if [ "$RPI_REV" = "a01041" ] || [ "$RPI_REV" = "a21041" ] || [ "$RPI_REV" = "900092" ] || [ "$RPI_REV" = "900093" ] && [ "$EW7811Un" != '' ]; then
|
||||
# This is a RPi2B or RPi0 with Edimax USB Wifi dongle.
|
||||
DAEMON_CONF=/etc/hostapd/hostapd-edimax.conf
|
||||
DAEMON_SBIN=/usr/sbin/hostapd-edimax
|
||||
##### Function for setting up new file structure for hostapd settings
|
||||
##### Look for hostapd.user and if found do nothing.
|
||||
##### If not assume because of previous version and convert to new file structure
|
||||
|
||||
function hostapd-upgrade {
|
||||
DAEMON_CONF=/etc/hostapd/hostapd.conf
|
||||
DAEMON_CONF_EDIMAX=/etc/hostapd/hostapd-edimax.conf
|
||||
HOSTAPD_VALUES=('ssid=' 'channel=' 'auth_algs=' 'wpa=' 'wpa_passphrase=' 'wpa_key_mgmt=' 'wpa_pairwise=' 'rsn_pairwise=')
|
||||
HOSTAPD_VALUES_RM=('#auth_algs=' '#wpa=' '#wpa_passphrase=' '#wpa_key_mgmt=' '#wpa_pairwise=' '#rsn_pairwise=')
|
||||
|
||||
for i in "${HOSTAPD_VALUES[@]}"
|
||||
do
|
||||
if grep -q "^$i" $DAEMON_CONF
|
||||
then
|
||||
grep "^$i" $DAEMON_CONF >> $DAEMON_USER_PREF
|
||||
sed -i '/^'"$i"'/d' $DAEMON_CONF
|
||||
sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX
|
||||
fi
|
||||
done
|
||||
for i in "${HOSTAPD_VALUES_RM[@]}"
|
||||
do
|
||||
if grep -q "^$i" $DAEMON_CONF
|
||||
then
|
||||
sed -i '/^'"$i"'/d' $DAEMON_CONF
|
||||
sed -i '/^'"$i"'/d' $DAEMON_CONF_EDIMAX
|
||||
fi
|
||||
done
|
||||
sleep 1 #make sure there is time to get the file written before checking for it again
|
||||
# If once the code above runs and there is still no hostapd.user file then something is wrong and we will just create the file with basic settings.
|
||||
# Any more then this they somebody was messing with things and its not our fault things are this bad
|
||||
if [ ! -f $DAEMON_USER_PREF ]; then
|
||||
echo "ssid=stratux" > $DAEMON_USER_PREF
|
||||
echo "channel=1" >> $DAEMON_USER_PREF
|
||||
fi
|
||||
}
|
||||
##### End hostapd settings structure function
|
||||
|
||||
##### Hostapd Driver check function #####
|
||||
function ap-start {
|
||||
|
||||
# Preliminaries. Kill off old services.
|
||||
/usr/bin/killall -9 hostapd hostapd-edimax hostapd-edimax-alt hostapd-edimax-newest
|
||||
/usr/sbin/service isc-dhcp-server stop
|
||||
|
||||
#EDIMAX Mac Addresses from http://www.adminsub.net/mac-address-finder/edimax
|
||||
#for logic check all addresses must be lowercase
|
||||
# 74:da:38 is my MAC on my NANO
|
||||
edimaxMac=(80:1f:02 74:da:38 00:50:fc 00:1f:1f 00:0e:2e 00:00:b4)
|
||||
|
||||
#Assume PI3 settings
|
||||
DAEMON_CONF=/etc/hostapd/hostapd.conf
|
||||
DAEMON_SBIN=/usr/sbin/hostapd
|
||||
|
||||
# Location of temporary hostapd.conf built by combining
|
||||
# non-editable /etc/hostapd/hostapd.conf or hostapd-edimax.conf
|
||||
# and the user configurable /etc/hostapd/hostapd.conf
|
||||
DAEMON_TMP=/tmp/hostapd.conf
|
||||
|
||||
#get the first 3 octets of the MAC(XX:XX:XX) at wlan0
|
||||
wlan0mac=$(head -c 8 /sys/class/net/wlan0/address)
|
||||
|
||||
# Is there an Edimax Mac Address at wlan0
|
||||
if [[ ${edimaxMac[*]} =~ "$wlan0mac" ]]; then
|
||||
DAEMON_CONF=/etc/hostapd/hostapd-edimax.conf
|
||||
DAEMON_SBIN=/usr/sbin/hostapd-edimax
|
||||
fi
|
||||
|
||||
#Make a new hostapd or hostapd-edimax conf file based on logic above
|
||||
cat ${DAEMON_USER_PREF} <(echo) ${DAEMON_CONF} > ${DAEMON_TMP}
|
||||
|
||||
${DAEMON_SBIN} -B ${DAEMON_TMP}
|
||||
|
||||
sleep 3
|
||||
|
||||
/usr/sbin/service isc-dhcp-server start
|
||||
}
|
||||
##### End Hostapd driver check function #####
|
||||
|
||||
#Do we need to upgrade the hostapd configuration files
|
||||
if [ ! -f $DAEMON_USER_PREF ]; then
|
||||
hostapd-upgrade
|
||||
fi
|
||||
|
||||
#Make a new hostapd or hostapd-edimax conf file based on logic above
|
||||
cat ${DAEMON_USER_PREF} ${DAEMON_CONF} > ${DAEMON_TMP}
|
||||
|
||||
${DAEMON_SBIN} -B ${DAEMON_TMP}
|
||||
|
||||
sleep 3
|
||||
|
||||
/usr/sbin/service isc-dhcp-server start
|
||||
# function to build /tmp/hostapd.conf and start AP
|
||||
ap-start
|
||||
|
|
Ładowanie…
Reference in New Issue