Browse code

Implemented as proposed by @tianon and @ypid. Restores the default behavior (using xz compression).

* `--compression=none` and `--no-compression` to disable compression.
* `--compression=auto` to use the default compression (enabled by default).
* `--compression=xz` to use xz compression (default compression).
* `--compression=gz` to use gzip compression.

Signed-off-by: Robin Schneider <ypid@riseup.net>

Robin Schneider authored on 2015/06/20 06:46:54
Showing 1 changed files
... ...
@@ -4,7 +4,7 @@ set -e
4 4
 mkimg="$(basename "$0")"
5 5
 
6 6
 usage() {
7
-	echo >&2 "usage: $mkimg [-d dir] [-t tag] script [script-args]"
7
+	echo >&2 "usage: $mkimg [-d dir] [-t tag] [-c compression] script [script-args]"
8 8
 	echo >&2 "   ie: $mkimg -t someuser/debian debootstrap --variant=minbase jessie"
9 9
 	echo >&2 "       $mkimg -t someuser/ubuntu debootstrap --include=ubuntu-minimal --components=main,universe trusty"
10 10
 	echo >&2 "       $mkimg -t someuser/busybox busybox-static"
... ...
@@ -16,16 +16,19 @@ usage() {
16 16
 
17 17
 scriptDir="$(dirname "$(readlink -f "$BASH_SOURCE")")/mkimage"
18 18
 
19
-optTemp=$(getopt --options '+d:t:h' --longoptions 'dir:,tag:,help' --name "$mkimg" -- "$@")
19
+optTemp=$(getopt --options '+d:t:c:hC' --longoptions 'dir:,tag:,compression:,no-compression,help' --name "$mkimg" -- "$@")
20 20
 eval set -- "$optTemp"
21 21
 unset optTemp
22 22
 
23 23
 dir=
24 24
 tag=
25
+compression="auto"
25 26
 while true; do
26 27
 	case "$1" in
27 28
 		-d|--dir) dir="$2" ; shift 2 ;;
28 29
 		-t|--tag) tag="$2" ; shift 2 ;;
30
+		-c|--compression) compression="$2" ; shift 2 ;;
31
+		-C|--no-compression) compression="none" ; shift 1 ;;
29 32
 		-h|--help) usage ;;
30 33
 		--) shift ; break ;;
31 34
 	esac
... ...
@@ -35,6 +38,18 @@ script="$1"
35 35
 [ "$script" ] || usage
36 36
 shift
37 37
 
38
+if [ "$compression" == "auto" ] || [ -z "$compression" ]
39
+then
40
+	compression="xz"
41
+fi
42
+
43
+if [ "$compression" == "none" ]
44
+then
45
+	compression=""
46
+else
47
+	compression=".${compression}"
48
+fi
49
+
38 50
 if [ ! -x "$scriptDir/$script" ]; then
39 51
 	echo >&2 "error: $script does not exist or is not executable"
40 52
 	echo >&2 "  see $scriptDir for possible scripts"
... ...
@@ -71,18 +86,18 @@ nameserver 8.8.8.8
71 71
 nameserver 8.8.4.4
72 72
 EOF
73 73
 
74
-tarFile="$dir/rootfs.tar"
74
+tarFile="$dir/rootfs.tar${compression}"
75 75
 touch "$tarFile"
76 76
 
77 77
 (
78 78
 	set -x
79
-	tar --numeric-owner -cf "$tarFile" -C "$rootfsDir" --transform='s,^./,,' .
79
+	tar --numeric-owner --create --auto-compress --file "$tarFile" --directory "$rootfsDir" --transform='s,^./,,' .
80 80
 )
81 81
 
82 82
 echo >&2 "+ cat > '$dir/Dockerfile'"
83
-cat > "$dir/Dockerfile" <<'EOF'
83
+cat > "$dir/Dockerfile" <<EOF
84 84
 FROM scratch
85
-ADD rootfs.tar /
85
+ADD $tarFile /
86 86
 EOF
87 87
 
88 88
 # if our generated image has a decent shell, let's set a default command