Commit 3fc6bc46 authored by Igor Pecovnik's avatar Igor Pecovnik
Browse files

Cleanup

parent d1641e7f
......@@ -18,6 +18,7 @@ while true; do
LIST+=( "Software" "System and 3rd party" )
LIST+=( "Networking" "WiFI, BT, Hotspot" )
LIST+=( "Settings" "Board and system settings" )
LIST+=( "About" "Information about this configuration tool" )
# count number of menu items to adjust window sizee
LISTLENGHT="$((9+${#LIST[@]}/2))"
......@@ -29,7 +30,7 @@ while true; do
exec 3>&1
selection=$(dialog --backtitle "$BACKTITLE" --title "armbian-config" --clear \
--cancel-label "Exit to shell" --menu "\n$BOARD_NAME $IPADDRESS running $DISTRO $DISTROID \n " $LISTLENGHT 70 $BOXLENGHT \
--cancel-label "Exit to shell" --menu "\nConfiguration tool for the $BOARD_NAME running $DISTRO $DISTROID \n " $LISTLENGHT 70 $BOXLENGHT \
"${LIST[@]}" 2>&1 1>&3)
exit_status=$?
exec 3>&-
......@@ -47,5 +48,8 @@ while true; do
"Settings" )
submenu_settings
;;
"About" )
show_box "Info" "This tool provides a straightforward way of doing initial configuration of the ${BOARD_NAME}. Although it can be run at any time, some of the options may have difficulties if you have heavily customised your installation.\n\nSources: https://github.com/armbian/config\n\nSupport: https://forum.armbian.com" "15"
;;
esac
done
\ No newline at end of file
......@@ -124,50 +124,16 @@ function jobs ()
# Connect to wireless access point
#
"WiFi" )
# scan for wifi modules
array=( $(nmcli dev | grep "wifi" | awk '{print $1}') )
declared_wlans=0;
for i in "${array[@]}"
do
if grep --quiet "^iface $i" /etc/network/interfaces; then
let declared_wlans+=1
fi
done
if [[ -n $(service hostapd status | grep -w active | grep -w running) ]]; then
DIALOG_CANCEL=1
dialog --title "Hostapd service is running" --backtitle "$BACKTITLE" --help-button --help-label "Cancel" --yes-label "Stop" \
--no-label "Edit" --yesno "\nStop: stop and disable\n\nEdit: change basic parameters: SSID, password and channel" 9 70
exitstatus=$?;
if [[ $exitstatus = 0 ]]; then service hostapd stop ; sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=/" /etc/init.d/hostapd; \
systemctl daemon-reload; fi
if [[ $exitstatus = 1 ]]; then wlan_edit; service hostapd stop; sleep 1; service hostapd start; fi
elif [ $declared_wlans = ${#array[@]} ]; then
dialog --title "Error" --backtitle "$BACKTITLE" --no-collapse \
--msgbox "\nWireless network is in use by if-up service. Remove it from config." 8 57
else
CURRENT_UUID=$(nmcli -f UUID,TYPE connection show --active | grep wireless | awk '{print $1}')
if [[ -n $(service hostapd status | grep -w active | grep -w running) ]]; then
dialog --title "Error" --backtitle "$BACKTITLE" --no-collapse \
--msgbox "\nHostapd service is running. Disable it and try again." 7 57
exit
elif [[ -n $CURRENT_UUID ]]; then
dialog --title "Info" --backtitle "$BACKTITLE" --no-collapse \
--yesno "\nAlready connected to $WIFICONNECTED.\n\nDo you want to disconnect?" 9 57
[[ $? = 0 ]] && nmcli connection down uuid $CURRENT_UUID > /dev/null 2>&1
else
# disable AP mode on certain adapters
wlan_exceptions "off"
nmtui-connect
fi
fi
;;
# Create WiFi access point
#
"Hotspot" )
systemctl daemon-reload
CURRENT_UUID=$(nmcli -f UUID,TYPE connection show --active | grep wireless | awk '{print $1}')
CURRENT_UUID=$(nmcli -f DEVICE,TYPE,STATE device status | grep -w " wifi " | grep -w " disconnected")
if [[ -n $(service hostapd status | grep -w active | grep -w running) ]]; then
dialog --title "Hostapd service is running" --backtitle "$BACKTITLE" --help-button --help-label "Cancel" --yes-label "Stop" \
--no-label "Edit" --yesno "\nStop: stop and disable\n\nEdit: change basic parameters: SSID, password and channel" 9 70
......@@ -176,14 +142,16 @@ function jobs ()
service hostapd stop
sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=/" /etc/init.d/hostapd
systemctl daemon-reload
systemctl disable dnsmasq.service >/dev/null 2>&1
rm /etc/NetworkManager/conf.d/armbian.conf
rm -f /etc/network/interfaces.d/bridge.conf
rm -f /etc/network/interfaces.d/nat.conf
service network-manager reload
sed -i '/^iptables/ d' /etc/rc.local
fi
if [[ $exitstatus = 1 ]]; then wlan_edit; service hostapd stop; sleep 1; service hostapd start; fi
elif [[ -n $CURRENT_UUID ]]; then
dialog --title "Info" --backtitle "$BACKTITLE" --no-collapse \
--yesno "\nWireless connection is in use.\n\nDo you want to disconnect?" 9 57
[[ $? = 0 ]] && nmcli connection down uuid $CURRENT_UUID 2> /dev/null
elif [[ -z $CURRENT_UUID ]]; then
dialog --title "Info" --backtitle "$BACKTITLE" --no-collapse --msgbox "\nAll wireless connections are in use." 7 40
else
# change special adapters to AP mode
wlan_exceptions "on"
......@@ -236,32 +204,20 @@ function jobs ()
case $response in
# bridge
0)
sed -i '/^#/ d' $TEMP_CONF
apt-get -qq -y --no-install-recommends install bridge-utils >> /dev/null
sed -i "s/^auto lo.*/auto lo br0/" $TEMP_CONF
# if we have dhcp on default adapter
if [[ -n $(grep dhcp $TEMP_CONF | grep "$DEFAULT_ADAPTER" | grep -v br) ]]; then
sed -i "s/^iface $DEFAULT_ADAPTER inet dhcp/iface $DEFAULT_ADAPTER inet manual/" $TEMP_CONF
echo -e "\niface br0 inet dhcp\nbridge_ports $DEFAULT_ADAPTER $WIRELESS_ADAPTER" >> $TEMP_CONF
echo -e "\nauto $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet manual" >> $TEMP_CONF
#fi
# if we have static on default adapter
#if [[ -n $(grep static $TEMP_CONF | grep "$DEFAULT_ADAPTER" | grep -v br) ]]; then
else
sed -i "s/^iface $DEFAULT_ADAPTER inet static/iface $DEFAULT_ADAPTER inet manual/" $TEMP_CONF
sed -i "/^iface $DEFAULT_ADAPTER inet manual/a iface br0 inet static" $TEMP_CONF
echo -e "bridge_ports $DEFAULT_ADAPTER $WIRELESS_ADAPTER" >> $TEMP_CONF
echo -e "\nauto $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet manual" >> $TEMP_CONF
fi
sed -i 's/^bridge=.*/bridge=br0/' /etc/hostapd.conf
if [[ $DEFAULT_ADAPTER == "br0" ]]; then NEW_DEFAULT_ADAPTER="eth0"; else NEW_DEFAULT_ADAPTER="$DEFAULT_ADAPTER"; fi
echo -e "#bridged wireless for hostapd by armbian-config\n" > /etc/network/interfaces.d/bridge.conf
echo -e "auto lo br0\niface lo inet loopback" >> /etc/network/interfaces.d/bridge.conf
echo -e "\nauto $NEW_DEFAULT_ADAPTER\nallow-hotplug $NEW_DEFAULT_ADAPTER\niface $NEW_DEFAULT_ADAPTER inet manual" >> /etc/network/interfaces.d/bridge.conf
echo -e "\nauto $WIRELESS_ADAPTER\nallow-hotplug $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet manual\n" >> /etc/network/interfaces.d/bridge.conf
create_if_config "$DEFAULT_ADAPTER" "br0" >> /etc/network/interfaces.d/bridge.conf
echo -e "\nbridge_ports $NEW_DEFAULT_ADAPTER $WIRELESS_ADAPTER" >> /etc/network/interfaces.d/bridge.conf
;;
# NAT
1)
sed -i '/^#/ d' $TEMP_CONF
debconf-apt-progress -- apt-get -qq -y --no-install-recommends install dnsmasq iptables
echo -e "\nallow-hotplug $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet static " >> $TEMP_CONF
echo -e "\naddress 172.24.1.1\nnetmask 255.255.255.0\nnetwork 172.24.1.0\nbroadcast 172.24.1.255" >> $TEMP_CONF
echo -e "\nallow-hotplug $WIRELESS_ADAPTER\niface $WIRELESS_ADAPTER inet static " > /etc/network/interfaces.d/nat.conf
echo -e "\naddress 172.24.1.1\nnetmask 255.255.255.0\nnetwork 172.24.1.0\nbroadcast 172.24.1.255" >> /etc/network/interfaces.d/nat.conf
# create new configuration
echo "interface=$WIRELESS_ADAPTER # Use interface $WIRELESS_ADAPTER" > /etc/dnsmasq.conf
echo "listen-address=172.24.1.1 # Explicitly specify the address to listen on" >> /etc/dnsmasq.conf
......@@ -297,8 +253,12 @@ function jobs ()
response=$?
service hostapd stop
if [[ $response = 0 ]]; then
mv $TEMP_CONF /etc/network/interfaces
echo "source /etc/network/interfaces.d/*" >> /etc/network/interfaces
reboot
else
# remove conf
rm -f /etc/network/interfaces.d/bridge.conf
rm -f /etc/network/interfaces.d/nat.conf
fi
fi
;;
......
......@@ -42,23 +42,19 @@ fi
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# show IP addresses
# create interface configuration section
#
function get_ip_addresses() {
local ips=()
for f in /sys/class/net/*; do
local intf=$(basename $f)
# match only interface names starting with e (Ethernet), w (wireless), r (some Ralink drivers use ra<number> format)
if [[ $intf =~ ^[ewr].* ]]; then
local tmp=$(ip -4 addr show dev $intf | awk '/inet/ {print $2}' | cut -d'/' -f1)
# add both name and IP - can be informative but becomes ugly with long persistent/predictable device names
#[[ -n $tmp ]] && ips+=("$intf: $tmp")
# add IP only
[[ -n $tmp ]] && ips+=("$tmp")
fi
done
[[ -n "$ips" ]] && echo "at ${ips[@]}"
} # get_ip_addresses
function create_if_config() {
local address=$(ip -4 addr show dev $1 | awk '/inet/ {print $2}' | cut -d'/' -f1)
local mask=$(ifconfig $1 | sed -rn '2s/ .*:(.*)$/\1/p')
local gateway=$(route -n | grep 'UG[ \t]' | awk '{print $2}' | sed -n '1p')
echo -e "allow-hotplug $2\nno-auto-down $2"
if grep -q "iface $1 inet dhcp" /etc/network/interfaces; then
echo -e "iface $2 inet dhcp"
else
echo -e "iface $2 inet static\n\taddress $address\n\tnetmask $mask\n\tgateway $gateway\n\tdns-nameservers 8.8.8.8"
fi
} #
#-----------------------------------------------------------------------------------------------------------------------------------------#
......@@ -70,9 +66,11 @@ DISTROID=$(lsb_release -sc)
KERNELID=$(uname -r)
BACKTITLE="Configuration utility, $ARMBIAN, https://www.armbian.com"
TITLE="$BOARD_NAME "
IPADDRESS=$(get_ip_addresses)
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nLoading Armbian configuration utility ... " 5 45
DEFAULT_ADAPTER=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)')
#IPADDRESS=$(get_ip_addresses "br0" "eth0" > /tmp/x)
IPADDRESS=$(create_if_config "br0" "eth0" )
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nLoading Armbian configuration utility ... " 5 45
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
......@@ -97,6 +95,16 @@ exec 3>&-
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# show box
#
function show_box ()
{
dialog --no-shadow --backtitle "$BACKTITLE" --no-collapse --title "$1" --clear --msgbox "\n$2\n \n" $3 56
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# show description for MOTD files
......@@ -336,11 +344,14 @@ function submenu_networking ()
while true; do
LIST=()
if [[ -n $(service hostapd status | grep -w active | grep -w running) ]]; then
[[ -n $(nmcli -f DEVICE,TYPE device status | grep wifi) ]] && LIST+=( "Hotspot" "Manage WiFi access point" )
HOSTAPDINFO=$(hostapd_cli get_config | grep ^ssid | sed 's/ssid=//g')
[[ -n $(nmcli device status | grep wifi | grep connected) ]] && LIST+=( "Hotspot" "Manage active wireless access point" )
else
[[ -n $(nmcli -f DEVICE,TYPE device status | grep wifi) ]] && LIST+=( "WiFi" "Manage wireless networking" )
[[ -n $(nmcli -f DEVICE,TYPE device status | grep wifi) ]] && LIST+=( "Hotspot" "Create WiFi access point" )
[[ -n $(nmcli device status | grep wifi | grep disconnected) ]] && LIST+=( "Hotspot" "Create WiFi access point" )
fi
[[ -n $(nmcli device status | grep wifi | grep -v unavailable) ]] && LIST+=( "WiFi" "Manage wireless networking" )
[[ $(hcitool dev | sed '1d') != "" && -n $(service bluetooth status | grep -w active | grep -w running) ]] && LIST+=( "Bluetooth" "Connect Bluetooth devices" )
LIST+=( "Network" "Edit network settings" )
......@@ -349,12 +360,18 @@ while true; do
BOXLENGHT=${#LIST[@]}
WIFICONNECTED=$(nmcli -f NAME,TYPE connection show --active | grep wireless | awk 'NF{NF-=1};1')
disclaimer=""
local disclaimer=""
if [[ -n $WIFICONNECTED ]]; then
LISTLENGHT=$((LISTLENGHT+1))
local connected="Connected to: $WIFICONNECTED\n"
local disclaimer=$connected
LISTLENGHT=$((LISTLENGHT+2))
local connected="\nConnected to SSID: $WIFICONNECTED\n"
disclaimer=$connected
fi
if [[ -n $HOSTAPDINFO ]]; then
LISTLENGHT=$((LISTLENGHT+2))
disclaimer=$disclaimer$"\nAccess point SSID: $HOSTAPDINFO\n"
fi
#disclaimer=$disclaimer"\n"
# display warning only we have wifi
#if [[ " ${LIST[*]} " == *" Hotspot "* ]]; then
......@@ -367,7 +384,7 @@ while true; do
DIALOG_ESC=255
exec 3>&1
selection=$(dialog --backtitle "$BACKTITLE" --title "WiFI, BT, Hotspot" --clear \
selection=$(dialog --backtitle "$BACKTITLE" --title "Wireless, Bluetooth, Hotspot" --clear \
--cancel-label "Back" --menu "$disclaimer" $LISTLENGHT 70 $BOXLENGHT \
"${LIST[@]}" 2>&1 1>&3)
exit_status=$?
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment