X-Git-Url: https://git.grml.org/?p=grml-debootstrap.git;a=blobdiff_plain;f=grml-debootstrap;h=96f4a45dd3b930ce394812bc0b22a446603f3b16;hp=7e88c1152a044d2b46044023dd0db805545af6d1;hb=fc0a6d8c09bd56cdd17ef2586c45a919356fbd88;hpb=98b48d427f082f3ce0aaea6cae7bd484c24cfb79 diff --git a/grml-debootstrap b/grml-debootstrap index 7e88c11..96f4a45 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -40,7 +40,7 @@ fi # variables {{{ PN="$(basename "$0")" -if [[ -d "$(dirname "$(which "$0")")"/.git ]]; then +if [[ -d "$(dirname "$(command -v "$0")")"/.git ]]; then VERSION="$(git describe | sed 's|^v||')" else VERSION="$(dpkg-query --show --showformat='${Version}' "$PN")" @@ -58,7 +58,7 @@ MNTPOINT="/mnt/debootstrap.$$" [ -n "$DEFAULT_LOCALES" ] || DEFAULT_LOCALES='en_US.UTF-8' [ -n "$DISK_IDENTIFIER" ] || DISK_IDENTIFIER='26ada0c0-1165-4098-884d-aafd2220c2c6' [ -n "$EXTRAPACKAGES" ] || EXTRAPACKAGES='yes' -[ -n "$FALLBACK_MIRROR" ] || FALLBACK_MIRROR='http://httpredir.debian.org/debian' +[ -n "$FALLBACK_MIRROR" ] || FALLBACK_MIRROR='http://deb.debian.org/debian' [ -n "$FIXED_DISK_IDENTIFIERS" ] || FIXED_DISK_IDENTIFIERS="no" [ -n "$FORCE" ] || FORCE='' [ -n "$HOSTNAME" ] || HOSTNAME='grml' @@ -186,7 +186,7 @@ WARN='' NORMAL='' einfo() { - einfon "$1\n" + einfon "$1\\n" return 0 } @@ -198,13 +198,13 @@ einfon() { } ewarn() { - printf " %s*%s $*\n" "${WARN}" "${NORMAL}" + printf " %s*%s $*\\n" "${WARN}" "${NORMAL}" return 0 } eerror() { [ "${RC_ENDCOL}" != "yes" ] && [ "${LAST_E_CMD}" = "ebegin" ] && echo - printf " %s*%s $*\n" "${BAD}" "${NORMAL}" >&2 + printf " %s*%s $*\\n" "${BAD}" "${NORMAL}" >&2 LAST_E_CMD=eerror return 0 } @@ -213,7 +213,7 @@ eend() { local retval="${1:-0}" shift if [ "$retval" -gt 0 ]; then - printf " %s-> Failed (rc=%s)%s\n" "${BAD}" "${retval}" "${NORMAL}" + printf " %s-> Failed (rc=%s)%s\\n" "${BAD}" "${retval}" "${NORMAL}" fi return "$retval" } @@ -227,7 +227,7 @@ check4root(){ check4progs(){ local RC='' for arg in "$@" ; do - which "$arg" >/dev/null 2>&1 || RC="$arg" + command -v "$arg" >/dev/null 2>&1 || RC="$arg" done if [ -n "$RC" ] ; then echo "$RC not installed" @@ -480,8 +480,11 @@ while :; do # == Other options --verbose|-v) # Increase verbosity - if [ "$_opt_verbose" ]; then _opt_verbose=`expr $_opt_verbose + 1` - else _opt_verbose=1; fi + if [ "$_opt_verbose" ]; then + _opt_verbose=$( _opt_verbose + 1 ) + else + _opt_verbose=1 + fi ;; --debug) # Execute in debug mode _opt_debug=T @@ -815,7 +818,7 @@ prompt_for_mirror() [ $? -eq 0 ] || bailout if [ "$CHOOSE_MIRROR" = 'net' ] ; then - [ -n "$MIRROR" ] || MIRROR='http://httpredir.debian.org/debian' + [ -n "$MIRROR" ] || MIRROR='http://deb.debian.org/debian' MIRROR="$(dialog --stdout --title "${PN}" --inputbox \ "Please enter Debian mirror you would like to use for installing packages." \ 0 0 $MIRROR)" @@ -925,6 +928,7 @@ Do you want to stop now?" 0 0 2>/dev/null } # }}} +# format efi partition {{{ format_efi_partition() { if [ -z "$EFI" ] ; then return 0 @@ -950,6 +954,7 @@ format_efi_partition() { fi fi } +# }}} # check for EFI support or try to enable it {{{ efi_support() { @@ -1284,6 +1289,7 @@ mkfs() { } # }}} +# retrieve ID_FS_UUID {{{ identify_target_uuid() { local device="$1" @@ -1299,7 +1305,9 @@ identify_target_uuid() { return 1 fi } +# }}} +# identify TARGET_UUID {{{ mountpoint_to_blockdevice() { TARGET_UUID='' @@ -1324,6 +1332,7 @@ mountpoint_to_blockdevice() { fi done } +# }}} # modify filesystem settings {{{ tunefs() { @@ -1378,6 +1387,21 @@ prepare_vm() { bailout 1 fi + # make sure loop module is present and an usable loop device exists + modprobe -q loop + if ! losetup -f >/dev/null 2>&1; then + eerror "Error finding usable loop device" ; eend 1 + bailout 1 + fi + + # if dm-mod isn't available then kpartx will fail with + # "Is device-mapper driver missing from kernel? [...]" + modprobe -q dm-mod + if ! grep -q 'device-mapper' /proc/misc >/dev/null 2>&1 ; then + einfo "Device-mapper support missing in kernel." + bailout 1 + fi + ORIG_TARGET="$TARGET" # store for later reuse if [ -n "$VMFILE" ]; then @@ -1388,32 +1412,13 @@ prepare_vm() { einfo "Adjusting disk signature to a fixed (non-random) value" MBRTMPFILE=$(mktemp) dd if="${TARGET}" of="${MBRTMPFILE}" bs=512 count=1 - echo -en "\x41\x41\x41\x41" | dd of="${MBRTMPFILE}" conv=notrunc seek=440 bs=1 + echo -en "\\x41\\x41\\x41\\x41" | dd of="${MBRTMPFILE}" conv=notrunc seek=440 bs=1 dd if="${MBRTMPFILE}" of="${TARGET}" conv=notrunc eend $? fi parted -s "${TARGET}" 'mkpart primary ext4 2M -1' parted -s "${TARGET}" 'set 1 boot on' - # if dm-mod isn't available then kpartx will fail with - # "Is device-mapper driver missing from kernel? [...]" - if ! kpartx -av "$TARGET" >/dev/null 2>&1 || ! grep -q 'device-mapper' /proc/misc >/dev/null 2>&1 ; then - einfo "Device-mapper not ready yet, trying to load dm-mod module." - modprobe dm-mod ; eend $? - fi - - # make sure loop module is present - if ! losetup -f >/dev/null 2>&1; then - einfo "Can not find a usable loop device, retrying after loading loop module." - modprobe loop - if losetup -f >/dev/null 2>&1; then - einfo "Found a usable loop device now, continuing." - else - eerror "Error finding usable loop device" ; eend 1 - bailout 1 - fi - fi - DEVINFO=$(kpartx -asv "$TARGET") # e.g. 'add map loop0p1 (254:5): 0 20477 linear 7:0 3' if [ -z "${DEVINFO}" ] ; then eerror "Error setting up loopback device." ; eend 1 @@ -1450,7 +1455,7 @@ finalize_vm() { # Has chroot-script installed GRUB to MBR using grub-install (successfully), already? # chroot-script skips installation for unset ${GRUB} -if [[ -z "${GRUB}" ]] || ! dd if="${GRUB}" bs=512 count=1 2>/dev/null | cat -v | fgrep -q GRUB; then +if [[ -z "${GRUB}" ]] || ! dd if="${GRUB}" bs=512 count=1 2>/dev/null | cat -v | grep -Fq GRUB; then einfo "Installing Grub as bootloader." if ! chroot "${MNTPOINT}" dpkg --list grub-pc 2>/dev/null | grep -q '^ii' ; then @@ -1498,7 +1503,7 @@ fi ewarn "Please note that your system might NOT be able to properly boot." else einfo "Adjusting grub.cfg for successful boot sequence." - sed -i "s;root=[^ ]\+;root=UUID=$TARGET_UUID;" "${MNTPOINT}"/boot/grub/grub.cfg + sed -i "s;root=[^ ]\\+;root=UUID=$TARGET_UUID;" "${MNTPOINT}"/boot/grub/grub.cfg fi umount "${MNTPOINT}"/proc @@ -1751,6 +1756,7 @@ execute_post_scripts() { } # }}} +# unmount mountpoint {{{ try_umount() { local tries=$1 local mountpoint="$2" @@ -1770,6 +1776,7 @@ try_umount() { done return 1 # Tried enough } +# }}} # execute chroot-script {{{ chrootscript() {