From 35b44f1615b2d8e018ad3383b972235dbe758f1a Mon Sep 17 00:00:00 2001 From: Serge Schneider Date: Thu, 9 Nov 2017 17:25:18 +0000 Subject: [PATCH] Add non-interactive timezone, locale and keyboard configuration --- raspi-config | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/raspi-config b/raspi-config index 109be6e..6de18ba 100755 --- a/raspi-config +++ b/raspi-config @@ -290,20 +290,47 @@ do_change_pass() { } do_configure_keyboard() { - dpkg-reconfigure keyboard-configuration && - printf "Reloading keymap. This may take a short while\n" && - invoke-rc.d keyboard-setup start || return $? + 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 setsid sh -c 'exec setupcon -k --force <> /dev/tty1 >&0 2>&1' udevadm trigger --subsystem-match=input --action=change return 0 } do_change_locale() { - dpkg-reconfigure locales + if [ "$INTERACTIVE" = True ]; then + dpkg-reconfigure locales + else + local LOCALE="$1" + if ! LOCALE_LINE="$(grep "^$LOCALE " /usr/share/i18n/SUPPORTED)"; then + return 1 + fi + local ENCODING="$(echo $LOCALE_LINE | cut -f2 -d " ")" + echo "$LOCALE $ENCODING" > /etc/locale.gen + sed -i "s/^\s*LANG=\S*/LANG=$LOCALE/" /etc/default/locale + dpkg-reconfigure -f noninteractive locales + fi } do_change_timezone() { - dpkg-reconfigure tzdata + 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 } get_wifi_country() { @@ -1469,23 +1496,12 @@ do_apply_os_config() { 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 -locales locales/locales_to_be_generated multiselect $DEBLANGUAGE UTF-8 -EOF - rm /etc/locale.gen - dpkg-reconfigure -f noninteractive locales - update-locale LANG="$DEBLANGUAGE" - cat << EOF | debconf-set-selections -locales locales/default_environment_locale select $DEBLANGUAGE -EOF + do_change_locale "$DEBLANGUAGE" 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 - setupcon -k --force - udevadm trigger -p ID_INPUT_KEY=1 + do_configure_keyboard "$NOOBSKEYBOARD" fi return 0 }