-
Notifications
You must be signed in to change notification settings - Fork 8
/
create-manifest
executable file
·150 lines (131 loc) · 2.59 KB
/
create-manifest
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
#
# Copyright (c) 2015 Joyent Inc., All rights reserved.
#
set -o errexit
now=$(date -u +%Y-%m-%dT%TZ)
vm_uuid=$(uuid)
SUM=/usr/bin/sum
description=
filename=
kernel=
min_platform=
name=
os=
version=
homepage=
usage()
{
cat <<USAGE
Create an image manifest from a given image file
Usage:
$0 -f <filename> -k <kernel_version> -m <min_platform> -n <name> -v <version>
-d <image description> (optional, default: "<NAME> <VERSION> VM Image")
-f <filename of VM image> (required)
-n <name of VM image> (required)
-v <version of VM image> (required)
-h <homepage link> (optional)
OPTIONS:
-d <image description> (optional, default: "<NAME> <VERSION> VM Image")
-f <filename of VM image> (required)
-k <kernel version for the VM image> (required)
-m <min_platform> (required)
-n <name of VM image> (required)
-o <the os of VM image> (optional, default: "other")
-v <version of VM image> (required)
-h <homepage link> (optional)
Example:
$0 -f alpine-20150319.zfs.gz -k 3.14.36 -m 20150316T201553Z -n lx-alpine -v 20150319
USAGE
exit 1
}
while getopts d:f:k:m:n:o:v:h:? OPTION
do
case $OPTION in
d)
description=${OPTARG}
;;
f)
filename=${OPTARG}
;;
k)
kernel=${OPTARG}
;;
m)
min_platform=${OPTARG}
;;
n)
name=${OPTARG}
;;
o)
os=${OPTARG}
;;
v)
version=${OPTARG}
;;
h)
homepage=${OPTARG}
;;
\?)
usage
;;
esac
done
if [[ -z ${filename} || -z ${kernel} || -z ${min_platform} || -z ${name} || -z ${version} ]]; then
echo "FATAL: All of -f, -k, -m, -n and -v are required."
usage
fi
if [[ -z ${description} ]]; then
description="${name} ${version} LX-brand image"
fi
if [[ -z ${os} ]]; then
os="other"
fi
if [[ -z ${homepage} ]]; then
homepage=https://docs.joyent.com/images
fi
if [[ ! -f ${filename} ]]; then
echo "FATAL: ${filename} does not exist."
usage
fi
shasum=$($SUM -x sha1 ${filename} | cut -d' ' -f1)
filesize=$(wc -c < ${filename})
cat <<EOF
{
"v": "2",
"name": "${name}",
"version": "${version}",
"type": "lx-dataset",
"description": "${description}",
"homepage": "${homepage}",
"published_at": "${now}",
"os": "${os}",
"files": [
{
"sha1": "${shasum}",
"size": ${filesize},
"compression": "gzip"
}
],
"requirements": {
"networks": [
{
"name": "net0",
"description": "public"
}
],
"min_platform": {
"7.0": "${min_platform}"
},
"brand": "lx"
},
"uuid": "${vm_uuid}",
"public": false,
"owner": "00000000-0000-0000-0000-000000000000",
"tags": {
"role": "os",
"kernel_version": "${kernel}"
}
}
EOF
exit 0