forked from TritonDataCenter/imagetools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-image
executable file
·108 lines (97 loc) · 3.97 KB
/
create-image
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
#
# Create an image and manifest out of a shut down zone. The zone
# should have been prepared with sm-prepare-image.
#
if [ $# -ne 2 ]; then
echo "usage: $0 <name> <zone>" >&2
exit 2
else
name=$1; shift
zone=$1; shift
fi
set -e
outdir="$(dirname $0)/output"
case ${name} in
minimal-32-*)
description="A 32-bit SmartOS image with just bootstrap packages installed. Ideal for users who want the smallest possible image upon which to build."
homepage="https://docs.joyent.com/images/smartos/minimal"
;;
minimal-64-*)
description="A 64-bit SmartOS image with just bootstrap packages installed. Ideal for users who want the smallest possible image upon which to build."
homepage="https://docs.joyent.com/images/smartos/minimal"
;;
minimal-multiarch-*)
description="A multiarch SmartOS image with just bootstrap packages installed. Ideal for users who want the smallest possible image upon which to build."
homepage="https://docs.joyent.com/images/smartos/minimal"
;;
base-32-*)
description="A 32-bit SmartOS image with just essential packages installed. Ideal for users who are comfortable with setting up their own environment and tools."
homepage="https://docs.joyent.com/images/smartos/base"
;;
base-64-*)
description="A 64-bit SmartOS image with just essential packages installed. Ideal for users who are comfortable with setting up their own environment and tools."
homepage="https://docs.joyent.com/images/smartos/base"
;;
base-multiarch-*)
description="A multiarch SmartOS image with just essential packages installed. Ideal for users who are comfortable with setting up their own environment and tools."
homepage="https://docs.joyent.com/images/smartos/base"
;;
base-*)
description="A 32-bit SmartOS image with just essential packages installed. Ideal for users who are comfortable with setting up their own environment and tools."
homepage="http://wiki.joyent.com/jpc2/Base+Instance"
;;
base64-*)
description="A 64-bit SmartOS image with just essential packages installed. Ideal for users who are comfortable with setting up their own environment and tools."
homepage="http://wiki.joyent.com/jpc2/Base+Instance"
;;
multiarch-*)
description="A multiarch SmartOS image with just essential packages installed. This is a beta image only. Please submit any issues to https://github.com/joyent/pkgsrc/issues"
homepage="http://wiki.joyent.com/jpc2/Base+Instance"
;;
pkgbuild-*)
description="A SmartOS image pre-configured for building pkgsrc packages."
homepage="https://docs.joyent.com/images/smartos/pkgbuild"
;;
seed-*)
description="Seed Image"
homepage="https://docs.joyent.com/images/smartos/base"
;;
esac
[[ -n "${description}" ]] || read -p 'Enter description: ' description
[[ -n "${homepage}" ]] || read -p 'Enter homepage: ' homepage
if [ -z "${description}" ]; then
echo "WARNING: No description entered. Edit ${outdir}/${name}.json"
echo "when this script finishes."
fi
if [ -z "${homepage}" ]; then
echo "WARNING: No homepage entered. Edit ${outdir}/${name}.json"
echo "when this script finishes."
fi
echo "Taking snapshot ..."
zfs snapshot zones/${zone}@snap$$
echo "Sending snapshot to ${outdir}/${name}.zfs.gz ..."
mkdir -p ${outdir}
zfs send zones/${zone}@snap$$ | \
$(dirname $0)/bin/zstreamdeholer | \
gzip -9 >${outdir}/${name}.zfs.gz
zfs destroy zones/${zone}@snap$$
echo "Creating ${outdir}/${name}.json ..."
sha1=$(digest -a sha1 ${outdir}/${name}.zfs.gz)
size=$(ls -l ${outdir}/${name}.zfs.gz | awk '{print $5}')
uuid=$(uuid)
datestamp=$(date '+%FT%TZ')
cat $(dirname $0)/imgjson.in \
| sed -e "s!@NAME@!${name%-*}!g" \
-e "s!@VERSION@!${name##*-}!g" \
-e "s!@DATESTAMP@!${datestamp}!g" \
-e "s!@DESCRIPTION@!${description}!g" \
-e "s!@HOMEPAGE@!${homepage}!g" \
-e "s!@SHA1@!${sha1}!g" \
-e "s!@SIZE@!${size}!g" \
-e "s!@UUID@!${uuid}!g" \
>${outdir}/${name}.json
echo "Done. Now run this to install the image:"
echo ""
echo " imgadm install -m ${outdir}/${name}.json -f ${outdir}/${name}.zfs.gz"
echo ""