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
2013-03-27 06:58:32 +09:00
INTERACTIVE=True
2012-07-16 02:32:30 +09:00
ASK_TO_REBOOT=0
2015-01-30 08:30:09 +09:00
BLACKLIST=/etc/modprobe.d/raspi-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 }')}
2017-01-10 01:52:10 +09:00
is_pi () {
2017-12-01 18:01:38 +09:00
ARCH=$(dpkg --print-architecture)
2020-02-27 02:52:43 +09:00
if [ "$ARCH" = "armhf" ] || [ "$ARCH" = "arm64" ] ; then
2017-12-01 18:01:38 +09:00
return 0
else
return 1
fi
2017-01-10 01:52:10 +09:00
}
2017-01-10 20:47:45 +09:00
if is_pi ; then
CMDLINE=/boot/cmdline.txt
else
CMDLINE=/proc/cmdline
fi
2013-05-23 03:37:56 +09:00
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
2019-12-10 22:09:49 +09:00
WT_HEIGHT=18
2013-05-23 03:37:56 +09:00
WT_WIDTH=$(tput cols)
if [ -z "$WT_WIDTH" ] || [ "$WT_WIDTH" -lt 60 ]; then
WT_WIDTH=80
fi
2013-05-24 09:51:37 +09:00
if [ "$WT_WIDTH" -gt 178 ]; then
WT_WIDTH=120
fi
2015-01-30 08:30:09 +09:00
WT_MENU_HEIGHT=$(($WT_HEIGHT-7))
2013-05-23 03:37:56 +09:00
}
2013-05-23 04:11:00 +09:00
do_about() {
2012-07-14 01:13:30 +09:00
whiptail --msgbox "\
2020-10-08 01:15:23 +09:00
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
2013-03-27 06:58:32 +09:00
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.
$(dpkg -s raspi-config 2> /dev/null | grep Version)\
2012-07-14 01:13:30 +09:00
" 20 70 1
2021-06-25 21:22:56 +09:00
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")"
2013-05-21 03:45:01 +09:00
2020-05-15 19:10:26 +09:00
PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")"
2013-05-21 03:45:01 +09:00
2013-05-23 04:47:15 +09:00
# 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:)
2015-05-29 19:35:13 +09:00
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
2013-05-21 03:45:01 +09:00
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
2013-03-27 06:58:32 +09:00
# 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
2013-05-21 03:45:01 +09:00
$PART_NUM
2012-06-11 05:32:01 +09:00
n
p
2013-05-21 03:45:01 +09:00
$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
2015-05-29 19:35:13 +09:00
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:
2015-05-29 19:35:13 +09:00
# 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
2015-05-29 19:35:13 +09:00
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 &&
2015-05-29 19:35:13 +09:00
rm /etc/init.d/resize2fs_once &&
log_end_msg \$?
2012-06-11 05:32:01 +09:00
;;
*)
2015-05-29 19:35:13 +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 &&
2013-03-27 06:58:32 +09:00
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
}
2013-05-23 04:17:32 +09:00
do_change_locale() {
2017-11-10 02:25:18 +09:00
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
2017-11-10 02:25:18 +09:00
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"
2017-11-10 02:25:18 +09:00
dpkg-reconfigure -f noninteractive locales
fi
2012-06-11 05:32:01 +09:00
}
2013-05-23 04:17:32 +09:00
do_change_timezone() {
2017-11-10 02:25:18 +09:00
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() {
2019-05-08 00:05:30 +09:00
CODE=${1:-0}
2019-05-02 21:38:59 +09:00
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
2019-06-21 04:02:40 +09:00
wpa_cli -i "$IFACE" save_config > /dev/null 2>&1
2019-05-02 21:38:59 +09:00
COUNTRY="$(wpa_cli -i "$IFACE" get country)"
if [ "$COUNTRY" = "FAIL" ]; then
return 1
fi
2019-05-08 00:05:30 +09:00
if [ $CODE = 0 ]; then
echo "$COUNTRY"
fi
return 0
2016-05-24 01:43:13 +09:00
}
2016-05-26 00:36:39 +09:00
do_wifi_country() {
2018-04-06 22:28:32 +09:00
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
2016-02-24 02:17:26 +09:00
oIFS="$IFS"
2016-02-24 02:42:14 +09:00
if [ "$INTERACTIVE" = True ]; then
value=$(cat /usr/share/zoneinfo/iso3166.tab | tail -n +26 | tr '\t' '/' | tr '\n' '/')
2020-10-12 23:04:47 +09:00
IFS="/"
2016-02-24 02:42:14 +09:00
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
2016-02-24 02:17:26 +09:00
if [ $? -eq 0 ];then
2018-04-06 22:28:32 +09:00
wpa_cli -i "$IFACE" set country "$COUNTRY"
2019-04-29 22:56:59 +09:00
wpa_cli -i "$IFACE" save_config > /dev/null 2>&1
2020-10-12 23:04:47 +09:00
if iw reg set "$COUNTRY" 2> /dev/null; then
2022-01-06 17:21:43 +09:00
ASK_TO_REBOOT=1
2018-03-01 02:30:37 +09:00
fi
2019-04-29 22:56:59 +09:00
if hash rfkill 2> /dev/null; then
2020-07-27 23:47:15 +09:00
rfkill unblock wifi
2020-07-27 23:59:52 +09:00
if is_pi ; then
for filename in /var/lib/systemd/rfkill/*:wlan ; do
echo 0 > $filename
done
fi
2018-03-01 02:30:37 +09:00
fi
2016-02-24 02:17:26 +09:00
if [ "$INTERACTIVE" = True ]; then
2022-01-06 17:21:43 +09:00
whiptail --msgbox "Wireless LAN country set to $COUNTRY" 20 60 1
2016-02-24 02:17:26 +09:00
fi
fi
2020-10-12 23:04:47 +09:00
IFS=$oIFS
2016-02-24 02:17:26 +09:00
}
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
}
2016-05-26 00:36:39 +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
}
2016-05-23 22:20:18 +09:00
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() {
2012-07-05 00:13:28 +09:00
if [ -e /var/log/regen_ssh_keys.log ] && ! grep -q "^finished" /var/log/regen_ssh_keys.log; then
2012-06-17 23:16:05 +09:00
whiptail --msgbox "Initial ssh key generation still running. Please wait and try again." 20 60 2
return 1
fi
2016-05-24 21:01:17 +09:00
DEFAULT=--defaultno
if [ $(get_ssh) -eq 0 ]; then
DEFAULT=
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
2020-01-14 02:08:24 +09:00
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
2019-04-29 22:57:44 +09:00
ssh-keygen -A &&
2012-06-11 05:32:01 +09:00
update-rc.d ssh enable &&
invoke-rc.d ssh start &&
2016-05-24 21:01:17 +09:00
STATUS=enabled
2012-06-11 05:32:01 +09:00
elif [ $RET -eq 1 ]; then
update-rc.d ssh disable &&
2016-05-23 22:20:18 +09:00
invoke-rc.d ssh stop &&
2016-05-24 21:01:17 +09:00
STATUS=disabled
2012-06-11 05:32:01 +09:00
else
return $RET
fi
2016-05-24 21:01:17 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The SSH server is $STATUS" 20 60 1
fi
2012-06-11 05:32:01 +09:00
}
2022-05-15 01:42:08 +09:00
disable_raspi_config_at_boot() {
if [ -e /etc/profile.d/raspi-config.sh ]; then
rm -f /etc/profile.d/raspi-config.sh
if [ -e /etc/systemd/system/getty@tty1.service.d/raspi-config-override.conf ]; then
rm /etc/systemd/system/getty@tty1.service.d/raspi-config-override.conf
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
2016-11-30 23:48:48 +09:00
else
2022-05-15 01:42:08 +09:00
echo 0
2016-11-30 23:48:48 +09:00
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
}
2017-10-27 15:49:33 +09:00
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
2017-10-27 15:49:33 +09:00
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
2017-10-27 15:49:33 +09:00
return 1
fi
2018-04-06 21:44:40 +09:00
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
2017-10-27 15:49:33 +09:00
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
2017-10-27 15:49:33 +09:00
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" \
2017-10-27 15:49:33 +09:00
| 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')"
2017-10-27 15:49:33 +09:00
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
2017-10-27 15:49:33 +09:00
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() {
2013-09-10 07:55:22 +09:00
disable_raspi_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
}
2019-10-01 18:53:22 +09:00
get_bootro_now() {
2022-01-06 17:21:43 +09:00
findmnt /boot | grep -q " ro,"
2022-01-19 03:40:59 +09:00
echo $?
2019-10-01 18:53:22 +09:00
}
get_bootro_conf() {
2022-03-21 21:04:41 +09:00
grep /boot /etc/fstab | grep -q "defaults.*,ro[ ,]"
2022-01-19 03:40:59 +09:00
echo $?
2019-10-01 18:53:22 +09:00
}
2020-01-17 20:51:49 +09:00
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
}
2012-08-21 05:53:15 +09:00
#
# Command line options for non-interactive use
#
for i in $*
do
case $i in
2013-03-27 06:58:32 +09:00
--expand-rootfs)
INTERACTIVE=False
2013-05-23 04:11:00 +09:00
do_expand_rootfs
2013-03-27 06:58:32 +09:00
printf "Please reboot\n"
exit 0
;;
2013-09-10 07:55:22 +09:00
--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
;;
2012-08-21 05:53:15 +09:00
*)
# unknown option
;;
esac
done
2022-04-26 00:41:27 +09:00
# Everything else needs to be run as root
if [ $(id -u) -ne 0 ]; then
printf "Script must be run as root. Try 'sudo raspi-config'\n"
exit 1
fi
2020-10-08 01:15:23 +09:00
do_system_menu() {
2022-05-15 01:42:08 +09:00
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "System Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"S1 Wireless LAN" "Enter SSID and passphrase" \
"S3 Password" "Change password for the '$USER' user" \
"S4 Hostname" "Set name for this computer on a network" \
3>&1 1>&2 2>&3)
2013-05-23 01:44:15 +09:00
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
2013-05-23 04:17:32 +09:00
case "$FUN" in
2020-10-08 01:15:23 +09:00
S1\ *) do_wifi_ssid_passphrase ;;
S3\ *) do_change_pass ;;
S4\ *) do_hostname ;;
2013-05-23 04:17:32 +09:00
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
2013-05-23 01:44:15 +09:00
fi
2013-05-19 16:56:35 +09:00
}
2016-11-30 23:48:48 +09:00
do_interface_menu() {
2022-05-15 01:42:08 +09:00
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Interfacing Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"I2 SSH" "Enable/disable remote command line access using SSH" \
2013-05-23 04:21:24 +09:00
3>&1 1>&2 2>&3)
2013-05-23 01:44:15 +09:00
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
2013-05-23 04:21:24 +09:00
case "$FUN" in
2022-05-15 01:42:08 +09:00
I2\ *) do_ssh ;;
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
2013-05-23 01:44:15 +09:00
fi
2013-05-19 16:56:35 +09:00
}
2020-10-08 01:15:23 +09:00
do_internationalisation_menu() {
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-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" \
"L4 WLAN Country" "Set legal wireless channels for your country" \
2020-10-08 01:15:23 +09:00
3>&1 1>&2 2>&3)
2016-09-29 22:21:53 +09:00
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
2020-10-08 01:15:23 +09:00
L1\ *) do_change_locale ;;
L2\ *) do_change_timezone ;;
L4\ *) do_wifi_country ;;
2016-09-29 22:21:53 +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
}
2013-05-19 16:56:35 +09:00
2020-10-08 01:15:23 +09:00
do_advanced_menu() {
2022-05-15 01:42:08 +09:00
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Advanced Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"A1 Expand Filesystem" "Ensures that all of the SD card is available" \
"A4 Network Interface Names" "Enable/disable predictable network i/f names" \
3>&1 1>&2 2>&3)
2017-10-27 15:49:33 +09:00
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
2020-10-08 01:15:23 +09:00
A1\ *) do_expand_rootfs ;;
A4\ *) do_net_names ;;
2017-10-27 15:49:33 +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
}
2012-08-21 05:53:15 +09:00
#
# Interactive use loop
#
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
2016-05-24 19:57:24 +09:00
[ -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
if ! USER=$(whiptail --inputbox "raspi-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
2015-09-15 18:25:53 +09:00
while true; do
2022-05-15 01:42:08 +09:00
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
"1 System Options" "Configure system settings" \
"5 Localisation Options" "Configure language and regional settings" \
"6 Advanced Options" "Configure advanced settings" \
"9 About raspi-config" "Information about this configuration tool" \
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
2020-10-08 01:15:23 +09:00
case "$FUN" in
1\ *) do_system_menu ;;
5\ *) do_internationalisation_menu ;;
6\ *) do_advanced_menu ;;
9\ *) 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