From e6b5746203c18b1c2e935a9a714909ad7e92e5f6 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Thu, 3 Mar 2011 19:31:48 +0100 Subject: be more strict and correct in worker exit codes --- src/core/libs/lib-blockdevices-filesystems.sh | 1 + src/core/libs/lib-misc.sh | 17 +++++++++++---- src/core/libs/lib-pacman.sh | 14 ++++++++---- src/core/libs/lib-ui-interactive.sh | 23 ++++++++++++++------ src/core/procedures/automatic | 11 +++++----- src/core/procedures/base | 31 +++++++++++++++++---------- src/core/procedures/interactive | 11 +++++----- 7 files changed, 72 insertions(+), 36 deletions(-) diff --git a/src/core/libs/lib-blockdevices-filesystems.sh b/src/core/libs/lib-blockdevices-filesystems.sh index 01e91e9..5b078a7 100644 --- a/src/core/libs/lib-blockdevices-filesystems.sh +++ b/src/core/libs/lib-blockdevices-filesystems.sh @@ -91,6 +91,7 @@ get_possible_fs () { do which ${filesystem_programs[$fs]} &>/dev/null && possible_fs=("${possible_fs[@]}" $fs) done + true } supported_bootloaders=('grub') diff --git a/src/core/libs/lib-misc.sh b/src/core/libs/lib-misc.sh index 13379a2..2dee841 100644 --- a/src/core/libs/lib-misc.sh +++ b/src/core/libs/lib-misc.sh @@ -122,17 +122,26 @@ cleanup_runtime () dohwclock() { # TODO: we probably only need to do this once and then actually use adjtime on next invocations inform "Resetting hardware clock adjustment file" - [ ! -d /var/lib/hwclock ] && mkdir -p /var/lib/hwclock + [ -d /var/lib/hwclock ] || mkdir -p /var/lib/hwclock || return 1 if [ ! -f /var/lib/hwclock/adjtime ]; then - echo "0.0 0 0.0" > /var/lib/hwclock/adjtime + echo "0.0 0 0.0" > /var/lib/hwclock/adjtime || return 1 fi inform "Syncing clocks ($2), hc being $1 ..." if [ "$1" = "UTC" ]; then - hwclock --$2 --utc + if ! hwclock --$2 --utc + then + show_warning 'Hwclock failure' "Could not hwclock --$2 --utc" + return 1 + fi else - hwclock --$2 --localtime + if ! hwclock --$2 --localtime + then + show_warning 'Hwclock failure' "Could not hwclock --$2 --localtime" + return 1 + fi fi + return 0 } target_configure_initial_keymap_font () diff --git a/src/core/libs/lib-pacman.sh b/src/core/libs/lib-pacman.sh index 78e800e..bfd307c 100644 --- a/src/core/libs/lib-pacman.sh +++ b/src/core/libs/lib-pacman.sh @@ -47,14 +47,20 @@ do #TODO: this is a VERY, VERY dirty hack. we fall back to net for any non-core repo because we only have core on the CD. also user maybe didn't pick a mirror yet if [ "$repo" != core ] then - add_pacman_repo target ${repo} "Include = $var_MIRRORLIST" + add_pacman_repo target ${repo} "Include = $var_MIRRORLIST" || return 1 else - add_pacman_repo target ${repo} "Server = ${serverurl/\$repo/$repo}" # replace literal '$repo' in the serverurl string by "$repo" where $repo is our variable. + # replace literal '$repo' in the serverurl string by "$repo" where $repo is our variable. + add_pacman_repo target ${repo} "Server = ${serverurl/\$repo/$repo}" || return 1 fi done # Set up the necessary directories for pacman use - [ ! -d "${var_TARGET_DIR}/var/cache/pacman/pkg" ] && mkdir -m 755 -p "${var_TARGET_DIR}/var/cache/pacman/pkg" - [ ! -d "${var_TARGET_DIR}/var/lib/pacman" ] && mkdir -m 755 -p "${var_TARGET_DIR}/var/lib/pacman" + for dir in var/cache/pacman/pkg var/lib/pacman + do + if [ ! -d "${var_TARGET_DIR}/$dir" ] + then + mkdir -m 755 -p "${var_TARGET_DIR}/$dir" || return 1 + fi + done inform "Refreshing package database..." $PACMAN_TARGET -Sy >$LOG 2>&1 || return 1 diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 89e62bd..8281bc0 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -125,9 +125,10 @@ interactive_timezone () { then # This changes probably also the systemtime (UTC->$TIMEZONE)! # localtime users will have a false time after that! - /bin/rm -f /etc/localtime - /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime + /bin/rm -f /etc/localtime || return 1 + /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime || return 1 fi + return 0 } @@ -138,8 +139,12 @@ interactive_time () { # To avoid a false time for localtime users after above # we must re-read the hwclock value again, but now into the # correct timezone. - [ "$HARDWARECLOCK" == "localtime" ] && dohwclock $HARDWARECLOCK hctosys + if [ "$HARDWARECLOCK" == "localtime" ] + then + dohwclock $HARDWARECLOCK hctosys || return $? + fi + timeset= local default=no while true; do current=$(date) @@ -153,21 +158,27 @@ interactive_time () { inform "Syncing clock with internet pool ..." if ntpdate pool.ntp.org >/dev/null; then notify "Synced clock with internet pool successfully." - dohwclock $HARDWARECLOCK systohc && default=3 + dohwclock $HARDWARECLOCK systohc && default=3 || return $? + timeset=1 else show_warning 'Ntp failure' "An error has occured, time was not changed!" + timeset=0 fi fi if [ "$ANSWER_OPTION" = manual ]; then ask_datetime || continue if date -s "$ANSWER_DATETIME"; then - dohwclock $HARDWARECLOCK systohc && default=3 + dohwclock $HARDWARECLOCK systohc && default=3 || return $? + timeset=1 else show_warning "Date/time setting failed" "Something went wrong when doing date -s $ANSWER_DATETIME" + timeset=0 fi fi - [ "$ANSWER_OPTION" = return ] && break + [ "$ANSWER_OPTION" = return ] && timeset=1 && break done + [ "$timeset" = '0' ] && return 1 + return 0 } diff --git a/src/core/procedures/automatic b/src/core/procedures/automatic index a37803e..407a35b 100644 --- a/src/core/procedures/automatic +++ b/src/core/procedures/automatic @@ -82,7 +82,6 @@ worker_prepare_disks () inform "Partitions and filesystems made successfully" # TODO: fstab? auto-add to fstab with libs? auto mkdir's on target_dir? - true } worker_package_list () @@ -91,13 +90,13 @@ worker_package_list () var_TARGET_GROUPS=$TARGET_GROUPS var_TARGET_PACKAGES_EXCLUDE=$TARGET_PACKAGES_EXCLUDE [ -z "$var_TARGET_PACKAGES" -a -z "$var_TARGET_GROUPS" ] && var_TARGET_GROUPS=base + true } worker_install_packages () { - target_prepare_pacman core extra community - installpkg + target_prepare_pacman core extra community && installpkg } @@ -110,11 +109,11 @@ worker_set_clock () worker_install_bootloader () { - get_grub_map - grub-install $var_GRUB_DEVICE --root-directory=/mnt + get_grub_map || return 1 + grub-install $var_GRUB_DEVICE --root-directory=/mnt || return 1 # check if we have a seperate bootdev (/boot) # ToDo: This is double-work, find a better place! # See comment in generate_grub_menulst and interactive_grub bootdev=$(mount | grep $var_TARGET_DIR/boot | cut -d' ' -f 1) - generate_grub_menulst + generate_grub_menulst || return 1 } diff --git a/src/core/procedures/base b/src/core/procedures/base index 432a9f3..ec38f51 100644 --- a/src/core/procedures/base +++ b/src/core/procedures/base @@ -44,6 +44,7 @@ worker_intro () then die_error "User aborted base profile execution" fi + true } @@ -81,8 +82,12 @@ worker_runtime_repositories () do repo=${var_RUNTIME_REPOSITORIES[$(($i*2))]} location=${var_RUNTIME_REPOSITORIES[$(($i*2+1))]} - list_pacman_repos runtime | grep -q $repo || add_pacman_repo runtime $repo "$location" + if ! list_pacman_repos runtime | grep -q $repo + then + add_pacman_repo runtime $repo "$location" || return 1 + fi done + return 0 } @@ -90,8 +95,9 @@ worker_runtime_packages () { for pkg in $var_RUNTIME_PACKAGES do - $PACMAN -Sy --noconfirm --needed $pkg + $PACMAN -Sy --noconfirm --needed $pkg || return 1 done + return 0 } @@ -103,10 +109,16 @@ worker_set_clock () "1" "Select region and timezone" \ "2" "Set time and date" \ "3" "Return to Main Menu" || return 1 - [ "$ANSWER_OPTION" = 1 ] && execute worker interactive_timezone && default=2 - [ "$ANSWER_OPTION" = 2 ] && check_depend worker interactive_timezone && execute worker interactive_time && default=3 - [ "$ANSWER_OPTION" = 3 ] && break + case $ANSWER_OPTION in + "1") execute worker interactive_timezone && default=2 || return 1 ;; + "2") if check_depend worker interactive_timezone + then + execute worker interactive_time && default=3 || return 1 + fi ;; + "3") break ;; + esac done + return 0 } @@ -124,8 +136,7 @@ worker_interactive_time () worker_prepare_disks () { - partition # use lib-archboot function by default - get_possible_fs + partition && get_possible_fs # in official installer: autoprepare or diy first partitions, then mountpoints } @@ -139,14 +150,12 @@ worker_package_list () worker_install_packages () { - target_prepare_pacman core - installpkg + target_prepare_pacman core && installpkg } worker_configure_system () { - preconfigure_target - postconfigure_target + preconfigure_target && postconfigure_target } diff --git a/src/core/procedures/interactive b/src/core/procedures/interactive index 40021ef..0148389 100644 --- a/src/core/procedures/interactive +++ b/src/core/procedures/interactive @@ -86,8 +86,7 @@ worker_configure_system() worker_prepare_disks() { - get_possible_fs - interactive_prepare_disks + get_possible_fs && interactive_prepare_disks } @@ -111,9 +110,11 @@ select_source_extras_menu () "1" "${workertitles['runtime_network']}" \ "2" "Select mirror" \ "3" "Return to Main Menu" || return 1 - [ "$ANSWER_OPTION" = 1 ] && execute worker runtime_network && default=2 - [ "$ANSWER_OPTION" = 2 ] && interactive_select_mirror && default=3 - [ "$ANSWER_OPTION" = 3 ] && break + case $ANSWER_OPTION in + "1") execute worker runtime_network && default=2 || return 1 ;; + "2") interactive_select_mirror && default=3 || return 1 ;; + "3") break ;; + esac done return 0 } -- cgit v1.2.3-54-g00ecf