diff --git a/arch-template.json b/arch-template.json index a34799a..ff74f8b 100644 --- a/arch-template.json +++ b/arch-template.json @@ -4,6 +4,7 @@ "iso_checksum_url": "https://mirrors.kernel.org/archlinux/iso/{{isotime \"2006.01\"}}.01/sha1sums.txt", "ssh_timeout": "20m", "country": "US", + "write_zeros": "true", "headless": "false" }, "builders": [ @@ -124,7 +125,7 @@ }, { "type": "shell", - "execute_command": "{{ .Vars }} sudo -E -S bash '{{ .Path }}'", + "execute_command": "{{ .Vars }} WRITE_ZEROS={{ user `write_zeros` }} sudo -E -S bash '{{ .Path }}'", "script": "scripts/cleanup.sh" } ], diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh index 7227397..967c505 100755 --- a/scripts/cleanup.sh +++ b/scripts/cleanup.sh @@ -5,8 +5,10 @@ echo ">>>> cleanup.sh: Cleaning pacman cache.." /usr/bin/pacman -Scc --noconfirm # Write zeros to improve virtual disk compaction. -echo ">>>> cleanup.sh: Writing zeros to improve virtual disk compaction.." -zerofile=$(/usr/bin/mktemp /zerofile.XXXXX) -/usr/bin/dd if=/dev/zero of="$zerofile" bs=1M -/usr/bin/rm -f "$zerofile" -/usr/bin/sync +if [[ $WRITE_ZEROS == "true" ]]; then + echo ">>>> cleanup.sh: Writing zeros to improve virtual disk compaction.." + zerofile=$(/usr/bin/mktemp /zerofile.XXXXX) + /usr/bin/dd if=/dev/zero of="$zerofile" bs=1M + /usr/bin/rm -f "$zerofile" + /usr/bin/sync +fi diff --git a/wrapacker b/wrapacker index 23e50f2..6ae77a5 100755 --- a/wrapacker +++ b/wrapacker @@ -64,7 +64,7 @@ validate_country() { # print this script's usage message to stderr usage() { cat <<-EOF >&2 - usage: wrapacker [-c COUNTRY] [-p PROVIDER] [-t TIMEOUT] [-o ON-ERROR ACTION] [-f] [-d] [-h] + usage: wrapacker [-c COUNTRY] [-p PROVIDER] [-t TIMEOUT] [-w] [-o ON-ERROR ACTION] [-f] [-d] [-h] EOF } @@ -129,6 +129,9 @@ help() { sets the amount of time packer will wait for trying ssh login; defaults to 20m + -w, --skip-write-zeros + don't inflate the disk to improve virtual disk compaction + -o, --on-error=ACTION error handling if the build fails; defaults to cleanup @@ -165,6 +168,7 @@ country='' provider='' dry_run=false timeout='' +skip_write_zeros=false on_error='' force=false headless=false @@ -193,6 +197,9 @@ while [[ $1 != '' ]]; do --timeout=*) timeout=${1#*=} ;; + -w | --skip-write-zeros) + skip_write_zeros=true + ;; -o | --on-error) on_error=$2 shift @@ -288,6 +295,12 @@ else SSH_TIMEOUT='20m' fi +if [[ $skip_write_zeros = true ]]; then + WRITE_ZEROS="false" +else + WRITE_ZEROS="true" +fi + if [[ $on_error ]]; then case $(echo "$on_error" | tr '[:upper:]' '[:lower:]') in cleanup) @@ -320,6 +333,7 @@ cat <<-EOF -var "ssh_timeout=$SSH_TIMEOUT" \\ -var "country=$country" \\ -var "headless=$headless" \\ + -var "write_zeros=$WRITE_ZEROS" \\ -on-error=$ON_ERROR \\ -force \\ arch-template.json @@ -333,6 +347,7 @@ cat <<-EOF -var "ssh_timeout=$SSH_TIMEOUT" \\ -var "country=$country" \\ -var "headless=$headless" \\ + -var "write_zeros=$WRITE_ZEROS" \\ -on-error=$ON_ERROR \\ arch-template.json EOF @@ -346,6 +361,7 @@ else -var "ssh_timeout=$SSH_TIMEOUT" \ -var "country=$country" \ -var "headless=$headless" \ + -var "write_zeros=$WRITE_ZEROS" \ -on-error=$ON_ERROR \ -force \ arch-template.json @@ -357,6 +373,7 @@ else -var "ssh_timeout=$SSH_TIMEOUT" \ -var "country=$country" \ -var "headless=$headless" \ + -var "write_zeros=$WRITE_ZEROS" \ -on-error=$ON_ERROR \ arch-template.json fi