brain-config/brain-config

659 lines
18 KiB
Plaintext
Raw Permalink Normal View History

2012-06-11 05:32:01 +09:00
#!/bin/sh
2022-05-15 01:42:08 +09:00
# Part of brain-config https://github.com/brain-hackers/brain-config
# Forked from raspi-config https://github.com/RPi-Distro/raspi-config
2012-06-11 05:32:01 +09:00
#
# See LICENSE file for copyright and license details
INTERACTIVE=True
2012-07-16 02:32:30 +09:00
ASK_TO_REBOOT=0
2022-07-02 23:23:31 +09:00
BLACKLIST=/etc/modprobe.d/brain-blacklist.conf
CONFIG=/boot/config.txt
2022-05-15 01:42:08 +09:00
# TODO: erase these envs
2012-07-16 02:32:30 +09:00
2020-01-09 23:37:08 +09:00
USER=${SUDO_USER:-$(who -m | awk '{ print $1 }')}
2022-07-02 23:23:31 +09:00
CMDLINE=/boot/cmdline.txt
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))
}
2013-05-23 04:11:00 +09:00
do_about() {
whiptail --msgbox "\
This tool provides a straightforward way of doing initial
2022-05-15 01:42:08 +09:00
configuration of the SHARP Brain. Although it can be run
at any time, some of the options may have difficulties if
2021-07-09 00:40:08 +09:00
you have heavily customised your installation.
2022-07-02 23:23:31 +09:00
$(dpkg -s brain-config 2> /dev/null | grep Version)\
" 20 70 1
return 0
2012-06-11 05:32:01 +09:00
}
2013-05-23 04:11:00 +09:00
do_expand_rootfs() {
2020-05-15 19:10:26 +09:00
ROOT_PART="$(findmnt / -o source -n)"
ROOT_DEV="/dev/$(lsblk -no pkname "$ROOT_PART")"
2020-05-15 19:10:26 +09:00
PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")"
# NOTE: the NOOBS partition layout confuses parted. For now, let's only
# agree to work with a sufficiently simple partition layout
if [ "$PART_NUM" -ne 2 ]; then
whiptail --msgbox "Your partition layout is not currently supported by this tool. You are probably using NOOBS, in which case your root filesystem is already expanded anyway." 20 60 2
return 0
fi
2020-05-15 19:10:26 +09:00
LAST_PART_NUM=$(parted "$ROOT_DEV" -ms unit s p | tail -n 1 | cut -f 1 -d:)
if [ $LAST_PART_NUM -ne $PART_NUM ]; then
whiptail --msgbox "$ROOT_PART is not the last partition. Don't know how to expand" 20 60 2
return 0
fi
2012-06-11 05:32:01 +09:00
# Get the starting offset of the root partition
2020-05-15 19:10:26 +09:00
PART_START=$(parted "$ROOT_DEV" -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
2012-06-11 05:32:01 +09:00
[ "$PART_START" ] || return 1
# Return value will likely be error for fdisk as it fails to reload the
2012-06-11 05:32:01 +09:00
# partition table because the root fs is mounted
2020-05-15 19:10:26 +09:00
fdisk "$ROOT_DEV" <<EOF
2012-06-11 05:32:01 +09:00
p
d
$PART_NUM
2012-06-11 05:32:01 +09:00
n
p
$PART_NUM
2012-06-11 05:32:01 +09:00
$PART_START
p
w
EOF
2012-07-16 02:32:30 +09:00
ASK_TO_REBOOT=1
2012-06-11 05:32:01 +09:00
# now set up an init.d script
cat <<EOF > /etc/init.d/resize2fs_once &&
2012-06-17 21:43:38 +09:00
#!/bin/sh
2012-06-11 05:32:01 +09:00
### BEGIN INIT INFO
# Provides: resize2fs_once
# Required-Start:
# Required-Stop:
# Default-Start: 3
2012-06-11 05:32:01 +09:00
# Default-Stop:
# Short-Description: Resize the root filesystem to fill partition
# Description:
### END INIT INFO
. /lib/lsb/init-functions
case "\$1" in
2012-06-11 05:32:01 +09:00
start)
log_daemon_msg "Starting resize2fs_once" &&
2020-05-15 19:10:26 +09:00
resize2fs "$ROOT_PART" &&
2012-06-11 05:32:01 +09:00
update-rc.d resize2fs_once remove &&
rm /etc/init.d/resize2fs_once &&
log_end_msg \$?
2012-06-11 05:32:01 +09:00
;;
*)
echo "Usage: \$0 start" >&2
2012-06-11 05:32:01 +09:00
exit 3
;;
esac
EOF
chmod +x /etc/init.d/resize2fs_once &&
update-rc.d resize2fs_once defaults &&
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Root partition has been resized.\nThe filesystem will be enlarged upon the next reboot" 20 60 2
fi
2012-06-11 05:32:01 +09:00
}
2013-05-23 04:11:00 +09:00
do_change_pass() {
2020-01-09 23:37:08 +09:00
whiptail --msgbox "You will now be asked to enter a new password for the $USER user" 20 60 1
passwd $USER &&
2012-06-11 05:32:01 +09:00
whiptail --msgbox "Password changed successfully" 20 60 1
}
do_change_locale() {
if [ "$INTERACTIVE" = True ]; then
dpkg-reconfigure locales
else
2022-01-06 01:52:08 +09:00
if ! LOCALE_LINE="$(grep -E "^$1( |$)" /usr/share/i18n/SUPPORTED)"; then
return 1
fi
2022-01-06 01:52:08 +09:00
export LC_ALL=C
export LANG=C
local LG="/etc/locale.gen"
local NEW_LANG="$(echo $LOCALE_LINE | cut -f1 -d " ")"
[ -L "$LG" ] && [ "$(readlink $LG)" = "/usr/share/i18n/SUPPORTED" ] && rm -f "$LG"
echo "$LOCALE_LINE" > /etc/locale.gen
update-locale --no-checks LANG
update-locale --no-checks "LANG=$NEW_LANG"
dpkg-reconfigure -f noninteractive locales
fi
2012-06-11 05:32:01 +09:00
}
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
2012-06-11 05:32:01 +09:00
}
2016-05-24 01:43:13 +09:00
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
2016-05-24 01:43:13 +09:00
}
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
2022-01-06 17:21:43 +09:00
ASK_TO_REBOOT=1
fi
if hash rfkill 2> /dev/null; then
rfkill unblock wifi
2022-07-02 23:23:31 +09:00
for filename in /var/lib/systemd/rfkill/*:wlan ; do
echo 0 > $filename
done
fi
if [ "$INTERACTIVE" = True ]; then
2022-01-06 17:21:43 +09:00
whiptail --msgbox "Wireless LAN country set to $COUNTRY" 20 60 1
fi
fi
IFS=$oIFS
}
2016-05-24 02:14:18 +09:00
get_hostname() {
2022-01-06 17:21:43 +09:00
cat /etc/hostname | tr -d " \t\n\r"
2016-05-24 02:14:18 +09:00
}
do_hostname() {
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "\
2013-04-26 17:43:03 +09:00
Please note: RFCs mandate that a hostname's labels \
may contain only the ASCII letters 'a' through 'z' (case-insensitive),
the digits '0' through '9', and the hyphen.
Hostname labels cannot begin or end with a hyphen.
No other symbols, punctuation characters, or blank spaces are permitted.\
" 20 70 1
2015-09-15 18:25:53 +09:00
fi
2013-04-26 17:43:03 +09:00
CURRENT_HOSTNAME=`cat /etc/hostname | tr -d " \t\n\r"`
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
NEW_HOSTNAME=$(whiptail --inputbox "Please enter a hostname" 20 60 "$CURRENT_HOSTNAME" 3>&1 1>&2 2>&3)
else
NEW_HOSTNAME=$1
true
fi
2013-04-26 17:43:03 +09:00
if [ $? -eq 0 ]; then
echo $NEW_HOSTNAME > /etc/hostname
sed -i "s/127.0.1.1.*$CURRENT_HOSTNAME/127.0.1.1\t$NEW_HOSTNAME/g" /etc/hosts
ASK_TO_REBOOT=1
fi
}
get_ssh() {
if service ssh status | grep -q inactive; then
echo 1
else
echo 0
fi
}
2013-05-23 04:21:24 +09:00
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
2015-09-15 18:25:53 +09:00
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
2015-09-15 18:25:53 +09:00
RET=$?
else
RET=$1
fi
2012-06-11 05:32:01 +09:00
if [ $RET -eq 0 ]; then
ssh-keygen -A &&
2012-06-11 05:32:01 +09:00
update-rc.d ssh enable &&
invoke-rc.d ssh start &&
STATUS=enabled
2012-06-11 05:32:01 +09:00
elif [ $RET -eq 1 ]; then
update-rc.d ssh disable &&
invoke-rc.d ssh stop &&
STATUS=disabled
2012-06-11 05:32:01 +09:00
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The SSH server is $STATUS" 20 60 1
fi
2012-06-11 05:32:01 +09:00
}
2023-03-22 03:58:56 +09:00
do_usb() {
if [ "$INTERACTIVE" = True ]; then
MODE=$(whiptail --menu "Select the role of the USB Host Controller." 20 60 10 "host" "USB Host Mode" "peripheral" "USB Device Mode (for Gadget)" 3>&1 1>&2 2>&3)
else
MODE=$1
true
fi
MODEL=$(cat /sys/firmware/devicetree/base/compatible | grep -Eao 'pw-[a-z0-9]+' | sed -E 's/-//g')
DTB="/boot/imx28-${MODEL}.dtb"
DTS=`mktemp`
if [ "${MODE}" != "host" -a "${MODE}" != "peripheral" ]; then
echo "Specify the mode from 'host' or 'peripheral'."
return 1
fi
dtc -I dtb -O dts ${DTB} > ${DTS} 2> /dev/null
RE='(^[\t ]*dr_mode[\t ]*=[\t ]*\")(.*)(\"[\t ]*;[\t ]*$)'
CURRENT=`sed -En "s|${RE}|\2|p" ${DTS} | head -1`
if [ "${CURRENT}" != "${MODE}" ]; then
mount -o rw,remount /boot
echo "Changing dr_mode to ${MODE}"
sed -Ei "s|${RE}|\1${MODE}\3|" ${DTS}
dtc -I dts -O dtb ${DTS} > ${DTB} 2> /dev/null
sync
ASK_TO_REBOOT=1
fi
}
2022-07-02 23:23:31 +09:00
disable_brain_config_at_boot() {
if [ -e /etc/profile.d/brain-config.sh ]; then
rm -f /etc/profile.d/brain-config.sh
if [ -e /etc/systemd/system/getty@tty1.service.d/brain-config-override.conf ]; then
rm /etc/systemd/system/getty@tty1.service.d/brain-config-override.conf
2022-05-15 01:42:08 +09:00
fi
telinit q
2016-08-11 00:04:28 +09:00
fi
}
2022-05-15 01:42:08 +09:00
get_net_names() {
if grep -q "net.ifnames=0" $CMDLINE || \
( [ "$(readlink -f /etc/systemd/network/99-default.link)" = "/dev/null" ] && \
[ "$(readlink -f /etc/systemd/network/73-usb-net-by-mac.link)" = "/dev/null" ] ); then
echo 1
else
2022-05-15 01:42:08 +09:00
echo 0
fi
}
2022-05-15 01:42:08 +09:00
do_net_names () {
DEFAULT=--defaultno
CURRENT=0
if [ $(get_net_names) -eq 0 ]; then
DEFAULT=
CURRENT=1
2021-11-10 19:31:50 +09:00
fi
2021-11-10 18:47:01 +09:00
if [ "$INTERACTIVE" = True ]; then
2022-05-15 01:42:08 +09:00
whiptail --yesno "Would you like to enable predictable network interface names?" $DEFAULT 20 60 2
2021-11-10 18:47:01 +09:00
RET=$?
else
2022-05-15 01:42:08 +09:00
RET=$1
2021-11-10 18:47:01 +09:00
fi
2022-05-15 01:42:08 +09:00
if [ $RET -eq $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
sed -i $CMDLINE -e "s/net.ifnames=0 *//"
rm -f /etc/systemd/network/99-default.link
rm -f /etc/systemd/network/73-usb-net-by-mac.link
STATUS=enabled
elif [ $RET -eq 1 ]; then
ln -sf /dev/null /etc/systemd/network/99-default.link
ln -sf /dev/null /etc/systemd/network/73-usb-net-by-mac.link
STATUS=disabled
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Predictable network interface names are $STATUS" 20 60 1
2021-11-10 18:47:01 +09:00
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
2017-11-09 00:15:24 +09:00
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
2017-11-09 00:15:24 +09:00
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
2017-11-09 00:15:24 +09:00
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
2017-11-09 00:15:24 +09:00
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
2017-11-09 00:15:24 +09:00
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' \
2017-11-09 00:15:24 +09:00
-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
2017-11-09 00:15:24 +09:00
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
}
2012-06-11 05:32:01 +09:00
do_finish() {
2022-07-02 23:23:31 +09:00
disable_brain_config_at_boot
2012-07-16 02:32:30 +09:00
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
fi
2012-06-11 05:32:01 +09:00
exit 0
}
get_bootro_now() {
2022-01-06 17:21:43 +09:00
findmnt /boot | grep -q " ro,"
echo $?
}
get_bootro_conf() {
grep /boot /etc/fstab | grep -q "defaults.*,ro[ ,]"
echo $?
}
is_uname_current() {
test -d "/lib/modules/$(uname -r)"
}
2015-09-15 18:25:53 +09:00
nonint() {
2017-11-09 00:15:24 +09:00
"$@"
2015-09-15 18:25:53 +09:00
}
#
# Command line options for non-interactive use
#
for i in $*
do
case $i in
--expand-rootfs)
INTERACTIVE=False
2013-05-23 04:11:00 +09:00
do_expand_rootfs
printf "Please reboot\n"
exit 0
;;
--apply-os-config)
INTERACTIVE=False
do_apply_os_config
exit $?
;;
2015-09-15 18:25:53 +09:00
nonint)
INTERACTIVE=False
2017-11-09 00:15:24 +09:00
"$@"
exit $?
2015-09-15 18:25:53 +09:00
;;
*)
# unknown option
;;
esac
done
# Everything else needs to be run as root
if [ $(id -u) -ne 0 ]; then
2022-07-02 23:23:31 +09:00
printf "Script must be run as root. Try 'sudo brain-config'\n"
exit 1
fi
do_system_menu() {
2022-07-02 23:23:31 +09:00
FUN=$(whiptail --title "SHARP Brain Software Configuration Tool (brain-config)" --menu "System Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
2022-05-15 01:42:08 +09:00
"S1 Wireless LAN" "Enter SSID and passphrase" \
"S2 Password" "Change password for the '$USER' user" \
"S3 Hostname" "Set name for this computer on a network" \
2022-05-15 01:42:08 +09:00
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
S1\ *) do_wifi_ssid_passphrase ;;
S2\ *) do_change_pass ;;
S3\ *) do_hostname ;;
*) 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() {
2022-07-02 23:23:31 +09:00
FUN=$(whiptail --title "SHARP Brain Software Configuration Tool (brain-config)" --menu "Interfacing Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"I1 SSH" "Enable/disable remote command line access using SSH" \
2023-03-22 03:58:56 +09:00
"I2 USB" "Switch the role of the USB Host Controller" \
2013-05-23 04:21:24 +09:00
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
2013-05-23 04:21:24 +09:00
case "$FUN" in
I1\ *) do_ssh ;;
2023-03-22 03:58:56 +09:00
I2\ *) do_usb ;;
2013-05-23 04:21:24 +09:00
*) 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() {
2022-07-02 23:23:31 +09:00
FUN=$(whiptail --title "SHARP Brain Software Configuration Tool (brain-config)" --menu "Localisation Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
2020-10-14 22:59:19 +09:00
"L1 Locale" "Configure language and regional settings" \
"L2 Timezone" "Configure time zone" \
"L3 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
L1\ *) do_change_locale ;;
L2\ *) do_change_timezone ;;
L3\ *) 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
}
do_advanced_menu() {
2022-07-02 23:23:31 +09:00
FUN=$(whiptail --title "SHARP Brain Software Configuration Tool (brain-config)" --menu "Advanced Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
2022-05-15 01:42:08 +09:00
"A1 Expand Filesystem" "Ensures that all of the SD card is available" \
"A2 Network Interface Names" "Enable/disable predictable network i/f names" \
2022-05-15 01:42:08 +09:00
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
A1\ *) do_expand_rootfs ;;
A2\ *) do_net_names ;;
*) 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
#
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
[ -e $CONFIG ] || touch $CONFIG
2015-09-15 18:25:53 +09:00
calc_wt_size
2020-01-09 23:37:08 +09:00
while [ "$USER" = "root" ] || [ -z "$USER" ]; do
2022-07-02 23:23:31 +09:00
if ! USER=$(whiptail --inputbox "brain-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
2020-01-09 23:37:08 +09:00
return 0
fi
done
2015-09-15 18:25:53 +09:00
while true; do
2022-07-02 23:23:31 +09:00
FUN=$(whiptail --title "SHARP Brain Software Configuration Tool (brain-config)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
2022-05-15 01:42:08 +09:00
"1 System Options" "Configure system settings" \
"2 Interface Options" "Configure connections to peripherals" \
"3 Localisation Options" "Configure language and regional settings" \
"4 Advanced Options" "Configure advanced settings" \
"5 About brain-config" "Information about this configuration tool" \
2022-05-15 01:42:08 +09:00
3>&1 1>&2 2>&3)
2015-09-15 18:25:53 +09:00
RET=$?
if [ $RET -eq 1 ]; then
do_finish
elif [ $RET -eq 0 ]; then
case "$FUN" in
1\ *) do_system_menu ;;
2\ *) do_interface_menu ;;
3\ *) do_internationalisation_menu ;;
4\ *) do_advanced_menu ;;
5\ *) do_about ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
2015-09-15 18:25:53 +09:00
else
exit 1
fi
done
2015-09-24 05:25:39 +09:00
fi