diff options
author | Helmut Grohne <helmut@subdivi.de> | 2022-12-28 10:09:06 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2022-12-28 10:09:06 +0100 |
commit | 1f16c8718bebb1f4a3065599581dad392f6afc94 (patch) | |
tree | 9046fb0fe7ec5c2e84f1b7149fec9996e4d3db20 /debvm-create | |
parent | 0c50e3b74ec8173d6b0b5f26250a8feee0ceda7b (diff) | |
parent | b666a2909890a7954b103388ec846cac8ce55722 (diff) | |
download | debvm-1f16c8718bebb1f4a3065599581dad392f6afc94.tar.gz |
Merge branch main into branch pod2man
This merge picks up long options and the -s to -z rename.
Diffstat (limited to 'debvm-create')
-rwxr-xr-x | debvm-create | 133 |
1 files changed, 80 insertions, 53 deletions
diff --git a/debvm-create b/debvm-create index 65b3c54..37fa514 100755 --- a/debvm-create +++ b/debvm-create @@ -94,67 +94,88 @@ SSHKEY= SUITE=unstable VMNAME=testvm +nth_arg() { + shift "$1" + printf "%s" "$1" +} + die() { echo "$*" 1>&2 exit 1 } - usage() { - die "usage: $0 [-a architecture] [-h hostname] [-k sshkey] [-m mirror] [-o output] [-p packages] [-r release] [-s size_in_GB] [-- mmdebstrap options]" + die "usage: $0 [-a architecture] [-h hostname] [-k sshkey] [-m mirror] [-o output] [-p packages] [-r release] [-z size_in_GB] [-- mmdebstrap options]" +} +usage_error() { + echo "error: $*" 1>&2 + usage } +opt_architecture() { + ARCHITECTURE=$1 +} +opt_hostname() { + VMNAME=$1 +} +opt_mirror() { + MIRROR=$1 +} +opt_sshkey() { + SSHKEY=$1 +} +opt_output() { + IMAGE=$1 +} +opt_package() { + INCLUDE_PACKAGES="$INCLUDE_PACKAGES,$1" +} +opt_release() { + SUITE=$1 +} +opt_size() { + SIZE=$(($1*1024*1024*1024)) +} -while test "$#" -gt 0; do - case "$1" in - -a) - test "$#" -eq 1 && usage - ARCHITECTURE=$2 - shift 2 - ;; - -h) - test "$#" -eq 1 && usage - VMNAME=$2 - shift 2 +while getopts :a:h:k:m:o:p:r:z:-: OPTCHAR; do + case "$OPTCHAR" in + a) opt_architecture "$OPTARG" ;; + h) opt_hostname "$OPTARG" ;; + k) opt_sshkey "$OPTARG" ;; + m) opt_mirror "$OPTARG" ;; + o) opt_output "$OPTARG" ;; + p) opt_package "$OPTARG" ;; + r) opt_release "$OPTARG" ;; + z) opt_size "$OPTARG" ;; + -) + case "$OPTARG" in + help) + usage + ;; + architecture|hostname|mirror|output|package|release|size|sshkey) + test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG" + "opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")" + OPTIND=$((OPTIND+1)) + ;; + architecture=*|hostname=*|mirror=*|output=*|package=*|release=*|size=*|sshkey=*) + "opt_${OPTARG%%=*}" "${OPTARG#*=}" + ;; + *) + usage_error "unrecognized option --$OPTARG" + ;; + esac ;; - -k) - test "$#" -eq 1 && usage - SSHKEY=$2 - shift 2 + :) + usage_error "missing argument for -$OPTARG" ;; - -m) - test "$#" -eq 1 && usage - MIRROR=$2 - shift 2 - ;; - -o) - test "$#" -eq 1 && usage - IMAGE=$2 - shift 2 - ;; - -p) - test "$#" -eq 1 && usage - INCLUDE_PACKAGES="$INCLUDE_PACKAGES,$2" - shift 2 - ;; - -r) - test "$#" -eq 1 && usage - SUITE=$2 - shift 2 - ;; - -s) - test "$#" -eq 1 && usage - SIZE=$(($2*1024*1024*1024)) - shift 2 - ;; - --) - shift - break + '?') + usage_error "unrecognized option -$OPTARG" ;; *) - usage + die "internal error while parsing command options, please report a bug" ;; esac done +shift "$((OPTIND - 1))" if test -n "$SSHKEY" && ! test -f "$SSHKEY"; then die "error: ssh keyfile '$SSHKEY' not found" @@ -190,8 +211,6 @@ case "$SUITE" in ;; esac - - KERNEL_SUFFIX=-$ARCHITECTURE case "$ARCHITECTURE" in amd64|arm64) @@ -217,7 +236,13 @@ case "$ARCHITECTURE" in ;; esac -INCLUDE_PACKAGES="$INCLUDE_PACKAGES,linux-image$KERNEL_SUFFIX" +case ",$INCLUDE_PACKAGES," in + *,linux-image-*) + ;; + *) + INCLUDE_PACKAGES="$INCLUDE_PACKAGES,linux-image$KERNEL_SUFFIX" + ;; +esac if test -n "$SSHKEY"; then INCLUDE_PACKAGES="$INCLUDE_PACKAGES,openssh-server" @@ -284,8 +309,7 @@ if test "$DEBVER" -le 8; then # Use obsolete and expired keys. set -- '--keyring=/usr/share/keyrings/debian-archive-removed-keys.gpg' "$@" set -- --aptopt='Apt::Key::gpgvcommand "/usr/libexec/mmdebstrap/gpgvnoexpkeysig"' "$@" - # chfn does not work, because libpam-runtime.postinst is late setting up /etc/pam.d/common-auth et al, see #1026765 - set -- --extract-hook='chroot "$1" pam-auth-update --package --force' "$@" + set -- --hook-dir=/usr/share/mmdebstrap/hooks/jessie-or-older "$@" fi if test "$DEBVER" -ge 12; then @@ -300,8 +324,11 @@ set -ex mmdebstrap "$@" -truncate -s "$SIZE" "$IMAGE" -/sbin/resize2fs "$IMAGE" +IMAGESIZE=$(stat -c %s "$IMAGE") +if test "$IMAGESIZE" -lt "$SIZE"; then + truncate -s "$SIZE" "$IMAGE" + /sbin/resize2fs "$IMAGE" +fi /sbin/tune2fs -L debvm -i 0 -O extents,uninit_bg,dir_index,has_journal "$IMAGE" # Must fsck after tune2fs: https://ext4.wiki.kernel.org/index.php/UpgradeToExt4 /sbin/fsck.ext4 -fDp "$IMAGE" |