2012-06-11 05:32:01 +09:00
#!/bin/sh
# Part of raspi-config http://github.com/asb/raspi-config
#
# 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
2015-05-29 19:35:13 +09:00
get_init_sys() {
if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then
SYSTEMD=1
elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then
SYSTEMD=0
else
echo "Unrecognised init system"
return 1
fi
}
2013-05-23 03:37:56 +09:00
calc_wt_size() {
# NOTE: it's tempting to redirect stderr to /dev/null, so supress error
# output from tput. However in this case, tput detects neither stdout or
# stderr is a tty and so only gives default 80, 24 values
2013-05-24 10:01:35 +09:00
WT_HEIGHT=17
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 "\
2013-03-27 06:58:32 +09:00
This tool provides a straight-forward way of doing initial
configuration of the Raspberry Pi. Although it can be run
at any time, some of the options may have difficulties if
2012-07-14 01:13:30 +09:00
you have heavily customised your installation.\
" 20 70 1
2012-06-11 05:32:01 +09:00
}
2013-05-23 04:11:00 +09:00
do_expand_rootfs() {
2015-09-15 18:25:53 +09:00
get_init_sys
2015-05-29 19:35:13 +09:00
if [ $SYSTEMD -eq 1 ]; then
ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
else
if ! [ -h /dev/root ]; then
whiptail --msgbox "/dev/root does not exist or is not a symlink. Don't know how to expand" 20 60 2
return 0
fi
ROOT_PART=$(readlink /dev/root)
2013-05-21 03:45:01 +09:00
fi
PART_NUM=${ROOT_PART#mmcblk0p}
if [ "$PART_NUM" = "$ROOT_PART" ]; then
2015-05-29 19:35:13 +09:00
whiptail --msgbox "$ROOT_PART is not an SD card. Don't know how to expand" 20 60 2
2013-05-21 03:45:01 +09:00
return 0
fi
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
2013-05-21 03:45:01 +09:00
LAST_PART_NUM=$(parted /dev/mmcblk0 -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
2015-05-29 19:35:13 +09:00
PART_START=$(parted /dev/mmcblk0 -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
fdisk /dev/mmcblk0 <<EOF
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" &&
2015-05-29 19:35:13 +09:00
resize2fs /dev/$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
}
2012-06-11 05:32:01 +09:00
# $1 is 0 to disable overscan, 1 to disable it
set_overscan() {
# Stop if /boot is not a mountpoint
if ! mountpoint -q /boot; then
return 1
fi
2015-01-30 08:30:09 +09:00
[ -e $CONFIG ] || touch $CONFIG
2012-06-11 05:32:01 +09:00
if [ "$1" -eq 0 ]; then # disable overscan
2015-01-30 08:30:09 +09:00
sed $CONFIG -i -e "s/^overscan_/#overscan_/"
set_config_var disable_overscan 1 $CONFIG
2012-06-11 05:32:01 +09:00
else # enable overscan
2015-01-30 08:30:09 +09:00
set_config_var disable_overscan 0 $CONFIG
2012-06-11 05:32:01 +09:00
fi
}
2013-05-23 04:21:24 +09:00
do_overscan() {
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "What would you like to do with overscan" 20 60 2 \
--yes-button Disable --no-button Enable
RET=$?
else
RET=$1
fi
2012-06-11 05:32:01 +09:00
if [ $RET -eq 0 ] || [ $RET -eq 1 ]; then
2012-07-16 02:32:30 +09:00
ASK_TO_REBOOT=1
2012-06-11 05:32:01 +09:00
set_overscan $RET;
else
return 1
fi
}
2013-05-23 04:11:00 +09:00
do_change_pass() {
2012-06-11 05:32:01 +09:00
whiptail --msgbox "You will now be asked to enter a new password for the pi user" 20 60 1
passwd pi &&
whiptail --msgbox "Password changed successfully" 20 60 1
}
2013-05-23 04:17:32 +09:00
do_configure_keyboard() {
2012-06-17 07:06:12 +09:00
dpkg-reconfigure keyboard-configuration &&
2012-06-11 05:32:01 +09:00
printf "Reloading keymap. This may take a short while\n" &&
2015-05-27 16:23:36 +09:00
invoke-rc.d keyboard-setup start || return $?
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() {
2012-06-11 05:32:01 +09:00
dpkg-reconfigure locales
}
2013-05-23 04:17:32 +09:00
do_change_timezone() {
2012-06-11 05:32:01 +09:00
dpkg-reconfigure tzdata
}
2013-05-23 04:21:24 +09:00
do_change_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
if ! mountpoint -q /boot; then
return 1
fi
## get current memory split from /boot/config.txt
2015-01-30 08:30:09 +09:00
CUR_GPU_MEM=$(get_config_var gpu_mem $CONFIG)
2012-10-29 05:38:27 +09:00
[ -z "$CUR_GPU_MEM" ] && CUR_GPU_MEM=64
## ask users what gpu_mem they want
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
NEW_GPU_MEM=$(whiptail --inputbox "How much memory should the GPU have? e.g. 16/32/64/128/256" \
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
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-06-11 05:32:01 +09:00
# Stop if /boot is not a mountpoint
if ! mountpoint -q /boot; then
return 1
fi
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() {
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.
See http://elinux.org/RPi_Overclocking for more information.\
2012-09-17 19:28:39 +09:00
" 20 70 1
2015-09-15 18:25:53 +09:00
OVERCLOCK=$(whiptail --menu "Chose overclock preset" 20 60 10 \
"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" \
"Pi2" "1000MHz ARM, 500MHz core, 500MHz SDRAM, 2 overvolt" \
3>&1 1>&2 2>&3)
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)
2012-10-29 05:54:10 +09:00
set_overclock High 950 250 450 6
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
;;
2015-02-01 05:18:38 +09:00
Pi2)
set_overclock Pi2 1000 500 500 2
;;
2015-09-15 18:25:53 +09:00
Pi2None)
2015-11-17 20:35:04 +09:00
clear_overclock
2015-09-15 18:25:53 +09:00
;;
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
}
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
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the SSH server enabled or disabled?" 20 60 2 \
--yes-button Enable --no-button Disable
RET=$?
else
RET=$1
fi
2012-06-11 05:32:01 +09:00
if [ $RET -eq 0 ]; then
update-rc.d ssh enable &&
invoke-rc.d ssh start &&
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "SSH server enabled" 20 60 1
fi
2012-06-11 05:32:01 +09:00
elif [ $RET -eq 1 ]; then
update-rc.d ssh disable &&
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "SSH server disabled" 20 60 1
fi
2012-06-11 05:32:01 +09:00
else
return $RET
fi
}
2015-01-30 08:30:09 +09:00
do_devicetree() {
CURRENT_SETTING="enabled" # assume not disabled
DEFAULT=
if [ -e $CONFIG ] && grep -q "^device_tree=$" $CONFIG; then
CURRENT_SETTING="disabled"
DEFAULT=--defaultno
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the kernel to use Device Tree?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
2015-01-30 08:30:09 +09:00
if [ $RET -eq 0 ]; then
sed $CONFIG -i -e "s/^\(device_tree=\)$/#\1/"
sed $CONFIG -i -e "s/^#\(device_tree=.\)/\1/"
SETTING=enabled
elif [ $RET -eq 1 ]; then
sed $CONFIG -i -e "s/^#\(device_tree=\)$/\1/"
sed $CONFIG -i -e "s/^\(device_tree=.\)/#\1/"
if ! grep -q "^device_tree=$" $CONFIG; then
printf "device_tree=\n" >> $CONFIG
fi
SETTING=disabled
else
return 0
fi
TENSE=is
REBOOT=
if [ $SETTING != $CURRENT_SETTING ]; then
TENSE="will be"
REBOOT=" after a reboot"
2015-02-01 05:18:38 +09:00
ASK_TO_REBOOT=1
2015-01-30 08:30:09 +09:00
fi
whiptail --msgbox "Device Tree $TENSE $SETTING$REBOOT" 20 60 1
}
2013-09-26 02:56:38 +09:00
do_spi() {
2015-01-30 08:30:09 +09:00
DEVICE_TREE="yes" # assume not disabled
DEFAULT=
if [ -e $CONFIG ] && grep -q "^device_tree=$" $CONFIG; then
DEVICE_TREE="no"
fi
CURRENT_SETTING="off" # assume disabled
DEFAULT=--defaultno
if [ -e $CONFIG ] && grep -q -E "^(device_tree_param|dtparam)=([^,]*,)*spi(=(on|true|yes|1))?(,.*)?$" $CONFIG; then
CURRENT_SETTING="on"
DEFAULT=
fi
if [ $DEVICE_TREE = "yes" ]; then
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the SPI interface to be enabled?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
2015-01-30 08:30:09 +09:00
if [ $RET -eq 0 ]; then
SETTING=on
STATUS=enabled
elif [ $RET -eq 1 ]; then
SETTING=off
STATUS=disabled
else
return 0
fi
TENSE=is
REBOOT=
if [ $SETTING != $CURRENT_SETTING ]; then
TENSE="will be"
REBOOT=" after a reboot"
2015-02-01 05:18:38 +09:00
ASK_TO_REBOOT=1
2015-01-30 08:30:09 +09:00
fi
sed $CONFIG -i -r -e "s/^((device_tree_param|dtparam)=([^,]*,)*spi)(=[^,]*)?/\1=$SETTING/"
if ! grep -q -E "^(device_tree_param|dtparam)=([^,]*,)*spi=[^,]*" $CONFIG; then
printf "dtparam=spi=$SETTING\n" >> $CONFIG
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The SPI interface $TENSE $STATUS$REBOOT" 20 60 1
fi
2015-01-30 08:30:09 +09:00
if [ $SETTING = "off" ]; then
return 0
fi
fi
2013-09-26 02:56:38 +09:00
CURRENT_STATUS="yes" # assume not blacklisted
2015-01-30 08:30:09 +09:00
DEFAULT=
if [ -e $BLACKLIST ] && grep -q "^blacklist[[:space:]]*spi[-_]bcm2708" $BLACKLIST; then
2013-09-26 02:56:38 +09:00
CURRENT_STATUS="no"
2015-01-30 08:30:09 +09:00
DEFAULT=--defaultno
2013-09-26 02:56:38 +09:00
fi
2015-02-01 05:18:38 +09:00
if ! [ -e $BLACKLIST ]; then
touch $BLACKLIST
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the SPI kernel module to be loaded by default?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
2013-09-26 02:56:38 +09:00
if [ $RET -eq 0 ]; then
2015-01-30 08:30:09 +09:00
sed $BLACKLIST -i -e "s/^\(blacklist[[:space:]]*spi[-_]bcm2708\)/#\1/"
modprobe spi-bcm2708
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "SPI kernel module will now be loaded by default" 20 60 1
fi
2013-09-26 02:56:38 +09:00
elif [ $RET -eq 1 ]; then
2015-01-30 08:30:09 +09:00
sed $BLACKLIST -i -e "s/^#\(blacklist[[:space:]]*spi[-_]bcm2708\)/\1/"
if ! grep -q "^blacklist spi[-_]bcm2708" $BLACKLIST; then
printf "blacklist spi-bcm2708\n" >> $BLACKLIST
2013-09-26 02:56:38 +09:00
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "SPI kernel module will no longer be loaded by default" 20 60 1
fi
2013-09-26 02:56:38 +09:00
else
2015-01-30 08:30:09 +09:00
return 0
2013-09-26 02:56:38 +09:00
fi
}
2014-09-01 19:44:45 +09:00
do_i2c() {
2015-01-30 08:30:09 +09:00
DEVICE_TREE="yes" # assume not disabled
DEFAULT=
if [ -e $CONFIG ] && grep -q "^device_tree=$" $CONFIG; then
DEVICE_TREE="no"
fi
CURRENT_SETTING="off" # assume disabled
DEFAULT=--defaultno
if [ -e $CONFIG ] && grep -q -E "^(device_tree_param|dtparam)=([^,]*,)*i2c(_arm)?(=(on|true|yes|1))?(,.*)?$" $CONFIG; then
CURRENT_SETTING="on"
DEFAULT=
fi
if [ $DEVICE_TREE = "yes" ]; then
2015-09-15 18:25:53 +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
2015-01-30 08:30:09 +09:00
if [ $RET -eq 0 ]; then
SETTING=on
STATUS=enabled
elif [ $RET -eq 1 ]; then
SETTING=off
STATUS=disabled
else
return 0
fi
TENSE=is
REBOOT=
if [ $SETTING != $CURRENT_SETTING ]; then
TENSE="will be"
REBOOT=" after a reboot"
2015-02-01 05:18:38 +09:00
ASK_TO_REBOOT=1
2015-01-30 08:30:09 +09:00
fi
sed $CONFIG -i -r -e "s/^((device_tree_param|dtparam)=([^,]*,)*i2c(_arm)?)(=[^,]*)?/\1=$SETTING/"
if ! grep -q -E "^(device_tree_param|dtparam)=([^,]*,)*i2c(_arm)?=[^,]*" $CONFIG; then
printf "dtparam=i2c_arm=$SETTING\n" >> $CONFIG
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "The ARM I2C interface $TENSE $STATUS$REBOOT" 20 60 1
fi
2015-01-30 08:30:09 +09:00
if [ $SETTING = "off" ]; then
return 0
fi
fi
2014-09-01 19:44:45 +09:00
CURRENT_STATUS="yes" # assume not blacklisted
2015-01-30 08:30:09 +09:00
DEFAULT=
if [ -e $BLACKLIST ] && grep -q "^blacklist[[:space:]]*i2c[-_]bcm2708" $BLACKLIST; then
2014-09-01 19:44:45 +09:00
CURRENT_STATUS="no"
2015-01-30 08:30:09 +09:00
DEFAULT=--defaultno
2014-09-01 19:44:45 +09:00
fi
2015-02-01 05:18:38 +09:00
if ! [ -e $BLACKLIST ]; then
touch $BLACKLIST
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like the I2C kernel module to be loaded by default?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
fi
2014-09-01 19:44:45 +09:00
if [ $RET -eq 0 ]; then
2015-01-30 08:30:09 +09:00
sed $BLACKLIST -i -e "s/^\(blacklist[[:space:]]*i2c[-_]bcm2708\)/#\1/"
2015-06-02 18:46:18 +09:00
sed /etc/modules -i -e "s/^#[[:space:]]*\(i2c[-_]dev\)/\1/"
if ! grep -q "^i2c[-_]dev" /etc/modules; then
printf "i2c-dev\n" >> /etc/modules
fi
2015-01-30 08:30:09 +09:00
modprobe i2c-bcm2708
2015-06-02 18:46:18 +09:00
modprobe i2c-dev
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "I2C kernel module will now be loaded by default" 20 60 1
fi
2014-09-01 19:44:45 +09:00
elif [ $RET -eq 1 ]; then
2015-01-30 08:30:09 +09:00
sed $BLACKLIST -i -e "s/^#\(blacklist[[:space:]]*i2c[-_]bcm2708\)/\1/"
if ! grep -q "^blacklist i2c[-_]bcm2708" $BLACKLIST; then
printf "blacklist i2c-bcm2708\n" >> $BLACKLIST
2014-09-01 19:44:45 +09:00
fi
2015-06-02 18:46:18 +09:00
sed /etc/modules -i -e "s/^\(i2c[-_]dev\)/#\1/"
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "I2C kernel module will no longer be loaded by default" 20 60 1
fi
2014-09-01 19:44:45 +09:00
else
2015-01-30 08:30:09 +09:00
return 0
2014-09-01 19:44:45 +09:00
fi
}
2014-09-03 01:25:58 +09:00
do_serial() {
2015-05-29 19:35:13 +09:00
DEFAULT=
if ! grep -q "console=ttyAMA0" /boot/cmdline.txt; then
DEFAULT=--defaultno
2014-09-03 01:25:58 +09:00
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Would you like a login shell to be accessible over serial?" $DEFAULT 20 60 2
RET=$?
else
get_init_sys
RET=$1
fi
2014-09-03 01:25:58 +09:00
if [ $RET -eq 1 ]; then
2015-05-29 19:35:13 +09:00
if [ $SYSTEMD -eq 0 ]; then
sed -i /etc/inittab -e "s|^.*:.*:respawn:.*ttyAMA0|#&|"
fi
2014-09-03 01:25:58 +09:00
sed -i /boot/cmdline.txt -e "s/console=ttyAMA0,[0-9]\+ //"
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Serial is now disabled" 20 60 1
fi
2014-09-03 01:25:58 +09:00
elif [ $RET -eq 0 ]; then
2015-05-29 19:35:13 +09:00
if [ $SYSTEMD -eq 0 ]; then
sed -i /etc/inittab -e "s|^#\(.*:.*:respawn:.*ttyAMA0\)|\1|"
if ! grep -q "^T.*:.*:respawn:.*ttyAMA0" /etc/inittab; then
printf "T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100\n" >> /etc/inittab
fi
2014-09-03 01:25:58 +09:00
fi
if ! grep -q "console=ttyAMA0" /boot/cmdline.txt; then
2015-05-29 19:35:13 +09:00
sed -i /boot/cmdline.txt -e "s/root=/console=ttyAMA0,115200 root=/"
2014-09-03 01:25:58 +09:00
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --msgbox "Serial is now enabled" 20 60 1
fi
2014-09-03 01:25:58 +09:00
else
return $RET
fi
2015-05-29 19:35:13 +09:00
ASK_TO_REBOOT=1
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
2015-05-29 19:35:13 +09:00
if [ $SYSTEMD -eq 1 ]; then
if [ -e /etc/systemd/system/getty@tty1.service.d/raspi-config-override.conf ]; then
rm /etc/systemd/system/getty@tty1.service.d/raspi-config-override.conf
fi
else
sed -i /etc/inittab \
-e "s/^#\(.*\)#\s*RPICFG_TO_ENABLE\s*/\1/" \
-e "/#\s*RPICFG_TO_DISABLE/d"
fi
2013-09-10 07:55:22 +09:00
telinit q
fi
}
2015-09-15 18:25:53 +09:00
do_boot_behaviour_new() {
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" \
"B2 Console Autologin" "Text console, automatically logged in as 'pi' user" \
"B3 Desktop" "Desktop GUI, requiring user to login" \
"B4 Desktop Autologin" "Desktop GUI, automatically logged in as 'pi' user" \
3>&1 1>&2 2>&3)
else
get_init_sys
BOOTOPT=$1
true
fi
if [ $? -eq 0 ]; then
case "$BOOTOPT" in
B1*)
if [ -e /etc/init.d/lightdm ]; then
if [ $SYSTEMD -eq 1 ]; then
systemctl set-default multi-user.target
2015-09-24 05:25:39 +09:00
ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
2015-09-15 18:25:53 +09:00
else
update-rc.d lightdm disable 2
sed /etc/inittab -i -e "s/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/"
fi
fi
;;
B2*)
if [ -e /etc/init.d/lightdm ]; then
if [ $SYSTEMD -eq 1 ]; then
systemctl set-default multi-user.target
2015-09-24 05:25:39 +09:00
ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
2015-09-15 18:25:53 +09:00
else
update-rc.d lightdm disable 2
sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/"
fi
fi
;;
B3*)
if [ -e /etc/init.d/lightdm ]; then
if [ $SYSTEMD -eq 1 ]; then
systemctl set-default graphical.target
2015-09-24 05:25:39 +09:00
ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
2015-09-15 18:25:53 +09:00
else
update-rc.d lightdm enable 2
fi
sed /etc/lightdm/lightdm.conf -i -e "s/^autologin-user=pi/#autologin-user=/"
disable_raspi_config_at_boot
else
whiptail --msgbox "Do sudo apt-get install lightdm to allow configuration of boot to desktop" 20 60 2
return 1
fi
;;
B4*)
if [ -e /etc/init.d/lightdm ]; then
if id -u pi > /dev/null 2>&1; then
if [ $SYSTEMD -eq 1 ]; then
systemctl set-default graphical.target
2015-09-24 05:25:39 +09:00
ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
2015-09-15 18:25:53 +09:00
else
update-rc.d lightdm enable 2
fi
sed /etc/lightdm/lightdm.conf -i -e "s/^#autologin-user=.*/autologin-user=pi/"
disable_raspi_config_at_boot
else
whiptail --msgbox "The pi user has been removed, can't set up boot to desktop" 20 60 2
fi
else
whiptail --msgbox "Do sudo apt-get install lightdm to allow configuration of boot to desktop" 20 60 2
return 1
fi
;;
*)
whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2
return 1
;;
esac
ASK_TO_REBOOT=1
fi
}
2015-10-19 20:58:20 +09:00
do_wait_for_network() {
get_init_sys
if [ $SYSTEMD -eq 0 ]; then
whiptail --msgbox "This option can only be selected when using systemd" 20 60 2
return 1
fi
if [ "$INTERACTIVE" = True ]; then
RET=$(whiptail --menu "Chose boot option" 20 70 10 \
"Fast" "Boot without waiting for network connection" \
"Slow" "Wait for network connection before completing boot" \
3>&1 1>&2 2>&3)
else
get_init_sys
RET=$1
true
fi
if [ $? -eq 0 ]; then
case "$RET" in
Fast)
rm /etc/systemd/system/dhcpcd.service.d/wait.conf
;;
Slow)
mkdir -p /etc/systemd/system/dhcpcd.service.d/
cat > /etc/systemd/system/dhcpcd.service.d/wait.conf << EOF
[Service]
ExecStart=
ExecStart=/sbin/dhcpcd -q -w
EOF
;;
*)
whiptail --msgbox "Programmer error, unrecognised option" 20 60 2
return 1
;;
esac
fi
}
2013-05-23 04:11:00 +09:00
do_boot_behaviour() {
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
BOOTOPT=$(whiptail --menu "Chose boot option" 20 60 10 \
"Console" "Text console, requiring login (default)" \
"Desktop" "Log in as user 'pi' at the graphical desktop" \
3>&1 1>&2 2>&3)
else
get_init_sys
BOOTOPT=$1
true
fi
2013-09-10 07:55:22 +09:00
if [ $? -eq 0 ]; then
case "$BOOTOPT" in
Console)
2015-05-29 19:35:13 +09:00
if [ -e /etc/init.d/lightdm ]; then
if [ $SYSTEMD -eq 1 ]; then
2015-06-03 23:12:15 +09:00
systemctl set-default multi-user.target
2015-05-29 19:35:13 +09:00
else
update-rc.d lightdm disable 2
fi
fi
2013-09-10 07:55:22 +09:00
;;
Desktop)
if [ -e /etc/init.d/lightdm ]; then
2013-12-17 05:55:23 +09:00
if id -u pi > /dev/null 2>&1; then
2015-05-29 19:35:13 +09:00
if [ $SYSTEMD -eq 1 ]; then
2015-06-03 23:12:15 +09:00
systemctl set-default graphical.target
2015-05-29 19:35:13 +09:00
else
update-rc.d lightdm enable 2
fi
2013-12-17 05:55:23 +09:00
sed /etc/lightdm/lightdm.conf -i -e "s/^#autologin-user=.*/autologin-user=pi/"
disable_raspi_config_at_boot
else
whiptail --msgbox "The pi user has been removed, can't set up boot to desktop" 20 60 2
fi
2013-09-10 07:55:22 +09:00
else
whiptail --msgbox "Do sudo apt-get install lightdm to allow configuration of boot to desktop" 20 60 2
return 1
fi
;;
*)
whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2
return 1
;;
esac
ASK_TO_REBOOT=1
2012-07-14 06:52:06 +09:00
fi
}
2013-05-23 04:11:00 +09:00
do_rastrack() {
2013-05-10 20:03:00 +09:00
whiptail --msgbox "\
Rastrack (http://rastrack.co.uk) is a website run by Ryan Walmsley
for tracking where people are using Raspberry Pis around the world.
If you have an internet connection, you can add yourself directly
using this tool. This is just a bit of fun, not any sort of official
registration.\
" 20 70 1
if [ $? -ne 0 ]; then
return 0;
fi
2013-05-07 22:37:14 +09:00
UNAME=$(whiptail --inputbox "Username / Nickname For Rastrack Addition" 20 70 3>&1 1>&2 2>&3)
2013-05-10 20:03:00 +09:00
if [ $? -ne 0 ]; then
return 1;
fi
2013-05-07 22:37:14 +09:00
EMAIL=$(whiptail --inputbox "Email Address For Rastrack Addition" 20 70 3>&1 1>&2 2>&3)
2013-05-10 20:03:00 +09:00
if [ $? -ne 0 ]; then
return 1;
fi
2013-05-07 22:37:14 +09:00
curl --data "name=$UNAME&email=$EMAIL" http://rastrack.co.uk/api.php
2013-05-10 20:03:00 +09:00
printf "Hit enter to continue\n"
read TMP
2013-04-05 21:36:33 +09:00
}
2013-05-08 17:57:36 +09:00
# $1 is 0 to disable camera, 1 to enable it
set_camera() {
# Stop if /boot is not a mountpoint
if ! mountpoint -q /boot; then
return 1
fi
2015-01-30 08:30:09 +09:00
[ -e $CONFIG ] || touch $CONFIG
2013-05-08 17:57:36 +09:00
if [ "$1" -eq 0 ]; then # disable camera
2015-01-30 08:30:09 +09:00
set_config_var start_x 0 $CONFIG
sed $CONFIG -i -e "s/^startx/#startx/"
sed $CONFIG -i -e "s/^start_file/#start_file/"
sed $CONFIG -i -e "s/^fixup_file/#fixup_file/"
2013-05-08 17:57:36 +09:00
else # enable camera
2015-01-30 08:30:09 +09:00
set_config_var start_x 1 $CONFIG
CUR_GPU_MEM=$(get_config_var gpu_mem $CONFIG)
2013-12-17 06:09:43 +09:00
if [ -z "$CUR_GPU_MEM" ] || [ "$CUR_GPU_MEM" -lt 128 ]; then
2015-01-30 08:30:09 +09:00
set_config_var gpu_mem 128 $CONFIG
2013-12-17 06:09:43 +09:00
fi
2015-01-30 08:30:09 +09:00
sed $CONFIG -i -e "s/^startx/#startx/"
sed $CONFIG -i -e "s/^fixup_file/#fixup_file/"
2013-05-08 17:57:36 +09:00
fi
}
2013-05-23 04:11:00 +09:00
do_camera() {
2013-05-10 19:50:13 +09:00
if [ ! -e /boot/start_x.elf ]; then
whiptail --msgbox "Your firmware appears to be out of date (no start_x.elf). Please update" 20 60 2
return 1
fi
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
whiptail --yesno "Enable support for Raspberry Pi camera?" 20 60 2 \
--yes-button Disable --no-button Enable
RET=$?
else
RET=$1
fi
2013-05-08 17:57:36 +09:00
if [ $RET -eq 0 ] || [ $RET -eq 1 ]; then
ASK_TO_REBOOT=1
set_camera $RET;
else
return 1
fi
}
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() {
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)
if [ $? -eq 0 ]; then
amixer cset numid=3 "$AUDIO_OUT"
fi
}
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"
cat << EOF | debconf-set-selections
2013-09-26 02:16:19 +09:00
locales locales/locales_to_be_generated multiselect $DEBLANGUAGE UTF-8
2013-09-10 07:55:22 +09:00
EOF
rm /etc/locale.gen
dpkg-reconfigure -f noninteractive locales
2013-09-26 02:16:19 +09:00
update-locale LANG="$DEBLANGUAGE"
2013-09-10 07:55:22 +09:00
cat << EOF | debconf-set-selections
2013-09-26 02:16:19 +09:00
locales locales/default_environment_locale select $DEBLANGUAGE
2013-09-10 07:55:22 +09:00
EOF
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"
sed -i /etc/default/keyboard -e "s/^XKBLAYOUT.*/XKBLAYOUT=\"$NOOBSKEYBOARD\"/"
dpkg-reconfigure -f noninteractive keyboard-configuration
invoke-rc.d keyboard-setup start
fi
return 0
}
2015-09-15 18:25:53 +09:00
nonint() {
$*
}
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
$@
;;
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
2013-05-23 04:11:00 +09:00
do_internationalisation_menu() {
2013-05-23 03:37:56 +09:00
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Internationalisation Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
2013-05-23 04:17:32 +09:00
"I1 Change Locale" "Set up language and regional settings to match your location" \
"I2 Change Timezone" "Set up timezone to match your location" \
"I3 Change Keyboard Layout" "Set the keyboard layout to match your keyboard" \
3>&1 1>&2 2>&3)
2013-05-23 01:44:15 +09:00
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
2013-05-23 04:17:32 +09:00
case "$FUN" in
I1\ *) do_change_locale ;;
I2\ *) do_change_timezone ;;
I3\ *) do_configure_keyboard ;;
*) 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
}
2013-05-23 04:11:00 +09:00
do_advanced_menu() {
2013-05-23 03:37:56 +09:00
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Advanced Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
2013-05-23 04:21:24 +09:00
"A1 Overscan" "You may need to configure overscan if black bars are present on display" \
"A2 Hostname" "Set the visible name for this Pi on a network" \
"A3 Memory Split" "Change the amount of memory made available to the GPU" \
2013-05-23 04:24:58 +09:00
"A4 SSH" "Enable/Disable remote command line access to your Pi using SSH" \
2015-01-30 08:30:09 +09:00
"A5 Device Tree" "Enable/Disable the use of Device Tree" \
"A6 SPI" "Enable/Disable automatic loading of SPI kernel module (needed for e.g. PiFace)" \
"A7 I2C" "Enable/Disable automatic loading of I2C kernel module" \
"A8 Serial" "Enable/Disable shell and kernel messages on the serial connection" \
"A9 Audio" "Force audio out through HDMI or 3.5mm jack" \
"A0 Update" "Update this tool to the latest version" \
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
A1\ *) do_overscan ;;
A2\ *) do_change_hostname ;;
A3\ *) do_memory_split ;;
2013-05-23 04:24:58 +09:00
A4\ *) do_ssh ;;
2015-01-30 08:30:09 +09:00
A5\ *) do_devicetree ;;
A6\ *) do_spi ;;
A7\ *) do_i2c ;;
A8\ *) do_serial ;;
A9\ *) do_audio ;;
A0\ *) do_update ;;
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
}
2012-08-21 05:53:15 +09:00
#
# Interactive use loop
#
2015-09-15 18:25:53 +09:00
if [ "$INTERACTIVE" = True ]; then
get_init_sys
calc_wt_size
while true; do
FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
"1 Expand Filesystem" "Ensures that all of the SD card storage is available to the OS" \
"2 Change User Password" "Change password for the default user (pi)" \
"3 Boot Options" "Choose whether to boot into a desktop environment or the command line" \
2015-10-19 20:58:20 +09:00
"4 Wait for Network at Boot" "Choose whether to wait for network connection during boot" \
"5 Internationalisation Options" "Set up language and regional settings to match your location" \
"6 Enable Camera" "Enable this Pi to work with the Raspberry Pi Camera" \
"7 Add to Rastrack" "Add this Pi to the online Raspberry Pi Map (Rastrack)" \
"8 Overclock" "Configure overclocking for your Pi" \
"9 Advanced Options" "Configure advanced settings" \
"0 About raspi-config" "Information about this configuration tool" \
2015-09-15 18:25:53 +09:00
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
do_finish
elif [ $RET -eq 0 ]; then
case "$FUN" in
1\ *) do_expand_rootfs ;;
2\ *) do_change_pass ;;
3\ *) do_boot_behaviour_new ;;
2015-10-19 20:58:20 +09:00
4\ *) do_wait_for_network ;;
5\ *) do_internationalisation_menu ;;
6\ *) do_camera ;;
7\ *) do_rastrack ;;
8\ *) do_overclock ;;
9\ *) do_advanced_menu ;;
0\ *) do_about ;;
2015-09-15 18:25: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
else
exit 1
fi
done
2015-09-24 05:25:39 +09:00
fi