mirror of
https://github.com/brain-hackers/brain-config.git
synced 2025-01-03 10:00:07 +09:00
support boot to scratch and applying language/keyboard settings from noobs
This commit is contained in:
parent
4c499fde81
commit
c8c9cf02d2
198
raspi-config
198
raspi-config
@ -379,24 +379,106 @@ do_ssh() {
|
||||
fi
|
||||
}
|
||||
|
||||
disable_raspi_config_at_boot() {
|
||||
if [ -e /etc/profile.d/raspi-config.sh ]; then
|
||||
rm -f /etc/profile.d/raspi-config.sh
|
||||
sed -i /etc/inittab \
|
||||
-e "s/^#\(.*\)#\s*RPICFG_TO_ENABLE\s*/\1/" \
|
||||
-e "/#\s*RPICFG_TO_DISABLE/d"
|
||||
telinit q
|
||||
fi
|
||||
}
|
||||
|
||||
enable_boot_to_scratch() {
|
||||
if [ -e /etc/profile.d/boottoscratch.sh ]; then
|
||||
printf "/etc/profile.d/boottoscratch.sh exists, so assuming boot to scratch enabled\n"
|
||||
return 0;
|
||||
fi
|
||||
sed -i /etc/inittab -e "s|^\(1:2345.*getty.*tty1.*\)|\
|
||||
#\1 # BTS_TO_ENABLE\n1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>\&1 # BTS_TO_DISABLE|"
|
||||
cat <<\EOF > /etc/profile.d/boottoscratch.sh
|
||||
#!/bin/sh
|
||||
# Part of raspi-config http://github.com/asb/raspi-config
|
||||
#
|
||||
# See LICENSE file for copyright and license details
|
||||
|
||||
# Should be installed to /etc/profile.d/boottoscratch.sh to force scratch to run upon boot
|
||||
|
||||
# You may also want to set automatic login in /etc/inittab on tty1 by adding a
|
||||
# line such as the following (raspi-config does this for you):
|
||||
# 1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1 # BTS_TO_DISABLE
|
||||
|
||||
if [ $(tty) = "/dev/tty1" ]; then
|
||||
printf "openbox --config-file /home/pi/boottoscratch/openbox_rc.xml & scratch" | xinit /dev/stdin
|
||||
printf "\n\n\nShutting down in 5 seconds, hit ctrl-C to cancel\n" && sleep 5 && sudo shutdown -h now
|
||||
fi
|
||||
EOF
|
||||
|
||||
mkdir -p /home/pi/boottoscratch
|
||||
cat <<\EOF > /home/pi/boottoscratch/openbox_rc.xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openbox_config xmlns="http://openbox.org/3.4/rc"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<applications>
|
||||
<application name="squeak" type="normal">
|
||||
<focus>yes</focus>
|
||||
<fullscreen>yes</fullscreen>
|
||||
</application>
|
||||
</applications>
|
||||
</openbox_config>
|
||||
EOF
|
||||
telinit q
|
||||
}
|
||||
|
||||
disable_boot_to_scratch() {
|
||||
if [ -e /etc/profile.d/boottoscratch.sh ]; then
|
||||
rm -f /etc/profile.d/boottoscratch.sh
|
||||
sed -i /etc/inittab \
|
||||
-e "s/^#\(.*\)#\s*BTS_TO_ENABLE\s*/\1/" \
|
||||
-e "/#\s*BTS_TO_DISABLE/d"
|
||||
telinit q
|
||||
fi
|
||||
}
|
||||
|
||||
do_boot_behaviour() {
|
||||
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" \
|
||||
"Scratch" "Start the Scratch programming environment upon boot" \
|
||||
3>&1 1>&2 2>&3)
|
||||
if [ $? -eq 0 ]; then
|
||||
case "$BOOTOPT" in
|
||||
Console)
|
||||
[ -e /etc/init.d/lightdm ] && update-rc.d lightdm disable 2
|
||||
disable_boot_to_scratch
|
||||
;;
|
||||
Desktop)
|
||||
if [ -e /etc/init.d/lightdm ]; then
|
||||
whiptail --yesno "Should we boot straight to desktop?" 20 60 2
|
||||
RET=$?
|
||||
if [ $RET -eq 0 ]; then # yes
|
||||
update-rc.d lightdm enable 2
|
||||
sed /etc/lightdm/lightdm.conf -i -e "s/^#autologin-user=.*/autologin-user=pi/"
|
||||
ASK_TO_REBOOT=1
|
||||
elif [ $RET -eq 1 ]; then # no
|
||||
update-rc.d lightdm disable 2
|
||||
ASK_TO_REBOOT=1
|
||||
else # user hit escape
|
||||
return 1
|
||||
fi
|
||||
disable_boot_to_scratch
|
||||
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
|
||||
;;
|
||||
Scratch)
|
||||
if [ -e /usr/bin/scratch ]; then
|
||||
[ -e /etc/init.d/lightdm ] && update-rc.d lightdm disable 2
|
||||
enable_boot_to_scratch
|
||||
disable_raspi_config_at_boot
|
||||
else
|
||||
whiptail --msgbox "Do sudo apt-get install scratch to allow configuration of boot to scratch" 20 60 2
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
ASK_TO_REBOOT=1
|
||||
fi
|
||||
}
|
||||
|
||||
do_rastrack() {
|
||||
@ -470,13 +552,7 @@ do_update() {
|
||||
}
|
||||
|
||||
do_finish() {
|
||||
if [ -e /etc/profile.d/raspi-config.sh ]; then
|
||||
rm -f /etc/profile.d/raspi-config.sh
|
||||
sed -i /etc/inittab \
|
||||
-e "s/^#\(.*\)#\s*RPICFG_TO_ENABLE\s*/\1/" \
|
||||
-e "/#\s*RPICFG_TO_DISABLE/d"
|
||||
telinit q
|
||||
fi
|
||||
disable_raspi_config_at_boot
|
||||
if [ $ASK_TO_REBOOT -eq 1 ]; then
|
||||
whiptail --yesno "Would you like to reboot now?" 20 60 2
|
||||
if [ $? -eq 0 ]; then # yes
|
||||
@ -487,6 +563,87 @@ do_finish() {
|
||||
exit 0
|
||||
}
|
||||
|
||||
# $1 = filename, $2 = key name
|
||||
get_json_string_val() {
|
||||
sed -n -e "s/^[[:space:]]*\"$2\"[[:space:]]*:[[:space:]]*\"\(.*\)\"[[:space:]]*,$/\1/p" $1
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
if [ "$NOOBSFLAVOUR" = "Scratch" ]; then
|
||||
disable_raspi_config_at_boot
|
||||
enable_boot_to_scratch
|
||||
else
|
||||
printf "Unrecognised flavour. Ignoring\n"
|
||||
fi
|
||||
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"
|
||||
;;
|
||||
*)
|
||||
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"
|
||||
# TODO: map noobs language to Debian spec
|
||||
cat << EOF | debconf-set-selections
|
||||
locales locales/locales_to_be_generated multiselect fr_FR.UTF-8 UTF-8
|
||||
EOF
|
||||
rm /etc/locale.gen
|
||||
dpkg-reconfigure -f noninteractive locales
|
||||
update-locale LANG=fr_FR.UTF-8
|
||||
cat << EOF | debconf-set-selections
|
||||
locales locales/default_environment_locale select fr_FR.UTF-8
|
||||
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
|
||||
}
|
||||
|
||||
#
|
||||
# Command line options for non-interactive use
|
||||
#
|
||||
@ -509,6 +666,11 @@ do
|
||||
printf "Please reboot\n"
|
||||
exit 0
|
||||
;;
|
||||
--apply-os-config)
|
||||
INTERACTIVE=False
|
||||
do_apply_os_config
|
||||
exit $?
|
||||
;;
|
||||
*)
|
||||
# unknown option
|
||||
;;
|
||||
@ -585,7 +747,7 @@ 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 Enable Boot to Desktop" "Choose whether to boot into a desktop environment or the command-line" \
|
||||
"3 Enable Boot to Desktop/Scratch" "Choose whether to boot into a desktop environment, Scratch, or the command-line" \
|
||||
"4 Internationalisation Options" "Set up language and regional settings to match your location" \
|
||||
"5 Enable Camera" "Enable this Pi to work with the Raspberry Pi Camera" \
|
||||
"6 Add to Rastrack" "Add this Pi to the online Raspberry Pi Map (Rastrack)" \
|
||||
|
Loading…
Reference in New Issue
Block a user