Commit d32368b2 authored by Igor Pecovnik's avatar Igor Pecovnik
Browse files

Added fex editor and few bugfixes

parent 3788e55b
...@@ -53,9 +53,10 @@ function wlan_exceptions () ...@@ -53,9 +53,10 @@ function wlan_exceptions ()
function get_wlan_interface () function get_wlan_interface ()
{ {
# search for wlan interfaces and provide a selection menu if there are more than one # search for wlan interfaces and provide a selection menu if there are more than one
# selected is stored into variable WLAN_SELECTED
# #
IFS=$'\r\n' GLOBIGNORE='*' command eval 'WLAN_INTERFACES=($(iw dev | grep Interface | sed -e "s/\tInterface //" | sort))' IFS=$'\r\n'
GLOBIGNORE='*'
WLAN_INTERFACES=($(nmcli dev status | grep wifi |awk '{print $1}'))
local LIST=() local LIST=()
for i in "${WLAN_INTERFACES[@]}" for i in "${WLAN_INTERFACES[@]}"
do do
...@@ -63,10 +64,10 @@ function get_wlan_interface () ...@@ -63,10 +64,10 @@ function get_wlan_interface ()
done done
LIST_LENGHT=$((${#LIST[@]}/2)); LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 1 ]; then if [ "$LIST_LENGHT" -eq 1 ]; then
WLAN_SELECTED=${WLAN_INTERFACES[0]} WIRELESS_ADAPTER=${WLAN_INTERFACES[0]}
else else
exec 3>&1 exec 3>&1
WLAN_SELECTED=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse --title "Select interface" --clear --menu "" $((6+${LIST_LENGHT})) 30 15 "${LIST[@]}" 2>&1 1>&3) WIRELESS_ADAPTER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse --title "Select interface" --clear --menu "" $((6+${LIST_LENGHT})) 30 15 "${LIST[@]}" 2>&1 1>&3)
exec 3>&- exec 3>&-
fi fi
} }
...@@ -89,9 +90,11 @@ LIST=() ...@@ -89,9 +90,11 @@ LIST=()
# here we add new items to menu. with condition when needed # here we add new items to menu. with condition when needed
if [[ -f /etc/update-motd.d/41-armbian-config ]]; then if [[ -f /etc/update-motd.d/41-armbian-config ]]; then
[[ -x /etc/update-motd.d/41-armbian-config ]] && LIST+=( "Remove" "Remove armbian-config from welcome screen" ) [[ -x /etc/update-motd.d/41-armbian-config ]] && LIST+=( "Remove" "Remove armbian-config from welcome screen" )
[[ ! -x /etc/update-motd.d/41-armbian-config ]] && LIST+=( "Add" "Add armbian-config to welcome screen" ) [[ ! -x /etc/update-motd.d/41-armbian-config ]] && LIST+=( "Add" "Add armbian-config to welcome screen" )
fi fi
[[ -f /usr/bin/bin2fex && "$LINUXFAMILY" = sun*i && "$BRANCH" = "default" ]] && LIST+=( "Fexedit" "Board (fex) settings editor" )
[[ -f /usr/bin/h3disp && "$LINUXFAMILY" = "sun8i" && "$BRANCH" = "default" && -n $(bin2fex </boot/script.bin 2>/dev/null | grep -w "hdmi_used = 1") ]] && LIST+=( "Display" "set the display resolution" ) [[ -f /usr/bin/h3disp && "$LINUXFAMILY" = "sun8i" && "$BRANCH" = "default" && -n $(bin2fex </boot/script.bin 2>/dev/null | grep -w "hdmi_used = 1") ]] && LIST+=( "Display" "set the display resolution" )
[[ -n $(nmcli -f DEVICE,TYPE device status | grep wifi) ]] && LIST+=( "Wireless" "Connect to your router" ) [[ -n $(nmcli -f DEVICE,TYPE device status | grep wifi) ]] && LIST+=( "Wireless" "Connect to your router" )
[[ -n $(grep -w apt /etc/apt/sources.list.d/armbian.list) ]] && LIST+=( "Nightly" "Switch to daily builds" ) [[ -n $(grep -w apt /etc/apt/sources.list.d/armbian.list) ]] && LIST+=( "Nightly" "Switch to daily builds" )
...@@ -145,6 +148,15 @@ while true; do ...@@ -145,6 +148,15 @@ while true; do
h3disp h3disp
exit exit
;; ;;
"Fexedit" )
TEMP=$(mktemp -d || exit 1)
trap "rm -rf \"${TEMP}\" ; exit 0" 0 1 2 3 15
bin2fex /boot/script.bin ${TEMP}/tempfex.txt >/dev/null 2>&1
dialog --title "Edit u-boot environment" --help-button --help-label "Save & reboot" --ok-label "Save" --no-collapse --editbox ${TEMP}/tempfex.txt 40 0 2> ${TEMP}/tempfex.out
exitstatus=$?;
[[ $exitstatus = 0 ]] && fex2bin ${TEMP}/tempfex.out /boot/script.bin
[[ $exitstatus = 2 ]] && fex2bin ${TEMP}/tempfex.out /boot/script.bin && reboot
;;
"Services" ) "Services" )
rcconf rcconf
;; ;;
...@@ -163,11 +175,14 @@ while true; do ...@@ -163,11 +175,14 @@ while true; do
;; ;;
"Network" ) "Network" )
dialog --backtitle "$BACKTITLE" --title "Edit network configuration" --no-collapse --editbox /etc/network/interfaces 30 0 2> /etc/network/interfaces.out dialog --backtitle "$BACKTITLE" --title "Edit network configuration" --no-collapse --help-button --help-label "Save & reboot" --ok-label "Save" --editbox /etc/network/interfaces 30 0 2> /etc/network/interfaces.out
[[ $? = 0 ]] && mv /etc/network/interfaces.out /etc/network/interfaces && service network-manager restart exitstatus=$?;
[[ $exitstatus = 0 ]] && mv /etc/network/interfaces.out /etc/network/interfaces && service network-manager restart
[[ $exitstatus = 2 ]] && mv /etc/network/interfaces.out /etc/network/interfaces && reboot
;; ;;
"Hotspot" ) "Hotspot" )
systemctl daemon-reload
CURRENT_UUID=$(nmcli -f UUID,TYPE connection show --active | grep wireless | awk '{print $1}') 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 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 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
...@@ -184,31 +199,31 @@ while true; do ...@@ -184,31 +199,31 @@ while true; do
# check for WLAN interfaces # check for WLAN interfaces
get_wlan_interface get_wlan_interface
# display dialog # display dialog
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nChecking nl80211 hostapd driver compatibility." 5 50 dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nProbing nl80211 hostapd driver compatibility." 7 50
apt-get -o Dpkg::Options::="--force-confnew" -y -qq --no-install-recommends install hostapd > /dev/null apt-get -o Dpkg::Options::="--force-confnew" -y -qq --no-install-recommends install hostapd > /dev/null
# change to selected interface # change to selected interface
sed -i "s/^interface=.*/interface=$WLAN_SELECTED/" /etc/hostapd.conf sed -i "s/^interface=.*/interface=$WIRELESS_ADAPTER/" /etc/hostapd.conf
# add hostapd.conf to services # add hostapd.conf to services
sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=\/etc\/hostapd.conf/" /etc/init.d/hostapd sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=\/etc\/hostapd.conf/" /etc/init.d/hostapd
# check both options # check both options
CHECK=$(systemctl daemon-reload;service hostapd restart;service hostapd status|grep fail) CHECK=$(systemctl daemon-reload;service hostapd restart;service hostapd status|grep fail)
if [[ -n "$CHECK" ]]; then if [[ -n "$CHECK" ]]; then
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nChecking Realtek hostapd driver compatibility." 5 50 dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nProbing Realtek hostapd driver compatibility." 7 50
apt-get -o Dpkg::Options::="--force-confnew" -y -qq --no-install-recommends install hostapd-realtek > /dev/null apt-get -o Dpkg::Options::="--force-confnew" -y -qq --no-install-recommends install hostapd-realtek > /dev/null
# change to selected interface # change to selected interface
sed -i "s/^interface=.*/interface=$WLAN_SELECTED/" /etc/hostapd.conf sed -i "s/^interface=.*/interface=$WIRELESS_ADAPTER/" /etc/hostapd.conf
fi fi
CHECK=$(systemctl daemon-reload;service hostapd restart;service hostapd status|grep fail) CHECK=$(systemctl daemon-reload;service hostapd restart;service hostapd status|grep fail)
# if both fails there is other problem # if both fails there is other problem
if [[ -n "$CHECK" ]]; then if [[ -n "$CHECK" ]]; then
dialog --backtitle "$BACKTITLE" --title "Warning" --infobox "\nNo compatible hostapd driver found." 5 39 dialog --backtitle "$BACKTITLE" --title "Warning" --infobox "\nWireless adapter: $WIRELESS_ADAPTER\n\nNo compatible hostapd driver found." 7 39
sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=/" /etc/init.d/hostapd sed -i "s/^DAEMON_CONF=.*/DAEMON_CONF=/" /etc/init.d/hostapd
systemctl daemon-reload;service hostapd restart systemctl daemon-reload;service hostapd restart
sleep 3 sleep 3
exit exit
fi fi
dialog --title "Choose a AP mode" --backtitle "$BACKTITLE" --help-button --help-label "Manual" --yes-label "Bridge" --no-label "NAT" --yesno "\nBridge: wireless clients will use your routers DHCP server\n\nNAT: with own DHCP server, out of your primary network\n\nManual: edit configuration manually" 11 70 dialog --title "Choose Access Point mode for $WIRELESS_ADAPTER" --backtitle "$BACKTITLE" --help-button --help-label "Manual" --yes-label "Bridge" --no-label "NAT" --yesno "\nBridge: wireless clients will use your routers DHCP server\n\nNAT: with own DHCP server, out of your primary network\n\nManual: edit configuration manually" 11 70
response=$? response=$?
DEFAULT_ADAPTER=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)') DEFAULT_ADAPTER=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)')
...@@ -266,11 +281,13 @@ while true; do ...@@ -266,11 +281,13 @@ while true; do
echo "iptables-restore < /etc/iptables.ipv4.nat" >> /etc/rc.local echo "iptables-restore < /etc/iptables.ipv4.nat" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local echo "exit 0" >> /etc/rc.local
;; ;;
3) exit;; 3)exit;;
255) exit;; 255) exit;;
esac esac
dialog --title "Manually adjust network configuration if needed" --backtitle "$BACKTITLE" \ dialog --title "Manually adjust network configuration if needed" --backtitle "$BACKTITLE" \
--ok-label "Reboot to apply new settings" --no-collapse --editbox $TEMP_CONF 30 0 2> $TEMP_CONF".tmp" --ok-label "Reboot to apply new settings" --no-collapse --editbox $TEMP_CONF 30 0 2> $TEMP_CONF".tmp"
service hostapd stop
if [[ $? = 0 ]]; then if [[ $? = 0 ]]; then
mv $TEMP_CONF $NETWORK_CONF mv $TEMP_CONF $NETWORK_CONF
reboot reboot
...@@ -279,8 +296,10 @@ while true; do ...@@ -279,8 +296,10 @@ while true; do
;; ;;
"Booting" ) "Booting" )
dialog --title "Edit u-boot environment" --no-collapse --editbox /boot/armbianEnv.txt 30 0 2> /boot/armbianEnv.txt.out dialog --title "Edit u-boot environment" --help-button --help-label "Save & reboot" --ok-label "Save" --no-collapse --editbox /boot/armbianEnv.txt 30 0 2> /boot/armbianEnv.txt.out
[[ $? = 0 ]] && mv /boot/armbianEnv.txt.out /boot/armbianEnv.txt exitstatus=$?;
[[ $exitstatus = 0 ]] && mv /boot/armbianEnv.txt.out /boot/armbianEnv.txt
[[ $exitstatus = 2 ]] && mv /boot/armbianEnv.txt.out /boot/armbianEnv.txt && reboot
;; ;;
"Nightly" ) "Nightly" )
......
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