742 lines
19 KiB
Bash
Executable File
742 lines
19 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Altered from raspi-config tool below
|
|
# https://github.com/RPi-Distro/birdnet-pi-config
|
|
#
|
|
# See LICENSE file for copyright and license details
|
|
# Copyright (c) 2012 Alex Bradbury <asb@asbradbury.org>
|
|
#set -x
|
|
birdnetpi_dir=/home/pi/BirdNET-Pi
|
|
branch=newinstaller
|
|
INTERACTIVE=True
|
|
ASK_TO_REBOOT=0
|
|
BLACKLIST=/etc/modprobe.d/raspi-blacklist.conf
|
|
CONFIG=/boot/config.txt
|
|
|
|
USER=${SUDO_USER:-$(who -m | awk '{ print $1 }')}
|
|
|
|
is_pi () {
|
|
ARCH=$(dpkg --print-architecture)
|
|
if [ "$ARCH" = "armhf" ] || [ "$ARCH" = "arm64" ] ; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
if is_pi ; then
|
|
CMDLINE=/boot/cmdline.txt
|
|
else
|
|
CMDLINE=/proc/cmdline
|
|
fi
|
|
|
|
is_pione() {
|
|
if grep -q "^Revision\s*:\s*00[0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo; then
|
|
return 0
|
|
elif grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[0-36][0-9a-fA-F]$" /proc/cpuinfo ; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
is_pitwo() {
|
|
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]04[0-9a-fA-F]$" /proc/cpuinfo
|
|
return $?
|
|
}
|
|
|
|
is_pizero() {
|
|
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[9cC][0-9a-fA-F]$" /proc/cpuinfo
|
|
return $?
|
|
}
|
|
|
|
is_pifour() {
|
|
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]3[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo
|
|
return $?
|
|
}
|
|
|
|
get_pi_type() {
|
|
if is_pione; then
|
|
echo 1
|
|
elif is_pitwo; then
|
|
echo 2
|
|
else
|
|
echo 0
|
|
fi
|
|
}
|
|
|
|
is_live() {
|
|
grep -q "boot=live" $CMDLINE
|
|
return $?
|
|
}
|
|
|
|
is_ssh() {
|
|
if pstree -p | egrep --quiet --extended-regexp ".*sshd.*\($$\)"; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
is_fkms() {
|
|
if grep -s -q okay /proc/device-tree/soc/v3d@7ec00000/status \
|
|
/proc/device-tree/soc/firmwarekms@7e600000/status \
|
|
/proc/device-tree/v3dbus/v3d@7ec04000/status; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
is_pulseaudio() {
|
|
PS=$(ps ax)
|
|
echo "$PS" | grep -q pulseaudio
|
|
return $?
|
|
}
|
|
|
|
has_analog() {
|
|
if [ $(get_leds) -eq -1 ] ; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
is_installed() {
|
|
if [ "$(dpkg -l "$1" 2> /dev/null | tail -n 1 | cut -d ' ' -f 1)" != "ii" ]; then
|
|
return 1
|
|
else
|
|
return 0
|
|
fi
|
|
}
|
|
|
|
deb_ver () {
|
|
ver=`cat /etc/debian_version | cut -d . -f 1`
|
|
echo $ver
|
|
}
|
|
|
|
calc_wt_size() {
|
|
# NOTE: it's tempting to redirect stderr to /dev/null, so supress error
|
|
# output from tput. However in this case, tput detects neither stdout or
|
|
# stderr is a tty and so only gives default 80, 24 values
|
|
WT_HEIGHT=18
|
|
WT_WIDTH=$(tput cols)
|
|
|
|
if [ -z "$WT_WIDTH" ] || [ "$WT_WIDTH" -lt 60 ]; then
|
|
WT_WIDTH=80
|
|
fi
|
|
if [ "$WT_WIDTH" -gt 178 ]; then
|
|
WT_WIDTH=120
|
|
fi
|
|
WT_MENU_HEIGHT=$(($WT_HEIGHT-7))
|
|
}
|
|
|
|
set_config_var() {
|
|
lua - "$1" "$2" "$3" <<EOF > "$3.bak"
|
|
local key=assert(arg[1])
|
|
local value=assert(arg[2])
|
|
local fn=assert(arg[3])
|
|
local file=assert(io.open(fn))
|
|
local made_change=false
|
|
for line in file:lines() do
|
|
if line:match("^#?%s*"..key.."=.*$") then
|
|
line=key.."="..value
|
|
made_change=true
|
|
end
|
|
print(line)
|
|
end
|
|
|
|
if not made_change then
|
|
print(key.."="..value)
|
|
end
|
|
EOF
|
|
mv "$3.bak" "$3"
|
|
}
|
|
|
|
clear_config_var() {
|
|
lua - "$1" "$2" <<EOF > "$2.bak"
|
|
local key=assert(arg[1])
|
|
local fn=assert(arg[2])
|
|
local file=assert(io.open(fn))
|
|
for line in file:lines() do
|
|
if line:match("^%s*"..key.."=.*$") then
|
|
line="#"..line
|
|
end
|
|
print(line)
|
|
end
|
|
EOF
|
|
mv "$2.bak" "$2"
|
|
}
|
|
|
|
get_config_var() {
|
|
lua - "$1" "$2" <<EOF
|
|
local key=assert(arg[1])
|
|
local fn=assert(arg[2])
|
|
local file=assert(io.open(fn))
|
|
local found=false
|
|
for line in file:lines() do
|
|
local val = line:match("^%s*"..key.."=(.*)$")
|
|
if (val ~= nil) then
|
|
print(val)
|
|
found=true
|
|
break
|
|
end
|
|
end
|
|
if not found then
|
|
print(0)
|
|
end
|
|
EOF
|
|
}
|
|
|
|
is_number() {
|
|
case $1 in
|
|
''|*[!0-9]*) return 0 ;;
|
|
*) return 1 ;;
|
|
esac
|
|
}
|
|
|
|
do_change_pass() {
|
|
whiptail --msgbox "You will now be asked to enter a new password for the $USER user" 20 60 1
|
|
passwd $USER &&
|
|
whiptail --msgbox "Password changed successfully" 20 60 1
|
|
}
|
|
|
|
do_configure_keyboard() {
|
|
printf "Reloading keymap. This may take a short while\n"
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
dpkg-reconfigure keyboard-configuration
|
|
else
|
|
local KEYMAP="$1"
|
|
sed -i /etc/default/keyboard -e "s/^XKBLAYOUT.*/XKBLAYOUT=\"$KEYMAP\"/"
|
|
dpkg-reconfigure -f noninteractive keyboard-configuration
|
|
fi
|
|
invoke-rc.d keyboard-setup start
|
|
setsid sh -c 'exec setupcon -k --force <> /dev/tty1 >&0 2>&1'
|
|
udevadm trigger --subsystem-match=input --action=change
|
|
return 0
|
|
}
|
|
|
|
do_change_locale() {
|
|
dpkg-reconfigure locales
|
|
if [ $? -eq 0 ];then
|
|
return 0
|
|
ASK_TO_REBOOT=2
|
|
fi
|
|
}
|
|
|
|
do_change_timezone() {
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
dpkg-reconfigure tzdata
|
|
else
|
|
local TIMEZONE="$1"
|
|
if [ ! -f "/usr/share/zoneinfo/$TIMEZONE" ]; then
|
|
return 1;
|
|
fi
|
|
rm /etc/localtime
|
|
echo "$TIMEZONE" > /etc/timezone
|
|
dpkg-reconfigure -f noninteractive tzdata
|
|
fi
|
|
}
|
|
|
|
get_wifi_country() {
|
|
CODE=${1:-0}
|
|
IFACE="$(list_wlan_interfaces | head -n 1)"
|
|
if [ -z "$IFACE" ]; then
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
whiptail --msgbox "No wireless interface found" 20 60
|
|
fi
|
|
return 1
|
|
fi
|
|
if ! wpa_cli -i "$IFACE" status > /dev/null 2>&1; then
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
whiptail --msgbox "Could not communicate with wpa_supplicant" 20 60
|
|
fi
|
|
return 1
|
|
fi
|
|
wpa_cli -i "$IFACE" save_config > /dev/null 2>&1
|
|
COUNTRY="$(wpa_cli -i "$IFACE" get country)"
|
|
if [ "$COUNTRY" = "FAIL" ]; then
|
|
return 1
|
|
fi
|
|
if [ $CODE = 0 ]; then
|
|
echo "$COUNTRY"
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
do_wifi_country() {
|
|
IFACE="$(list_wlan_interfaces | head -n 1)"
|
|
if [ -z "$IFACE" ]; then
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
whiptail --msgbox "No wireless interface found" 20 60
|
|
fi
|
|
return 1
|
|
fi
|
|
|
|
if ! wpa_cli -i "$IFACE" status > /dev/null 2>&1; then
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
whiptail --msgbox "Could not communicate with wpa_supplicant" 20 60
|
|
fi
|
|
return 1
|
|
fi
|
|
|
|
oIFS="$IFS"
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
value=$(cat /usr/share/zoneinfo/iso3166.tab | tail -n +26 | tr '\t' '/' | tr '\n' '/')
|
|
IFS="/"
|
|
COUNTRY=$(whiptail --menu "Select the country in which the Pi is to be used" 20 60 10 ${value} 3>&1 1>&2 2>&3)
|
|
else
|
|
COUNTRY=$1
|
|
true
|
|
fi
|
|
if [ $? -eq 0 ];then
|
|
wpa_cli -i "$IFACE" set country "$COUNTRY"
|
|
wpa_cli -i "$IFACE" save_config > /dev/null 2>&1
|
|
if iw reg set "$COUNTRY" 2> /dev/null; then
|
|
ASK_TO_REBOOT=1
|
|
fi
|
|
if hash rfkill 2> /dev/null; then
|
|
rfkill unblock wifi
|
|
if is_pi ; then
|
|
for filename in /var/lib/systemd/rfkill/*:wlan ; do
|
|
echo 0 > $filename
|
|
done
|
|
fi
|
|
fi
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
whiptail --msgbox "Wireless LAN country set to $COUNTRY" 20 60 1
|
|
fi
|
|
fi
|
|
IFS=$oIFS
|
|
}
|
|
|
|
get_ssh() {
|
|
if service ssh status | grep -q inactive; then
|
|
echo 1
|
|
else
|
|
echo 0
|
|
fi
|
|
}
|
|
|
|
do_ssh() {
|
|
if [ -e /var/log/regen_ssh_keys.log ] && ! grep -q "^finished" /var/log/regen_ssh_keys.log; then
|
|
whiptail --msgbox "Initial ssh key generation still running. Please wait and try again." 20 60 2
|
|
return 1
|
|
fi
|
|
DEFAULT=--defaultno
|
|
if [ $(get_ssh) -eq 0 ]; then
|
|
DEFAULT=
|
|
fi
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
whiptail --yesno \
|
|
"Would you like the SSH server to be enabled?\n\nCaution: Default and weak passwords are a security risk when SSH is enabled!" \
|
|
$DEFAULT 20 60 2
|
|
RET=$?
|
|
else
|
|
RET=$1
|
|
fi
|
|
if [ $RET -eq 0 ]; then
|
|
ssh-keygen -A &&
|
|
update-rc.d ssh enable &&
|
|
invoke-rc.d ssh start &&
|
|
STATUS=enabled
|
|
elif [ $RET -eq 1 ]; then
|
|
update-rc.d ssh disable &&
|
|
invoke-rc.d ssh stop &&
|
|
STATUS=disabled
|
|
else
|
|
return $RET
|
|
fi
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
whiptail --msgbox "The SSH server is $STATUS" 20 60 1
|
|
fi
|
|
}
|
|
|
|
get_vnc() {
|
|
if systemctl status vncserver-x11-serviced.service | grep -q -w active; then
|
|
echo 0
|
|
else
|
|
echo 1
|
|
fi
|
|
}
|
|
|
|
do_config_zram() {
|
|
if [ -e /etc/udev/rules.d/99-zram.rules ]; then
|
|
## get current swap allocation from /etc/udev/rules.d/99-zram.rules
|
|
size="$(awk -F\" '{print $4}' /etc/udev/rules.d/99-zram.rules)"
|
|
else
|
|
size="4G"
|
|
fi
|
|
new_size=$(whiptail --inputbox "How much memory (G) should the zRAM swap partition have? Choose 1G, 2G, or 4G - 4G recommended" \
|
|
19 70 -- "$size" 3>&1 1>&2 2>&3)
|
|
if [ $? -eq 0 ];then
|
|
return 0
|
|
ASK_TO_REBOOT=2
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
do_install_zram() {
|
|
echo "Configuring zram.service"
|
|
touch /etc/modules-load.d/zram.conf
|
|
echo 'zram' > /etc/modules-load.d/zram.conf
|
|
touch /etc/modprobe.d/zram.conf
|
|
echo 'options zram num_devices=1' > /etc/modprobe.d/zram.conf
|
|
touch /etc/udev/rules.d/99-zram.rules
|
|
echo "KERNEL==\"zram0\", ATTR{disksize}=\"${new_size}\",TAG+=\"systemd\"" \
|
|
> /etc/udev/rules.d/99-zram.rules
|
|
touch /etc/systemd/system/zram.service
|
|
echo "Installing zram.service"
|
|
cat << EOF > /etc/systemd/system/zram.service
|
|
[Unit]
|
|
Description=Swap with zram
|
|
After=multi-user.target
|
|
|
|
[Service]
|
|
Type=oneshot
|
|
RemainAfterExit=true
|
|
ExecStartPre=/sbin/mkswap /dev/zram0
|
|
ExecStart=/sbin/swapon /dev/zram0
|
|
ExecStop=/sbin/swapoff /dev/zram0
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
systemctl enable zram
|
|
if [ $? -eq 0 ];then
|
|
return 0
|
|
ASK_TO_REBOOT=2
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
do_zram_menu() {
|
|
whiptail --yesno "Would like to enable the zram swapping kernel module?" --defaultno 20 60 2
|
|
RET=$?
|
|
if [ $RET -eq 0 ]; then
|
|
do_config_zram
|
|
do_install_zram
|
|
STATUS=enabled
|
|
elif [ $RET -eq 1 ]; then
|
|
if [ -e /etc/udev/rules.d/99-zram.rules ];then
|
|
systemctl disable --now zram
|
|
fi
|
|
STATUS=disabled
|
|
fi
|
|
whiptail --msgbox "ZRAM swapping is $STATUS" 20 60 1
|
|
return $RET
|
|
}
|
|
|
|
do_vnc() {
|
|
DEFAULT=--defaultno
|
|
if [ $(get_vnc) -eq 0 ]; then
|
|
DEFAULT=
|
|
fi
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
whiptail --yesno "Would you like the VNC Server to be enabled?" $DEFAULT 20 60 2
|
|
RET=$?
|
|
else
|
|
RET=$1
|
|
fi
|
|
if [ $RET -eq 0 ]; then
|
|
if is_installed realvnc-vnc-server || apt-get install realvnc-vnc-server; then
|
|
systemctl enable vncserver-x11-serviced.service &&
|
|
systemctl start vncserver-x11-serviced.service &&
|
|
STATUS=enabled
|
|
else
|
|
return 1
|
|
fi
|
|
elif [ $RET -eq 1 ]; then
|
|
if is_installed realvnc-vnc-server; then
|
|
systemctl disable vncserver-x11-serviced.service
|
|
systemctl stop vncserver-x11-serviced.service
|
|
fi
|
|
STATUS=disabled
|
|
else
|
|
return $RET
|
|
fi
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
whiptail --msgbox "The VNC Server is $STATUS" 20 60 1
|
|
fi
|
|
}
|
|
|
|
do_audio() {
|
|
if is_pulseaudio ; then
|
|
oIFS="$IFS"
|
|
list=$(sudo -u $SUDO_USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID pacmd list-sources | grep -B1 -e 'alsa.card_name' -e 'name.*input' | grep -A4 index | sed -e s/*//g | sed s/^[' '\\t]*//g | grep -e index -e card_name | sed s/'index: '//g | sed s/'alsa.card_name = '//g | sed s/\"//g | tr '\n' '\/')
|
|
if ! [ -z "$list" ] ; then
|
|
IFS="/"
|
|
AUDIO_IN=$(whiptail --menu "Choose the audio input" 20 60 10 ${list} 3>&1 1>&2 2>&3)
|
|
return 0
|
|
else
|
|
whiptail --msgbox "No internal audio devices found" 20 60 1
|
|
return 1
|
|
fi
|
|
if [ $? -eq 0 ]; then
|
|
sudo -u $SUDO_USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID pactl set-default-source "$AUDIO_IN"
|
|
fi
|
|
IFS=$oIFS
|
|
fi
|
|
}
|
|
|
|
list_wlan_interfaces() {
|
|
for dir in /sys/class/net/*/wireless; do
|
|
if [ -d "$dir" ]; then
|
|
basename "$(dirname "$dir")"
|
|
fi
|
|
done
|
|
}
|
|
|
|
do_wifi_ssid_passphrase() {
|
|
RET=0
|
|
IFACE_LIST="$(list_wlan_interfaces)"
|
|
IFACE="$(echo "$IFACE_LIST" | head -n 1)"
|
|
|
|
if [ -z "$IFACE" ]; then
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
whiptail --msgbox "No wireless interface found" 20 60
|
|
fi
|
|
return 1
|
|
fi
|
|
|
|
if ! wpa_cli -i "$IFACE" status > /dev/null 2>&1; then
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
whiptail --msgbox "Could not communicate with wpa_supplicant" 20 60
|
|
fi
|
|
return 1
|
|
fi
|
|
|
|
if [ "$INTERACTIVE" = True ] && [ -z "$(get_wifi_country)" ]; then
|
|
do_wifi_country
|
|
fi
|
|
|
|
SSID="$1"
|
|
while [ -z "$SSID" ] && [ "$INTERACTIVE" = True ]; do
|
|
SSID=$(whiptail --inputbox "Please enter SSID" 20 60 3>&1 1>&2 2>&3)
|
|
if [ $? -ne 0 ]; then
|
|
return 0
|
|
elif [ -z "$SSID" ]; then
|
|
whiptail --msgbox "SSID cannot be empty. Please try again." 20 60
|
|
fi
|
|
done
|
|
|
|
PASSPHRASE="$2"
|
|
while [ "$INTERACTIVE" = True ]; do
|
|
PASSPHRASE=$(whiptail --passwordbox "Please enter passphrase. Leave it empty if none." 20 60 3>&1 1>&2 2>&3)
|
|
if [ $? -ne 0 ]; then
|
|
return 0
|
|
else
|
|
break
|
|
fi
|
|
done
|
|
|
|
# Escape special characters for embedding in regex below
|
|
local ssid="$(echo "$SSID" \
|
|
| sed 's;\\;\\\\;g' \
|
|
| sed -e 's;\.;\\\.;g' \
|
|
-e 's;\*;\\\*;g' \
|
|
-e 's;\+;\\\+;g' \
|
|
-e 's;\?;\\\?;g' \
|
|
-e 's;\^;\\\^;g' \
|
|
-e 's;\$;\\\$;g' \
|
|
-e 's;\/;\\\/;g' \
|
|
-e 's;\[;\\\[;g' \
|
|
-e 's;\];\\\];g' \
|
|
-e 's;{;\\{;g' \
|
|
-e 's;};\\};g' \
|
|
-e 's;(;\\(;g' \
|
|
-e 's;);\\);g' \
|
|
-e 's;";\\\\\";g')"
|
|
|
|
wpa_cli -i "$IFACE" list_networks \
|
|
| tail -n +2 | cut -f -2 | grep -P "\t$ssid$" | cut -f1 \
|
|
| while read ID; do
|
|
wpa_cli -i "$IFACE" remove_network "$ID" > /dev/null 2>&1
|
|
done
|
|
|
|
ID="$(wpa_cli -i "$IFACE" add_network)"
|
|
wpa_cli -i "$IFACE" set_network "$ID" ssid "\"$SSID\"" 2>&1 | grep -q "OK"
|
|
RET=$((RET + $?))
|
|
|
|
if [ -z "$PASSPHRASE" ]; then
|
|
wpa_cli -i "$IFACE" set_network "$ID" key_mgmt NONE 2>&1 | grep -q "OK"
|
|
RET=$((RET + $?))
|
|
else
|
|
wpa_cli -i "$IFACE" set_network "$ID" psk "\"$PASSPHRASE\"" 2>&1 | grep -q "OK"
|
|
RET=$((RET + $?))
|
|
fi
|
|
|
|
if [ $RET -eq 0 ]; then
|
|
wpa_cli -i "$IFACE" enable_network "$ID" > /dev/null 2>&1
|
|
else
|
|
wpa_cli -i "$IFACE" remove_network "$ID" > /dev/null 2>&1
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
whiptail --msgbox "Failed to set SSID or passphrase" 20 60
|
|
fi
|
|
fi
|
|
wpa_cli -i "$IFACE" save_config > /dev/null 2>&1
|
|
|
|
echo "$IFACE_LIST" | while read IFACE; do
|
|
wpa_cli -i "$IFACE" reconfigure > /dev/null 2>&1
|
|
done
|
|
|
|
return $RET
|
|
}
|
|
|
|
do_update_os() {
|
|
apt update && apt -y full-upgrade
|
|
ASK_TO_REBOOT=1
|
|
}
|
|
|
|
do_install_birdnet() {
|
|
sudo -E -upi ${birdnetpi_dir}/Birders_Guide_Installer.sh
|
|
ASK_TO_REBOOT=1
|
|
}
|
|
|
|
insist_on_reboot() {
|
|
if [ $ASK_TO_REBOOT -eq 2 ]; then
|
|
whiptail --yesno "You really should reboot. Do that now?" 20 60 2
|
|
if [ $? -eq 0 ]; then # yes
|
|
sync
|
|
reboot
|
|
fi
|
|
fi
|
|
}
|
|
|
|
do_finish() {
|
|
if [ $ASK_TO_REBOOT -eq 1 ]; then
|
|
whiptail --yesno "Would you like to reboot now?" 20 60 2
|
|
if [ $? -eq 0 ]; then # yes
|
|
sync
|
|
reboot
|
|
fi
|
|
elif [ $ASK_TO_REBOOT -eq 2 ]; then
|
|
whiptail --yesno "You really should reboot. Do that now?" 20 60 2
|
|
if [ $? -eq 0 ]; then # yes
|
|
sync
|
|
reboot
|
|
fi
|
|
fi
|
|
exit 0
|
|
}
|
|
|
|
# Everything else needs to be run as root
|
|
if [ $(id -u) -ne 0 ]; then
|
|
printf "Script must be run as root. Try 'sudo birdnet-pi-config'\n"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -n "${OPT_MEMORY_SPLIT:-}" ]; then
|
|
set -e # Fail when a command errors
|
|
set_memory_split "${OPT_MEMORY_SPLIT}"
|
|
exit 0
|
|
fi
|
|
|
|
do_system_menu() {
|
|
if is_pi ; then
|
|
FUN=$(whiptail --title "BirdNET-Pi Software Configuration Tool (birdnet-pi-config)" --menu "System Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
|
|
"Password" "Change password for the '$USER' user" \
|
|
"Audio" "Select audio device you'd like BirdNET-Pi to use" \
|
|
"Wireless LAN" "Enter SSID and passphrase" \
|
|
"Update the OS" "Update the underlying operating system" \
|
|
"Interface Options" "Enable/Disable SSH and VNC" \
|
|
"Configure zRAM" "Enable/Disable zRAM" \
|
|
3>&1 1>&2 2>&3)
|
|
else
|
|
exit
|
|
fi
|
|
RET=$?
|
|
if [ $RET -eq 1 ]; then
|
|
return 0
|
|
elif [ $RET -eq 0 ]; then
|
|
case "$FUN" in
|
|
Password*) do_change_pass ;;
|
|
Audio*) do_audio ;;
|
|
Wireless*) do_wifi_ssid_passphrase ;;
|
|
Update*) do_update_os ;;
|
|
Interface*) do_interface_menu ;;
|
|
Configure*) do_zram_menu ;;
|
|
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
|
|
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
|
|
fi
|
|
}
|
|
|
|
do_interface_menu() {
|
|
if is_pi ; then
|
|
FUN=$(whiptail --title "BirdNET-Pi Software Configuration Tool (birdnet-pi-config)" --menu "Interfacing Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
|
|
"SSH" "Enable/disable remote command line access using SSH" \
|
|
"VNC" "Enable/disable graphical remote access using RealVNC" \
|
|
3>&1 1>&2 2>&3)
|
|
else
|
|
exit
|
|
fi
|
|
RET=$?
|
|
if [ $RET -eq 1 ]; then
|
|
return 0
|
|
elif [ $RET -eq 0 ]; then
|
|
case "$FUN" in
|
|
SSH*) do_ssh ;;
|
|
VNC*) do_vnc ;;
|
|
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
|
|
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
|
|
fi
|
|
}
|
|
|
|
do_internationalisation_menu() {
|
|
FUN=$(whiptail --title "BirdNET-Pi Software Configuration Tool (birdnet-pi-config)" --menu "Localisation Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
|
|
"Locale" "Configure language and regional settings" \
|
|
"Timezone" "Configure time zone" \
|
|
"Keyboard" "Set keyboard layout to match your keyboard" \
|
|
"WLAN Country" "Set legal wireless channels for your country" \
|
|
3>&1 1>&2 2>&3)
|
|
RET=$?
|
|
if [ $RET -eq 1 ]; then
|
|
return 0
|
|
elif [ $RET -eq 0 ]; then
|
|
case "$FUN" in
|
|
Locale*) do_change_locale; insist_on_reboot;;
|
|
Time*) do_change_timezone; insist_on_reboot ;;
|
|
Key*) do_configure_keyboard ;;
|
|
WLAN*) do_wifi_country ;;
|
|
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
|
|
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
|
|
fi
|
|
}
|
|
#
|
|
# Interactive use loop
|
|
#
|
|
if [ "$INTERACTIVE" = True ]; then
|
|
[ -e $CONFIG ] || touch $CONFIG
|
|
calc_wt_size
|
|
while [ "$USER" = "root" ] || [ -z "$USER" ]; do
|
|
if ! USER=$(whiptail --inputbox "birdnet-pi-config could not determine the default user.\\n\\nWhat user should these settings apply to?" 20 60 pi 3>&1 1>&2 2>&3); then
|
|
return 0
|
|
fi
|
|
done
|
|
while true; do
|
|
if is_pi ; then
|
|
FUN=$(whiptail --title "BirdNET-Pi Software Configuration Tool (birdnet-pi-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
|
|
"Step 1" "Configure language and regional settings" \
|
|
"Step 2" "Install BirdNET-Pi" \
|
|
"System Options" "Configure system settings" \
|
|
3>&1 1>&2 2>&3)
|
|
else
|
|
exit
|
|
fi
|
|
RET=$?
|
|
if [ $RET -eq 1 ]; then
|
|
do_finish
|
|
elif [ $RET -eq 0 ]; then
|
|
case "$FUN" in
|
|
*1) do_internationalisation_menu ;;
|
|
*2) do_install_birdnet;;
|
|
Sys*) do_system_menu ;;
|
|
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
|
|
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
|
|
else
|
|
exit 1
|
|
fi
|
|
done
|
|
fi
|