Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows the skip of timezone and password dialogs #49

Merged
merged 10 commits into from
May 21, 2019
114 changes: 59 additions & 55 deletions files/usr/lib/jeos-firstboot
Original file line number Diff line number Diff line change
Expand Up @@ -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
aplanas marked this conversation as resolved.
Show resolved Hide resolved

stty_size() {
set -- `stty size`; LINES=$1; COLUMNS=$2
# stty size can return zero when not ready or
Expand Down Expand Up @@ -100,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
Expand Down Expand Up @@ -179,7 +186,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"
Expand All @@ -196,41 +203,36 @@ if [ -z "$LOCALE_PRESET" ]; 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="$LOCALE_PRESET"
systemd_firstboot_args+=("--locale=$locale")
JEOS_LOCALE="${newlocale}.UTF-8"
fi

if [ -z "$KEYTABLE_PRESET" ]; then
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)"
[ -n "$vconsole_keymap" ] && default="$vconsole_keymap"

if findkeymaps \
&& 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"
JEOS_KEYTABLE="$result"
fi
else
d --msgbox $"Error setting keyboard" 0 0
fi
else
keytable="$result"
fi

if [ ! -z "$JEOS_LOCALE" -a ! -z "$JEOS_KEYTABLE" ]; then
# Activate the selected keyboard layout
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
Expand All @@ -240,10 +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
export LOCALE_PRESET="$locale"
export KEYTABLE_PRESET="$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"
Expand Down Expand Up @@ -271,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"
Expand All @@ -289,45 +288,50 @@ 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 "$JEOS_TIMEZONE" ]; 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")
JEOS_TIMEZONE="$result"
fi
else
else
d --msgbox $"error setting timezone" 0 0
fi
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
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 "$JEOS_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
aplanas marked this conversation as resolved.
Show resolved Hide resolved

if [ -x /usr/bin/SUSEConnect ]; then
d --msgbox $"Please register this image using your existing SUSE entitlement.
Expand Down Expand Up @@ -389,7 +393,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"
Expand Down
18 changes: 18 additions & 0 deletions files/usr/share/defaults/jeos-firstboot.conf
Original file line number Diff line number Diff line change
@@ -0,0 +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'
aplanas marked this conversation as resolved.
Show resolved Hide resolved

# 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