X-Git-Url: https://git.grml.org/?p=grml-debootstrap.git;a=blobdiff_plain;f=grml-debootstrap;h=3a3e67b3f0c91c1c759b6e9d5bb6567a4134d4c5;hp=111e8e80409863885ae27be8535d54b4fe1f10ef;hb=4384a101128e1244ea0f7ce7d7923d9417f1e981;hpb=fc6d883482b5787110ef2d6b19918d4fbeb9d851 diff --git a/grml-debootstrap b/grml-debootstrap index 111e8e8..3a3e67b 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -7,8 +7,6 @@ ################################################################################ # http://www.debian.org/releases/stable/i386/index.html.en -set -e # exit on any error - # variables {{{ PN="$(basename $0)" VERSION="$(dpkg --list $PN 2>/dev/null| awk '/^i/ {print $3}')" @@ -17,6 +15,7 @@ MNTPOINT="/mnt/debootstrap.$$" # defaults VMSIZE="2G" +FORCE='' # inside the chroot system locales might not be available, so use minimum: export LANG=C @@ -27,11 +26,6 @@ export LC_ALL=C INTERACTIVE='' # }}} -# source core functions {{{ -. /etc/grml/lsb-functions -. /etc/grml/script-functions -# }}} - # help text {{{ usage() { echo "$PN - wrapper around debootstrap for installing Debian @@ -56,6 +50,7 @@ Bootstrap options: --filesystem Filesystem that should be used when target is a partition or Virtual Machine (see --vmfile). --insecure Do not download and check Release file signatures. + --force Do not prompt for user acknowledgement. Options for Virtual Machine deployment: @@ -101,6 +96,60 @@ if [ "$1" = '-h' ] || [ "$1" = '-help' ] || [ "$1" = "--help" ] ; then fi # }}} +# {{{ +GOOD='' +WARN='' +BAD='' +NORMAL='' +HILITE='' +BRACKET='' + +einfo() { + einfon "$1\n" + return 0 +} + +einfon() { + [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo + printf " ${GOOD}*${NORMAL} $*" + LAST_E_CMD=einfon + return 0 +} + +eerror() { + [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo + printf " ${BAD}*${NORMAL} $*\n" + LAST_E_CMD=eerror + return 0 +} + +eend() { + local retval="${1:-0}" + shift + if [ $retval -gt 0 ]; then + printf " ${BAD}-> Failed (rc=${retval})${NORMAL}\n" + fi +} + +check4root(){ + if [ "$(id -u 2>/dev/null)" != 0 ] ; then + echo 1>&2 "Error: please run this script with uid 0 (root)." ; return 1 + fi +} + +check4progs(){ + local RC='' + for arg in $* ; do + which $arg >/dev/null 2>&1 || RC="$arg" + done + if [ -n "$RC" ] ; then + echo "$RC not installed" + return 1 + fi +} + +# }}} + # make sure we have what we need {{{ check4progs debootstrap dialog || exit 1 # }}} @@ -118,7 +167,8 @@ if [ -r ./cmdlineopts.clp ] ; then elif [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then . /usr/share/grml-debootstrap/functions/cmdlineopts.clp else - echo "Error: cmdline function file not found, exiting.">&2 + eerror "Error: cmdline function file not found, exiting." + eend 1 exit 1 fi @@ -163,6 +213,7 @@ fi [ "$_opt_grub" ] && GRUB=$_opt_grub [ "$_opt_arch" ] && ARCH=$_opt_arch [ "$_opt_insecure" ] && SECURE='false' +[ "$_opt_force" ] && FORCE=$_opt_force [ "$_opt_verbose" ] && VERBOSE="-v" [ "$_opt_help" ] && { @@ -203,15 +254,17 @@ fi # backwards compability checks {{{ if [ -n "$GROOT" ] ; then - echo "Error: you seem to have \$GROOT configured." >&2 - echo "This variable is no longer supported, please visit the" >&2 - echo "grml-debootstrap documentation for details." >&2 + eerror "Error: you seem to have \$GROOT configured." + eerror "This variable is no longer supported, please visit the" + eerror "grml-debootstrap documentation for details." + eend 1 exit 1 fi if echo "$GRUB" | grep -q '^hd' ; then - echo "Error: this syntax for the grub configuration variable is no longer supported." >&2 - echo "Please do not use hd... any longer but /dev/sdX instead." >&2 + eerror "Error: this syntax for the grub configuration variable is no longer supported." + eerror "Please do not use hd... any longer but /dev/sdX instead." + eend 1 exit 1 fi # }}} @@ -444,13 +497,9 @@ if [ $RELEASE = "lenny" ]; then fi ERRORFILE=$(mktemp) -set +e -# TODO: better error handling? yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \ --raid-devices="${NUM_PARTITIONS}" ${METADATA_VERSION} ${SELECTED_PARTITIONS} >/dev/null 2>$ERRORFILE RC=$? -set -e - if [ "$RC" = 0 ] ; then dialog --title "$PN" --msgbox \ "Creating $TARGET was successful." 0 0 @@ -491,6 +540,7 @@ Last chance to quit. Timeout of 10 seconds running.... Do you want to stop now?" 0 0 2>/dev/null } +# }}} # make sure the user is aware of the used configuration {{{ checkconfiguration() @@ -550,12 +600,16 @@ else # if not running automatic installation display configuration and prompt fo echo echo " Important! Continuing will delete all data from ${TARGET}!" - echo - einfon "Is this ok for you? [y/N] " - read a - if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then - eerror "Exiting as requested." ; eend 1 - exit 1 + if [ -n "$FORCE" ] ; then + einfo "Skip user acknowledgement as requested via --force option." + else + echo + einfon "Is this ok for you? [y/N] " + read a + if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then + eerror "Exiting as requested." ; eend 1 + exit 1 + fi fi fi } @@ -732,9 +786,7 @@ stage() { return 0 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0 - eindent - ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0 - eoutdent + ewarn " To reexecute it clean up the according directory inside $STAGES" ; eend 0 return 1 fi } @@ -832,7 +884,7 @@ prepare_vm() { DEVINFO=$(kpartx -av $TARGET) # 'add map loop1p1 (253:0): 0 6289408 linear /dev/loop1 2048' if [ -z "${DEVINFO}" ] ; then - echo Error setting up loopback device >&2 + eerror "Error setting up loopback device." ; eend 1 exit 1 fi @@ -845,7 +897,7 @@ prepare_vm() { blockdev --rereadpt "${LOOP}" if [ -z "$TARGET" ] ; then - echo "Error: target could not be set to according /dev/mapper/* device." >&2 + eerror "Error: target could not be set to according /dev/mapper/* device." ; eend 1 exit 1 fi }