2012-06-11 05:32:01 +09:00
#!/bin/sh
2016-01-08 19:41:39 +09:00
# Part of 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
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
2016-01-23 00:05:27 +09:00
is_pione() {
2022-01-06 17:21:43 +09:00
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
2016-01-23 00:05:27 +09:00
}
is_pitwo() {
2022-01-06 17:21:43 +09:00
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 $?
2016-01-23 00:05:27 +09:00
}
2016-01-23 18:48:28 +09:00
is_pizero() {
2022-01-06 17:21:43 +09:00
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 $?
2016-01-23 18:48:28 +09:00
}
2019-05-15 23:54:09 +09:00
is_pifour() {
2022-01-06 17:21:43 +09:00
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 $?
2019-05-15 23:54:09 +09:00
}
2016-01-23 00:05:27 +09:00
get_pi_type() {
2022-01-06 17:21:43 +09:00
if is_pione; then
echo 1
elif is_pitwo; then
echo 2
else
echo 0
fi
2016-01-23 00:05:27 +09:00
}
2017-01-10 23:11:21 +09:00
is_live() {
2022-01-06 17:21:43 +09:00
grep -q "boot=live" $CMDLINE
return $?
2017-01-10 23:11:21 +09:00
}
2017-01-28 00:29:05 +09:00
is_ssh() {
if pstree -p | egrep --quiet --extended-regexp ".*sshd.*\($$\)"; then
return 0
else
return 1
fi
}
2019-05-15 00:01:45 +09:00
is_fkms() {
2020-02-27 02:52:43 +09:00
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
2019-05-15 00:01:45 +09:00
return 0
else
return 1
fi
}
2020-10-12 19:28:43 +09:00
is_pulseaudio() {
PS=$(ps ax)
echo "$PS" | grep -q pulseaudio
return $?
}
2020-10-24 19:35:32 +09:00
has_analog() {
if [ $(get_leds) -eq -1 ] ; then
return 0
else
return 1
fi
}
2020-02-06 20:52:12 +09:00
is_installed() {
2022-01-06 17:21:43 +09:00
if [ "$(dpkg -l "$1" 2> /dev/null | tail -n 1 | cut -d ' ' -f 1)" != "ii" ]; then
return 1
else
return 0
fi
2020-02-06 20:52:12 +09:00
}
2019-02-19 18:49:41 +09:00
deb_ver () {
ver=`cat /etc/debian_version | cut -d . -f 1`
echo $ver
}
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
2013-03-27 06:58:32 +09:00
configuration of the Raspberry Pi. 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.
$(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
}
2016-05-25 01:28:29 +09:00
get_can_expand() {
2020-05-15 19:10:26 +09:00
ROOT_PART="$(findmnt / -o source -n)"
ROOT_DEV="/dev/$(lsblk -no pkname "$ROOT_PART")"
2016-05-25 01:28:29 +09:00
2020-05-15 19:10:26 +09:00
PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")"
2016-05-25 01:28:29 +09:00
if [ "$PART_NUM" -ne 2 ]; then
echo 1
exit
fi
2020-06-02 01:39:42 +09:00
LAST_PART_NUM=$(parted "$ROOT_DEV" -ms unit s p | tail -n 1 | cut -f 1 -d:)
2020-05-15 19:10:26 +09:00
if [ "$LAST_PART_NUM" -ne "$PART_NUM" ]; then
2016-05-25 01:28:29 +09:00
echo 1
exit
fi
echo 0
}
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
}
2012-07-14 01:01:48 +09:00
set_config_var() {
2013-05-08 23:11:53 +09:00
lua - "$1" "$2" "$3" <<EOF > "$3.bak"
2012-07-14 01:01:48 +09:00
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"
}
2015-11-17 20:35:04 +09:00
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"
}
2012-10-29 05:38:27 +09:00
get_config_var() {
lua - "$1" "$2" <<EOF
local key=assert(arg[1])
local fn=assert(arg[2])
local file=assert(io.open(fn))
2015-09-24 05:25:39 +09:00
local found=false
2012-10-29 05:38:27 +09:00
for line in file:lines() do
2015-09-24 05:25:39 +09:00
local val = line:match("^%s*"..key.."=(.*)$")
2012-10-29 05:38:27 +09:00
if (val ~= nil) then
print(val)
2015-09-24 05:25:39 +09:00
found=true
2012-10-29 05:38:27 +09:00
break
end
end
2015-09-24 05:25:39 +09:00
if not found then
print(0)
end
2012-10-29 05:38:27 +09:00
EOF
}
2016-05-25 01:28:29 +09:00
get_overscan() {
OVS=$(get_config_var disable_overscan $CONFIG)
if [ $OVS -eq 1 ]; then
echo 1
else
echo 0
2012-06-11 05:32:01 +09:00
fi
}
2013-05-23 04:21:24 +09:00
do_overscan() {
2016-05-25 01:28:29 +09:00
DEFAULT=--defaultno
CURRENT=0
if [ $(get_overscan) -eq 0 ]; then
2022-01-06 17:21:43 +09:00
DEFAULT=
CURRENT=1
2016-05-25 01:28:29 +09:00
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
2016-05-25 01:53:44 +09:00
whiptail --yesno "Would you like to enable compensation for displays with overscan?" $DEFAULT 20 60 2
2015-09-15 18:25:53 +09:00
RET=$?
else
RET=$1
fi
2016-05-25 01:28:29 +09:00
if [ $RET -eq $CURRENT ]; then
2012-07-16 02:32:30 +09:00
ASK_TO_REBOOT=1
2016-05-25 01:28:29 +09:00
fi
if [ $RET -eq 0 ] ; then
set_config_var disable_overscan 0 $CONFIG
2016-05-25 02:35:46 +09:00
STATUS=enabled
2016-05-25 01:28:29 +09:00
elif [ $RET -eq 1 ]; then
sed $CONFIG -i -e "s/^overscan_/#overscan_/"
set_config_var disable_overscan 1 $CONFIG
2016-05-25 02:35:46 +09:00
STATUS=disabled
2012-06-11 05:32:01 +09:00
else
2016-05-25 01:28:29 +09:00
return $RET
2012-06-11 05:32:01 +09:00
fi
2016-05-25 02:35:46 +09:00
if [ "$INTERACTIVE" = True ]; then
2016-05-25 22:22:16 +09:00
whiptail --msgbox "Display overscan compensation is $STATUS" 20 60 1
2016-05-25 02:35:46 +09:00
fi
2012-06-11 05:32:01 +09:00
}
2019-12-10 22:09:49 +09:00
get_blanking() {
if ! [ -f "/etc/X11/xorg.conf.d/10-blanking.conf" ]; then
echo 0
else
echo 1
fi
}
# shellcheck disable=SC2120
do_blanking() {
DEFAULT=--defaultno
CURRENT=0
if [ "$(get_blanking)" -eq 0 ]; then
2022-01-06 17:21:43 +09:00
DEFAULT=
CURRENT=1
2019-12-10 22:09:49 +09:00
fi
if [ "$INTERACTIVE" = True ]; then
if [ "$(dpkg -l xscreensaver | tail -n 1 | cut -d ' ' -f 1)" = "ii" ]; then
whiptail --msgbox "Warning: xscreensaver is installed may override raspi-config settings" 20 60 2
fi
whiptail --yesno "Would you like to enable screen blanking?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ "$RET" -eq "$CURRENT" ]; then
ASK_TO_REBOOT=1
fi
rm -f /etc/X11/xorg.conf.d/10-blanking.conf
sed -i '/^\o033/d' /etc/issue
if [ "$RET" -eq 0 ] ; then
STATUS=enabled
elif [ "$RET" -eq 1 ]; then
mkdir -p /etc/X11/xorg.conf.d/
cp /usr/share/raspi-config/10-blanking.conf /etc/X11/xorg.conf.d/
printf "\\033[9;0]" >> /etc/issue
STATUS=disabled
else
return "$RET"
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Screen blanking is $STATUS" 20 60 1
fi
}
2017-11-29 19:14:03 +09:00
get_pixdub() {
2020-02-03 18:38:15 +09:00
if is_pi && ! is_fkms; then
2017-11-29 22:15:24 +09:00
FBW=$(get_config_var framebuffer_width $CONFIG)
if [ $FBW -eq 0 ]; then
echo 1
else
echo 0
fi
2017-11-29 19:14:03 +09:00
else
2020-02-03 18:38:15 +09:00
if grep -q 'scale 0.5x0.5' /usr/share/dispsetup.sh ; then
2017-11-29 22:15:24 +09:00
echo 0
else
echo 1
fi
2017-11-29 19:14:03 +09:00
fi
}
is_number() {
case $1 in
''|*[!0-9]*) return 0 ;;
*) return 1 ;;
esac
}
do_pixdub() {
DEFAULT=--defaultno
CURRENT=0
if [ $(get_pixdub) -eq 0 ]; then
2022-01-06 17:21:43 +09:00
DEFAULT=
CURRENT=1
2017-11-29 19:14:03 +09:00
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like to enable pixel doubling?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
2020-02-03 18:38:15 +09:00
if is_pi && ! is_fkms; then
2017-11-29 22:15:24 +09:00
if [ $RET -eq 0 ] ; then
2022-01-06 17:21:43 +09:00
XVAL=$(xrandr 2>&1 | grep current | cut -f2 -d, | cut -f3 -d' ')
YVAL=$(xrandr 2>&1 | grep current | cut -f2 -d, | cut -f5 -d' ')
if is_number $XVAL || is_number $YVAL ; then
2017-11-29 22:15:24 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Could not read current screen dimensions - unable to enable pixel doubling" 20 60 1
fi
2022-01-06 17:21:43 +09:00
return 1
fi
NEWX=`expr $XVAL / 2`
NEWY=`expr $YVAL / 2`
2017-11-29 22:15:24 +09:00
set_config_var framebuffer_width $NEWX $CONFIG
set_config_var framebuffer_height $NEWY $CONFIG
set_config_var scaling_kernel 8 $CONFIG
STATUS=enabled
elif [ $RET -eq 1 ]; then
clear_config_var framebuffer_width $CONFIG
clear_config_var framebuffer_height $CONFIG
clear_config_var scaling_kernel $CONFIG
STATUS=disabled
else
return $RET
fi
2017-11-29 19:14:03 +09:00
else
2017-11-29 22:15:24 +09:00
if [ $RET -eq 0 ] ; then
2020-02-03 18:38:15 +09:00
if [ -e /usr/share/dispsetup.sh ] ; then
rm /usr/share/dispsetup.sh
fi
echo '#!/bin/sh' > /usr/share/dispsetup.sh
2017-11-29 22:15:24 +09:00
DEV=$(xrandr | grep -w connected | cut -f1 -d' ')
for item in $DEV
do
2020-02-05 17:16:22 +09:00
echo xrandr --output $item --scale 0.5x0.5 --filter nearest >> /usr/share/dispsetup.sh
2017-11-29 22:15:24 +09:00
done
STATUS=enabled
elif [ $RET -eq 1 ]; then
2020-02-03 18:38:15 +09:00
if [ -e /usr/share/dispsetup.sh ] ; then
rm /usr/share/dispsetup.sh
fi
echo '#!/bin/sh' > /usr/share/dispsetup.sh
echo 'exit 0' >> /usr/share/dispsetup.sh
2017-11-29 22:15:24 +09:00
STATUS=disabled
else
return $RET
fi
2020-02-03 18:38:15 +09:00
chmod a+x /usr/share/dispsetup.sh
2017-11-29 19:14:03 +09:00
fi
if [ $RET -eq $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Pixel doubling is $STATUS" 20 60 1
fi
}
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_configure_keyboard() {
2017-11-10 02:25:18 +09:00
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
2017-10-30 21:11:57 +09:00
setsid sh -c 'exec setupcon -k --force <> /dev/tty1 >&0 2>&1'
2015-05-26 07:19:35 +09:00
udevadm trigger --subsystem-match=input --action=change
2015-05-27 16:23:36 +09:00
return 0
2012-06-11 05:32:01 +09:00
}
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
}
2013-05-23 04:21:24 +09:00
do_memory_split() { # Memory Split
2012-10-29 05:38:27 +09:00
if [ -e /boot/start_cd.elf ]; then
# New-style memory split setting
## get current memory split from /boot/config.txt
2017-10-30 21:20:14 +09:00
arm=$(vcgencmd get_mem arm | cut -d '=' -f 2 | cut -d 'M' -f 1)
gpu=$(vcgencmd get_mem gpu | cut -d '=' -f 2 | cut -d 'M' -f 1)
tot=$(($arm+$gpu))
2016-04-22 00:02:13 +09:00
if [ $tot -gt 512 ]; then
2017-10-30 21:20:14 +09:00
CUR_GPU_MEM=$(get_config_var gpu_mem_1024 $CONFIG)
elif [ $tot -gt 256 ]; then
CUR_GPU_MEM=$(get_config_var gpu_mem_512 $CONFIG)
else
CUR_GPU_MEM=$(get_config_var gpu_mem_256 $CONFIG)
fi
2016-04-22 00:02:13 +09:00
if [ -z "$CUR_GPU_MEM" ] || [ $CUR_GPU_MEM = "0" ]; then
2017-10-30 21:20:14 +09:00
CUR_GPU_MEM=$(get_config_var gpu_mem $CONFIG)
fi
2016-04-22 00:02:13 +09:00
[ -z "$CUR_GPU_MEM" ] || [ $CUR_GPU_MEM = "0" ] && CUR_GPU_MEM=64
2012-10-29 05:38:27 +09:00
## ask users what gpu_mem they want
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
2017-07-11 20:24:40 +09:00
NEW_GPU_MEM=$(whiptail --inputbox "How much memory (MB) should the GPU have? e.g. 16/32/64/128/256" \
2015-09-15 18:25:53 +09:00
20 70 -- "$CUR_GPU_MEM" 3>&1 1>&2 2>&3)
else
NEW_GPU_MEM=$1
true
fi
2012-10-29 05:38:27 +09:00
if [ $? -eq 0 ]; then
2017-10-30 21:20:14 +09:00
if [ $(get_config_var gpu_mem_1024 $CONFIG) != "0" ] || [ $(get_config_var gpu_mem_512 $CONFIG) != "0" ] || [ $(get_config_var gpu_mem_256 $CONFIG) != "0" ]; then
2016-04-22 00:02:13 +09:00
if [ "$INTERACTIVE" = True ]; then
2017-10-30 21:20:14 +09:00
whiptail --msgbox "Device-specific memory settings were found. These have been cleared." 20 60 2
fi
clear_config_var gpu_mem_1024 $CONFIG
clear_config_var gpu_mem_512 $CONFIG
clear_config_var gpu_mem_256 $CONFIG
fi
2015-01-30 08:30:09 +09:00
set_config_var gpu_mem "$NEW_GPU_MEM" $CONFIG
2012-10-29 05:38:27 +09:00
ASK_TO_REBOOT=1
fi
else # Old firmware so do start.elf renaming
get_current_memory_split
MEMSPLIT=$(whiptail --menu "Set memory split.\n$MEMSPLIT_DESCRIPTION" 20 60 10 \
"240" "240MiB for ARM, 16MiB for VideoCore" \
"224" "224MiB for ARM, 32MiB for VideoCore" \
"192" "192MiB for ARM, 64MiB for VideoCore" \
"128" "128MiB for ARM, 128MiB for VideoCore" \
3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
set_memory_split ${MEMSPLIT}
ASK_TO_REBOOT=1
fi
2012-08-21 05:53:15 +09:00
fi
}
get_current_memory_split() {
2012-08-10 01:54:01 +09:00
AVAILABLE_SPLITS="128 192 224 240"
2012-08-16 04:41:11 +09:00
MEMSPLIT_DESCRIPTION=""
for SPLIT in $AVAILABLE_SPLITS;do
if [ -e /boot/arm${SPLIT}_start.elf ] && cmp /boot/arm${SPLIT}_start.elf /boot/start.elf >/dev/null 2>&1;then
CURRENT_MEMSPLIT=$SPLIT
MEMSPLIT_DESCRIPTION="Current: ${CURRENT_MEMSPLIT}MiB for ARM, $((256 - $CURRENT_MEMSPLIT))MiB for VideoCore"
break
fi
done
2012-08-21 05:53:15 +09:00
}
set_memory_split() {
cp -a /boot/arm${1}_start.elf /boot/start.elf
sync
2012-06-11 05:32:01 +09:00
}
2013-05-23 04:21:24 +09:00
do_overclock() {
2016-01-23 00:05:27 +09:00
if ! is_pione && ! is_pitwo; then
2019-04-01 20:50:17 +09:00
whiptail --msgbox "Only Pi 1 or Pi 2 can be overclocked with this tool." 20 60 2
2016-01-23 00:05:27 +09:00
return 1
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "\
2012-09-17 19:28:39 +09:00
Be aware that overclocking may reduce the lifetime of your
Raspberry Pi. If overclocking at a certain level causes
2012-10-29 05:54:10 +09:00
system instability, try a more modest overclock. Hold down
shift during boot to temporarily disable overclock.
2019-03-20 00:31:13 +09:00
See https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md for more information.\
2012-09-17 19:28:39 +09:00
" 20 70 1
2022-01-06 17:21:43 +09:00
if is_pione; then
2016-01-08 19:30:24 +09:00
OVERCLOCK=$(whiptail --menu "Choose overclock preset" 20 60 10 \
2015-09-15 18:25:53 +09:00
"None" "700MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \
"Modest" "800MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \
"Medium" "900MHz ARM, 250MHz core, 450MHz SDRAM, 2 overvolt" \
"High" "950MHz ARM, 250MHz core, 450MHz SDRAM, 6 overvolt" \
"Turbo" "1000MHz ARM, 500MHz core, 600MHz SDRAM, 6 overvolt" \
3>&1 1>&2 2>&3)
2022-01-06 17:21:43 +09:00
elif is_pitwo; then
2016-01-23 00:05:27 +09:00
OVERCLOCK=$(whiptail --menu "Choose overclock preset" 20 60 10 \
"None" "900MHz ARM, 250MHz core, 450MHz SDRAM, 0 overvolt" \
"High" "1000MHz ARM, 500MHz core, 500MHz SDRAM, 2 overvolt" \
3>&1 1>&2 2>&3)
2022-01-06 17:21:43 +09:00
fi
2015-09-15 18:25:53 +09:00
else
OVERCLOCK=$1
true
fi
2012-09-17 19:28:39 +09:00
if [ $? -eq 0 ]; then
case "$OVERCLOCK" in
None)
2015-11-17 20:35:04 +09:00
clear_overclock
2012-09-17 19:28:39 +09:00
;;
Modest)
2012-10-29 05:54:10 +09:00
set_overclock Modest 800 250 400 0
2012-09-17 19:28:39 +09:00
;;
Medium)
2012-10-29 05:54:10 +09:00
set_overclock Medium 900 250 450 2
2012-09-17 19:28:39 +09:00
;;
High)
2016-01-23 00:05:27 +09:00
if is_pione; then
set_overclock High 950 250 450 6
else
set_overclock High 1000 500 500 2
fi
2012-09-17 19:28:39 +09:00
;;
Turbo)
2012-10-29 05:54:10 +09:00
set_overclock Turbo 1000 500 600 6
2012-09-17 19:28:39 +09:00
;;
*)
whiptail --msgbox "Programmer error, unrecognised overclock preset" 20 60 2
return 1
;;
esac
ASK_TO_REBOOT=1
fi
}
set_overclock() {
2015-01-30 08:30:09 +09:00
set_config_var arm_freq $2 $CONFIG &&
set_config_var core_freq $3 $CONFIG &&
set_config_var sdram_freq $4 $CONFIG &&
set_config_var over_voltage $5 $CONFIG &&
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Set overclock to preset '$1'" 20 60 2
fi
2012-09-17 19:28:39 +09:00
}
2015-11-17 20:35:04 +09:00
clear_overclock () {
clear_config_var arm_freq $CONFIG &&
clear_config_var core_freq $CONFIG &&
clear_config_var sdram_freq $CONFIG &&
clear_config_var over_voltage $CONFIG &&
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Set overclock to preset 'None'" 20 60 2
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
}
2016-08-11 00:04:28 +09:00
get_vnc() {
2020-02-06 22:26:56 +09:00
if systemctl status vncserver-x11-serviced.service | grep -q -w active; then
2016-08-11 00:04:28 +09:00
echo 0
2020-02-06 22:26:56 +09:00
else
echo 1
2016-08-11 00:04:28 +09:00
fi
}
do_vnc() {
DEFAULT=--defaultno
if [ $(get_vnc) -eq 0 ]; then
DEFAULT=
fi
2022-01-12 18:06:17 +09:00
APT_GET_FLAGS=""
2016-08-11 00:04:28 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the VNC Server to be enabled?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
2022-01-12 18:06:17 +09:00
APT_GET_FLAGS="-y"
2016-08-11 00:04:28 +09:00
fi
if [ $RET -eq 0 ]; then
2022-01-12 18:06:17 +09:00
if is_installed realvnc-vnc-server || apt-get install "$APT_GET_FLAGS" realvnc-vnc-server; then
2020-01-13 21:49:43 +09:00
systemctl enable vncserver-x11-serviced.service &&
systemctl start vncserver-x11-serviced.service &&
STATUS=enabled
else
return 1
2017-02-24 03:18:18 +09:00
fi
2016-08-11 00:04:28 +09:00
elif [ $RET -eq 1 ]; then
2020-02-07 21:52:14 +09:00
if is_installed realvnc-vnc-server; then
2022-01-06 17:21:43 +09:00
systemctl disable vncserver-x11-serviced.service
systemctl stop vncserver-x11-serviced.service
2020-02-07 21:52:14 +09:00
fi
2016-08-11 00:04:28 +09:00
STATUS=disabled
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The VNC Server is $STATUS" 20 60 1
fi
}
2016-05-23 22:20:18 +09:00
get_spi() {
2016-05-24 19:57:24 +09:00
if grep -q -E "^(device_tree_param|dtparam)=([^,]*,)*spi(=(on|true|yes|1))?(,.*)?$" $CONFIG; then
2016-05-23 22:20:18 +09:00
echo 0
else
echo 1
fi
}
2016-05-19 23:11:12 +09:00
do_spi() {
DEFAULT=--defaultno
2016-05-23 22:20:18 +09:00
if [ $(get_spi) -eq 0 ]; then
2016-05-19 23:11:12 +09:00
DEFAULT=
2015-01-30 08:30:09 +09:00
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
2016-05-19 23:11:12 +09:00
whiptail --yesno "Would you like the SPI interface to be enabled?" $DEFAULT 20 60 2
2015-09-15 18:25:53 +09:00
RET=$?
else
RET=$1
fi
2015-01-30 08:30:09 +09:00
if [ $RET -eq 0 ]; then
2016-05-19 23:11:12 +09:00
SETTING=on
STATUS=enabled
2015-01-30 08:30:09 +09:00
elif [ $RET -eq 1 ]; then
2016-05-19 23:11:12 +09:00
SETTING=off
STATUS=disabled
2015-01-30 08:30:09 +09:00
else
2016-05-24 21:01:17 +09:00
return $RET
2015-01-30 08:30:09 +09:00
fi
2016-05-24 21:01:17 +09:00
2016-05-19 23:11:12 +09:00
set_config_var dtparam=spi $SETTING $CONFIG &&
2015-02-01 05:18:38 +09:00
if ! [ -e $BLACKLIST ]; then
touch $BLACKLIST
fi
2016-04-27 22:25:39 +09:00
sed $BLACKLIST -i -e "s/^\(blacklist[[:space:]]*spi[-_]bcm2708\)/#\1/"
2016-05-19 23:11:12 +09:00
dtparam spi=$SETTING
2016-05-25 02:35:46 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The SPI interface is $STATUS" 20 60 1
fi
2013-09-26 02:56:38 +09:00
}
2016-05-23 22:20:18 +09:00
get_i2c() {
2016-05-24 19:57:24 +09:00
if grep -q -E "^(device_tree_param|dtparam)=([^,]*,)*i2c(_arm)?(=(on|true|yes|1))?(,.*)?$" $CONFIG; then
2016-05-23 22:20:18 +09:00
echo 0
else
echo 1
fi
}
2014-09-01 19:44:45 +09:00
do_i2c() {
2015-01-30 08:30:09 +09:00
DEFAULT=--defaultno
2016-05-23 22:20:18 +09:00
if [ $(get_i2c) -eq 0 ]; then
2015-01-30 08:30:09 +09:00
DEFAULT=
fi
2016-05-19 23:11:12 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the ARM I2C interface to be enabled?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq 0 ]; then
SETTING=on
STATUS=enabled
elif [ $RET -eq 1 ]; then
SETTING=off
STATUS=disabled
else
2016-05-24 21:01:17 +09:00
return $RET
2015-01-30 08:30:09 +09:00
fi
2016-05-19 23:11:12 +09:00
set_config_var dtparam=i2c_arm $SETTING $CONFIG &&
2015-02-01 05:18:38 +09:00
if ! [ -e $BLACKLIST ]; then
touch $BLACKLIST
fi
2016-04-27 22:25:39 +09:00
sed $BLACKLIST -i -e "s/^\(blacklist[[:space:]]*i2c[-_]bcm2708\)/#\1/"
sed /etc/modules -i -e "s/^#[[:space:]]*\(i2c[-_]dev\)/\1/"
if ! grep -q "^i2c[-_]dev" /etc/modules; then
printf "i2c-dev\n" >> /etc/modules
2014-09-01 19:44:45 +09:00
fi
2016-05-19 23:11:12 +09:00
dtparam i2c_arm=$SETTING
2016-04-27 22:25:39 +09:00
modprobe i2c-dev
2016-05-25 02:35:46 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The ARM I2C interface is $STATUS" 20 60 1
fi
2014-09-01 19:44:45 +09:00
}
2016-05-06 22:47:12 +09:00
get_serial() {
2017-01-11 03:11:31 +09:00
if grep -q -E "console=(serial0|ttyAMA0|ttyS0)" $CMDLINE ; then
echo 0
2016-05-06 22:47:12 +09:00
else
2017-01-11 03:11:31 +09:00
echo 1
fi
}
get_serial_hw() {
if grep -q -E "^enable_uart=1" $CONFIG ; then
echo 0
elif grep -q -E "^enable_uart=0" $CONFIG ; then
echo 1
elif [ -e /dev/serial0 ] ; then
echo 0
else
echo 1
2016-05-06 22:47:12 +09:00
fi
}
2014-09-03 01:25:58 +09:00
do_serial() {
2017-01-11 03:11:31 +09:00
DEFAULTS=--defaultno
DEFAULTH=--defaultno
CURRENTS=0
CURRENTH=0
2016-05-25 01:28:29 +09:00
if [ $(get_serial) -eq 0 ]; then
2022-01-06 17:21:43 +09:00
DEFAULTS=
CURRENTS=1
2017-01-11 03:11:31 +09:00
fi
if [ $(get_serial_hw) -eq 0 ]; then
2022-01-06 17:21:43 +09:00
DEFAULTH=
CURRENTH=1
2014-09-03 01:25:58 +09:00
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
2017-01-11 03:11:31 +09:00
whiptail --yesno "Would you like a login shell to be accessible over serial?" $DEFAULTS 20 60 2
2015-09-15 18:25:53 +09:00
RET=$?
else
RET=$1
fi
2017-01-11 03:11:31 +09:00
if [ $RET -eq $CURRENTS ]; then
2016-05-24 19:37:36 +09:00
ASK_TO_REBOOT=1
fi
2016-05-24 21:01:17 +09:00
if [ $RET -eq 0 ]; then
2016-10-11 18:33:02 +09:00
if grep -q "console=ttyAMA0" $CMDLINE ; then
2016-02-23 23:20:45 +09:00
if [ -e /proc/device-tree/aliases/serial0 ]; then
2016-10-11 18:33:02 +09:00
sed -i $CMDLINE -e "s/console=ttyAMA0/console=serial0/"
2016-02-23 23:20:45 +09:00
fi
2016-10-11 18:33:02 +09:00
elif ! grep -q "console=ttyAMA0" $CMDLINE && ! grep -q "console=serial0" $CMDLINE ; then
2016-02-23 23:20:45 +09:00
if [ -e /proc/device-tree/aliases/serial0 ]; then
2016-10-11 18:33:02 +09:00
sed -i $CMDLINE -e "s/root=/console=serial0,115200 root=/"
2016-02-23 23:20:45 +09:00
else
2016-10-11 18:33:02 +09:00
sed -i $CMDLINE -e "s/root=/console=ttyAMA0,115200 root=/"
2016-02-23 23:20:45 +09:00
fi
2014-09-03 01:25:58 +09:00
fi
2016-04-22 01:28:02 +09:00
set_config_var enable_uart 1 $CONFIG
2017-01-11 03:11:31 +09:00
SSTATUS=enabled
HSTATUS=enabled
2018-04-30 19:04:26 +09:00
elif [ $RET -eq 1 ] || [ $RET -eq 2 ]; then
2016-10-11 18:33:02 +09:00
sed -i $CMDLINE -e "s/console=ttyAMA0,[0-9]\+ //"
sed -i $CMDLINE -e "s/console=serial0,[0-9]\+ //"
2017-01-11 03:11:31 +09:00
SSTATUS=disabled
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the serial port hardware to be enabled?" $DEFAULTH 20 60 2
RET=$?
else
2018-04-30 19:04:26 +09:00
RET=$((2-$RET))
2017-01-11 03:11:31 +09:00
fi
if [ $RET -eq $CURRENTH ]; then
2022-01-06 17:21:43 +09:00
ASK_TO_REBOOT=1
2017-01-11 03:11:31 +09:00
fi
if [ $RET -eq 0 ]; then
set_config_var enable_uart 1 $CONFIG
HSTATUS=enabled
elif [ $RET -eq 1 ]; then
set_config_var enable_uart 0 $CONFIG
HSTATUS=disabled
else
return $RET
fi
2014-09-03 01:25:58 +09:00
else
return $RET
fi
2016-05-24 21:01:17 +09:00
if [ "$INTERACTIVE" = True ]; then
2022-01-06 17:21:43 +09:00
whiptail --msgbox "The serial login shell is $SSTATUS\nThe serial interface is $HSTATUS" 20 60 1
2016-05-24 21:01:17 +09:00
fi
2014-09-03 01:25:58 +09:00
}
2013-09-10 07:55:22 +09:00
disable_raspi_config_at_boot() {
if [ -e /etc/profile.d/raspi-config.sh ]; then
rm -f /etc/profile.d/raspi-config.sh
2017-07-14 18:21:07 +09:00
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
2015-05-29 19:35:13 +09:00
fi
2013-09-10 07:55:22 +09:00
telinit q
fi
}
2016-05-24 01:17:37 +09:00
get_boot_cli() {
2017-02-18 00:55:35 +09:00
if systemctl get-default | grep -q multi-user ; then
2016-05-24 01:17:37 +09:00
echo 0
else
echo 1
fi
}
get_autologin() {
if [ $(get_boot_cli) -eq 0 ]; then
2019-02-19 18:49:41 +09:00
# booting to CLI
# stretch or buster - is there an autologin conf file?
2019-01-15 20:30:14 +09:00
if [ -e /etc/systemd/system/getty@tty1.service.d/autologin.conf ] ; then
2017-07-14 18:21:07 +09:00
echo 0
2016-05-24 01:17:37 +09:00
else
2019-02-19 18:49:41 +09:00
# stretch or earlier - check the getty service symlink for autologin
if [ $(deb_ver) -le 9 ] && grep -q autologin /etc/systemd/system/getty.target.wants/getty@tty1.service ; then
echo 0
else
echo 1
fi
2016-05-24 01:17:37 +09:00
fi
else
2019-02-19 18:49:41 +09:00
# booting to desktop - check the autologin for lightdm
2017-07-14 18:21:07 +09:00
if grep -q "^autologin-user=" /etc/lightdm/lightdm.conf ; then
2016-05-24 01:17:37 +09:00
echo 0
else
echo 1
fi
fi
}
2019-05-15 23:54:09 +09:00
get_pi4video () {
2019-07-09 21:32:18 +09:00
if grep -q "^hdmi_enable_4kp60=1" $CONFIG ; then
2019-05-15 23:54:09 +09:00
echo 1
2019-06-19 23:56:53 +09:00
elif grep -q "^enable_tvout=1" $CONFIG ; then
2019-05-15 23:54:09 +09:00
echo 2
else
echo 0
fi
}
do_pi4video() {
if ! is_pifour ; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "This option can only be used on a Pi 4" 20 60 1
fi
return 1
fi
CURRENT=$(get_pi4video)
if [ "$INTERACTIVE" = True ]; then
VIDOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Pi 4 Video Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \
2021-01-19 23:52:51 +09:00
"V1 Enable 4Kp60 HDMI" "Enable 4Kp60 resolution on HDMI0" \
"V2 Enable composite " "Enable composite video output (disables HDMI)" \
"V3 Default" "Disable 4Kp60 HDMI and composite video" \
2019-05-15 23:54:09 +09:00
3>&1 1>&2 2>&3)
else
VIDOPT=$1
true
fi
if [ $? -eq 0 ]; then
case "$VIDOPT" in
V1*)
2019-07-09 21:32:18 +09:00
sed $CONFIG -i -e "s/^#\?hdmi_enable_4kp60=.*/hdmi_enable_4kp60=1/"
2019-06-19 23:56:53 +09:00
sed $CONFIG -i -e "s/^enable_tvout=/#enable_tvout=/"
2019-07-09 21:32:18 +09:00
if ! grep -q "hdmi_enable_4kp60" $CONFIG ; then
2022-01-06 17:21:43 +09:00
sed $CONFIG -i -e "\$ahdmi_enable_4kp60=1"
2019-05-15 23:54:09 +09:00
fi
2021-11-11 23:14:07 +09:00
sed $CONFIG -i -e "s/^dtoverlay=vc4-kms-v3d.*/dtoverlay=vc4-kms-v3d/"
2021-01-19 23:52:51 +09:00
STATUS="4Kp60 is enabled on HDMI0"
2019-05-15 23:54:09 +09:00
OPT=1
;;
V2*)
2021-01-19 23:52:51 +09:00
if whiptail --yesno "If composite video is enabled, both HDMI outputs will be disabled, and unless a composite monitor is connected, no video output will be available.\n\nAre you sure you want to enable composite and disable HDMI?" 20 60 2 --defaultno ; then
sed $CONFIG -i -e "s/^#\?enable_tvout=.*/enable_tvout=1/"
sed $CONFIG -i -e "s/^hdmi_enable_4kp60=/#hdmi_enable_4kp60=/"
if ! grep -q "enable_tvout" $CONFIG ; then
2022-01-06 17:21:43 +09:00
sed $CONFIG -i -e "\$aenable_tvout=1"
2021-01-19 23:52:51 +09:00
fi
2021-11-11 23:14:07 +09:00
sed $CONFIG -i -e "s/^dtoverlay=vc4-kms-v3d.*/dtoverlay=vc4-kms-v3d,composite/"
2021-01-19 23:52:51 +09:00
STATUS="Composite video is enabled. HDMI is disabled."
OPT=2
else
STATUS="Video output settings unchanged"
OPT=$CURRENT
2019-05-15 23:54:09 +09:00
fi
;;
V3*)
2019-07-09 21:32:18 +09:00
sed $CONFIG -i -e "s/^hdmi_enable_4kp60=/#hdmi_enable_4kp60=/"
2019-06-19 23:56:53 +09:00
sed $CONFIG -i -e "s/^enable_tvout=/#enable_tvout=/"
2021-11-11 23:14:07 +09:00
sed $CONFIG -i -e "s/^dtoverlay=vc4-kms-v3d.*/dtoverlay=vc4-kms-v3d/"
2021-01-19 23:52:51 +09:00
STATUS="Both HDMI ports set to defaults - 4Kp60 and composite disabled"
2019-05-15 23:54:09 +09:00
OPT=0
;;
*)
whiptail --msgbox "Programmer error, unrecognised video option" 20 60 2
return 1
;;
esac
if [ $OPT -ne $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ "$INTERACTIVE" = True ]; then
2021-01-19 23:52:51 +09:00
whiptail --msgbox "$STATUS" 20 60 1
2019-05-15 23:54:09 +09:00
fi
fi
}
2021-11-11 23:14:07 +09:00
get_composite() {
if grep -q "^dtoverlay=vc4-kms-v3d,composite" $CONFIG ; then
echo 0
else
echo 1
fi
}
do_composite() {
CURRENT=$(get_composite)
DEFAULT=--defaultno
if [ $CURRENT -eq 0 ]; then
DEFAULT=
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like composite video output to be enabled?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq 0 ]; then
sed $CONFIG -i -e "s/^dtoverlay=vc4-kms-v3d.*/dtoverlay=vc4-kms-v3d,composite/"
STATUS=enabled
elif [ $RET -eq 1 ]; then
sed $CONFIG -i -e "s/^dtoverlay=vc4-kms-v3d.*/dtoverlay=vc4-kms-v3d/"
STATUS=disabled
else
return $RET
fi
if [ $RET -ne $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Composite video output is $STATUS" 20 60 1
fi
}
2020-09-02 19:47:21 +09:00
get_leds () {
if grep -q "\\[actpwr\\]" /sys/class/leds/led0/trigger ; then
echo 0
2020-09-04 00:38:34 +09:00
elif grep -q "\\[default-on\\]" /sys/class/leds/led0/trigger ; then
2020-09-02 21:55:40 +09:00
echo 1
2020-09-04 00:38:34 +09:00
else
echo -1
2020-09-02 19:47:21 +09:00
fi
}
do_leds() {
2020-09-04 00:38:34 +09:00
CURRENT=$(get_leds)
if [ $CURRENT -eq -1 ] ; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The LED behaviour cannot be changed on this model of Raspberry Pi" 20 60 1
fi
return 1
fi
2020-09-02 19:47:21 +09:00
DEFAULT=--defaultno
2020-09-04 00:38:34 +09:00
if [ $CURRENT -eq 0 ]; then
2020-09-02 19:47:21 +09:00
DEFAULT=
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the power LED to flash during disk activity?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq 0 ]; then
LEDSET="actpwr"
STATUS="flash for disk activity"
elif [ $RET -eq 1 ]; then
LEDSET="default-on"
STATUS="be on constantly"
else
return $RET
fi
sed $CONFIG -i -e "s/dtparam=act_led_trigger=.*/dtparam=act_led_trigger=$LEDSET/"
if ! grep -q "dtparam=act_led_trigger" $CONFIG ; then
sed $CONFIG -i -e "\$adtparam=act_led_trigger=$LEDSET"
fi
echo $LEDSET | tee /sys/class/leds/led0/trigger > /dev/null
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The power LED will $STATUS" 20 60 1
fi
}
2019-05-15 23:54:09 +09:00
2020-10-06 02:45:22 +09:00
get_fan() {
if grep -q ^dtoverlay=gpio-fan $CONFIG ; then
echo 0
else
echo 1
fi
}
get_fan_gpio() {
GPIO=$(grep ^dtoverlay=gpio-fan $CONFIG | cut -d, -f2 | cut -d= -f2)
if [ -z $GPIO ]; then
GPIO=14
fi
echo $GPIO
}
get_fan_temp() {
TEMP=$(grep ^dtoverlay=gpio-fan $CONFIG | cut -d, -f3 | cut -d= -f2)
if [ -z $TEMP ]; then
TEMP=80000
fi
echo $(( $TEMP / 1000 ))
}
do_fan() {
GNOW=$(get_fan_gpio)
TNOW=$(get_fan_temp)
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like to enable fan temperature control?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq 0 ] ; then
if [ "$INTERACTIVE" = True ]; then
GPIO=$(whiptail --inputbox "To which GPIO is the fan connected?" 20 60 "$GNOW" 3>&1 1>&2 2>&3)
else
if [ -z $2 ]; then
GPIO=14
else
GPIO=$2
fi
fi
2020-10-13 00:19:35 +09:00
if ! [ $? -eq 0 ] ; then
return 0
fi
2020-10-06 23:11:23 +09:00
if ! echo "$GPIO" | grep -q ^[[:digit:]]*$ ; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "GPIO must be a number between 2 and 27" 20 60 1
fi
return 1
fi
if [ "$GPIO" -lt 2 ] || [ "$GPIO" -gt 27 ] ; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "GPIO must be a number between 2 and 27" 20 60 1
fi
return 1
fi
2020-10-06 02:45:22 +09:00
if [ "$INTERACTIVE" = True ]; then
TIN=$(whiptail --inputbox "At what temperature in degrees should the fan turn on?" 20 60 "$TNOW" 3>&1 1>&2 2>&3)
else
if [ -z $3 ]; then
TIN=80
else
TIN=$3
fi
fi
2020-10-13 00:19:35 +09:00
if ! [ $? -eq 0 ] ; then
return 0
fi
2020-10-06 23:11:23 +09:00
if ! echo "$TIN" | grep -q ^[[:digit:]]*$ ; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Temperature must be a number between 60 and 120" 20 60 1
fi
return 1
fi
if [ "$TIN" -lt 60 ] || [ "$TIN" -gt 120 ] ; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Temperature must be a number between 60 and 120" 20 60 1
fi
return 1
fi
2020-10-06 02:45:22 +09:00
TEMP=$(( $TIN * 1000 ))
fi
if [ $RET -eq 0 ]; then
if ! grep -q "dtoverlay=gpio-fan" $CONFIG ; then
2020-10-06 02:45:52 +09:00
if ! tail -1 $CONFIG | grep -q "\\[all\\]" ; then
2020-10-06 02:45:22 +09:00
sed $CONFIG -i -e "\$a[all]"
fi
2020-11-08 20:37:54 +09:00
sed $CONFIG -i -e "\$adtoverlay=gpio-fan,gpiopin=$GPIO,temp=$TEMP"
2020-10-06 02:45:22 +09:00
else
2020-11-08 20:37:54 +09:00
sed $CONFIG -i -e "s/^.*dtoverlay=gpio-fan.*/dtoverlay=gpio-fan,gpiopin=$GPIO,temp=$TEMP/"
2020-10-06 02:45:22 +09:00
fi
2020-10-13 00:19:35 +09:00
ASK_TO_REBOOT=1
2020-10-06 02:45:22 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The fan on GPIO $GPIO is enabled and will turn on at $TIN degrees" 20 60 1
fi
else
2020-10-13 00:19:35 +09:00
if grep -q "^dtoverlay=gpio-fan" $CONFIG ; then
ASK_TO_REBOOT=1
fi
2020-10-06 02:45:22 +09:00
sed $CONFIG -i -e "/^.*dtoverlay=gpio-fan.*/d"
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The fan is disabled" 20 60 1
fi
fi
}
2016-05-24 01:17:37 +09:00
do_boot_behaviour() {
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
BOOTOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Boot Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \
"B1 Console" "Text console, requiring user to login" \
2020-01-09 23:37:08 +09:00
"B2 Console Autologin" "Text console, automatically logged in as '$USER' user" \
2015-09-15 18:25:53 +09:00
"B3 Desktop" "Desktop GUI, requiring user to login" \
2020-01-09 23:37:08 +09:00
"B4 Desktop Autologin" "Desktop GUI, automatically logged in as '$USER' user" \
2015-09-15 18:25:53 +09:00
3>&1 1>&2 2>&3)
else
BOOTOPT=$1
true
fi
if [ $? -eq 0 ]; then
case "$BOOTOPT" in
B1*)
2017-07-14 18:21:07 +09:00
systemctl set-default multi-user.target
ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
2019-01-15 00:18:04 +09:00
rm /etc/systemd/system/getty@tty1.service.d/autologin.conf
2015-09-15 18:25:53 +09:00
;;
B2*)
2017-07-14 18:21:07 +09:00
systemctl set-default multi-user.target
2019-01-15 00:18:04 +09:00
ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
cat > /etc/systemd/system/getty@tty1.service.d/autologin.conf << EOF
[Service]
ExecStart=
2020-01-09 23:37:08 +09:00
ExecStart=-/sbin/agetty --autologin $USER --noclear %I \$TERM
2019-01-15 00:18:04 +09:00
EOF
2015-09-15 18:25:53 +09:00
;;
B3*)
if [ -e /etc/init.d/lightdm ]; then
2017-07-14 18:21:07 +09:00
systemctl set-default graphical.target
ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
2019-01-15 00:18:04 +09:00
rm /etc/systemd/system/getty@tty1.service.d/autologin.conf
2016-10-21 23:10:56 +09:00
sed /etc/lightdm/lightdm.conf -i -e "s/^autologin-user=.*/#autologin-user=/"
2015-09-15 18:25:53 +09:00
disable_raspi_config_at_boot
else
2017-07-14 18:21:07 +09:00
whiptail --msgbox "Do 'sudo apt-get install lightdm' to allow configuration of boot to desktop" 20 60 2
2015-09-15 18:25:53 +09:00
return 1
fi
;;
B4*)
if [ -e /etc/init.d/lightdm ]; then
2017-07-14 18:21:07 +09:00
systemctl set-default graphical.target
2019-01-15 00:18:04 +09:00
ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
cat > /etc/systemd/system/getty@tty1.service.d/autologin.conf << EOF
[Service]
ExecStart=
2020-01-09 23:37:08 +09:00
ExecStart=-/sbin/agetty --autologin $USER --noclear %I \$TERM
2019-01-15 00:18:04 +09:00
EOF
2020-01-09 23:37:08 +09:00
sed /etc/lightdm/lightdm.conf -i -e "s/^\(#\|\)autologin-user=.*/autologin-user=$USER/"
2017-07-14 18:21:07 +09:00
disable_raspi_config_at_boot
2015-09-15 18:25:53 +09:00
else
2017-07-14 18:21:07 +09:00
whiptail --msgbox "Do 'sudo apt-get install lightdm' to allow configuration of boot to desktop" 20 60 2
2015-09-15 18:25:53 +09:00
return 1
fi
;;
*)
whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2
return 1
;;
esac
ASK_TO_REBOOT=1
fi
}
2020-06-19 17:31:38 +09:00
do_boot_order() {
if [ "$INTERACTIVE" = True ]; then
BOOTOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Boot Device Order" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \
2021-02-10 19:26:30 +09:00
"B1 SD Card Boot" "Boot from SD Card if available, otherwise boot from USB" \
"B2 USB Boot" "Boot from USB if available, otherwise boot from SD Card" \
"B3 Network Boot" "Boot from network if SD card boot fails" \
2020-06-19 17:31:38 +09:00
3>&1 1>&2 2>&3)
else
BOOTOPT=$1
true
fi
if [ $? -eq 0 ]; then
CURDATE=$(date -d "`vcgencmd bootloader_version | head -n 1`" +%Y%m%d)
FILNAME="none"
2020-07-06 05:20:10 +09:00
if grep -q "stable" /etc/default/rpi-eeprom-update ; then
2020-07-07 00:22:13 +09:00
EEPATH="/lib/firmware/raspberrypi/bootloader/stable/pieeprom*.bin"
2020-07-06 05:20:10 +09:00
else
2020-07-07 00:22:13 +09:00
EEPATH="/lib/firmware/raspberrypi/bootloader/critical/pieeprom*.bin"
2020-07-06 05:20:10 +09:00
fi
for filename in $EEPATH ; do
2020-06-19 17:31:38 +09:00
FILDATE=$(date -d "`echo $filename | cut -d - -f 2- | cut -d . -f 1`" +%Y%m%d)
if [ $FILDATE -eq $CURDATE ]; then
FILNAME=$filename
fi
done
if [ "$FILNAME" = "none" ]; then
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "No EEPROM bin file found for version `date -d $CURDATE +%Y-%m-%d` - aborting" 20 60 2
fi
return 1
fi
EECFG=$(mktemp)
vcgencmd bootloader_config > $EECFG
2020-06-22 21:30:34 +09:00
sed $EECFG -i -e "/SD_BOOT_MAX_RETRIES/d"
sed $EECFG -i -e "/NET_BOOT_MAX_RETRIES/d"
2020-06-19 17:31:38 +09:00
case "$BOOTOPT" in
B1*)
if ! grep -q "BOOT_ORDER" $EECFG ; then
sed $EECFG -i -e "\$a[all]\nBOOT_ORDER=0xf41"
else
sed $EECFG -i -e "s/^BOOT_ORDER=.*/BOOT_ORDER=0xf41/"
fi
2021-02-10 19:26:30 +09:00
STATUS="SD Card"
2020-06-19 17:31:38 +09:00
;;
B2*)
2021-02-10 19:26:30 +09:00
if ! grep -q "BOOT_ORDER" $EECFG ; then
sed $EECFG -i -e "\$a[all]\nBOOT_ORDER=0xf14"
else
sed $EECFG -i -e "s/^BOOT_ORDER=.*/BOOT_ORDER=0xf14/"
fi
STATUS="USB"
;;
B3*)
2020-06-19 17:31:38 +09:00
if ! grep -q "BOOT_ORDER" $EECFG ; then
sed $EECFG -i -e "\$a[all]\nBOOT_ORDER=0xf21"
else
sed $EECFG -i -e "s/^BOOT_ORDER=.*/BOOT_ORDER=0xf21/"
fi
STATUS="Network"
;;
*)
whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2
return 1
;;
esac
EEBIN=$(mktemp)
rpi-eeprom-config --config $EECFG --out $EEBIN $FILNAME
rpi-eeprom-update -d -f $EEBIN
ASK_TO_REBOOT=1
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "$STATUS is default boot device" 20 60 1
fi
fi
}
2020-07-06 05:20:10 +09:00
2020-07-06 15:22:54 +09:00
do_boot_rom() {
2020-07-06 05:20:10 +09:00
if [ "$INTERACTIVE" = True ]; then
2020-07-06 15:22:54 +09:00
BOOTOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Boot ROM Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \
2020-07-06 22:04:52 +09:00
"E1 Latest" "Use the latest version boot ROM software" \
"E2 Default" "Use the factory default boot ROM software" \
2020-07-06 05:20:10 +09:00
3>&1 1>&2 2>&3)
else
BOOTOPT=$1
true
fi
if [ $? -eq 0 ]; then
case "$BOOTOPT" in
E1*)
2020-07-07 17:26:35 +09:00
sed /etc/default/rpi-eeprom-update -i -e "s/^FIRMWARE_RELEASE_STATUS.*/FIRMWARE_RELEASE_STATUS=\"stable\"/"
2020-07-06 22:04:52 +09:00
EETYPE="Latest version"
2020-07-06 05:20:10 +09:00
;;
E2*)
2020-07-07 17:26:35 +09:00
sed /etc/default/rpi-eeprom-update -i -e "s/^FIRMWARE_RELEASE_STATUS.*/FIRMWARE_RELEASE_STATUS=\"critical\"/"
2020-07-06 22:04:52 +09:00
EETYPE="Factory default"
2020-07-06 05:20:10 +09:00
;;
*)
2020-07-06 15:22:54 +09:00
whiptail --msgbox "Programmer error, unrecognised boot ROM option" 20 60 2
2020-07-06 05:20:10 +09:00
return 1
;;
esac
if [ "$INTERACTIVE" = True ]; then
2020-07-06 22:04:52 +09:00
whiptail --yesno "$EETYPE boot ROM selected - will be loaded at next reboot.\n\nReset boot ROM to defaults?" 20 60 2
2020-07-06 15:22:54 +09:00
DEFAULTS=$?
2022-01-06 17:21:43 +09:00
else
2020-07-06 15:22:54 +09:00
DEFAULTS=$2
fi
if [ "$DEFAULTS" -eq 0 ]; then # yes
if grep -q "stable" /etc/default/rpi-eeprom-update ; then
2020-07-06 22:04:52 +09:00
EEPATH="/lib/firmware/raspberrypi/bootloader/stable/"
2020-07-06 15:22:54 +09:00
else
2020-07-06 22:04:52 +09:00
EEPATH="/lib/firmware/raspberrypi/bootloader/critical/"
2020-07-06 15:22:54 +09:00
fi
2020-07-06 22:04:52 +09:00
MATCH=".*/pieeprom-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].bin"
FILNAME="$(find "${EEPATH}" -maxdepth 1 -type f -size 524288c -regex "${MATCH}" | sort -r | head -n1)"
if [ -z "$FILNAME" ]; then
2020-07-06 15:22:54 +09:00
if [ "$INTERACTIVE" = True ]; then
2020-07-06 22:04:52 +09:00
whiptail --msgbox "No EEPROM bin file found - cannot reset to defaults" 20 60 2
2020-07-06 05:20:10 +09:00
fi
else
2020-07-06 15:22:54 +09:00
rpi-eeprom-update -d -f $FILNAME
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Boot ROM reset to defaults" 20 60 2
fi
2020-07-06 05:20:10 +09:00
fi
else
rpi-eeprom-update
2020-07-06 15:22:54 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Boot ROM not reset to defaults" 20 60 2
fi
2020-07-06 05:20:10 +09:00
fi
ASK_TO_REBOOT=1
fi
}
2016-05-25 21:53:55 +09:00
get_boot_wait() {
2016-05-23 22:54:26 +09:00
if test -e /etc/systemd/system/dhcpcd.service.d/wait.conf; then
echo 0
2016-05-24 01:17:37 +09:00
else
echo 1
2016-05-23 22:54:26 +09:00
fi
}
2016-05-25 21:53:55 +09:00
do_boot_wait() {
DEFAULT=--defaultno
if [ $(get_boot_wait) -eq 0 ]; then
DEFAULT=
fi
2015-10-19 20:58:20 +09:00
if [ "$INTERACTIVE" = True ]; then
2016-05-25 21:53:55 +09:00
whiptail --yesno "Would you like boot to wait until a network connection is established?" $DEFAULT 20 60 2
RET=$?
2015-10-19 20:58:20 +09:00
else
RET=$1
fi
2016-05-25 21:53:55 +09:00
if [ $RET -eq 0 ]; then
mkdir -p /etc/systemd/system/dhcpcd.service.d/
cat > /etc/systemd/system/dhcpcd.service.d/wait.conf << EOF
2015-10-19 20:58:20 +09:00
[Service]
ExecStart=
2022-01-10 20:55:59 +09:00
ExecStart=/usr/sbin/dhcpcd -w -q
2015-10-19 20:58:20 +09:00
EOF
2016-05-25 21:53:55 +09:00
STATUS=enabled
elif [ $RET -eq 1 ]; then
rm -f /etc/systemd/system/dhcpcd.service.d/wait.conf
STATUS=disabled
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Waiting for network on boot is $STATUS" 20 60 1
2015-10-19 20:58:20 +09:00
fi
}
2016-09-29 22:21:53 +09:00
get_boot_splash() {
2017-05-18 21:24:03 +09:00
if is_pi ; then
if grep -q "splash" $CMDLINE ; then
echo 0
else
echo 1
fi
2016-09-29 22:21:53 +09:00
else
2017-05-18 21:24:03 +09:00
if grep -q "GRUB_CMDLINE_LINUX_DEFAULT.*splash" /etc/default/grub ; then
echo 0
else
echo 1
fi
2016-09-29 22:21:53 +09:00
fi
}
do_boot_splash() {
if [ ! -e /usr/share/plymouth/themes/pix/pix.script ]; then
2017-01-10 20:47:45 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The splash screen is not installed so cannot be activated" 20 60 2
fi
2016-09-29 22:21:53 +09:00
return 1
fi
DEFAULT=--defaultno
if [ $(get_boot_splash) -eq 0 ]; then
DEFAULT=
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like to show the splash screen at boot?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq 0 ]; then
2017-10-30 21:20:14 +09:00
if is_pi ; then
if ! grep -q "splash" $CMDLINE ; then
sed -i $CMDLINE -e "s/$/ quiet splash plymouth.ignore-serial-consoles/"
fi
else
sed -i /etc/default/grub -e "s/GRUB_CMDLINE_LINUX_DEFAULT=\"\(.*\)\"/GRUB_CMDLINE_LINUX_DEFAULT=\"\1 quiet splash plymouth.ignore-serial-consoles\"/"
sed -i /etc/default/grub -e "s/ \+/ /g"
sed -i /etc/default/grub -e "s/GRUB_CMDLINE_LINUX_DEFAULT=\" /GRUB_CMDLINE_LINUX_DEFAULT=\"/"
update-grub
fi
2016-09-29 22:21:53 +09:00
STATUS=enabled
elif [ $RET -eq 1 ]; then
2017-10-30 21:20:14 +09:00
if is_pi ; then
if grep -q "splash" $CMDLINE ; then
sed -i $CMDLINE -e "s/ quiet//"
sed -i $CMDLINE -e "s/ splash//"
sed -i $CMDLINE -e "s/ plymouth.ignore-serial-consoles//"
fi
else
sed -i /etc/default/grub -e "s/GRUB_CMDLINE_LINUX_DEFAULT=\"\(.*\)quiet\(.*\)\"/GRUB_CMDLINE_LINUX_DEFAULT=\"\1\2\"/"
sed -i /etc/default/grub -e "s/GRUB_CMDLINE_LINUX_DEFAULT=\"\(.*\)splash\(.*\)\"/GRUB_CMDLINE_LINUX_DEFAULT=\"\1\2\"/"
sed -i /etc/default/grub -e "s/GRUB_CMDLINE_LINUX_DEFAULT=\"\(.*\)plymouth.ignore-serial-consoles\(.*\)\"/GRUB_CMDLINE_LINUX_DEFAULT=\"\1\2\"/"
sed -i /etc/default/grub -e "s/ \+/ /g"
sed -i /etc/default/grub -e "s/GRUB_CMDLINE_LINUX_DEFAULT=\" /GRUB_CMDLINE_LINUX_DEFAULT=\"/"
update-grub
fi
2016-09-29 22:21:53 +09:00
STATUS=disabled
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Splash screen at boot is $STATUS" 20 60 1
fi
}
2016-05-23 22:54:26 +09:00
get_rgpio() {
if test -e /etc/systemd/system/pigpiod.service.d/public.conf; then
echo 0
else
echo 1
fi
}
2016-05-25 21:53:55 +09:00
do_rgpio() {
2016-05-25 21:21:58 +09:00
DEFAULT=--defaultno
if [ $(get_rgpio) -eq 0 ]; then
DEFAULT=
fi
2016-04-22 00:32:24 +09:00
if [ "$INTERACTIVE" = True ]; then
2016-05-25 21:21:58 +09:00
whiptail --yesno "Would you like the GPIO server to be accessible over the network?" $DEFAULT 20 60 2
RET=$?
2016-04-22 00:32:24 +09:00
else
RET=$1
fi
2016-05-25 21:21:58 +09:00
if [ $RET -eq 0 ]; then
mkdir -p /etc/systemd/system/pigpiod.service.d/
cat > /etc/systemd/system/pigpiod.service.d/public.conf << EOF
2016-04-22 01:28:02 +09:00
[Service]
ExecStart=
ExecStart=/usr/bin/pigpiod
EOF
2016-05-25 21:21:58 +09:00
STATUS=enabled
elif [ $RET -eq 1 ]; then
rm -f /etc/systemd/system/pigpiod.service.d/public.conf
STATUS=disabled
else
return $RET
fi
2017-08-11 23:35:56 +09:00
systemctl daemon-reload
if systemctl -q is-enabled pigpiod ; then
systemctl restart pigpiod
fi
2016-05-25 21:21:58 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Remote access to the GPIO server is $STATUS" 20 60 1
2016-04-22 00:32:24 +09:00
fi
}
2016-05-24 19:37:36 +09:00
get_camera() {
2021-08-28 00:14:39 +09:00
if [ $(deb_ver) -le 10 ]; then
CAM=$(get_config_var start_x $CONFIG)
if [ $CAM -eq 1 ]; then
echo 0
else
echo 1
fi
2016-05-24 19:37:36 +09:00
else
2021-08-28 00:14:39 +09:00
if grep -q camera_auto_detect $CONFIG ; then
CAM=$(get_config_var camera_auto_detect $CONFIG)
if [ $CAM -eq 1 ]; then
echo 0
else
echo 1
fi
else
echo 0
fi
2013-05-08 17:57:36 +09:00
fi
}
2013-05-23 04:11:00 +09:00
do_camera() {
2021-08-28 00:14:39 +09:00
if [ $(deb_ver) -le 10 ] && [ ! -e /boot/start_x.elf ]; then
2013-05-10 19:50:13 +09:00
whiptail --msgbox "Your firmware appears to be out of date (no start_x.elf). Please update" 20 60 2
return 1
fi
2016-05-24 21:01:17 +09:00
sed $CONFIG -i -e "s/^startx/#startx/"
sed $CONFIG -i -e "s/^fixup_file/#fixup_file/"
2016-05-24 19:37:36 +09:00
DEFAULT=--defaultno
CURRENT=0
2016-05-25 01:28:29 +09:00
if [ $(get_camera) -eq 0 ]; then
2022-01-06 17:21:43 +09:00
DEFAULT=
CURRENT=1
2016-05-24 19:37:36 +09:00
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
2016-05-24 19:37:36 +09:00
whiptail --yesno "Would you like the camera interface to be enabled?" $DEFAULT 20 60 2
2015-09-15 18:25:53 +09:00
RET=$?
else
RET=$1
fi
2016-05-24 19:37:36 +09:00
if [ $RET -eq $CURRENT ]; then
2013-05-08 17:57:36 +09:00
ASK_TO_REBOOT=1
2016-05-24 19:37:36 +09:00
fi
2016-05-24 21:01:17 +09:00
if [ $RET -eq 0 ]; then
2021-08-28 00:14:39 +09:00
if [ $(deb_ver) -le 10 ] ; then
set_config_var start_x 1 $CONFIG
CUR_GPU_MEM=$(get_config_var gpu_mem $CONFIG)
if [ -z "$CUR_GPU_MEM" ] || [ "$CUR_GPU_MEM" -lt 128 ]; then
set_config_var gpu_mem 128 $CONFIG
fi
else
set_config_var camera_auto_detect 1 $CONFIG
2016-05-24 19:37:36 +09:00
fi
2016-05-24 21:01:17 +09:00
STATUS=enabled
elif [ $RET -eq 1 ]; then
2021-08-28 00:14:39 +09:00
if [ $(deb_ver) -le 10 ] ; then
set_config_var start_x 0 $CONFIG
sed $CONFIG -i -e "s/^start_file/#start_file/"
else
set_config_var camera_auto_detect 0 $CONFIG
fi
2016-05-24 21:01:17 +09:00
STATUS=disabled
2013-05-08 17:57:36 +09:00
else
2016-05-24 21:01:17 +09:00
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The camera interface is $STATUS" 20 60 1
2013-05-08 17:57:36 +09:00
fi
}
2016-05-23 22:20:18 +09:00
get_onewire() {
2016-05-24 19:57:24 +09:00
if grep -q -E "^dtoverlay=w1-gpio" $CONFIG; then
2016-05-23 22:20:18 +09:00
echo 0
else
echo 1
fi
}
2016-03-18 22:50:30 +09:00
do_onewire() {
2016-05-23 22:20:18 +09:00
DEFAULT=--defaultno
2016-05-24 19:37:36 +09:00
CURRENT=0
2016-05-23 22:20:18 +09:00
if [ $(get_onewire) -eq 0 ]; then
DEFAULT=
2016-05-24 19:37:36 +09:00
CURRENT=1
2016-05-23 22:20:18 +09:00
fi
2016-03-18 22:50:30 +09:00
if [ "$INTERACTIVE" = True ]; then
2016-05-23 22:20:18 +09:00
whiptail --yesno "Would you like the one-wire interface to be enabled?" $DEFAULT 20 60 2
2016-03-18 22:50:30 +09:00
RET=$?
else
RET=$1
fi
2016-05-24 19:37:36 +09:00
if [ $RET -eq $CURRENT ]; then
2016-03-18 22:50:30 +09:00
ASK_TO_REBOOT=1
2016-05-24 19:37:36 +09:00
fi
if [ $RET -eq 0 ]; then
sed $CONFIG -i -e "s/^#dtoverlay=w1-gpio/dtoverlay=w1-gpio/"
if ! grep -q -E "^dtoverlay=w1-gpio" $CONFIG; then
printf "dtoverlay=w1-gpio\n" >> $CONFIG
fi
2016-05-24 21:01:17 +09:00
STATUS=enabled
2016-05-24 19:37:36 +09:00
elif [ $RET -eq 1 ]; then
sed $CONFIG -i -e "s/^dtoverlay=w1-gpio/#dtoverlay=w1-gpio/"
2016-05-24 21:01:17 +09:00
STATUS=disabled
2016-03-18 22:50:30 +09:00
else
2016-05-24 21:01:17 +09:00
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The one-wire interface is $STATUS" 20 60 1
2016-03-18 22:50:30 +09:00
fi
}
2021-11-19 04:14:25 +09:00
get_legacy() {
if sed -n '/\[pi4\]/,/\[/ !p' $CONFIG | grep -q '^dtoverlay=vc4-kms-v3d' ; then
echo 1
else
echo 0
fi
}
do_legacy() {
DEFAULT=--defaultno
CURRENT=0
if [ $(get_legacy) -eq 0 ]; then
DEFAULT=
CURRENT=1
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like to enable legacy camera support?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
sed $CONFIG -i -e '/\[pi4\]/,/\[/ s/^#\?dtoverlay=vc4-f\?kms-v3d/dtoverlay=vc4-fkms-v3d/g'
sed $CONFIG -i -e '/\[pi4\]/,/\[/ !s/^dtoverlay=vc4-kms-v3d/#dtoverlay=vc4-kms-v3d/g'
sed $CONFIG -i -e '/\[pi4\]/,/\[/ !s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/g'
if ! sed -n '/\[pi4\]/,/\[/ p' $CONFIG | grep -q '^dtoverlay=vc4-fkms-v3d' ; then
if grep -q '[pi4]' $CONFIG ; then
sed $CONFIG -i -e 's/\[pi4\]/\[pi4\]\ndtoverlay=vc4-fkms-v3d/'
else
printf "[pi4]\ndtoverlay=vc4-fkms-v3d\n" >> $CONFIG
fi
fi
2021-11-19 05:57:48 +09:00
CUR_GPU_MEM=$(get_config_var gpu_mem $CONFIG)
if [ -z "$CUR_GPU_MEM" ] || [ "$CUR_GPU_MEM" -lt 128 ]; then
set_config_var gpu_mem 128 $CONFIG
fi
sed $CONFIG -i -e 's/^camera_auto_detect.*/start_x=1/g'
sed $CONFIG -i -e 's/^dtoverlay=camera/#dtoverlay=camera/g'
2021-11-19 23:28:55 +09:00
STATUS="Legacy camera support is enabled.\n\nPlease note that this functionality is deprecated and will not be supported for future development."
2021-11-19 04:14:25 +09:00
else
sed $CONFIG -i -e 's/^#\?dtoverlay=vc4-f\?kms-v3d/dtoverlay=vc4-kms-v3d/g'
sed $CONFIG -i -e '/\[pi4\]/,/\[/ {/dtoverlay=vc4-kms-v3d/d}'
if ! sed -n '/\[pi4\]/,/\[/ !p' $CONFIG | grep -q '^dtoverlay=vc4-kms-v3d' ; then
if grep -q '[all]' $CONFIG ; then
sed $CONFIG -i -e 's/\[all\]/\[all\]\ndtoverlay=vc4-kms-v3d/'
else
printf "[all]\ndtoverlay=vc4-kms-v3d\n" >> $CONFIG
fi
fi
2021-11-19 05:57:48 +09:00
sed $CONFIG -i -e 's/^start_x.*/camera_auto_detect=1/g'
sed $CONFIG -i -e 's/^#dtoverlay=camera/dtoverlay=camera/g'
2021-11-19 04:14:25 +09:00
STATUS="Legacy camera support is disabled."
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "$STATUS" 20 60 1
fi
}
2016-01-19 22:52:11 +09:00
do_gldriver() {
2016-05-07 03:07:03 +09:00
if [ ! -e /boot/overlays/vc4-kms-v3d.dtbo ]; then
2016-01-19 22:52:11 +09:00
whiptail --msgbox "Driver and kernel not present on your system. Please update" 20 60 2
return 1
fi
2020-01-14 01:56:24 +09:00
for package in gldriver-test libgl1-mesa-dri; do
if [ "$(dpkg -l "$package" 2> /dev/null | tail -n 1 | cut -d ' ' -f 1)" != "ii" ]; then
missing_packages="$package $missing_packages"
fi
done
if [ -n "$missing_packages" ] && ! apt-get install $missing_packages; then
whiptail --msgbox "Required packages not found, please install: ${missing_packages}" 20 60 2
2016-02-09 22:52:03 +09:00
return 1
fi
2019-05-15 23:54:09 +09:00
GLOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "GL Driver" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \
"G1 Legacy" "Original non-GL desktop driver" \
2021-09-24 22:34:17 +09:00
"G2 GL (Full KMS)" "OpenGL desktop driver with full KMS" \
2019-05-15 23:54:09 +09:00
3>&1 1>&2 2>&3)
2017-01-18 03:02:14 +09:00
if [ $? -eq 0 ]; then
case "$GLOPT" in
G1*)
2021-09-24 22:34:17 +09:00
if sed -n "/\[pi4\]/,/\[/ !p" $CONFIG | grep -q -E "^dtoverlay=vc4-f?kms-v3d" ; then
ASK_TO_REBOOT=1
2017-01-18 03:02:14 +09:00
fi
2019-05-15 23:54:09 +09:00
sed $CONFIG -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/g"
2021-09-24 22:34:17 +09:00
sed $CONFIG -i -e "s/^dtoverlay=vc4-kms-v3d/#dtoverlay=vc4-kms-v3d/g"
2019-05-15 23:54:09 +09:00
STATUS="The GL driver is disabled."
2017-01-18 03:02:14 +09:00
;;
G2*)
2019-05-15 23:54:09 +09:00
if ! sed -n "/\[pi4\]/,/\[/ !p" $CONFIG | grep -q "^dtoverlay=vc4-kms-v3d" ; then
2017-01-18 03:02:14 +09:00
ASK_TO_REBOOT=1
fi
2019-05-15 23:54:09 +09:00
sed $CONFIG -i -e "s/^dtoverlay=vc4-fkms-v3d/#dtoverlay=vc4-fkms-v3d/g"
sed $CONFIG -i -e "s/^#dtoverlay=vc4-kms-v3d/dtoverlay=vc4-kms-v3d/g"
if ! sed -n "/\[pi4\]/,/\[/ !p" $CONFIG | grep -q "^dtoverlay=vc4-kms-v3d" ; then
printf "[all]\ndtoverlay=vc4-kms-v3d\n" >> $CONFIG
fi
STATUS="The full KMS GL driver is enabled."
2017-01-18 03:02:14 +09:00
;;
*)
whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2
return 1
;;
esac
2016-01-19 22:52:11 +09:00
else
2017-01-18 03:02:14 +09:00
return 0
2016-05-25 22:22:16 +09:00
fi
2017-01-18 03:02:14 +09:00
whiptail --msgbox "$STATUS" 20 60 1
2019-04-24 21:46:55 +09:00
}
2019-05-08 00:05:30 +09:00
do_xcompmgr() {
2019-04-24 21:46:55 +09:00
DEFAULT=--defaultno
CURRENT=0
2019-05-08 00:05:30 +09:00
if [ -e /etc/xdg/autostart/xcompmgr.desktop ]; then
2019-04-24 21:46:55 +09:00
DEFAULT=
CURRENT=1
fi
if [ "$INTERACTIVE" = True ]; then
2019-05-08 00:05:30 +09:00
whiptail --yesno "Would you like the xcompmgr composition manager to be enabled?" $DEFAULT 20 60 2
2019-04-24 21:46:55 +09:00
RET=$?
else
RET=$1
fi
if [ $RET -eq $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
2019-05-08 00:05:30 +09:00
if [ ! -e /usr/bin/xcompmgr ] ; then
apt-get -y install xcompmgr
2019-04-24 21:49:33 +09:00
fi
2019-05-08 00:05:30 +09:00
cat << EOF > /etc/xdg/autostart/xcompmgr.desktop
2019-04-24 21:46:55 +09:00
[Desktop Entry]
Type=Application
2019-05-08 00:05:30 +09:00
Name=xcompmgr
Comment=Start xcompmgr compositor
2019-04-24 21:46:55 +09:00
NoDisplay=true
2019-05-15 23:54:09 +09:00
Exec=/usr/lib/raspi-config/cmstart.sh
2019-04-24 21:46:55 +09:00
EOF
STATUS=enabled
elif [ $RET -eq 1 ]; then
2019-05-08 00:05:30 +09:00
if [ -e /etc/xdg/autostart/xcompmgr.desktop ]; then
rm /etc/xdg/autostart/xcompmgr.desktop
2019-04-24 21:46:55 +09:00
fi
STATUS=disabled
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
2019-05-08 00:05:30 +09:00
whiptail --msgbox "The xcompmgr composition manager is $STATUS" 20 60 1
2019-04-24 21:46:55 +09:00
fi
}
2016-01-19 22:52:11 +09:00
2021-10-20 02:36:02 +09:00
do_glamor() {
DEFAULT=
CURRENT=1
if [ -e /usr/share/X11/xorg.conf.d/20-noglamor.conf ] ; then
DEFAULT=--defaultno
CURRENT=0
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like glamor acceleration to be enabled?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
systemctl disable glamor-test.service
systemctl stop glamor-test.service
if [ -e /usr/share/X11/xorg.conf.d/20-noglamor.conf ] ; then
rm /usr/share/X11/xorg.conf.d/20-noglamor.conf
fi
STATUS=enabled
elif [ $RET -eq 1 ]; then
systemctl enable glamor-test.service &&
systemctl start glamor-test.service &&
STATUS=disabled
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Glamor acceleration is $STATUS" 20 60 1
fi
}
2017-09-26 20:41:05 +09:00
get_net_names() {
2021-09-23 00:20:17 +09:00
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
2017-09-26 20:41:05 +09:00
echo 1
else
echo 0
fi
}
do_net_names () {
DEFAULT=--defaultno
CURRENT=0
if [ $(get_net_names) -eq 0 ]; then
DEFAULT=
CURRENT=1
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like to enable predictable network interface names?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq $CURRENT ]; then
ASK_TO_REBOOT=1
fi
if [ $RET -eq 0 ]; then
2017-10-30 21:20:14 +09:00
sed -i $CMDLINE -e "s/net.ifnames=0 *//"
rm -f /etc/systemd/network/99-default.link
2021-09-23 00:20:17 +09:00
rm -f /etc/systemd/network/73-usb-net-by-mac.link
2017-09-26 20:41:05 +09:00
STATUS=enabled
elif [ $RET -eq 1 ]; then
2017-10-30 21:20:14 +09:00
ln -sf /dev/null /etc/systemd/network/99-default.link
2021-09-23 00:20:17 +09:00
ln -sf /dev/null /etc/systemd/network/73-usb-net-by-mac.link
2017-09-26 20:41:05 +09:00
STATUS=disabled
else
return $RET
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Predictable network interface names are $STATUS" 20 60 1
fi
2022-01-06 17:21:43 +09:00
}
2017-09-26 20:41:05 +09:00
2013-05-23 04:21:24 +09:00
do_update() {
2012-07-16 02:40:06 +09:00
apt-get update &&
apt-get install raspi-config &&
2012-09-17 03:47:17 +09:00
printf "Sleeping 5 seconds before reloading raspi-config\n" &&
sleep 5 &&
exec raspi-config
2012-07-16 02:40:06 +09:00
}
2013-12-17 06:29:14 +09:00
do_audio() {
2020-10-12 22:48:37 +09:00
if is_pulseaudio ; then
2020-10-12 23:04:47 +09:00
oIFS="$IFS"
2020-01-20 20:40:07 +09:00
if [ "$INTERACTIVE" = True ]; then
2020-10-12 22:48:37 +09:00
list=$(sudo -u $SUDO_USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID pacmd list-sinks | grep -e index -e alsa.name | sed s/*//g | sed s/^[' '\\t]*//g | sed s/'index: '//g | sed s/'alsa.name = '//g | sed s/'bcm2835 '//g | sed s/\"//g | tr '\n' '/')
if ! [ -z "$list" ] ; then
2020-10-12 23:04:47 +09:00
IFS="/"
2020-10-12 22:48:37 +09:00
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 ${list} 3>&1 1>&2 2>&3)
else
whiptail --msgbox "No internal audio devices found" 20 60 1
return 1
fi
2020-01-20 20:40:07 +09:00
else
AUDIO_OUT=$1
2020-10-12 23:04:47 +09:00
true
2020-01-20 20:40:07 +09:00
fi
2020-10-12 23:04:47 +09:00
if [ $? -eq 0 ]; then
sudo -u $SUDO_USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID pactl set-default-sink $AUDIO_OUT
fi
IFS=$oIFS
2017-01-11 03:15:43 +09:00
else
2020-10-12 22:48:37 +09:00
if aplay -l | grep -q "bcm2835 ALSA"; then
if [ "$INTERACTIVE" = True ]; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \
"0" "Auto" \
"1" "Force 3.5mm ('headphone') jack" \
"2" "Force HDMI" \
3>&1 1>&2 2>&3)
2020-01-20 20:40:07 +09:00
else
2020-10-12 22:48:37 +09:00
AUDIO_OUT=$1
fi
if [ $? -eq 0 ]; then
amixer cset numid=3 "$AUDIO_OUT"
2020-01-20 20:40:07 +09:00
fi
else
2020-10-12 22:48:37 +09:00
ASPATH=$(getent passwd $USER | cut -d : -f 6)/.asoundrc
if [ "$INTERACTIVE" = True ]; then
CARD0=$(LC_ALL=C aplay -l | grep bcm2835 | grep "card 0" | cut -d [ -f 3 | cut -d ] -f 1 | cut -d ' ' -f 2-)
CARD1=$(LC_ALL=C aplay -l | grep bcm2835 | grep "card 1" | cut -d [ -f 3 | cut -d ] -f 1 | cut -d ' ' -f 2-)
CARD2=$(LC_ALL=C aplay -l | grep bcm2835 | grep "card 2" | cut -d [ -f 3 | cut -d ] -f 1 | cut -d ' ' -f 2-)
if ! [ -z "$CARD2" ]; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \
"0" "$CARD0" \
"1" "$CARD1" \
"2" "$CARD2" \
3>&1 1>&2 2>&3)
elif ! [ -z "$CARD1" ]; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \
"0" "$CARD0" \
"1" "$CARD1" \
3>&1 1>&2 2>&3)
elif ! [ -z "$CARD0" ]; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \
"0" "$CARD0" \
3>&1 1>&2 2>&3)
else
whiptail --msgbox "No internal audio devices found" 20 60 1
false
fi
else
AUDIO_OUT=$1
fi
if [ $? -eq 0 ]; then
cat << EOF > $ASPATH
2020-01-20 20:40:07 +09:00
pcm.!default {
type asym
playback.pcm {
type plug
slave.pcm "output"
}
capture.pcm {
type plug
slave.pcm "input"
}
}
pcm.output {
type hw
card $AUDIO_OUT
}
ctl.!default {
type hw
card $AUDIO_OUT
}
EOF
2020-10-12 22:48:37 +09:00
fi
2020-01-20 20:40:07 +09:00
fi
2013-12-17 06:29:14 +09:00
fi
}
2016-11-30 23:48:48 +09:00
do_resolution() {
if [ "$INTERACTIVE" = True ]; then
2017-10-30 21:20:14 +09:00
CMODE=$(get_config_var hdmi_mode $CONFIG)
CGROUP=$(get_config_var hdmi_group $CONFIG)
if [ $CMODE -eq 0 ] ; then
CSET="Default"
elif [ $CGROUP -eq 2 ] ; then
CSET="DMT Mode "$CMODE
else
CSET="CEA Mode "$CMODE
fi
2016-11-30 23:48:48 +09:00
oIFS="$IFS"
IFS="/"
if tvservice -d /dev/null | grep -q Nothing ; then
2016-12-01 00:06:53 +09:00
value="Default/720x480/DMT Mode 4/640x480 60Hz 4:3/DMT Mode 9/800x600 60Hz 4:3/DMT Mode 16/1024x768 60Hz 4:3/DMT Mode 85/1280x720 60Hz 16:9/DMT Mode 35/1280x1024 60Hz 5:4/DMT Mode 51/1600x1200 60Hz 4:3/DMT Mode 82/1920x1080 60Hz 16:9/"
2017-10-30 21:20:14 +09:00
else
2016-11-30 23:48:48 +09:00
value="Default/Monitor preferred resolution/"
value=$value$(tvservice -m CEA | grep progressive | cut -b 12- | sed 's/mode \([0-9]\+\): \([0-9]\+\)x\([0-9]\+\) @ \([0-9]\+\)Hz \([0-9]\+\):\([0-9]\+\), clock:[0-9]\+MHz progressive/CEA Mode \1\/\2x\3 \4Hz \5:\6/' | tr '\n' '/')
value=$value$(tvservice -m DMT | grep progressive | cut -b 12- | sed 's/mode \([0-9]\+\): \([0-9]\+\)x\([0-9]\+\) @ \([0-9]\+\)Hz \([0-9]\+\):\([0-9]\+\), clock:[0-9]\+MHz progressive/DMT Mode \1\/\2x\3 \4Hz \5:\6/' | tr '\n' '/')
2017-10-30 21:20:14 +09:00
fi
2016-11-30 23:48:48 +09:00
RES=$(whiptail --default-item $CSET --menu "Choose screen resolution" 20 60 10 ${value} 3>&1 1>&2 2>&3)
STATUS=$?
IFS=$oIFS
if [ $STATUS -eq 0 ] ; then
GRS=$(echo "$RES" | cut -d ' ' -f 1)
MODE=$(echo "$RES" | cut -d ' ' -f 3)
if [ $GRS = "Default" ] ; then
2017-10-30 21:20:14 +09:00
MODE=0
2016-11-30 23:48:48 +09:00
elif [ $GRS = "DMT" ] ; then
2017-10-30 21:20:14 +09:00
GROUP=2
else
GROUP=1
fi
fi
2016-11-30 23:48:48 +09:00
else
GROUP=$1
MODE=$2
STATUS=0
fi
if [ $STATUS -eq 0 ]; then
2017-10-30 21:20:14 +09:00
if [ $MODE -eq 0 ]; then
clear_config_var hdmi_force_hotplug $CONFIG
clear_config_var hdmi_group $CONFIG
clear_config_var hdmi_mode $CONFIG
else
set_config_var hdmi_force_hotplug 1 $CONFIG
set_config_var hdmi_group $GROUP $CONFIG
set_config_var hdmi_mode $MODE $CONFIG
fi
2016-11-30 23:48:48 +09:00
if [ "$INTERACTIVE" = True ]; then
2017-10-30 21:20:14 +09:00
if [ $MODE -eq 0 ] ; then
2016-11-30 23:48:48 +09:00
whiptail --msgbox "The resolution is set to default" 20 60 1
2017-10-30 21:20:14 +09:00
else
2016-11-30 23:48:48 +09:00
whiptail --msgbox "The resolution is set to $GRS mode $MODE" 20 60 1
fi
fi
2017-10-30 21:20:14 +09:00
if [ $MODE -eq 0 ] ; then
TSET="Default"
elif [ $GROUP -eq 2 ] ; then
TSET="DMT Mode "$MODE
else
TSET="CEA Mode "$MODE
fi
if [ "$TSET" != "$CSET" ] ; then
ASK_TO_REBOOT=1
fi
2016-11-30 23:48:48 +09:00
fi
}
2021-11-10 19:31:50 +09:00
get_vnc_resolution() {
if [ -e /etc/xdg/autostart/vnc_xrandr.desktop ] ; then
echo $(grep fb /etc/xdg/autostart/vnc_xrandr.desktop | cut -f 15 -d ' ')
else
2021-11-10 20:15:00 +09:00
echo ""
2021-11-10 19:31:50 +09:00
fi
}
2021-11-10 18:47:01 +09:00
do_vnc_resolution() {
if [ "$INTERACTIVE" = True ]; then
2021-11-10 19:31:50 +09:00
CUR=$(get_vnc_resolution)
2021-11-10 20:15:00 +09:00
if [ "$CUR" = "" ] ; then
2021-11-10 18:47:01 +09:00
CUR=640x480
fi
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --default-item $CUR --menu "Set VNC Resolution" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"640x480" "" "720x480" "" "800x600" "" "1024x768" "" "1280x720" "" "1280x1024" "" "1600x1200" "" "1920x1080" "" 3>&1 1>&2 2>&3)
RET=$?
else
FUN=$1
RET=0
fi
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
cat > /etc/xdg/autostart/vnc_xrandr.desktop << EOF
[Desktop Entry]
Type=Application
Name=vnc_xrandr
Comment=Set resolution for VNC
NoDisplay=true
Exec=sh -c "if ! (xrandr | grep -q -w connected) ; then /usr/bin/xrandr --fb $FUN ; fi"
EOF
2021-11-10 19:31:50 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The resolution is set to $FUN" 20 60 1
ASK_TO_REBOOT=1
fi
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
}
2013-09-10 07:55:22 +09:00
# $1 = filename, $2 = key name
get_json_string_val() {
sed -n -e "s/^[[:space:]]*\"$2\"[[:space:]]*:[[:space:]]*\"\(.*\)\"[[:space:]]*,$/\1/p" $1
}
2015-05-29 19:35:13 +09:00
# TODO: This is probably broken
2013-09-10 07:55:22 +09:00
do_apply_os_config() {
[ -e /boot/os_config.json ] || return 0
NOOBSFLAVOUR=$(get_json_string_val /boot/os_config.json flavour)
NOOBSLANGUAGE=$(get_json_string_val /boot/os_config.json language)
NOOBSKEYBOARD=$(get_json_string_val /boot/os_config.json keyboard)
if [ -n "$NOOBSFLAVOUR" ]; then
printf "Setting flavour to %s based on os_config.json from NOOBS. May take a while\n" "$NOOBSFLAVOUR"
2015-05-29 19:35:13 +09:00
printf "Unrecognised flavour. Ignoring\n"
2013-09-10 07:55:22 +09:00
fi
# TODO: currently ignores en_gb settings as we assume we are running in a
# first boot context, where UK English settings are default
case "$NOOBSLANGUAGE" in
"en")
if [ "$NOOBSKEYBOARD" = "gb" ]; then
DEBLANGUAGE="" # UK english is the default, so ignore
else
DEBLANGUAGE="en_US.UTF-8"
fi
;;
"de")
DEBLANGUAGE="de_DE.UTF-8"
;;
"fi")
DEBLANGUAGE="fi_FI.UTF-8"
;;
"fr")
DEBLANGUAGE="fr_FR.UTF-8"
;;
"hu")
DEBLANGUAGE="hu_HU.UTF-8"
;;
"ja")
DEBLANGUAGE="ja_JP.UTF-8"
;;
"nl")
DEBLANGUAGE="nl_NL.UTF-8"
;;
"pt")
DEBLANGUAGE="pt_PT.UTF-8"
;;
2013-12-17 05:31:02 +09:00
"ru")
DEBLANGUAGE="ru_RU.UTF-8"
;;
"zh_CN")
DEBLANGUAGE="zh_CN.UTF-8"
;;
2013-09-10 07:55:22 +09:00
*)
printf "Language '%s' not handled currently. Run sudo raspi-config to set up" "$NOOBSLANGUAGE"
;;
esac
if [ -n "$DEBLANGUAGE" ]; then
printf "Setting language to %s based on os_config.json from NOOBS. May take a while\n" "$DEBLANGUAGE"
2017-11-10 02:25:18 +09:00
do_change_locale "$DEBLANGUAGE"
2013-09-10 07:55:22 +09:00
fi
if [ -n "$NOOBSKEYBOARD" -a "$NOOBSKEYBOARD" != "gb" ]; then
printf "Setting keyboard layout to %s based on os_config.json from NOOBS. May take a while\n" "$NOOBSKEYBOARD"
2017-11-10 02:25:18 +09:00
do_configure_keyboard "$NOOBSKEYBOARD"
2013-09-10 07:55:22 +09:00
fi
return 0
}
2019-10-01 18:53:22 +09:00
get_overlay_now() {
grep -q "boot=overlay" /proc/cmdline
2022-01-19 03:40:59 +09:00
echo $?
2019-10-01 18:53:22 +09:00
}
get_overlay_conf() {
grep -q "boot=overlay" /boot/cmdline.txt
2022-01-19 03:40:59 +09:00
echo $?
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() {
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)"
}
2019-10-01 18:53:22 +09:00
enable_overlayfs() {
KERN=$(uname -r)
INITRD=initrd.img-"$KERN"-overlay
# mount the boot partition as writable if it isn't already
2022-01-19 03:40:59 +09:00
if [ $(get_bootro_now) -eq 0 ] ; then
2019-10-01 18:53:22 +09:00
if ! mount -o remount,rw /boot 2>/dev/null ; then
echo "Unable to mount boot partition as writable - cannot enable"
2019-10-02 18:13:49 +09:00
return 1
2019-10-01 18:53:22 +09:00
fi
BOOTRO=yes
else
BOOTRO=no
fi
2020-01-17 20:51:49 +09:00
cat > /etc/initramfs-tools/scripts/overlay << 'EOF'
2019-10-01 18:53:22 +09:00
# Local filesystem mounting -*- shell-script -*-
#
# This script overrides local_mount_root() in /scripts/local
# and mounts root as a read-only filesystem with a temporary (rw)
# overlay filesystem.
#
. /scripts/local
local_mount_root()
{
local_top
local_device_setup "${ROOT}" "root file system"
ROOT="${DEV}"
# Get the root filesystem type if not set
if [ -z "${ROOTFSTYPE}" ]; then
FSTYPE=$(get_fstype "${ROOT}")
else
FSTYPE=${ROOTFSTYPE}
fi
local_premount
# CHANGES TO THE ORIGINAL FUNCTION BEGIN HERE
# N.B. this code still lacks error checking
modprobe ${FSTYPE}
checkfs ${ROOT} root "${FSTYPE}"
# Create directories for root and the overlay
mkdir /lower /upper
# Mount read-only root to /lower
if [ "${FSTYPE}" != "unknown" ]; then
mount -r -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} /lower
else
mount -r ${ROOTFLAGS} ${ROOT} /lower
fi
2020-01-17 21:26:12 +09:00
modprobe overlay || insmod "/lower/lib/modules/$(uname -r)/kernel/fs/overlayfs/overlay.ko"
2019-10-01 18:53:22 +09:00
# Mount a tmpfs for the overlay in /upper
mount -t tmpfs tmpfs /upper
mkdir /upper/data /upper/work
# Mount the final overlay-root in $rootmnt
mount -t overlay \
-olowerdir=/lower,upperdir=/upper/data,workdir=/upper/work \
overlay ${rootmnt}
}
EOF
2020-01-17 20:51:49 +09:00
# add the overlay to the list of modules
if ! grep overlay /etc/initramfs-tools/modules > /dev/null; then
echo overlay >> /etc/initramfs-tools/modules
fi
2019-10-01 18:53:22 +09:00
2020-01-17 20:51:49 +09:00
# build the new initramfs
update-initramfs -c -k "$KERN"
2019-10-01 18:53:22 +09:00
2020-01-17 20:51:49 +09:00
# rename it so we know it has overlay added
mv /boot/initrd.img-"$KERN" /boot/"$INITRD"
2019-10-01 18:53:22 +09:00
# there is now a modified initramfs ready for use...
# modify config.txt
sed -i /boot/config.txt -e "/initramfs.*/d"
echo initramfs "$INITRD" >> /boot/config.txt
# modify command line
if ! grep -q "boot=overlay" /boot/cmdline.txt ; then
2022-01-06 17:21:43 +09:00
sed -i /boot/cmdline.txt -e "s/^/boot=overlay /"
2019-10-01 18:53:22 +09:00
fi
if [ "$BOOTRO" = "yes" ] ; then
if ! mount -o remount,ro /boot 2>/dev/null ; then
2022-01-06 17:21:43 +09:00
echo "Unable to remount boot partition as read-only"
2019-10-01 18:53:22 +09:00
fi
fi
}
disable_overlayfs() {
2020-01-17 20:51:49 +09:00
KERN=$(uname -r)
2019-10-01 18:53:22 +09:00
# mount the boot partition as writable if it isn't already
2022-01-19 03:40:59 +09:00
if [ $(get_bootro_now) -eq 0 ] ; then
2019-10-01 18:53:22 +09:00
if ! mount -o remount,rw /boot 2>/dev/null ; then
echo "Unable to mount boot partition as writable - cannot disable"
2019-10-02 18:13:49 +09:00
return 1
2019-10-01 18:53:22 +09:00
fi
BOOTRO=yes
else
BOOTRO=no
fi
# modify config.txt
sed -i /boot/config.txt -e "/initramfs.*/d"
2020-01-17 20:51:49 +09:00
update-initramfs -d -k "${KERN}-overlay"
2019-10-01 18:53:22 +09:00
# modify command line
sed -i /boot/cmdline.txt -e "s/\(.*\)boot=overlay \(.*\)/\1\2/"
if [ "$BOOTRO" = "yes" ] ; then
if ! mount -o remount,ro /boot 2>/dev/null ; then
2022-01-06 17:21:43 +09:00
echo "Unable to remount boot partition as read-only"
2019-10-01 18:53:22 +09:00
fi
fi
}
enable_bootro() {
2022-01-19 03:40:59 +09:00
if [ $(get_overlay_now) -eq 0 ] ; then
2019-10-02 18:34:14 +09:00
echo "Overlay in use; cannot update fstab"
return 1
fi
2019-10-01 18:53:22 +09:00
sed -i /etc/fstab -e "s/\(.*\/boot.*\)defaults\(.*\)/\1defaults,ro\2/"
}
disable_bootro() {
2022-01-19 03:40:59 +09:00
if [ $(get_overlay_now) -eq 0 ] ; then
2019-10-02 18:34:14 +09:00
echo "Overlay in use; cannot update fstab"
return 1
fi
2019-10-01 18:53:22 +09:00
sed -i /etc/fstab -e "s/\(.*\/boot.*\)defaults,ro\(.*\)/\1defaults\2/"
}
do_overlayfs() {
DEFAULT=--defaultno
CURRENT=0
STATUS="disabled"
2020-01-17 20:51:49 +09:00
if [ "$INTERACTIVE" = True ] && ! is_uname_current; then
whiptail --msgbox "Could not find modules for the running kernel ($(uname -r))." 20 60 1
return 1
fi
2022-01-19 03:40:59 +09:00
if [ $(get_overlay_conf) -eq 0 ] ; then
2019-10-01 18:53:22 +09:00
DEFAULT=
CURRENT=1
STATUS="enabled"
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the overlay file system to be enabled?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq $CURRENT ]; then
if [ $RET -eq 0 ]; then
2019-10-02 18:13:49 +09:00
if enable_overlayfs; then
STATUS="enabled"
2019-10-02 18:34:14 +09:00
ASK_TO_REBOOT=1
2019-10-02 18:13:49 +09:00
else
STATUS="unchanged"
fi
2019-10-01 18:53:22 +09:00
elif [ $RET -eq 1 ]; then
2019-10-02 18:13:49 +09:00
if disable_overlayfs; then
STATUS="disabled"
2019-10-02 18:34:14 +09:00
ASK_TO_REBOOT=1
2019-10-02 18:13:49 +09:00
else
STATUS="unchanged"
fi
2019-10-01 18:53:22 +09:00
else
return $RET
fi
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The overlay file system is $STATUS." 20 60 1
fi
2022-01-19 03:40:59 +09:00
if [ $(get_overlay_now) -eq 0 ] ; then
if [ $(get_bootro_conf) -eq 0 ] ; then
2019-10-01 18:53:22 +09:00
BPRO="read-only"
else
BPRO="writable"
fi
whiptail --msgbox "The boot partition is currently $BPRO. This cannot be changed while an overlay file system is enabled." 20 60 1
else
DEFAULT=--defaultno
CURRENT=0
STATUS="writable"
2022-01-19 03:40:59 +09:00
if [ $(get_bootro_conf) -eq 0 ]; then
2019-10-01 18:53:22 +09:00
DEFAULT=
CURRENT=1
STATUS="read-only"
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the boot partition to be write-protected?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
if [ $RET -eq $CURRENT ]; then
if [ $RET -eq 0 ]; then
2019-10-02 18:34:14 +09:00
if enable_bootro; then
STATUS="read-only"
ASK_TO_REBOOT=1
else
STATUS="unchanged"
fi
2019-10-01 18:53:22 +09:00
elif [ $RET -eq 1 ]; then
2019-10-02 18:34:14 +09:00
if disable_bootro; then
STATUS="writable"
ASK_TO_REBOOT=1
else
STATUS="unchanged"
fi
2019-10-01 18:53:22 +09:00
else
return $RET
fi
fi
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The boot partition is $STATUS." 20 60 1
fi
fi
}
2020-01-13 20:57:52 +09:00
get_proxy() {
SCHEME="$1"
VAR_NAME="${SCHEME}_proxy"
if [ -f /etc/profile.d/proxy.sh ]; then
# shellcheck disable=SC1091
. /etc/profile.d/proxy.sh
fi
eval "echo \$$VAR_NAME"
}
do_proxy() {
SCHEMES="$1"
ADDRESS="$2"
if [ "$SCHEMES" = "all" ]; then
CURRENT="$(get_proxy http)"
SCHEMES="http https ftp rsync"
else
CURRENT="$(get_proxy "$SCHEMES")"
fi
if [ "$INTERACTIVE" = True ]; then
if [ "$SCHEMES" = "no" ]; then
STRING="Please enter a comma separated list of addresses that should be excluded from using proxy servers.\\nEg: localhost,127.0.0.1,localaddress,.localdomain.com"
else
STRING="Please enter proxy address.\\nEg: http://user:pass@proxy:8080"
fi
if ! ADDRESS="$(whiptail --inputbox "$STRING" 20 60 "$CURRENT" 3>&1 1>&2 2>&3)"; then
return 0
fi
fi
for SCHEME in $SCHEMES; do
unset "${SCHEME}_proxy"
CURRENT="$(get_proxy "$SCHEME")"
if [ "$CURRENT" != "$ADDRESS" ]; then
ASK_TO_REBOOT=1
fi
if [ -f /etc/profile.d/proxy.sh ]; then
sed -i "/^export ${SCHEME}_/Id" /etc/profile.d/proxy.sh
fi
if [ "${SCHEME#*http}" != "$SCHEME" ]; then
if [ -f /etc/apt/apt.conf.d/01proxy ]; then
sed -i "/::${SCHEME}::Proxy/d" /etc/apt/apt.conf.d/01proxy
fi
fi
if [ -z "$ADDRESS" ]; then
STATUS=cleared
continue
fi
STATUS=updated
SCHEME_UPPER="$(echo "$SCHEME" | tr '[:lower:]' '[:upper:]')"
echo "export ${SCHEME_UPPER}_PROXY=\"$ADDRESS\"" >> /etc/profile.d/proxy.sh
if [ "$SCHEME" != "rsync" ]; then
echo "export ${SCHEME}_proxy=\"$ADDRESS\"" >> /etc/profile.d/proxy.sh
fi
if [ "${SCHEME#*http}" != "$SCHEME" ]; then
echo "Acquire::$SCHEME::Proxy \"$ADDRESS\";" >> /etc/apt/apt.conf.d/01proxy
fi
done
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Proxy settings $STATUS" 20 60 1
fi
}
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
--memory-split)
OPT_MEMORY_SPLIT=GET
2012-10-29 06:14:01 +09:00
printf "Not currently supported\n"
exit 1
2012-08-21 05:53:15 +09:00
;;
--memory-split=*)
OPT_MEMORY_SPLIT=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
2012-10-29 06:14:01 +09:00
printf "Not currently supported\n"
exit 1
2012-08-21 05:53:15 +09:00
;;
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
2012-10-29 06:14:01 +09:00
#if [ "GET" = "${OPT_MEMORY_SPLIT:-}" ]; then
# set -u # Fail on unset variables
# get_current_memory_split
# echo $CURRENT_MEMSPLIT
# exit 0
#fi
2012-08-21 05:53:15 +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
if [ -n "${OPT_MEMORY_SPLIT:-}" ]; then
set -e # Fail when a command errors
set_memory_split "${OPT_MEMORY_SPLIT}"
exit 0
fi
2020-10-08 01:15:23 +09:00
do_system_menu() {
if is_pi ; then
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" \
"S2 Audio" "Select audio out through HDMI or 3.5mm jack" \
2020-10-14 22:59:19 +09:00
"S3 Password" "Change password for the '$USER' user" \
2020-10-08 01:15:23 +09:00
"S4 Hostname" "Set name for this computer on a network" \
2020-10-14 22:59:19 +09:00
"S5 Boot / Auto Login" "Select boot into desktop or to command line" \
"S6 Network at Boot" "Select wait for network connection on boot" \
2020-10-08 01:15:23 +09:00
"S7 Splash Screen" "Choose graphical splash screen or text boot" \
"S8 Power LED" "Set behaviour of power LED" \
3>&1 1>&2 2>&3)
elif is_live ; then
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" \
2020-10-14 22:59:19 +09:00
"S3 Password" "Change password for the '$USER' user" \
2020-10-08 01:15:23 +09:00
"S4 Hostname" "Set name for this computer on a network" \
2020-10-14 22:59:19 +09:00
"S5 Boot / Auto Login" "Select boot into desktop or to command line" \
"S6 Network at Boot" "Select wait for network connection on boot" \
2020-10-08 01:15:23 +09:00
3>&1 1>&2 2>&3)
else
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" \
2020-10-14 22:59:19 +09:00
"S3 Password" "Change password for the '$USER' user" \
2020-10-08 01:15:23 +09:00
"S4 Hostname" "Set name for this computer on a network" \
2020-10-14 22:59:19 +09:00
"S5 Boot / Auto Login" "Select boot into desktop or to command line" \
"S6 Network at Boot" "Select wait for network connection on boot" \
2020-10-08 01:15:23 +09:00
"S7 Splash Screen" "Choose graphical splash screen or text boot" \
3>&1 1>&2 2>&3)
fi
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 ;;
S2\ *) do_audio ;;
S3\ *) do_change_pass ;;
S4\ *) do_hostname ;;
S5\ *) do_boot_behaviour ;;
S6\ *) do_boot_wait ;;
S7\ *) do_boot_splash ;;
S8\ *) do_leds ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
fi
}
do_display_menu() {
2021-01-19 23:52:51 +09:00
if is_pi ; then
2021-09-28 02:20:19 +09:00
if is_fkms; then
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Display Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"D2 Underscan" "Remove black border around screen" \
"D3 Pixel Doubling" "Enable/disable 2x2 pixel mapping" \
"D4 Screen Blanking" "Enable/disable screen blanking" \
2021-11-10 18:47:01 +09:00
"D5 VNC Resolution" "Set resolution for headless use" \
2021-11-25 19:07:11 +09:00
"D6 Composite" "Set options for composite output" \
2021-09-28 02:20:19 +09:00
3>&1 1>&2 2>&3)
else
2020-10-08 01:15:23 +09:00
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Display Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"D1 Resolution" "Set a specific screen resolution" \
2020-10-14 22:59:19 +09:00
"D2 Underscan" "Remove black border around screen" \
2020-10-08 01:15:23 +09:00
"D3 Pixel Doubling" "Enable/disable 2x2 pixel mapping" \
2021-01-19 23:52:51 +09:00
"D4 Screen Blanking" "Enable/disable screen blanking" \
2021-11-10 18:47:01 +09:00
"D5 VNC Resolution" "Set resolution for headless use" \
2021-11-25 19:07:11 +09:00
"D6 Composite" "Set options for composite output" \
2020-10-08 01:15:23 +09:00
3>&1 1>&2 2>&3)
2021-09-28 02:20:19 +09:00
fi
2020-10-08 01:15:23 +09:00
else
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Display Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"D3 Pixel Doubling" "Enable/disable 2x2 pixel mapping" \
2021-01-19 23:52:51 +09:00
"D4 Screen Blanking" "Enable/disable screen blanking" \
2020-10-08 01:15:23 +09:00
3>&1 1>&2 2>&3)
fi
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
D1\ *) do_resolution ;;
D2\ *) do_overscan ;;
D3\ *) do_pixdub ;;
2021-01-19 23:52:51 +09:00
D4\ *) do_blanking ;;
2021-11-10 18:47:01 +09:00
D5\ *) do_vnc_resolution ;;
2021-11-25 19:07:11 +09:00
D6\ *) if is_pifour ; then
do_pi4video
else
do_composite
fi
;;
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() {
2020-10-08 01:15:23 +09:00
if is_pi ; then
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 \
2021-12-02 20:52:03 +09:00
"I1 Legacy Camera" "Enable/disable legacy camera support" \
"I2 SSH" "Enable/disable remote command line access using SSH" \
"I3 VNC" "Enable/disable graphical remote access using RealVNC" \
"I4 SPI" "Enable/disable automatic loading of SPI kernel module" \
"I5 I2C" "Enable/disable automatic loading of I2C kernel module" \
"I6 Serial Port" "Enable/disable shell messages on the serial connection" \
"I7 1-Wire" "Enable/disable one-wire interface" \
"I8 Remote GPIO" "Enable/disable remote access to GPIO pins" \
2020-10-08 01:15:23 +09:00
3>&1 1>&2 2>&3)
else
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 \
2021-12-03 03:40:26 +09:00
"I2 SSH" "Enable/disable remote command line access using SSH" \
2020-10-08 01:15:23 +09:00
3>&1 1>&2 2>&3)
fi
2017-11-29 22:15:24 +09:00
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
2021-12-02 20:52:03 +09:00
I1\ *) do_legacy ;;
I2\ *) do_ssh ;;
I3\ *) do_vnc ;;
I4\ *) do_spi ;;
I5\ *) do_i2c ;;
I6\ *) do_serial ;;
I7\ *) do_onewire ;;
I8\ *) do_rgpio ;;
2017-11-29 22:15: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
2016-11-30 23:48:48 +09:00
fi
}
2020-10-08 01:15:23 +09:00
do_performance_menu() {
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"P1 Overclock" "Configure CPU overclocking" \
2020-10-14 22:59:19 +09:00
"P2 GPU Memory" "Change the amount of memory made available to the GPU" \
"P3 Overlay File System" "Enable/disable read-only file system" \
"P4 Fan" "Set behaviour of GPIO fan" \
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
2020-10-08 01:15:23 +09:00
P1\ *) do_overclock ;;
P2\ *) do_memory_split ;;
P3\ *) do_overlayfs ;;
P4\ *) do_fan ;;
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" \
"L3 Keyboard" "Set keyboard layout to match your keyboard" \
"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 ;;
L3\ *) do_configure_keyboard ;;
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() {
if is_pifour ; then
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" \
"A3 Compositor" "Enable/disable xcompmgr composition manager" \
"A4 Network Interface Names" "Enable/disable predictable network i/f names" \
"A5 Network Proxy Settings" "Configure network proxy settings" \
"A6 Boot Order" "Choose network or USB device boot" \
2020-10-30 20:00:49 +09:00
"A7 Bootloader Version" "Select latest or default boot ROM software" \
2020-10-08 01:15:23 +09:00
3>&1 1>&2 2>&3)
elif is_pi ; then
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" \
"A2 GL Driver" "Enable/disable experimental desktop GL driver" \
"A3 Compositor" "Enable/disable xcompmgr composition manager" \
"A4 Network Interface Names" "Enable/disable predictable network i/f names" \
"A5 Network Proxy Settings" "Configure network proxy settings" \
2021-11-25 19:07:11 +09:00
"A8 Glamor" "Enable/disable glamor graphics acceleration" \
2020-10-08 01:15:23 +09:00
3>&1 1>&2 2>&3)
else
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 \
"A4 Network Interface Names" "Enable/disable predictable network i/f names" \
"A5 Network Proxy Settings" "Configure network proxy settings" \
3>&1 1>&2 2>&3)
fi
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 ;;
A2\ *) do_gldriver ;;
A3\ *) do_xcompmgr ;;
A4\ *) do_net_names ;;
A5\ *) do_proxy_menu ;;
A6\ *) do_boot_order ;;
A7\ *) do_boot_rom ;;
2021-11-25 19:07:11 +09:00
A8\ *) do_glamor ;;
2020-01-13 20:57:52 +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_proxy_menu() {
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Network Proxy Settings" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"P1 All" "Set the same proxy for all schemes" \
"P2 HTTP" "Set the HTTP proxy" \
"P3 HTTPS" "Set the HTTPS/SSL proxy" \
"P4 FTP" "Set the FTP proxy" \
"P5 RSYNC" "Set the RSYNC proxy" \
"P6 Exceptions" "Set addresses for which a proxy server should not be used" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
P1\ *) do_proxy all ;;
P2\ *) do_proxy http ;;
P3\ *) do_proxy https ;;
P4\ *) do_proxy ftp ;;
P5\ *) do_proxy rsync ;;
P6\ *) do_proxy no;;
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
2017-10-30 21:20:14 +09:00
if is_pi ; then
2017-07-11 20:21:15 +09:00
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
2020-10-08 01:15:23 +09:00
"1 System Options" "Configure system settings" \
"2 Display Options" "Configure display settings" \
2020-10-14 22:59:19 +09:00
"3 Interface Options" "Configure connections to peripherals" \
2020-10-08 01:15:23 +09:00
"4 Performance Options" "Configure performance settings" \
"5 Localisation Options" "Configure language and regional settings" \
"6 Advanced Options" "Configure advanced settings" \
2017-01-10 01:52:10 +09:00
"8 Update" "Update this tool to the latest version" \
"9 About raspi-config" "Information about this configuration tool" \
3>&1 1>&2 2>&3)
else
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 \
2020-10-08 01:15:23 +09:00
"1 System Options" "Configure system settings" \
"2 Display Options" "Configure display settings" \
2020-10-14 22:59:19 +09:00
"3 Interface Options" "Configure connections to peripherals" \
2020-10-08 01:15:23 +09:00
"5 Localisation Options" "Configure language and regional settings" \
"6 Advanced Options" "Configure advanced settings" \
2017-01-10 01:52:10 +09:00
"8 Update" "Update this tool to the latest version" \
"9 About raspi-config" "Information about this configuration tool" \
3>&1 1>&2 2>&3)
fi
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 ;;
2\ *) do_display_menu ;;
3\ *) do_interface_menu ;;
4\ *) do_performance_menu ;;
5\ *) do_internationalisation_menu ;;
6\ *) do_advanced_menu ;;
8\ *) do_update ;;
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