Commit 97a57a7f authored by Igor Pecovnik's avatar Igor Pecovnik
Browse files

Move functions from submenu.sh and split network related into separate file

parent e1b59d57
......@@ -34,6 +34,7 @@ fi
[[ -f /usr/lib/armbian-config/jobs.sh ]] && source /usr/lib/armbian-config/jobs.sh || source ${BASH_SOURCE}-jobs
[[ -f /usr/lib/armbian-config/submenu.sh ]] && source /usr/lib/armbian-config/submenu.sh || source ${BASH_SOURCE}-submenu
[[ -f /usr/lib/armbian-config/functions.sh ]] && source /usr/lib/armbian-config/functions.sh || source ${BASH_SOURCE}-functions
[[ -f /usr/lib/armbian-config/functions-network.sh ]] && source /usr/lib/armbian-config/functions-network.sh || source ${BASH_SOURCE}-functions-network
......
......@@ -8,31 +8,55 @@
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# gather info about the board and start with loading menu
#
DIALOG_CANCEL=1
DIALOG_ESC=255
function main(){
[[ -f /etc/armbian-release ]] && source /etc/armbian-release && ARMBIAN="Armbian $VERSION $IMAGE_TYPE";
DISTRO=$(lsb_release -is)
DISTROID=$(lsb_release -sc)
KERNELID=$(uname -r)
[[ -z "${ARMBIAN// }" ]] && ARMBIAN="$DISTRO $DISTROID"
BACKTITLE="Configuration utility, $ARMBIAN, https://www.armbian.com"
TITLE="$BOARD_NAME "
DEFAULT_ADAPTER=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)')
[[ -z "${DEFAULT_ADAPTER// }" ]] && DEFAULT_ADAPTER="lo"
OVERLAYDIR="/boot/dtb/overlay";
[[ "$LINUXFAMILY" == "sunxi64" ]] && OVERLAYDIR="/boot/dtb/allwinner/overlay";
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nLoading Armbian configuration utility ... " 5 45
sleep 1
DIALOG_CANCEL=1
DIALOG_ESC=255
[[ -f /etc/armbian-release ]] && source /etc/armbian-release && ARMBIAN="Armbian $VERSION $IMAGE_TYPE";
DISTRO=$(lsb_release -is)
DISTROID=$(lsb_release -sc)
KERNELID=$(uname -r)
[[ -z "${ARMBIAN// }" ]] && ARMBIAN="$DISTRO $DISTROID"
BACKTITLE="Configuration utility, $ARMBIAN, https://www.armbian.com"
TITLE="$BOARD_NAME "
DEFAULT_ADAPTER=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)')
[[ -z "${DEFAULT_ADAPTER// }" ]] && DEFAULT_ADAPTER="lo"
OVERLAYDIR="/boot/dtb/overlay";
[[ "$LINUXFAMILY" == "sunxi64" ]] && OVERLAYDIR="/boot/dtb/allwinner/overlay";
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nLoading Armbian configuration utility ... " 5 45
sleep 1
#-----------------------------------------------------------------------------------------------------------------------------------------#
}
#
# check dpkg status of $1 -- currently only 'not installed at all' case catched
#
check_if_installed (){
local DPKG_Status="$(dpkg -s "$1" 2>/dev/null | awk -F": " '/^Status/ {print $2}')"
if [[ "X${DPKG_Status}" = "X" || "${DPKG_Status}" = *deinstall* ]]; then
return 1
else
return 0
fi
}
#
# check if package manager is doing something
#
function is_package_manager_running() {
fuser -s /var/lib/dpkg/lock
if [[ $? = 0 ]]; then
# 0 = true
......@@ -43,5 +67,280 @@ function is_package_manager_running() {
# 1 = false
return 1
fi
}
#
# show disclaimer
#
function beta_disclaimer ()
{
exec 3>&1
ACKNOWLEDGEMENT=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse --title " Warning " \
--clear \--radiolist "\n$1.\n \n" 12 56 7 "Yes, I understand" "" off 2>&1 1>&3)
exec 3>&-
}
#
# show box
#
function show_box ()
{
dialog --colors --backtitle "$BACKTITLE" --no-collapse --title " $1 " --clear --msgbox "\n$2\n \n" $3 56
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# show description for MOTD files
#
function description
{
case $1 in
*header*)
echo "Big board logo and kernel info"
;;
*sysinfo*)
echo "Sysinfo - load, ip, memory, uptime, ..."
;;
*tips*)
echo "Shows tip of the day"
;;
*updates*)
echo "Display number of avaliable updates"
;;
*armbian-config*)
echo "Show command for system configuration"
;;
*autoreboot-warn*)
echo "Show warning when reboot is needed"
;;
*uk.armbian.com*)
echo "United Kingdom"
;;
*.armbian.com*)
echo "Estonia"
;;
*)
echo ""
;;
esac
}
#
# check if board has alternative kernels
#
function aval_kernel ()
{
IFS=$'\r\n'
GLOBIGNORE='*'
AVAL_KERNEL=($(apt-cache search --names-only '^linux-'$(lsb_release -cs)'-root.*.'$BOARD'*' \
| grep -w "$BOARD " | sed 's/.*(\(.*\))/\1/' | awk '{print $1}' | grep -v "$BRANCH" ))
local LIST=()
for i in "${AVAL_KERNEL[@]}"
do
LIST+=( "${i[0]//[[:blank:]]/}" "" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 1 ]; then
TARGET_BRANCH=${AVAL_KERNEL[0]}
else
exec 3>&1
TARGET_BRANCH=$(dialog --cancel-label "Cancel" --backtitle "$BACKTITLE" --no-collapse \
--title "Upgrade from $BRANCH to:" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
exitstatus=$?;
exec 3>&-
fi
}
#
# check if board has alternative kernels
#
function aval_cubox ()
{
LIST=("imx6dl-hummingboard.dtb" "HB Solo/DualLite" "imx6dl-hummingboard-emmc-som-v15.dtb" "HB Solo/DualLite v1.5 with eMMC" "imx6dl-hummingboard-som-v15.dtb" "HB Solo/DualLite v1.5" \
"imx6dl-hummingboard2.dtb" "HB2 Solo/DualLite" "imx6dl-hummingboard2-emmc-som-v15.dtb" "HB2 Solo/DualLite v1.5 with eMMC" "imx6dl-hummingboard2-som-v15.dtb" "HB2 Solo/DualLite v1.5" \
"imx6q-hummingboard.dtb" "HB Dual/Quad" "imx6q-hummingboard-emmc-som-v15.dtb" "HB Dual/Quad v1.5 with eMMC" "imx6q-hummingboard-som-v15.dtb" "HB Dual/Quad v1.5" \
"imx6q-hummingboard2.dtb" "HB2 Dual/Quad" "imx6q-hummingboard2-emmc-som-v15.dtb" "HB2 Dual/Quad v1.5 with eMMC" "imx6q-hummingboard2-som-v15.dtb" "HB2 Dual/Quad v1.5" \
"imx6dl-cubox-i.dtb" "Cubox-i Solo/DualLite" "imx6dl-cubox-i-emmc-som-v15.dtb" "Cubox-i Solo/DualLite v1.5 with eMMC" "imx6dl-cubox-i-som-v15.dtb" "Cubox-i Solo/DualLite v1.5" \
"imx6q-cubox-i.dtb" "Cubox-i Dual/Quad" "imx6q-cubox-i-emmc-som-v15.dtb" "Cubox-i Dual/Quad v1.5 with eMMC" "imx6q-cubox-i-som-v15.dtb" "Cubox-i Dual/Quad v1.5")
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 1 ]; then
TARGET_BOARD=${AVAL_KERNEL[0]}
else
exec 3>&1
TARGET_BOARD=$(dialog --cancel-label "Cancel" --backtitle "$BACKTITLE" --no-collapse \
--title "Select board configuration" --clear --menu "" $((6+${LIST_LENGHT})) 80 25 "${LIST[@]}" 2>&1 1>&3)
exitstatus=$?;
exec 3>&-
fi
}
#
# select video modes for a10 and a20
#
function get_a20modes ()
{
IFS=$'\r'
GLOBIGNORE='*'
SCREEN_RESOLUTION=("1920x1080p60" "1280x720p60" "1920x1080p50" "1280x1024p60" "1024x768p60" "800x600p60" "640x480p60" "1360x768p60" "1440x900p60" "1680x1050p60")
local LIST=()
for i in "${SCREEN_RESOLUTION[@]}"
do
LIST+=( "${i[0]//[[:blank:]]/}" "" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
#echo $LIST_LENGHT
#exit
if [ "$LIST_LENGHT" -eq 1 ]; then
SCREEN_RESOLUTION=${SCREEN_RESOLUTION[0]}
else
exec 3>&1
SCREEN_RESOLUTION=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
--title "Select video mode" --clear --menu "" $((6+${LIST_LENGHT})) 25 $((1+${LIST_LENGHT})) "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
fi
}
#
# select video modes for h3
#
function get_h3modes ()
{
IFS=$'\r\n'
GLOBIGNORE='*'
SCREEN_RESOLUTION=($(h3disp -i))
local LIST=()
for i in "${SCREEN_RESOLUTION[@]}"
do
LIST+=( "${i[0]//[[:blank:]]/}" "" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
#echo $LIST_LENGHT
#exit
if [ "$LIST_LENGHT" -eq 1 ]; then
SCREEN_RESOLUTION=${SCREEN_RESOLUTION[0]}
else
exec 3>&1
SCREEN_RESOLUTION=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
--title "Select video mode" --clear --menu "" $((6+${LIST_LENGHT})) 25 $((1+${LIST_LENGHT})) "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
fi
}
#
# create or pick unprivileged user
#
function add_choose_user ()
{
IFS=$'\r\n'
GLOBIGNORE='*'
local USERS=($(awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd))
local LIST=()
for i in "${USERS[@]}"
do
LIST+=( "${i[0]//[[:blank:]]/}" "" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 0 ]; then
dialog --backtitle "$BACKTITLE" --title " Notice " --msgbox "\nWe didn't find any unprivileged user with sudo rights which is required to run this service.\
\n\nPress enter to create one!" 10 48
read -t 0 temp
echo -e "\nPlease provide a username (eg. your forename) or leave blank for canceling user creation: \c"
read -e username
CHOSEN_USER="$(echo "$username" | tr '[:upper:]' '[:lower:]' | tr -d -c '[:alnum:]')"
[ -z "$CHOSEN_USER" ] && return
echo "Trying to add user $CHOSEN_USER"
adduser $CHOSEN_USER || return
elif [ "$LIST_LENGHT" -eq 1 ]; then
CHOSEN_USER=${USERS[0]}
else
exec 3>&1
CHOSEN_USER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
--title "Select unprivileged user" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
fi
}
#
# configure armbian desktop
#
function configure_desktop ()
{
add_choose_user
if [ -n "$CHOSEN_USER" ]; then
# install desktop and nodm
debconf-apt-progress -- apt-get update
debconf-apt-progress -- apt-get -y install armbian-${DISTROID}-desktop
DEBIAN_FRONTEND=noninteractive debconf-apt-progress -- apt-get -y -qq install nodm
# add user to groups
for additionalgroup in sudo netdev audio video dialout plugdev bluetooth systemd-journal ssh; do
usermod -aG ${additionalgroup} ${CHOSEN_USER} 2>/dev/null
done
# fix for gksu in Xenial
touch /home/${CHOSEN_USER}/.Xauthority
cp -R /etc/skel/. /home/${CHOSEN_USER}
# set up profile sync daemon on desktop systems
which psd >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "${CHOSEN_USER} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> /etc/sudoers
touch /home/${CHOSEN_USER}/.activate_psd
fi
sed -i "s/NODM_USER=\(.*\)/NODM_USER=${CHOSEN_USER}/" /etc/default/nodm
sed -i "s/NODM_ENABLED=\(.*\)/NODM_ENABLED=true/g" /etc/default/nodm
chown -R ${CHOSEN_USER}:${CHOSEN_USER} /home/${CHOSEN_USER}/.
sleep 3
service nodm stop
sleep 1
service nodm start
fi
}
main "$@"
\ No newline at end of file
#!/bin/bash
#
# Copyright (c) 2017 Igor Pecovnik, igor.pecovnik@gma**.com
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# check hostapd configuration. Return error or empty if o.k.
#
check_hostapd ()
{
systemctl daemon-reload
hostapd_error=""
[[ -n $1 && -n $2 ]] && dialog --title " $1 " --backtitle "$BACKTITLE" --no-collapse --colors --infobox "$2" 5 $((${#2}-3))
service hostapd stop
rm -f /var/run/hostapd/*
sleep 1
service hostapd start
sleep 6
if [[ "$(hostapd_cli ping 2> /dev/null| grep PONG)" == "PONG" ]]; then
hostapd_error=""
else
hostapd_error=$(hostapd /etc/hostapd.conf)
sleep 6
[[ -n $(echo $hostapd_error | grep "channel") ]] && hostapd_error="channel_restriction"
[[ -n $(echo $hostapd_error | grep "does not support" | grep "hw_mode") ]] && hostapd_error="hw_mode"
[[ -n $(echo $hostapd_error | grep "not found from the channel list" | grep "802.11g") ]] && hostapd_error="wrong_channel"
[[ -n $(echo $hostapd_error | grep "VHT") ]] && hostapd_error="unsupported_vht"
[[ -n $(echo $hostapd_error | grep " HT capability") ]] && hostapd_error="unsupported_ht"
fi
}
#
# check all possible wireless modes
#
function check_advanced_modes ()
{
sed '/### IEEE 802.11n/,/^### IEEE 802.11n/ s/^# *//' -i /etc/hostapd.conf
check_hostapd "Probing" "\n802.11n \Z1(150-300Mbps)\Z0"
# check HT capability
check_ht_capab
if [[ -z "$hostapd_error" ]]; then
sed '/### IEEE 802.11a\>/,/^### IEEE 802.11a\>/ s/^# *//' -i /etc/hostapd.conf
sed -i "s/^channel=.*/channel=40/" /etc/hostapd.conf
check_hostapd "Probing" "\n802.11a \Z1(5Ghz)\Z0"
if [[ "$hostapd_error" == "channel_restriction" ]]; then check_channels; fi
if [[ "$hostapd_error" == "channel_restriction" ]]; then
# revering configuration
sed -i "s/^channel=.*/channel=5/" /etc/hostapd.conf
sed '/## IEEE 802.11a\>/,/^## IEEE 802.11a\>/ s/.*/#&/' -i /etc/hostapd.conf
check_hostapd "Reverting" "\nWireless \Z1802.11a (5Ghz)\Z0 is not supported"
else
sed '/### IEEE 802.11ac\>/,/^### IEEE 802.11ac\>/ s/^# *//' -i /etc/hostapd.conf
# check VHT capability
check_vht_capab
if [[ "$hostapd_error" == "unsupported_vht" || "$hostapd_error" == "channel_restriction" ]]; then
# revering configuration
sed '/## IEEE 802.11ac\>/,/^## IEEE 802.11ac\>/ s/.*/#&/' -i /etc/hostapd.conf
check_hostapd "Reverting" "\nWireless 802.11ac \Z1(433Mbps x n @ 5Ghz)\Z0 is not supported"
if [[ "$hostapd_error" == "channel_restriction" ]]; then check_channels; fi
fi
fi
else
sed '/## IEEE 802.11n/,/^## IEEE 802.11n/ s/.*/#&/' -i /etc/hostapd.conf
fi
}
#
# create interface configuration section
#
function create_if_config() {
address=$(ip -4 addr show dev $1 | awk '/inet/ {print $2}' | cut -d'/' -f1)
netmask=$(ip -4 addr show dev $1 | awk '/inet/ {print $2}' | cut -d'/' -f2)
gateway=$(route -n | grep 'UG[ \t]' | awk '{print $2}' | sed -n '1p')
echo -e "# armbian-config created"
echo -e "source /etc/network/interfaces.d/*\n"
if [[ "$3" == "fixed" ]]; then
echo -e "# Local loopback\nauto lo\niface lo init loopback\n"
echo -e "# Interface $2\nauto $2\nallow-hotplug $2"
echo -e "iface $2 inet static\n\taddress $address\n\tnetmask $netmask\n\tgateway $gateway\n\tdns-nameservers 8.8.8.8"
fi
}
#
# reload network related services
#
function reload-nety() {
systemctl daemon-reload
if [[ "$1" == "reload" ]]; then WHATODO="Reloading services"; else WHATODO="Stopping services"; fi
(service network-manager stop; echo 10; sleep 1; service hostapd stop; echo 20; sleep 1; service dnsmasq stop; echo 30; sleep 1;\
[[ "$1" == "reload" ]] && service dnsmasq start && echo 60 && sleep 1 && service hostapd start && echo 80 && sleep 1;\
service network-manager start; echo 90; sleep 5;) | dialog --backtitle "$BACKTITLE" --title " $WHATODO " --gauge "" 6 70 0
systemctl restart systemd-resolved.service
}
#
# Check if something is running on port $1 and display info
#
check_port ()
{
[[ -n $(netstat -lnt | awk '$6 == "LISTEN" && $4 ~ ".'$1'"') ]] && dialog --backtitle "$BACKTITLE" --title "Checking service" \
--msgbox "\nIt looks good.\n\nThere is $2 service on port $1" 9 52
}
#
# check wifi high throughput
#
function check_ht_capab ()
{
declare -a arr=("[HT40+][LDPC][SHORT-GI-20][SHORT-GI-40][TX-STBC][RX-STBC1][DSSS_CCK-40][SMPS-STATIC]" \
"[HT40-][SHORT-GI-40][SHORT-GI-40][DSSS_CCK-40]" "[SHORT-GI-20][SHORT-GI-40][HT40+]" "[DSSS_CK-40][HT20+]" "")
local j=0
for i in "${arr[@]}"
do
j=$((j+(100/${#arr[@]})))
echo $j | dialog --title " Probing HT " --colors --gauge "\nSeeking for optimal \Z1high throughput\Z0 settings." 8 50 0
sed -i "s/^ht_capab=.*/ht_capab=$i/" /etc/hostapd.conf
check_hostapd
if [[ "$hostapd_error" == "channel_restriction" ]]; then check_channels; fi
if [[ "$hostapd_error" == "" ]]; then break; fi
done
}
#
# check wifi high throughput
#
function check_vht_capab ()
{
declare -a arr=("[MAX-MPDU-11454][SHORT-GI-80][TX-STBC-2BY1][RX-STBC-1][MAX-A-MPDU-LEN-EXP3]" "[MAX-MPDU-11454][SHORT-GI-80][RX-STBC-1][MAX-A-MPDU-LEN-EXP3]" "")
local j=0
for i in "${arr[@]}"
do
j=$((j+(100/${#arr[@]})))
echo $j | dialog --title " Probing VHT " --colors --gauge "\nSeeking for optimal \Z1very high throughput\Z0 settings." 8 54 0
sed -i "s/^vht_capab=.*/vht_capab=$i/" /etc/hostapd.conf
check_hostapd
if [[ "$hostapd_error" == "channel_restriction" ]]; then check_channels; fi
if [[ "$hostapd_error" == "" ]]; then break; fi
done
}
#
# check 5Ghz channels
#
function check_channels ()
{
declare -a arr=("36" "40")
for i in "${arr[@]}"
do
sed -i "s/^channel=.*/channel=$i/" /etc/hostapd.conf
check_hostapd "Probing" "\nChannel:\Z1 ${i}\Z0"
if [[ "$hostapd_error" != "channel_restriction" ]]; then break; fi
done
}
#
# edit ip address witing network manager
#
function nm_ip_editor ()
{
exec 3>&1
dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1
\n " 12 38 0 \
"Address:" 1 1 "$address" 1 15 15 0 \
"Netmask:" 2 1 "$netmask" 2 15 15 0 \
"Gateway:" 3 1 "$gateway" 3 15 15 0 \
2>&1 1>&3 | {
read -r address;read -r netmask;read -r gateway
if [[ $? = 0 ]]; then
localuuid=$(LC_ALL=C nmcli -f UUID,DEVICE connection show | grep $1 | awk '{print $1}')
nmcli con mod $localuuid ipv4.method manual ipv4.addresses "$address/$netmask" >/dev/null 2>&1
nmcli con mod $localuuid ipv4.method manual ipv4.gateway "$gateway" >/dev/null 2>&1
nmcli con mod $localuuid ipv4.dns "8.8.8.8,$gateway" >/dev/null 2>&1
nmcli con down $localuuid >/dev/null 2>&1
sleep 2
nmcli con up $localuuid >/dev/null 2>&1
fi
}
}
#
# edit ip address
#
function systemd_ip_editor ()
{
local filename="/etc/systemd/network/10-$1.network"
if [[ -f $filename ]]; then
sed -i '/Network/,$d' $filename
exec 3>&1
dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1
\n " 12 38 0 \
"Address:" 1 1 "$address" 1 15 15 0 \
"Netmask:" 2 1 "$netmask" 2 15 15 0 \
"Gateway:" 3 1 "$gateway" 3 15 15 0 \
2>&1 1>&3 | {
read -r address;read -r netmask;read -r gateway
if [[ $? = 0 ]]; then
echo -e "[Network]" >>$filename
echo -e "Address=$address" >> $filename
echo -e "Gateway=$gateway" >> $filename
echo -e "DNS=8.8.8.8" >> $filename
fi
}
fi
}
#
# edit ip address
#
function ip_editor ()
{
exec 3>&1
dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1
\n " 12 38 0 \
"Address:" 1 1 "$address" 1 15 15 0 \
"Netmask:" 2 1 "$netmask" 2 15 15 0 \
"Gateway:" 3 1 "$gateway" 3 15 15 0 \
2>&1 1>&3 | {
read -r address;read -r netmask;read -r gateway
if [[ $? = 0 ]]; then
echo -e "# armbian-config created\nsource /etc/network/interfaces.d/*\n" >$3
echo -e "# Local loopback\nauto lo\niface lo inet loopback\n" >> $3
echo -e "# Interface $2\nauto $2\nallow-hotplug $2\niface $2 inet static\
\n\taddress $address\n\tnetmask $netmask\n\tgateway $gateway\n\tdns-nameservers 8.8.8.8" >> $3
fi
}
}
#
# edit hostapd parameters
#
function wlan_edit_basic ()
{
source /etc/hostapd.conf
exec 3>&1
dialog --title "AP configuration" --backtitle "$BACKTITLE" --form "\nWPA2 enabled, \
advanced config: edit /etc/hostapd.conf\n " 12 58 0 \
"SSID:" 1 1 "$ssid" 1 31 22 0 \
"Password:" 2 1 "$wpa_passphrase" 2 31 22 0 \
"Channel:" 3 1 "$channel" 3 31 3 0 \
2>&1 1>&3 | {
read -r ssid;read -r wpa_passphrase;read -r channel
if [[ $? = 0 ]]; then
sed -i "s/^ssid=.*/ssid=$ssid/" /etc/hostapd.conf
sed -i "s/^wpa_passphrase=.*/wpa_passphrase=$wpa_passphrase/" /etc/hostapd.conf
sed -i "s/^channel=.*/channel=$channel/" /etc/hostapd.conf
wpa_psk=$(wpa_passphrase $ssid $wpa_passphrase | grep '^[[:blank:]]*[^[:blank:]#;]' | grep psk | cut -d= -f2-)
sed -i "s/^wpa_psk=.*/wpa_psk=$wpa_psk/" /etc/hostapd.conf
fi
}
}
#
# edit hostapd parameters
#
function wlan_edit ()
{
# select default interfaces if there is more than one
select_default_interface
dialog --title " Configuration edit " --colors --backtitle "$BACKTITLE" --help-button --help-label "Cancel" --yes-label "Basic" \
--no-label "Advanced" --yesno "\n\Z1Basic:\Z0 Change SSID, password and channel\n\n\Z1Advanced:\Z0 Edit /etc/hostapd.conf file" 9 70
if [[ $? = 0 ]]; then
wlan_edit_basic
elif [[ $? = 1 ]]; then
dialog --backtitle "$BACKTITLE" --title " Edit hostapd configuration /etc/hostapd.conf" --no-collapse \
--ok-label "Save" --editbox /etc/hostapd.conf 30 0 2> /etc/hostapd.conf.out
[[ $? = 0 ]] && mv /etc/hostapd.conf.out /etc/hostapd.conf && service hostapd restart
fi
}
#
# naming exceptions for packages
#
function exceptions ()
{
TARGET_FAMILY=$LINUXFAMILY
UBOOT_BRANCH=$TARGET_BRANCH # uboot naming is different
if [[ $TARGET_BRANCH == "default" ]]; then TARGET_BRANCH=""; else TARGET_BRANCH="-"$TARGET_BRANCH; fi
# pine64
if [[ $TARGET_FAMILY == pine64 ]]; then
TARGET_FAMILY="sunxi64"
fi
# allwinner legacy kernels
if [[ $TARGET_FAMILY == sun*i ]]; then
TARGET_FAMILY="sunxi"
if [[ $UBOOT_BRANCH == "default" ]]; then
TARGET_FAMILY=$(cat /proc/cpuinfo | grep "Hardware" | sed 's/^.*Allwinner //' | awk '{print $1;}')
fi
fi
}
#
# here we add wifi exceptions
#
function wlan_exceptions ()
{
reboot_module=false
[[ -n "$(lsmod | grep -w dhd)" && $1 = "on" ]] && \
echo 'options dhd op_mode=2' >/etc/modprobe.d/ap6212.conf && rmmod dhd && modprobe dhd
[[ -n "$(lsmod | grep -w dhd)" && $1 = "off" ]] && \
rm /etc/modprobe.d/ap6212.conf && rmmod dhd && modprobe dhd
# Cubietruck
[[ -n "$(lsmod | grep -w ap6210)" && $1 = "on" ]] && \
echo 'options ap6210 op_mode=2' >/etc/modprobe.d/ap6210.conf && reboot_module=true
[[ -n "$(lsmod | grep -w ap6210)" && $1 = "off" ]] && \
rm /etc/modprobe.d/ap6210.conf && reboot_module=true
}
#
# here add shaddy wifi adaptors
#
function check_and_warn ()
{
local shaddy=false
# blacklist
[[ "$LINUXFAMILY" == "sun8i" && $BOARD == "orangepizero" ]] && shaddy=true
[[ -n "$(lsmod | grep mt7601u)" ]] && shaddy=true
[[ -n "$(lsmod | grep r8188eu)" ]] && shaddy=true
# blacklist
if [[ "$shaddy" == "true" ]]; then
dialog --title " Warning " --ok-label " Accept and proceed " --msgbox '\nOne of your wireless drivers are on a black list due to poor quality.\n\nAP mode might not be possible!' 9 73
fi
}
#
# search for wlan interfaces and provide a selection menu if there are more than one
#
function get_wlan_interface ()
{
IFS=$'\r\n'
GLOBIGNORE='*'
WLAN_INTERFACES=($(LC_ALL=C nmcli --wait 10 dev status | grep wifi | grep disconnected |awk '{print $1}'))
local LIST=()
for i in "${WLAN_INTERFACES[@]}"
do
LIST+=( "${i[0]//[[:blank:]]/}" "" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 1 ]; then
WIRELESS_ADAPTER=${WLAN_INTERFACES[0]}
else
exec 3>&1
WIRELESS_ADAPTER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
--title "Select interface" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
fi
}
#
# select interface if there is more than one
#
function select_default_interface ()
{
IFS=$'\r\n'
GLOBIGNORE='*'
local ADAPTER=($(ls /sys/class/net | grep -E -v 'lo|tun|bonding_masters|dummy0|bond0|sit0'))
local LIST=()
for i in "${ADAPTER[@]}"
do
local IPADDR=$(ip -4 addr show dev ${i[0]} | awk '/inet/ {print $2}' | cut -d'/' -f1)
[[ -n $IPADDR && $IPADDR != "172.24.1.1" ]] && LIST+=( "${i[0]//[[:blank:]]/}" "${IPADDR}" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 0 ]; then
DEFAULT_ADAPTER="lo"
elif [ "$LIST_LENGHT" -eq 1 ]; then
DEFAULT_ADAPTER=${ADAPTER[0]}
else
exec 3>&1
DEFAULT_ADAPTER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
--title "Select default interface" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
fi
}
#
# search and connect to Bluetooth devices
#
function connect_bt_interface ()
{
IFS=$'\r\n'
GLOBIGNORE='*'
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nDiscovering Bluetooth devices ... " 5 37
BT_INTERFACES=($(hcitool scan | sed '1d'))
local LIST=()
for i in "${BT_INTERFACES[@]}"
do
local a=$(echo ${i[0]//[[:blank:]]/} | sed -e 's/^\(.\{17\}\).*/\1/')
local b=${i[0]//$a/}
local b=$(echo $b | sed -e 's/^[ \t]*//')
LIST+=( "$a" "$b")
done
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 0 ]; then
BT_ADAPTER=${WLAN_INTERFACES[0]}
dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nNo nearby Bluetooth devices were found!" 7 43
else
exec 3>&1
BT_ADAPTER=$(dialog --backtitle "$BACKTITLE" --no-collapse --title "Select interface" \
--clear --menu "" $((6+${LIST_LENGHT})) 50 15 "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
if [[ $BT_ADAPTER != "" ]]; then
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nConnecting to $BT_ADAPTER " 5 35
BT_EXEC=$(
expect -c 'set prompt "#";set address '$BT_ADAPTER';spawn bluetoothctl;expect -re $prompt;send "disconnect $address\r";
sleep 1;send "remove $address\r";sleep 1;expect -re $prompt;send "scan on\r";sleep 8;send "scan off\r";
expect "Controller";send "trust $address\r";sleep 2;send "pair $address\r";sleep 2;send "connect $address\r";
send_user "\nShould be paired now.\r";sleep 2;send "quit\r";expect eof')
echo "$BT_EXEC" > /tmp/bt-connect-debug.log
if [[ $(echo "$BT_EXEC" | grep "Connection successful" ) != "" ]]; then
dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nYour device is ready to use!" 7 32
else
dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nError connecting. Try again!" 7 32
fi
fi
fi
}
\ No newline at end of file
......@@ -8,709 +8,6 @@
check_if_installed (){
#------------------------------------------------------------------------------------------------------------------------------------------
# check dpkg status of $1 -- currently only 'not installed at all' case catched
#
local DPKG_Status="$(dpkg -s "$1" 2>/dev/null | awk -F": " '/^Status/ {print $2}')"
if [[ "X${DPKG_Status}" = "X" || "${DPKG_Status}" = *deinstall* ]]; then
return 1
else
return 0
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# check hostapd configuration. Return error or empty if o.k.
#
check_hostapd ()
{
systemctl daemon-reload
hostapd_error=""
[[ -n $1 && -n $2 ]] && dialog --title " $1 " --backtitle "$BACKTITLE" --no-collapse --colors --infobox "$2" 5 $((${#2}-3))
service hostapd stop
rm -f /var/run/hostapd/*
sleep 1
service hostapd start
sleep 6
if [[ "$(hostapd_cli ping 2> /dev/null| grep PONG)" == "PONG" ]]; then
hostapd_error=""
else
hostapd_error=$(hostapd /etc/hostapd.conf)
sleep 6
[[ -n $(echo $hostapd_error | grep "channel") ]] && hostapd_error="channel_restriction"
[[ -n $(echo $hostapd_error | grep "does not support" | grep "hw_mode") ]] && hostapd_error="hw_mode"
[[ -n $(echo $hostapd_error | grep "not found from the channel list" | grep "802.11g") ]] && hostapd_error="wrong_channel"
[[ -n $(echo $hostapd_error | grep "VHT") ]] && hostapd_error="unsupported_vht"
[[ -n $(echo $hostapd_error | grep " HT capability") ]] && hostapd_error="unsupported_ht"
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# check all possible wireless modes
#
function check_advanced_modes ()
{
sed '/### IEEE 802.11n/,/^### IEEE 802.11n/ s/^# *//' -i /etc/hostapd.conf
check_hostapd "Probing" "\n802.11n \Z1(150-300Mbps)\Z0"
# check HT capability
check_ht_capab
if [[ -z "$hostapd_error" ]]; then
sed '/### IEEE 802.11a\>/,/^### IEEE 802.11a\>/ s/^# *//' -i /etc/hostapd.conf
sed -i "s/^channel=.*/channel=40/" /etc/hostapd.conf
check_hostapd "Probing" "\n802.11a \Z1(5Ghz)\Z0"
if [[ "$hostapd_error" == "channel_restriction" ]]; then check_channels; fi
if [[ "$hostapd_error" == "channel_restriction" ]]; then
# revering configuration
sed -i "s/^channel=.*/channel=5/" /etc/hostapd.conf
sed '/## IEEE 802.11a\>/,/^## IEEE 802.11a\>/ s/.*/#&/' -i /etc/hostapd.conf
check_hostapd "Reverting" "\nWireless \Z1802.11a (5Ghz)\Z0 is not supported"
else
sed '/### IEEE 802.11ac\>/,/^### IEEE 802.11ac\>/ s/^# *//' -i /etc/hostapd.conf
# check VHT capability
check_vht_capab
if [[ "$hostapd_error" == "unsupported_vht" || "$hostapd_error" == "channel_restriction" ]]; then
# revering configuration
sed '/## IEEE 802.11ac\>/,/^## IEEE 802.11ac\>/ s/.*/#&/' -i /etc/hostapd.conf
check_hostapd "Reverting" "\nWireless 802.11ac \Z1(433Mbps x n @ 5Ghz)\Z0 is not supported"
if [[ "$hostapd_error" == "channel_restriction" ]]; then check_channels; fi
fi
fi
else
sed '/## IEEE 802.11n/,/^## IEEE 802.11n/ s/.*/#&/' -i /etc/hostapd.conf
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# create interface configuration section
#
function create_if_config() {
address=$(ip -4 addr show dev $1 | awk '/inet/ {print $2}' | cut -d'/' -f1)
netmask=$(ip -4 addr show dev $1 | awk '/inet/ {print $2}' | cut -d'/' -f2)
gateway=$(route -n | grep 'UG[ \t]' | awk '{print $2}' | sed -n '1p')
echo -e "# armbian-config created"
echo -e "source /etc/network/interfaces.d/*\n"
if [[ "$3" == "fixed" ]]; then
echo -e "# Local loopback\nauto lo\niface lo init loopback\n"
echo -e "# Interface $2\nauto $2\nallow-hotplug $2"
echo -e "iface $2 inet static\n\taddress $address\n\tnetmask $netmask\n\tgateway $gateway\n\tdns-nameservers 8.8.8.8"
fi
} #
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# reaload network related services. some are "just in case"
#
function reload-nety() {
systemctl daemon-reload
if [[ "$1" == "reload" ]]; then WHATODO="Reloading services"; else WHATODO="Stopping services"; fi
(service network-manager stop; echo 10; sleep 1; service hostapd stop; echo 20; sleep 1; service dnsmasq stop; echo 30; sleep 1;\
[[ "$1" == "reload" ]] && service dnsmasq start && echo 60 && sleep 1 && service hostapd start && echo 80 && sleep 1;\
service network-manager start; echo 90; sleep 5;) | dialog --backtitle "$BACKTITLE" --title " $WHATODO " --gauge "" 6 70 0
systemctl restart systemd-resolved.service
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# Check if something is running on port $1 and display info
#
check_port ()
{
[[ -n $(netstat -lnt | awk '$6 == "LISTEN" && $4 ~ ".'$1'"') ]] && dialog --backtitle "$BACKTITLE" --title "Checking service" \
--msgbox "\nIt looks good.\n\nThere is $2 service on port $1" 9 52
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# show disclaimer
#
function beta_disclaimer ()
{
exec 3>&1
ACKNOWLEDGEMENT=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse --title " Warning " \
--clear \--radiolist "\n$1.\n \n" 12 56 7 "Yes, I understand" "" off 2>&1 1>&3)
exec 3>&-
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# show box
#
function show_box ()
{
dialog --colors --backtitle "$BACKTITLE" --no-collapse --title " $1 " --clear --msgbox "\n$2\n \n" $3 56
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# check wifi high throughput
#
function check_ht_capab ()
{
declare -a arr=("[HT40+][LDPC][SHORT-GI-20][SHORT-GI-40][TX-STBC][RX-STBC1][DSSS_CCK-40][SMPS-STATIC]" \
"[HT40-][SHORT-GI-40][SHORT-GI-40][DSSS_CCK-40]" "[SHORT-GI-20][SHORT-GI-40][HT40+]" "[DSSS_CK-40][HT20+]" "")
local j=0
for i in "${arr[@]}"
do
j=$((j+(100/${#arr[@]})))
echo $j | dialog --title " Probing HT " --colors --gauge "\nSeeking for optimal \Z1high throughput\Z0 settings." 8 50 0
sed -i "s/^ht_capab=.*/ht_capab=$i/" /etc/hostapd.conf
check_hostapd
if [[ "$hostapd_error" == "channel_restriction" ]]; then check_channels; fi
if [[ "$hostapd_error" == "" ]]; then break; fi
done
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# check wifi high throughput
#
function check_vht_capab ()
{
declare -a arr=("[MAX-MPDU-11454][SHORT-GI-80][TX-STBC-2BY1][RX-STBC-1][MAX-A-MPDU-LEN-EXP3]" "[MAX-MPDU-11454][SHORT-GI-80][RX-STBC-1][MAX-A-MPDU-LEN-EXP3]" "")
local j=0
for i in "${arr[@]}"
do
j=$((j+(100/${#arr[@]})))
echo $j | dialog --title " Probing VHT " --colors --gauge "\nSeeking for optimal \Z1very high throughput\Z0 settings." 8 54 0
sed -i "s/^vht_capab=.*/vht_capab=$i/" /etc/hostapd.conf
check_hostapd
if [[ "$hostapd_error" == "channel_restriction" ]]; then check_channels; fi
if [[ "$hostapd_error" == "" ]]; then break; fi
done
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# check 5Ghz channels
#
function check_channels ()
{
declare -a arr=("36" "40")
for i in "${arr[@]}"
do
sed -i "s/^channel=.*/channel=$i/" /etc/hostapd.conf
check_hostapd "Probing" "\nChannel:\Z1 ${i}\Z0"
if [[ "$hostapd_error" != "channel_restriction" ]]; then break; fi
done
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# show description for MOTD files
#
function description
{
case $1 in
*header*)
echo "Big board logo and kernel info"
;;
*sysinfo*)
echo "Sysinfo - load, ip, memory, uptime, ..."
;;
*tips*)
echo "Shows tip of the day"
;;
*updates*)
echo "Display number of avaliable updates"
;;
*armbian-config*)
echo "Show command for system configuration"
;;
*autoreboot-warn*)
echo "Show warning when reboot is needed"
;;
*uk.armbian.com*)
echo "United Kingdom"
;;
*.armbian.com*)
echo "Estonia"
;;
*)
echo ""
;;
esac
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit ip address witing network manager
#
function nm_ip_editor ()
{
exec 3>&1
dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1
\n " 12 38 0 \
"Address:" 1 1 "$address" 1 15 15 0 \
"Netmask:" 2 1 "$netmask" 2 15 15 0 \
"Gateway:" 3 1 "$gateway" 3 15 15 0 \
2>&1 1>&3 | {
read -r address;read -r netmask;read -r gateway
if [[ $? = 0 ]]; then
localuuid=$(LC_ALL=C nmcli -f UUID,DEVICE connection show | grep $1 | awk '{print $1}')
nmcli con mod $localuuid ipv4.method manual ipv4.addresses "$address/$netmask" >/dev/null 2>&1
nmcli con mod $localuuid ipv4.method manual ipv4.gateway "$gateway" >/dev/null 2>&1
nmcli con mod $localuuid ipv4.dns "8.8.8.8,$gateway" >/dev/null 2>&1
nmcli con down $localuuid >/dev/null 2>&1
sleep 2
nmcli con up $localuuid >/dev/null 2>&1
fi
}
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit ip address
#
function systemd_ip_editor ()
{
local filename="/etc/systemd/network/10-$1.network"
if [[ -f $filename ]]; then
sed -i '/Network/,$d' $filename
exec 3>&1
dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1
\n " 12 38 0 \
"Address:" 1 1 "$address" 1 15 15 0 \
"Netmask:" 2 1 "$netmask" 2 15 15 0 \
"Gateway:" 3 1 "$gateway" 3 15 15 0 \
2>&1 1>&3 | {
read -r address;read -r netmask;read -r gateway
if [[ $? = 0 ]]; then
echo -e "[Network]" >>$filename
echo -e "Address=$address" >> $filename
echo -e "Gateway=$gateway" >> $filename
echo -e "DNS=8.8.8.8" >> $filename
fi
}
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit ip address
#
function ip_editor ()
{
exec 3>&1
dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1
\n " 12 38 0 \
"Address:" 1 1 "$address" 1 15 15 0 \
"Netmask:" 2 1 "$netmask" 2 15 15 0 \
"Gateway:" 3 1 "$gateway" 3 15 15 0 \
2>&1 1>&3 | {
read -r address;read -r netmask;read -r gateway
if [[ $? = 0 ]]; then
echo -e "# armbian-config created\nsource /etc/network/interfaces.d/*\n" >$3
echo -e "# Local loopback\nauto lo\niface lo inet loopback\n" >> $3
echo -e "# Interface $2\nauto $2\nallow-hotplug $2\niface $2 inet static\
\n\taddress $address\n\tnetmask $netmask\n\tgateway $gateway\n\tdns-nameservers 8.8.8.8" >> $3
fi
}
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit hostapd parameters
#
function wlan_edit_basic ()
{
source /etc/hostapd.conf
exec 3>&1
dialog --title "AP configuration" --backtitle "$BACKTITLE" --form "\nWPA2 enabled, \
advanced config: edit /etc/hostapd.conf\n " 12 58 0 \
"SSID:" 1 1 "$ssid" 1 31 22 0 \
"Password:" 2 1 "$wpa_passphrase" 2 31 22 0 \
"Channel:" 3 1 "$channel" 3 31 3 0 \
2>&1 1>&3 | {
read -r ssid;read -r wpa_passphrase;read -r channel
if [[ $? = 0 ]]; then
sed -i "s/^ssid=.*/ssid=$ssid/" /etc/hostapd.conf
sed -i "s/^wpa_passphrase=.*/wpa_passphrase=$wpa_passphrase/" /etc/hostapd.conf
sed -i "s/^channel=.*/channel=$channel/" /etc/hostapd.conf
wpa_psk=$(wpa_passphrase $ssid $wpa_passphrase | grep '^[[:blank:]]*[^[:blank:]#;]' | grep psk | cut -d= -f2-)
sed -i "s/^wpa_psk=.*/wpa_psk=$wpa_psk/" /etc/hostapd.conf
fi
}
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit hostapd parameters
#
function wlan_edit ()
{
# select default interfaces if there is more than one
select_default_interface
dialog --title " Configuration edit " --colors --backtitle "$BACKTITLE" --help-button --help-label "Cancel" --yes-label "Basic" \
--no-label "Advanced" --yesno "\n\Z1Basic:\Z0 Change SSID, password and channel\n\n\Z1Advanced:\Z0 Edit /etc/hostapd.conf file" 9 70
if [[ $? = 0 ]]; then
wlan_edit_basic
elif [[ $? = 1 ]]; then
dialog --backtitle "$BACKTITLE" --title " Edit hostapd configuration /etc/hostapd.conf" --no-collapse \
--ok-label "Save" --editbox /etc/hostapd.conf 30 0 2> /etc/hostapd.conf.out
[[ $? = 0 ]] && mv /etc/hostapd.conf.out /etc/hostapd.conf && service hostapd restart
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# naming exceptions for packages
#
function exceptions ()
{
TARGET_FAMILY=$LINUXFAMILY
UBOOT_BRANCH=$TARGET_BRANCH # uboot naming is different
if [[ $TARGET_BRANCH == "default" ]]; then TARGET_BRANCH=""; else TARGET_BRANCH="-"$TARGET_BRANCH; fi
# pine64
if [[ $TARGET_FAMILY == pine64 ]]; then
TARGET_FAMILY="sunxi64"
fi
# allwinner legacy kernels
if [[ $TARGET_FAMILY == sun*i ]]; then
TARGET_FAMILY="sunxi"
if [[ $UBOOT_BRANCH == "default" ]]; then
TARGET_FAMILY=$(cat /proc/cpuinfo | grep "Hardware" | sed 's/^.*Allwinner //' | awk '{print $1;}')
fi
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# here we add wifi exceptions
#
function wlan_exceptions ()
{
reboot_module=false
[[ -n "$(lsmod | grep -w dhd)" && $1 = "on" ]] && \
echo 'options dhd op_mode=2' >/etc/modprobe.d/ap6212.conf && rmmod dhd && modprobe dhd
[[ -n "$(lsmod | grep -w dhd)" && $1 = "off" ]] && \
rm /etc/modprobe.d/ap6212.conf && rmmod dhd && modprobe dhd
# Cubietruck
[[ -n "$(lsmod | grep -w ap6210)" && $1 = "on" ]] && \
echo 'options ap6210 op_mode=2' >/etc/modprobe.d/ap6210.conf && reboot_module=true
[[ -n "$(lsmod | grep -w ap6210)" && $1 = "off" ]] && \
rm /etc/modprobe.d/ap6210.conf && reboot_module=true
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# here add shaddy wifi adaptors
#
function check_and_warn ()
{
local shaddy=false
# blacklist
[[ "$LINUXFAMILY" == "sun8i" && $BOARD == "orangepizero" ]] && shaddy=true
[[ -n "$(lsmod | grep mt7601u)" ]] && shaddy=true
[[ -n "$(lsmod | grep r8188eu)" ]] && shaddy=true
# blacklist
if [[ "$shaddy" == "true" ]]; then
dialog --title " Warning " --ok-label " Accept and proceed " --msgbox '\nOne of your wireless drivers are on a black list due to poor quality.\n\nAP mode might not be possible!' 9 73
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# check if board has alternative kernels
#
function aval_kernel ()
{
IFS=$'\r\n'
GLOBIGNORE='*'
AVAL_KERNEL=($(apt-cache search --names-only '^linux-'$(lsb_release -cs)'-root.*.'$BOARD'*' \
| grep -w "$BOARD " | sed 's/.*(\(.*\))/\1/' | awk '{print $1}' | grep -v "$BRANCH" ))
local LIST=()
for i in "${AVAL_KERNEL[@]}"
do
LIST+=( "${i[0]//[[:blank:]]/}" "" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 1 ]; then
TARGET_BRANCH=${AVAL_KERNEL[0]}
else
exec 3>&1
TARGET_BRANCH=$(dialog --cancel-label "Cancel" --backtitle "$BACKTITLE" --no-collapse \
--title "Upgrade from $BRANCH to:" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
exitstatus=$?;
exec 3>&-
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# check if board has alternative kernels
#
function aval_cubox ()
{
LIST=("imx6dl-hummingboard.dtb" "HB Solo/DualLite" "imx6dl-hummingboard-emmc-som-v15.dtb" "HB Solo/DualLite v1.5 with eMMC" "imx6dl-hummingboard-som-v15.dtb" "HB Solo/DualLite v1.5" \
"imx6dl-hummingboard2.dtb" "HB2 Solo/DualLite" "imx6dl-hummingboard2-emmc-som-v15.dtb" "HB2 Solo/DualLite v1.5 with eMMC" "imx6dl-hummingboard2-som-v15.dtb" "HB2 Solo/DualLite v1.5" \
"imx6q-hummingboard.dtb" "HB Dual/Quad" "imx6q-hummingboard-emmc-som-v15.dtb" "HB Dual/Quad v1.5 with eMMC" "imx6q-hummingboard-som-v15.dtb" "HB Dual/Quad v1.5" \
"imx6q-hummingboard2.dtb" "HB2 Dual/Quad" "imx6q-hummingboard2-emmc-som-v15.dtb" "HB2 Dual/Quad v1.5 with eMMC" "imx6q-hummingboard2-som-v15.dtb" "HB2 Dual/Quad v1.5" \
"imx6dl-cubox-i.dtb" "Cubox-i Solo/DualLite" "imx6dl-cubox-i-emmc-som-v15.dtb" "Cubox-i Solo/DualLite v1.5 with eMMC" "imx6dl-cubox-i-som-v15.dtb" "Cubox-i Solo/DualLite v1.5" \
"imx6q-cubox-i.dtb" "Cubox-i Dual/Quad" "imx6q-cubox-i-emmc-som-v15.dtb" "Cubox-i Dual/Quad v1.5 with eMMC" "imx6q-cubox-i-som-v15.dtb" "Cubox-i Dual/Quad v1.5")
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 1 ]; then
TARGET_BOARD=${AVAL_KERNEL[0]}
else
exec 3>&1
TARGET_BOARD=$(dialog --cancel-label "Cancel" --backtitle "$BACKTITLE" --no-collapse \
--title "Select board configuration" --clear --menu "" $((6+${LIST_LENGHT})) 80 25 "${LIST[@]}" 2>&1 1>&3)
exitstatus=$?;
exec 3>&-
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# select video modes for a10 and a20
#
function get_a20modes ()
{
IFS=$'\r'
GLOBIGNORE='*'
SCREEN_RESOLUTION=("1920x1080p60" "1280x720p60" "1920x1080p50" "1280x1024p60" "1024x768p60" "800x600p60" "640x480p60" "1360x768p60" "1440x900p60" "1680x1050p60")
local LIST=()
for i in "${SCREEN_RESOLUTION[@]}"
do
LIST+=( "${i[0]//[[:blank:]]/}" "" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
#echo $LIST_LENGHT
#exit
if [ "$LIST_LENGHT" -eq 1 ]; then
SCREEN_RESOLUTION=${SCREEN_RESOLUTION[0]}
else
exec 3>&1
SCREEN_RESOLUTION=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
--title "Select video mode" --clear --menu "" $((6+${LIST_LENGHT})) 25 $((1+${LIST_LENGHT})) "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# select video modes for h3
#
function get_h3modes ()
{
IFS=$'\r\n'
GLOBIGNORE='*'
SCREEN_RESOLUTION=($(h3disp -i))
local LIST=()
for i in "${SCREEN_RESOLUTION[@]}"
do
LIST+=( "${i[0]//[[:blank:]]/}" "" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
#echo $LIST_LENGHT
#exit
if [ "$LIST_LENGHT" -eq 1 ]; then
SCREEN_RESOLUTION=${SCREEN_RESOLUTION[0]}
else
exec 3>&1
SCREEN_RESOLUTION=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
--title "Select video mode" --clear --menu "" $((6+${LIST_LENGHT})) 25 $((1+${LIST_LENGHT})) "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
fi
}
function add_choose_user ()
#-----------------------------------------------------------------------------------------------------------------------------------------#
# create or pick unprivileged user
#
{
IFS=$'\r\n'
GLOBIGNORE='*'
local USERS=($(awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd))
local LIST=()
for i in "${USERS[@]}"
do
LIST+=( "${i[0]//[[:blank:]]/}" "" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 0 ]; then
dialog --backtitle "$BACKTITLE" --title " Notice " --msgbox "\nWe didn't find any unprivileged user with sudo rights which is required to run this service.\
\n\nPress enter to create one!" 10 48
read -t 0 temp
echo -e "\nPlease provide a username (eg. your forename) or leave blank for canceling user creation: \c"
read -e username
CHOSEN_USER="$(echo "$username" | tr '[:upper:]' '[:lower:]' | tr -d -c '[:alnum:]')"
[ -z "$CHOSEN_USER" ] && return
echo "Trying to add user $CHOSEN_USER"
adduser $CHOSEN_USER || return
elif [ "$LIST_LENGHT" -eq 1 ]; then
CHOSEN_USER=${USERS[0]}
else
exec 3>&1
CHOSEN_USER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
--title "Select unprivileged user" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# configure armbian desktop
#
function configure_desktop ()
{
add_choose_user
if [ -n "$CHOSEN_USER" ]; then
# install desktop and nodm
debconf-apt-progress -- apt-get update
debconf-apt-progress -- apt-get -y install armbian-${DISTROID}-desktop
DEBIAN_FRONTEND=noninteractive debconf-apt-progress -- apt-get -y -qq install nodm
# add user to groups
for additionalgroup in sudo netdev audio video dialout plugdev bluetooth systemd-journal ssh; do
usermod -aG ${additionalgroup} ${CHOSEN_USER} 2>/dev/null
done
# fix for gksu in Xenial
touch /home/${CHOSEN_USER}/.Xauthority
cp -R /etc/skel/. /home/${CHOSEN_USER}
# set up profile sync daemon on desktop systems
which psd >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "${CHOSEN_USER} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> /etc/sudoers
touch /home/${CHOSEN_USER}/.activate_psd
fi
sed -i "s/NODM_USER=\(.*\)/NODM_USER=${CHOSEN_USER}/" /etc/default/nodm
sed -i "s/NODM_ENABLED=\(.*\)/NODM_ENABLED=true/g" /etc/default/nodm
chown -R ${CHOSEN_USER}:${CHOSEN_USER} /home/${CHOSEN_USER}/.
sleep 3
service nodm stop
sleep 1
service nodm start
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# search for wlan interfaces and provide a selection menu if there are more than one
#
function get_wlan_interface ()
{
IFS=$'\r\n'
GLOBIGNORE='*'
WLAN_INTERFACES=($(LC_ALL=C nmcli --wait 10 dev status | grep wifi | grep disconnected |awk '{print $1}'))
local LIST=()
for i in "${WLAN_INTERFACES[@]}"
do
LIST+=( "${i[0]//[[:blank:]]/}" "" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 1 ]; then
WIRELESS_ADAPTER=${WLAN_INTERFACES[0]}
else
exec 3>&1
WIRELESS_ADAPTER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
--title "Select interface" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# select interface if there is more than one
#
function select_default_interface ()
{
IFS=$'\r\n'
GLOBIGNORE='*'
local ADAPTER=($(ls /sys/class/net | grep -E -v 'lo|tun|bonding_masters|dummy0|bond0|sit0'))
local LIST=()
for i in "${ADAPTER[@]}"
do
local IPADDR=$(ip -4 addr show dev ${i[0]} | awk '/inet/ {print $2}' | cut -d'/' -f1)
[[ -n $IPADDR && $IPADDR != "172.24.1.1" ]] && LIST+=( "${i[0]//[[:blank:]]/}" "${IPADDR}" )
done
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 0 ]; then
DEFAULT_ADAPTER="lo"
elif [ "$LIST_LENGHT" -eq 1 ]; then
DEFAULT_ADAPTER=${ADAPTER[0]}
else
exec 3>&1
DEFAULT_ADAPTER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
--title "Select default interface" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# search for BT devices and connect
#
function connect_bt_interface ()
{
IFS=$'\r\n'
GLOBIGNORE='*'
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nDiscovering Bluetooth devices ... " 5 37
BT_INTERFACES=($(hcitool scan | sed '1d'))
local LIST=()
for i in "${BT_INTERFACES[@]}"
do
local a=$(echo ${i[0]//[[:blank:]]/} | sed -e 's/^\(.\{17\}\).*/\1/')
local b=${i[0]//$a/}
local b=$(echo $b | sed -e 's/^[ \t]*//')
LIST+=( "$a" "$b")
done
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 0 ]; then
BT_ADAPTER=${WLAN_INTERFACES[0]}
dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nNo nearby Bluetooth devices were found!" 7 43
else
exec 3>&1
BT_ADAPTER=$(dialog --backtitle "$BACKTITLE" --no-collapse --title "Select interface" \
--clear --menu "" $((6+${LIST_LENGHT})) 50 15 "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
if [[ $BT_ADAPTER != "" ]]; then
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nConnecting to $BT_ADAPTER " 5 35
BT_EXEC=$(
expect -c 'set prompt "#";set address '$BT_ADAPTER';spawn bluetoothctl;expect -re $prompt;send "disconnect $address\r";
sleep 1;send "remove $address\r";sleep 1;expect -re $prompt;send "scan on\r";sleep 8;send "scan off\r";
expect "Controller";send "trust $address\r";sleep 2;send "pair $address\r";sleep 2;send "connect $address\r";
send_user "\nShould be paired now.\r";sleep 2;send "quit\r";expect eof')
echo "$BT_EXEC" > /tmp/bt-connect-debug.log
if [[ $(echo "$BT_EXEC" | grep "Connection successful" ) != "" ]]; then
dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nYour device is ready to use!" 7 32
else
dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nError connecting. Try again!" 7 32
fi
fi
fi
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# system
#
......
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