-
Notifications
You must be signed in to change notification settings - Fork 3
/
svr2ips_xtp.sh
executable file
·278 lines (246 loc) · 8.29 KB
/
svr2ips_xtp.sh
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/bash
#################################################################################################
##
## svr2ips_xtp.sh is a bash script to pack VirtualBox's extension package into an
## IPS packages.
##
## Copyright (C) 2013 Prominic - Thomas Gouverneur <[email protected]>
## This program is free software: you can redistribute it and/or modify it under the
## terms of the GNU General Public License as published by the Free Software Foundation,
## either version 3 of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
## without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along with this program.
## If not, see http://www.gnu.org/licenses/.
##
## Usage: svr2ips_xtp.sh <XTP> <IPS> [publisher] [cache]
##
## where:
## * XTP is an extention pack file
## of virtualbox release with the
## original file name.
## * IPS is an IPS repository location
## where the solaris publisher is
## present. Converted package
## will be sent to this repository.
## * publisher is the publisher this
## is published as. It defaults to "solaris"
## * cache dir is optional but recommended
## when you have multiple package to treat.
##
#################################################################################################
IREPO=http://pkg.oracle.com/solaris/release
PUBLISHER=solaris
if [ $# -lt 2 -o $# -gt 3 ]; then
echo "$0 <XTP> <IPS repo> [publisher] [cache]";
exit 1;
fi
if [ ! -f "${1}" ]; then
echo "[!] Extention pack not found";
exit 2;
fi
cleanup() {
tmpdir=$1
echo -n "\t* cleaning the mess: "
popd > /dev/null 2>&1
rm -rf ${tmpdir};
echo "[DONE]";
}
extpack=$1;
if [ ! -d "${2}" ]; then
echo "[!] IPS Repo directory not found";
exit 3;
fi
ipsrepo=$2;
pkgrepo -s ${ipsrepo} info > /dev/null 2>&1
rc=$?
if [ $rc -ne 0 ]; then
echo "[!] Invalid IPS repo $ipsrepo";
exit 4;
fi
if [ $# -eq 3 ]; then
PUBLISHER=$3;
else
echo "[!] publisher not specified";
fi
echo "[-] using publisher: $PUBLISHER";
cachedir=
if [ $# -eq 4 ]; then
cachedir=$4;
if [ ! -d "${cachedir}" ]; then
echo "[!] provided cachedir doesn't exist";
exit 7;
fi
echo "[-] using specified cachedir: ${cachedir}";
fi
filename=$(basename ${extpack} | sed 's/.pkg$//g');
major=$(echo $filename|cut -f 2 -d'-'|sed -e 's/_.*//g;s/\.vbox.extpack//g');
minor=$(echo $filename|cut -f 3 -d'-'|sed 's/\..*//g');
if [ "${minor}" = "" ]; then
minor=0;
fi
vboxfmri="pkg://${PUBLISHER}/system/[email protected],5.11-${major}.${minor}";
tmpdir=$(mktemp -d);
echo "[-] Will try to build IPS package ${vboxfmri}:";
echo -n "\t* building directory structure: ";
mkdir -p ${tmpdir}/proto_install/opt/VirtualBox/extpack
mkdir -p ${tmpdir}/proto_install/var/svc/manifest/application/virtualbox/
echo "[DONE]";
echo -n "\t* copying extpack: ";
cp ${extpack} ${tmpdir}/proto_install/opt/VirtualBox/extpack
echo "[DONE]";
pushd ${PWD} > /dev/null 2>&1
cd ${tmpdir};
echo -n "\t* copy hack-script: ";
echo "${major}.${minor}" > VERSION_XTP
cat > run-once-extpack.sh << "EOF"
#!/usr/bin/sh
. /lib/svc/share/smf_include.sh
lver=$(/usr/bin/svcprop -p config/version $SMF_FMRI)
if [ -f /opt/VirtualBox/VERSION_XTP ]; then
cver=$(cat /opt/VirtualBox/VERSION_XTP)
else
cver=""
fi
if [ "$lver" != "$cver" ]; then
svccfg -s $SMF_FMRI setprop config/assembled = false
svccfg -s $SMF_FMRI setprop config/version = astring: $cver
svccfg -s $SMF_FMRI refresh
echo "--UPDATE virtualbox/run-once-extpack"
fi
assembled=$(/usr/bin/svcprop -p config/assembled $SMF_FMRI)
if [ "$assembled" == "true" ] ; then
exit $SMF_EXIT_OK
fi
EOF
cat >> run-once-extpack.sh << EOF
/opt/VirtualBox/VBoxManage extpack install --replace /opt/VirtualBox/extpack/${filename}
EOF
cat >> run-once-extpack.sh << "EOF"
svccfg -s $SMF_FMRI setprop config/assembled = true
svccfg -s $SMF_FMRI refresh
echo "--DONE virtualbox/run-once-extpack"
EOF
cat > virtualbox-run-once-extpack.xml << "EOF"
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='VirtualBox:run-once-extpack'>
<service
name='application/virtualbox/run-once-extpack'
type='service'
version='1'>
<single_instance />
<dependency
name='fs-local'
grouping='require_all'
restart_on='none'
type='service'>
<service_fmri value='svc:/system/filesystem/local:default' />
</dependency>
<dependency name='virtualbox-run-once' grouping='require_all' restart_on='none' type='service'>
<service_fmri value='svc:/application/virtualbox/run-once'/>
</dependency>
<dependent
name='virtualbox-extpack-assembly-complete'
grouping='optional_all'
restart_on='none'>
<service_fmri value='svc:/milestone/self-assembly-complete' />
</dependent>
<instance enabled='true' name='default'>
<exec_method
type='method'
name='start'
exec='/opt/VirtualBox/run-once-extpack.sh'
timeout_seconds='0'/>
<exec_method
type='method'
name='stop'
exec=':true'
timeout_seconds='0'/>
<property_group name='startd' type='framework'>
<propval name='duration' type='astring' value='transient' />
</property_group>
<property_group name='config' type='application'>
<propval name='assembled' type='boolean' value='false' />
<propval name='version' type='astring' value='' />
</property_group>
</instance>
</service>
</service_bundle>
EOF
cp ./run-once-extpack.sh proto_install/opt/VirtualBox/
cp ./VERSION_XTP proto_install/opt/VirtualBox/
cp ./virtualbox-run-once-extpack.xml proto_install/var/svc/manifest/application/virtualbox/
echo "[DONE]";
echo -n "\t* generating metadata: ";
cat > ${filename}.manifest << EOF
dir path=var/svc/manifest/application/virtualbox owner=root group=root mode=0755
dir path=opt/VirtualBox owner=root group=bin mode=0755
dir path=opt/VirtualBox/extpack owner=root group=bin mode=0755
file opt/VirtualBox/extpack/${filename} \\
path=/opt/VirtualBox/extpack/${filename} owner=root group=sys mode=0755
file var/svc/manifest/application/virtualbox/virtualbox-run-once-extpack.xml \\
path=/var/svc/manifest/application/virtualbox/virtualbox-run-once-extpack.xml owner=root group=sys \\
mode=0644 restart_fmri=svc:/system/manifest-import:default
file opt/VirtualBox/run-once-extpack.sh \\
path=/opt/VirtualBox/run-once-extpack.sh owner=root group=sys mode=0755
file opt/VirtualBox/VERSION_XTP \\
path=/opt/VirtualBox/VERSION_XTP owner=root group=sys mode=0644
EOF
cat > ${filename}.meta << EOF
set name=pkg.fmri value="${vboxfmri}"
set name=info.classification \
value="org.opensolaris.category.2008:Applications/System Utilities"
set name=org.opensolaris.consolidation value=SUNWvbext
set name=variant.opensolaris.zone value=global
set name=pkg.summary value="Oracle VM VirtualBox Extension Pack"
set name=pkg.description value="A powerful PC virtualization solution"
set name=pkg.send.convert.email [email protected]
EOF
cp ${filename}.meta ${filename}.p5m
cat ${filename}.manifest >> ${filename}.p5m
echo "[DONE]";
echo -n "\t* adding dependancies: ";
cat >> ${filename}.p5m << EOF
depend type=require \\
fmri=pkg:/system/[email protected]${major}.${minor}
depend type=incorporate \\
fmri=pkg:/system/[email protected]${major}.${minor}
EOF
echo "[DONE]";
echo -n "\t* resolving dependancies: ";
pkgdepend resolve -m ${filename}.p5m > /dev/null 2>&1
rc=$?
if [ $rc -gt 1 -o ! -f ./${filename}.p5m.res ]; then
echo "[FAILED]";
cleanup ${tmpdir}
exit 5;
fi
echo "[DONE]";
echo -n "\t* checking package: ";
if [ -z "${cachedir}" ]; then
mkdir -p ./cache
cachedir=./cache
fi
pkglint -c ${cachedir} -r ${IREPO} ./${filename}.p5m.res > /dev/null 2>&1
rc=$?
if [ $rc -ne 0 ]; then
echo "[FAILED]";
cleanup ${tmpdir}
exit 5;
fi
echo "[DONE]";
echo -n "\t* publishing package: ";
pkgsend publish -d proto_install -s ${ipsrepo} ./${filename}.p5m.res > /dev/null 2>&1
rc=$?
if [ $rc -ne 0 ]; then
echo "[FAILED]";
cleanup ${tmpdir}
exit 5;
fi
echo "[DONE]";
cleanup ${tmpdir}
#EOF