From 9246712c6f24b144a4b4a9b4c7f9885c7d188d7b Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Wed, 8 May 2019 13:13:19 +0200 Subject: [PATCH 01/10] Add TIMEZONE_PRESET variable In the same way that LOCALE_PRESET and KEYTABLE_PRESET, this patch introduces a new variable, TIMEZONE_PRESET, that will skip the time-zone dialog box if is set. --- files/usr/lib/jeos-firstboot | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/files/usr/lib/jeos-firstboot b/files/usr/lib/jeos-firstboot index 5cdc0b7..31ea620 100755 --- a/files/usr/lib/jeos-firstboot +++ b/files/usr/lib/jeos-firstboot @@ -289,17 +289,22 @@ fi default="$(readlink -f /etc/localtime)" default="${default##/usr/share/zoneinfo/}" -# timedatectl doesn't work as dbus is not up yet -# menulist timedatectl --no-pager list-timezones -if menulist awk \ - 'BEGIN{print "UTC"; sort="sort"}/^#/{next;}{print $3|sort}END{close(sort)}' \ - /usr/share/zoneinfo/zone.tab \ - && d --default-item "$default" --menu $"Select Time Zone" 0 0 $dh_menu "${list[@]}"; then +if [ -z "$TIMEZONE_PRESET" ]; then + # timedatectl doesn't work as dbus is not up yet + # menulist timedatectl --no-pager list-timezones + if menulist awk \ + 'BEGIN{print "UTC"; sort="sort"}/^#/{next;}{print $3|sort}END{close(sort)}' \ + /usr/share/zoneinfo/zone.tab \ + && d --default-item "$default" --menu $"Select Time Zone" 0 0 $dh_menu "${list[@]}"; then if [ -n "$result" ]; then systemd_firstboot_args+=("--timezone=$result") fi -else + else d --msgbox $"error setting timezone" 0 0 + fi +else + timezone="$TIMEZONE_PRESET" + systemd_firstboot_args+=("--timezone=$timezone") fi # systemd-firstboot does not set the timezone if it exists, langset.sh created it From 39eb356f2d456620e2cff497d153219104cb1848 Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Wed, 8 May 2019 13:22:02 +0200 Subject: [PATCH 02/10] Add PASSWORD_ALREADY_SET variable As KIWI allows the creation of users and passwords, sometimes we want to skip the root password dialog from jeos-firstboot. This patch introduces a new variable PASSWORD_ALREADY_SET, that if is non zero, will skip the root password dialog. --- files/usr/lib/jeos-firstboot | 38 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/files/usr/lib/jeos-firstboot b/files/usr/lib/jeos-firstboot index 31ea620..89d496a 100755 --- a/files/usr/lib/jeos-firstboot +++ b/files/usr/lib/jeos-firstboot @@ -311,28 +311,30 @@ fi run rm -f /etc/localtime run systemd-firstboot "${systemd_firstboot_args[@]}" -# NOTE: must be last as dialog file is used to set the password -while true; do - password= - if d --insecure --passwordbox $"Enter root Password" 0 0; then - password="$result" - if d --insecure --passwordbox $"Confirm root Password" 0 0; then - if [ "$password" != "$result" ]; then - d --msgbox $"Entered passwords don't match" 5 40 || true - continue +if [ -z "$PASSWORD_ALREADY_SET" ]; then + # NOTE: must be last as dialog file is used to set the password + while true; do + password= + if d --insecure --passwordbox $"Enter root Password" 0 0; then + password="$result" + if d --insecure --passwordbox $"Confirm root Password" 0 0; then + if [ "$password" != "$result" ]; then + d --msgbox $"Entered passwords don't match" 5 40 || true + continue + fi + # don't use that one as we need to switch locale + #systemd_firstboot_args+=("--root-password-file=$dialog_out") fi - # don't use that one as we need to switch locale - #systemd_firstboot_args+=("--root-password-file=$dialog_out") fi - fi - if [ -z "$password" ]; then - warn $"Warning: No root password set. + if [ -z "$password" ]; then + warn $"Warning: No root password set. You cannot log in that way. A debug shell will be started on tty9 just this time. Use it to e.g. import your ssh key." 0 0 || true - run systemctl start debug-shell.service - fi - break -done + run systemctl start debug-shell.service + fi + break + done +fi if [ -x /usr/bin/SUSEConnect ]; then d --msgbox $"Please register this image using your existing SUSE entitlement. From ece0aa61bacd921cecbd7900853d433cd897b916 Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Wed, 8 May 2019 15:16:40 +0200 Subject: [PATCH 03/10] Check the file system before calling btrfs The currect code assume that if snapper is installed, the file system is btrfs. As both elements are not related, this test can fail for valid deployments. This patch will explicitly check for the file system before calling btrfs cli tools. --- files/usr/lib/jeos-firstboot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/usr/lib/jeos-firstboot b/files/usr/lib/jeos-firstboot index 89d496a..1f91b66 100755 --- a/files/usr/lib/jeos-firstboot +++ b/files/usr/lib/jeos-firstboot @@ -396,7 +396,7 @@ if ! [ -f "$EFI_SYSTAB" ]; then fi # Test if snapper is available -if [ -x /usr/bin/snapper ]; then +if [ -x /usr/bin/snapper -a "$(stat --format=%T -f /)" = "btrfs" ]; then if ! btrfs qgroup show / &>/dev/null; then # Run snapper to setup quota for btrfs run /usr/bin/snapper --no-dbus setup-quota || warn $"Could not setup quota for btrfs" From 4f01b85823f94b3a56fda180f89e063e0a923062 Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Mon, 13 May 2019 13:52:47 +0200 Subject: [PATCH 04/10] Add jeos-firstboot.conf file Add a configuration file for jeos-firstboot. --- files/usr/lib/jeos-firstboot | 4 ++++ files/usr/share/defaults/jeos-firstboot.conf | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 files/usr/share/defaults/jeos-firstboot.conf diff --git a/files/usr/lib/jeos-firstboot b/files/usr/lib/jeos-firstboot index 1f91b66..934aeb1 100755 --- a/files/usr/lib/jeos-firstboot +++ b/files/usr/lib/jeos-firstboot @@ -26,6 +26,10 @@ TEXTDOMAIN='jeos-firstboot' . /etc/os-release . "$0-functions" +# Read the optional configuration file +[ -f /usr/share/defaults/jeos-firstboot.conf ] && . /usr/share/defaults/jeos-firstboot.conf +[ -f /etc/jeos-firstboot.conf ] && . /etc/jeos-firstboot.conf + stty_size() { set -- `stty size`; LINES=$1; COLUMNS=$2 # stty size can return zero when not ready or diff --git a/files/usr/share/defaults/jeos-firstboot.conf b/files/usr/share/defaults/jeos-firstboot.conf new file mode 100644 index 0000000..56eedf8 --- /dev/null +++ b/files/usr/share/defaults/jeos-firstboot.conf @@ -0,0 +1,6 @@ +# Example configuration file for jeos-firstboot + +# LOCALE_PRESET='en_US' +# KEYTABLE_PRESET='en' +# TIMEZONE_PRESET='UTC' +# PASSWORD_ALREADY_SET=0 From a967c5336a0cbf83a27e247cf9fbdf4f7246ea6c Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Mon, 13 May 2019 13:59:31 +0200 Subject: [PATCH 05/10] Rename _PRESET variables Rename the *_PRESET variables and document the re-export in the second virtual console. --- files/usr/lib/jeos-firstboot | 18 ++++++++++-------- files/usr/share/defaults/jeos-firstboot.conf | 8 ++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/files/usr/lib/jeos-firstboot b/files/usr/lib/jeos-firstboot index 934aeb1..5b5542a 100755 --- a/files/usr/lib/jeos-firstboot +++ b/files/usr/lib/jeos-firstboot @@ -183,7 +183,7 @@ findlocales() [ -n "$list" ] } -if [ -z "$LOCALE_PRESET" ]; then +if [ -z "$JEOS_LOCALE" ]; then default="en_US" [ -f /etc/locale.conf ] && locale_lang="$(awk -F= '$1 == "LANG" { split($2,fs,"."); print fs[1]; exit }' /etc/locale.conf)" [ -n "$locale_lang" ] && default="$locale_lang" @@ -208,11 +208,11 @@ if [ -z "$LOCALE_PRESET" ]; then run langset.sh $locale || warn $"Setting the locale failed" fi else - locale="$LOCALE_PRESET" + locale="$JEOS_LOCALE" systemd_firstboot_args+=("--locale=$locale") fi -if [ -z "$KEYTABLE_PRESET" ]; then +if [ -z "$JEOS_KEYTABLE" ]; then default="us" [ -f /etc/vconsole.conf ] && vconsole_keymap="$(awk -F= '$1 == "KEYMAP" { split($2,fs,"."); print fs[1]; exit }' /etc/vconsole.conf)" [ -n "$vconsole_keymap" ] && default="$vconsole_keymap" @@ -245,8 +245,10 @@ if [[ "$(ps h -o tty -p $$)" = tty[0-9]* ]]; then start_kmscon["ko"]=1 if [ -n "$locale" -a -n "${start_kmscon[${language}]+_}" ]; then - export LOCALE_PRESET="$locale" - export KEYTABLE_PRESET="$keytable" + # We re-export the variables, as will be inspected when this + # script is re-executed in the secondary console + export JEOS_LOCALE="$locale" + export JEOS_KEYTABLE="$keytable" if kmscon_available; then ret_file="$(mktemp)" @@ -293,7 +295,7 @@ fi default="$(readlink -f /etc/localtime)" default="${default##/usr/share/zoneinfo/}" -if [ -z "$TIMEZONE_PRESET" ]; then +if [ -z "$JEOS_TIMEZONE" ]; then # timedatectl doesn't work as dbus is not up yet # menulist timedatectl --no-pager list-timezones if menulist awk \ @@ -307,7 +309,7 @@ if [ -z "$TIMEZONE_PRESET" ]; then d --msgbox $"error setting timezone" 0 0 fi else - timezone="$TIMEZONE_PRESET" + timezone="$JEOS_TIMEZONE" systemd_firstboot_args+=("--timezone=$timezone") fi @@ -315,7 +317,7 @@ fi run rm -f /etc/localtime run systemd-firstboot "${systemd_firstboot_args[@]}" -if [ -z "$PASSWORD_ALREADY_SET" ]; then +if [ -z "$JEOS_PASSWORD_ALREADY_SET" ]; then # NOTE: must be last as dialog file is used to set the password while true; do password= diff --git a/files/usr/share/defaults/jeos-firstboot.conf b/files/usr/share/defaults/jeos-firstboot.conf index 56eedf8..210ca50 100644 --- a/files/usr/share/defaults/jeos-firstboot.conf +++ b/files/usr/share/defaults/jeos-firstboot.conf @@ -1,6 +1,6 @@ # Example configuration file for jeos-firstboot -# LOCALE_PRESET='en_US' -# KEYTABLE_PRESET='en' -# TIMEZONE_PRESET='UTC' -# PASSWORD_ALREADY_SET=0 +# JEOS_LOCALE='en_US' +# JEOS_KEYTABLE='en' +# JEOS_TIMEZONE='UTC' +# JEOS_PASSWORD_ALREADY_SET=0 From bcab235f0ab704a41fc7bef78a734771fba8b859 Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Mon, 13 May 2019 14:59:29 +0200 Subject: [PATCH 06/10] Delay the activation of the locale and keytable. --- files/usr/lib/jeos-firstboot | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/files/usr/lib/jeos-firstboot b/files/usr/lib/jeos-firstboot index 5b5542a..80f4bfc 100755 --- a/files/usr/lib/jeos-firstboot +++ b/files/usr/lib/jeos-firstboot @@ -221,17 +221,20 @@ if [ -z "$JEOS_KEYTABLE" ]; then && d --default-item "$default" --menu $"Select Keyboard Layout" 0 0 $dh_menu "${list[@]}"; then if [ -n "$result" ]; then keytable="$result" - - # Activate the selected keyboard layout - run langset.sh "$locale" "$keytable" || warn $"Setting the keyboard layout failed" fi else d --msgbox $"Error setting keyboard" 0 0 fi else - keytable="$result" + keytable="$JEOS_KEYTABLE" +fi + +if [ ! -z "$locale" -a ! -z "$keytable" ]; then + # Activate the selected keyboard layout + run langset.sh "$locale" "$keytable" || warn $"Setting the keyboard layout failed" fi + [ -n "${locale}" ] && language="${locale%%_*}" || language="en" force_english_license=0 export LANG="$locale" From be71eadc9a328f7205d304ad3dec3a96a7e99999 Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Mon, 20 May 2019 15:46:08 +0200 Subject: [PATCH 07/10] Document variables in config file --- files/usr/share/defaults/jeos-firstboot.conf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/files/usr/share/defaults/jeos-firstboot.conf b/files/usr/share/defaults/jeos-firstboot.conf index 210ca50..322fc36 100644 --- a/files/usr/share/defaults/jeos-firstboot.conf +++ b/files/usr/share/defaults/jeos-firstboot.conf @@ -1,6 +1,18 @@ # Example configuration file for jeos-firstboot +# Valid system locale that will be used in JeOS. If is not set, a +# dialog box will ask for the system locale. # JEOS_LOCALE='en_US' + +# Keyboard layout used in the system and during jeos-firstboot. If is +# not set, a dialog box will ask for the keyboard layout. # JEOS_KEYTABLE='en' + +# Local timezone of the system. If is not set, a dialog box will ask +# for the local timezone. # JEOS_TIMEZONE='UTC' + +# If is set to a nonempty value, the dialog box for setting the +# initial password for the root user will be skipped. In this case is +# expected that the root password was set by other means. # JEOS_PASSWORD_ALREADY_SET=0 From 2d1727e7c9a299ee6e687a3e69d40acc4a6fd659 Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Mon, 20 May 2019 15:47:25 +0200 Subject: [PATCH 08/10] Remove useless timezone variable --- files/usr/lib/jeos-firstboot | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/files/usr/lib/jeos-firstboot b/files/usr/lib/jeos-firstboot index 80f4bfc..d12c198 100755 --- a/files/usr/lib/jeos-firstboot +++ b/files/usr/lib/jeos-firstboot @@ -312,8 +312,7 @@ if [ -z "$JEOS_TIMEZONE" ]; then d --msgbox $"error setting timezone" 0 0 fi else - timezone="$JEOS_TIMEZONE" - systemd_firstboot_args+=("--timezone=$timezone") + systemd_firstboot_args+=("--timezone=$JEOS_TIMEZONE") fi # systemd-firstboot does not set the timezone if it exists, langset.sh created it From 8143bd0bba27a5a59212c6186d72c81720e6de3b Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Mon, 20 May 2019 16:57:57 +0200 Subject: [PATCH 09/10] Remove locale and keytable variables --- files/usr/lib/jeos-firstboot | 44 ++++++++++++++---------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/files/usr/lib/jeos-firstboot b/files/usr/lib/jeos-firstboot index d12c198..3261e37 100755 --- a/files/usr/lib/jeos-firstboot +++ b/files/usr/lib/jeos-firstboot @@ -104,10 +104,13 @@ sleep 1 systemd_firstboot_args=('--setup-machine-id') +# If the configuration is not loaded and we are in the first terminal +# instance, make sure that the variables are declared. +JEOS_LOCALE=${JEOS_LOCALE-} +JEOS_KEYTABLE=${JEOS_KEYTABLE-} + result= list= -keytable='' -locale='' password='' let dh_menu=LINES-15 @@ -200,18 +203,12 @@ if [ -z "$JEOS_LOCALE" ]; then newlocale="${result}" fi - if [ -n "$newlocale" ]; then - locale="${newlocale}.UTF-8" - systemd_firstboot_args+=("--locale=$locale") - - # Run langset to get consolefont and keymap set up - run langset.sh $locale || warn $"Setting the locale failed" - fi -else - locale="$JEOS_LOCALE" - systemd_firstboot_args+=("--locale=$locale") + JEOS_LOCALE="${newlocale}.UTF-8" fi +run langset.sh $JEOS_LOCALE || warn $"Setting the locale failed" +systemd_firstboot_args+=("--locale=$JEOS_LOCALE") + if [ -z "$JEOS_KEYTABLE" ]; then default="us" [ -f /etc/vconsole.conf ] && vconsole_keymap="$(awk -F= '$1 == "KEYMAP" { split($2,fs,"."); print fs[1]; exit }' /etc/vconsole.conf)" @@ -220,24 +217,22 @@ if [ -z "$JEOS_KEYTABLE" ]; then if findkeymaps \ && d --default-item "$default" --menu $"Select Keyboard Layout" 0 0 $dh_menu "${list[@]}"; then if [ -n "$result" ]; then - keytable="$result" + JEOS_KEYTABLE="$result" fi else d --msgbox $"Error setting keyboard" 0 0 fi -else - keytable="$JEOS_KEYTABLE" fi -if [ ! -z "$locale" -a ! -z "$keytable" ]; then +if [ ! -z "$JEOS_LOCALE" -a ! -z "$JEOS_KEYTABLE" ]; then # Activate the selected keyboard layout - run langset.sh "$locale" "$keytable" || warn $"Setting the keyboard layout failed" + run langset.sh "$JEOS_LOCALE" "$JEOS_KEYTABLE" || warn $"Setting the keyboard layout failed" fi -[ -n "${locale}" ] && language="${locale%%_*}" || language="en" +[ -n "$JEOS_LOCALE" ] && language="${JEOS_LOCALE%%_*}" || language="en" force_english_license=0 -export LANG="$locale" +export LANG="$JEOS_LOCALE" if [[ "$(ps h -o tty -p $$)" = tty[0-9]* ]]; then # Those languages can't be displayed in the console @@ -247,12 +242,7 @@ if [[ "$(ps h -o tty -p $$)" = tty[0-9]* ]]; then start_kmscon["zh"]=1 start_kmscon["ko"]=1 - if [ -n "$locale" -a -n "${start_kmscon[${language}]+_}" ]; then - # We re-export the variables, as will be inspected when this - # script is re-executed in the secondary console - export JEOS_LOCALE="$locale" - export JEOS_KEYTABLE="$keytable" - + if [ -n "$JEOS_LOCALE" -a -n "${start_kmscon[${language}]+_}" ]; then if kmscon_available; then ret_file="$(mktemp)" kmscon --silent --font-size 10 --palette vga --no-reset-env -l -- /bin/sh -c "$0; echo \$? > $ret_file; kill \$PPID" @@ -280,8 +270,8 @@ fi if [ -e "$EULA_FILE" -a ! -e "${EULA_FILE%/*}/no-acceptance-needed" ]; then if [ "$force_english_license" = "0" ]; then - for i in "${EULA_FILE%.txt}.$locale.txt" \ - "${EULA_FILE%.txt}.${locale%%.UTF-8}.txt" \ + for i in "${EULA_FILE%.txt}.${JEOS_LOCALE}.txt" \ + "${EULA_FILE%.txt}.${JEOS_LOCALE%%.UTF-8}.txt" \ "${EULA_FILE%.txt}.${language}.txt"; do if [ -e "$i" ]; then EULA_FILE="$i" From 18101f1e6789ee9369f08832d31d89790aa4324b Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Tue, 21 May 2019 13:50:05 +0200 Subject: [PATCH 10/10] Refactor JEOS_TIMEZONE code --- files/usr/lib/jeos-firstboot | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/files/usr/lib/jeos-firstboot b/files/usr/lib/jeos-firstboot index 3261e37..7217886 100755 --- a/files/usr/lib/jeos-firstboot +++ b/files/usr/lib/jeos-firstboot @@ -296,14 +296,13 @@ if [ -z "$JEOS_TIMEZONE" ]; then /usr/share/zoneinfo/zone.tab \ && d --default-item "$default" --menu $"Select Time Zone" 0 0 $dh_menu "${list[@]}"; then if [ -n "$result" ]; then - systemd_firstboot_args+=("--timezone=$result") + JEOS_TIMEZONE="$result" fi else d --msgbox $"error setting timezone" 0 0 fi -else - systemd_firstboot_args+=("--timezone=$JEOS_TIMEZONE") fi +systemd_firstboot_args+=("--timezone=$JEOS_TIMEZONE") # systemd-firstboot does not set the timezone if it exists, langset.sh created it run rm -f /etc/localtime