-
Notifications
You must be signed in to change notification settings - Fork 38
/
mkmanifest
executable file
·55 lines (45 loc) · 1.27 KB
/
mkmanifest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
set -e
options=$(getopt -s sh -n $0 v:t:o: "$@")
if [ $? -ne 0 ]; then
echo >&2 "Usage: $0 [-v version] [-t template] [-o output] manifests..."
exit 1
fi
version=
template=
output=output.img
for option in $options; do
case "$option" in
-v) shift; version=$1; shift;;
-t) shift; template=$1; shift;;
-o) shift; output=$1; shift;;
--) break;;
esac
done
manifests="$@"
if [ "$version" = "" ]; then
echo >&2 "$0: you must specify a version (try '2.0.4')"
exit 1
fi
if [ "$template" = "" ]; then
echo >&2 "$0: you have to supply a template file (try something in '2.0.4/templates')"
exit 1
fi
if [ "$manifests" = "" ]; then
echo >&2 "$0: you have to supply at least one manifest (try something in '2.0.4/manifests')"
exit 1
fi
ROOT=$PWD/$version
echo "Version: $version"
echo "Template file: $template"
echo "Output image: $output"
echo "Manifests: $manifests"
mnt=mnt
mkdir -p $mnt
zcat $ROOT/templates/$template > $output
sudo mount $output $mnt -o loop 2>/dev/null || sudo mount $output $mnt -o loop,offset=512
trap "sudo umount $mnt" EXIT
for mf in $manifests; do
echo "Running manifest $mf"
(cd $mnt && sudo sh -c "set -e && . ../mkmanifest.sh && ROOT=$ROOT && . $ROOT/manifests/$mf")
done