onos-package
9.55 KB
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
#!/bin/bash
# -----------------------------------------------------------------------------
# Packages ONOS distributable into onos.tar.gz, onos.zip or a deb file
# -----------------------------------------------------------------------------
set -e
# Build the staging directory used to produce the packages
function build_stage_dir() {
# Make sure we have the original apache karaf bits first
[ ! -d $M2_REPO ] && echo "M2 repository $M2_REPO not found" && exit 1
[ -d $ONOS_STAGE ] && echo "ONOS stage $ONOS_STAGE already exists" && exit 1
# Create the stage directory and warp into it
mkdir -p $ONOS_STAGE
cd $ONOS_STAGE
# Check if Apache Karaf bits are available and if not, fetch them.
if [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ]; then
echo "Downloading $KARAF_TAR..."
curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR
fi
[ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \
echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1
# Unroll the Apache Karaf bits, prune them and make ONOS top-level directories.
[ -f $KARAF_ZIP ] && unzip -q $KARAF_ZIP && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
[ -f $KARAF_TAR ] && tar zxf $KARAF_TAR && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
mkdir bin
# Patch the log-file size in place to increase it to 10 MB
perl -pi.old -e "s/maxFileSize=1MB/maxFileSize=10MB/g" \
$ONOS_STAGE/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg
# Stage the ONOS admin scripts and patch in Karaf service wrapper extras
cp -r $ONOS_ROOT/tools/package/bin .
cp -r $ONOS_ROOT/tools/package/init $ONOS_STAGE/init
cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc
# Stage all builtin ONOS apps for factory install
onos-stage-apps $ONOS_STAGE/apps $ONOS_STAGE/$KARAF_DIST/system
# Mark the org.onosproject.drivers app active by default
touch $ONOS_STAGE/apps/org.onosproject.drivers/active
# Patch-in proper Karaf version into the startup script
sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
$ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service
sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
$ONOS_ROOT/tools/package/bin/onos-client > bin/onos
chmod a+x bin/onos-service bin/onos
if [ -d $ONOS_ROOT/tools/package/karaf-assembly/target/repo ]; then
cp -r $ONOS_ROOT/tools/package/karaf-assembly/target/repo/* $ONOS_STAGE/$KARAF_DIST/system
#FIXME we need to add onos-features manually
mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject/onos-features/$ONOS_POM_VERSION
cp $M2_REPO/org/onosproject/onos-features/$ONOS_POM_VERSION/onos-features* \
$ONOS_STAGE/$KARAF_DIST/system/org/onosproject/onos-features/$ONOS_POM_VERSION
else
# TODO: Deprecated so remove when confident staging works.
# Stage the ONOS bundles, but only those that match the version
mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject
find $M2_REPO/org/onosproject -type f -path "*/$ONOS_POM_VERSION/*" \
\( -name '*.jar' -o -name '*.pom' -o -name '*-features.xml' \) \
| grep -v -Ee '-tests.jar|-[0-9]{8}.[0-9]{6}-' \
| while read src; do
dst=$ONOS_STAGE/$KARAF_DIST/system/${src#$M2_REPO/*}
mkdir -p $(dirname $dst)
cp $src $dst
done
fi
# ONOS Patching ----------------------------------------------------------------
export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui"
[ "$ONOS_SECURITY_MODE" = true ] && enable_security_mode
# Patch the Apache Karaf distribution file to add ONOS features repository
perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \
$ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
# Patch the Apache Karaf distribution file to load default ONOS boot features
perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \
$ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
# Patch the Apache Karaf distribution with ONOS branding bundle
cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \
$ONOS_STAGE/$KARAF_DIST/lib
# Patch in the ONOS version file
echo $ONOS_VERSION > $ONOS_STAGE/VERSION
}
function clean_stage_dir() {
[ -d "$ONOS_STAGE" ] && rm -r $ONOS_STAGE || :
}
function enable_security_mode() {
echo "Enabling security mode ONOS..."
# SM-ONOS step 1: downgrade felix config admin
FELIX_CFG_ADMIN=${FELIX_CFG_ADMIN:-~/Downloads/org.apache.felix.configadmin-1.6.0.jar}
if [ ! -f $FELIX_CFG_ADMIN ]; then
echo "Downloading $FELIX_CFG_ADMIN..."
curl -sL http://archive.apache.org/dist/felix/org.apache.felix.configadmin-1.6.0.jar > $FELIX_CFG_ADMIN
fi
[ ! -f $FELIX_CFG_ADMIN ] && \
echo "Felix config admin not found: $FELIX_CFG_ADMIN" && exit 1
mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/apache/felix/org.apache.felix.configadmin/1.6.0
cp $FELIX_CFG_ADMIN $ONOS_STAGE/$KARAF_DIST/system/org/apache/felix/org.apache.felix.configadmin/1.6.0
perl -pi.old -e "s|^(.*org.apache.felix.configadmin.*)|mvn\\\\:org.apache.felix/org.apache.felix.configadmin/1.6.0 = 10|" \
$ONOS_STAGE/$KARAF_DIST/etc/startup.properties
# SM-ONOS step 2: stage ONOS Felix framework security (this is already done by karaf assembly); end
# SM-ONOS step 3.1: configure karaf
perl -pi.old -e "s|#java.security.policy|java.security.policy|" \
$ONOS_STAGE/$KARAF_DIST/etc/system.properties
perl -pi.old -e "s|#org.osgi.framework.security|org.osgi.framework.security|" \
$ONOS_STAGE/$KARAF_DIST/etc/system.properties
# SM-ONOS step 3.2: update featuresBoot
export BOOT_FEATURES="onos-security,$BOOT_FEATURES"
}
function build_compressed_zip() {
cd $ONOS_STAGE_ROOT
rm -f $ONOS_ZIP
which zip >/dev/null && zip -rq $ONOS_ZIP $ONOS_BITS && ls -lh $ONOS_ZIP
}
function build_compressed_tar() {
cd $ONOS_STAGE_ROOT
rm -f $ONOS_TAR
COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS && ls -lh $ONOS_TAR
}
# Build a DEB package
function build_deb() {
echo "This command may ask for your password to run commands as sudo,"
echo " because you need to be root in order to generate a proper DEB package."
sudo rm -fr $ONOS_DEB_ROOT
mkdir -p $ONOS_DEB_ROOT/{DEBIAN,opt,etc/init}
# Copy the debian directory and fill in version
cp -r $ONOS_ROOT/tools/package/deb/* $ONOS_DEB_ROOT/DEBIAN/
sed -i'' -E "s/@ONOS_POM_VERSION/$ONOS_POM_VERSION/" $ONOS_DEB_ROOT/DEBIAN/control
cp -r $ONOS_STAGE $ONOS_DEB_ROOT/opt/onos
cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_DEB_ROOT/etc/init/
mkdir -p $ONOS_DEB_ROOT/opt/onos/var/
sudo chown -R root:root $ONOS_DEB_ROOT
sudo dpkg-deb --build $ONOS_DEB_ROOT > /dev/null &&
sudo mv $ONOS_STAGE_ROOT/deb.deb $ONOS_DEB && ls -l $ONOS_DEB
#TODO run lintian on .deb
}
# Build an RPM package
function build_rpm() {
read -r -p "WARN: rpm-build utility and root priviledges are need to build the package. Do you want to continue? [Y/n] " response
[[ "$response" =~ ^[Nn] ]] && exit 0
sudo rm -fr $ONOS_RPM_ROOT
sudo yum -y install rpm-build
mkdir -p $ONOS_RPM_ROOT/{BUILD,RPMS,SOURCES/onos-$ONOS_RPM_VERSION/{etc/init,opt},SPECS,SRPMS}
cp -r $ONOS_STAGE $ONOS_RPM_ROOT/SOURCES/onos-$ONOS_RPM_VERSION/opt/onos
cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_RPM_ROOT/SOURCES/onos-$ONOS_RPM_VERSION/etc/init/
cd $ONOS_RPM_ROOT/SOURCES
COPYFILE_DISABLE=1 tar zcf onos-$ONOS_RPM_VERSION.tar.gz onos-$ONOS_RPM_VERSION
cp $ONOS_ROOT/tools/package/rpm/onos.spec $ONOS_RPM_ROOT/SPECS/
sed -i'' -E "s/@ONOS_RPM_VERSION/$ONOS_RPM_VERSION/g" $ONOS_RPM_ROOT/SPECS/onos.spec
rpmbuild --define "_topdir $ONOS_RPM_ROOT" -bb $ONOS_RPM_ROOT/SPECS/onos.spec
cp $ONOS_RPM_ROOT/RPMS/noarch/onos-$ONOS_RPM_VERSION-1.noarch.rpm $ONOS_STAGE_ROOT && ls -l $ONOS_STAGE_ROOT/onos-$ONOS_RPM_VERSION-1.noarch.rpm
}
# Script entry point
[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
. $ONOS_ROOT/tools/build/envDefaults
# Bail on any errors
set -e
[[ $# == 0 ]] && ONOS_PACKAGE_TAR_arg=true
while [[ $# > 0 ]]; do
case $1 in
-t|--tar)
ONOS_PACKAGE_TAR_arg=true
;;
-z|--zip)
ONOS_PACKAGE_ZIP_arg=true
;;
-d|--deb)
ONOS_PACKAGE_DEB_arg=true
;;
-r|--rpm)
ONOS_PACKAGE_RPM_arg=true
;;
-s|--secure)
ONOS_SECURITY_MODE=true
;;
*)
# unknown option
echo "Unknown options: $1"
echo "usage: $(basename $0) [--tar] [--zip] [--deb] [--rpm] [--secure]" >&2 && exit 1
;;
esac
shift
done
#TODO consider moving this block to build_stage_dir
# Run karaf assembly to collect artifacts for off-line installations.
aux=/tmp/assembly-$$.log
trap "rm -f $aux 2>/dev/null" EXIT
#TODO possibly merge with MAVEN_OPTS, also M2_REPO must be set for the reasons
[ -n "$M2_REPO" ] && args="-Dmaven.repo.local=$M2_REPO" || args=""
cd $ONOS_ROOT/tools/package/karaf-assembly &&
mvn $args clean install > $aux 2>&1 ||
( cat $aux &&
printf "\nFailed to run karaf-assembly, which stages artifacts for offline deployments.\n" &&
exit 1 )
# Before starting make sure the environment is clan - delete onos staging folder
clean_stage_dir
build_stage_dir
[ "$ONOS_PACKAGE_TAR_arg" = true ] && build_compressed_tar
[ "$ONOS_PACKAGE_ZIP_arg" = true ] && build_compressed_zip
[ "$ONOS_PACKAGE_DEB_arg" = true ] && build_deb
[ "$ONOS_PACKAGE_RPM_arg" = true ] && build_rpm
clean_stage_dir