Adding debian packaging.
Change-Id: I01cc2b9e3503c9c1621f5428f65b0c8d5ef1abc5
Showing
2 changed files
with
136 additions
and
83 deletions
... | @@ -25,6 +25,8 @@ export ONOS_VERSION=${ONOS_VERSION:-1.3.0.$BUILD_NUMBER} | ... | @@ -25,6 +25,8 @@ export ONOS_VERSION=${ONOS_VERSION:-1.3.0.$BUILD_NUMBER} |
25 | export ONOS_BITS=onos-${ONOS_VERSION%~*} | 25 | export ONOS_BITS=onos-${ONOS_VERSION%~*} |
26 | export ONOS_STAGE_ROOT=${ONOS_STAGE_ROOT:-/tmp} | 26 | export ONOS_STAGE_ROOT=${ONOS_STAGE_ROOT:-/tmp} |
27 | export ONOS_STAGE=$ONOS_STAGE_ROOT/$ONOS_BITS | 27 | export ONOS_STAGE=$ONOS_STAGE_ROOT/$ONOS_BITS |
28 | +export ONOS_DEB_ROOT=$ONOS_STAGE_ROOT/deb | ||
29 | +export ONOS_DEB=$ONOS_STAGE.deb | ||
28 | export ONOS_TAR=$ONOS_STAGE.tar.gz | 30 | export ONOS_TAR=$ONOS_STAGE.tar.gz |
29 | export ONOS_ZIP=$ONOS_STAGE.zip | 31 | export ONOS_ZIP=$ONOS_STAGE.zip |
30 | 32 | ... | ... |
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # ----------------------------------------------------------------------------- | 2 | # ----------------------------------------------------------------------------- |
3 | -# Packages ONOS distributable into onos.tar.gz and onos.zip | 3 | +# Packages ONOS distributable into onos.tar.gz, onos.zip or a deb file |
4 | # ----------------------------------------------------------------------------- | 4 | # ----------------------------------------------------------------------------- |
5 | 5 | ||
6 | +# Build the staging directory used to produce the packages | ||
7 | +function build_stage_dir() { | ||
8 | + # Make sure we have the original apache karaf bits first | ||
9 | + [ ! -d $M2_REPO ] && echo "M2 repository $M2_REPO not found" && exit 1 | ||
10 | + [ -d $ONOS_STAGE ] && echo "ONOS stage $ONOS_STAGE already exists" && exit 1 | ||
11 | + | ||
12 | + # Create the stage directory and warp into it | ||
13 | + mkdir -p $ONOS_STAGE | ||
14 | + cd $ONOS_STAGE | ||
15 | + | ||
16 | + # Check if Apache Karaf bits are available and if not, fetch them. | ||
17 | + if [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ]; then | ||
18 | + echo "Downloading $KARAF_TAR..." | ||
19 | + curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR | ||
20 | + fi | ||
21 | + [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \ | ||
22 | + echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1 | ||
23 | + | ||
24 | + # Unroll the Apache Karaf bits, prune them and make ONOS top-level directories. | ||
25 | + [ -f $KARAF_ZIP ] && unzip -q $KARAF_ZIP && rm -rf $ONOS_STAGE/$KARAF_DIST/demos | ||
26 | + [ -f $KARAF_TAR ] && tar zxf $KARAF_TAR && rm -rf $ONOS_STAGE/$KARAF_DIST/demos | ||
27 | + mkdir bin | ||
28 | + | ||
29 | + # Stage the ONOS admin scripts and patch in Karaf service wrapper extras | ||
30 | + cp -r $ONOS_ROOT/tools/package/bin . | ||
31 | + cp -r $ONOS_ROOT/tools/package/debian $ONOS_STAGE/debian | ||
32 | + cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc | ||
33 | + | ||
34 | + # Stage all builtin ONOS apps for factory install | ||
35 | + onos-stage-apps $ONOS_STAGE/apps $ONOS_STAGE/$KARAF_DIST/system | ||
36 | + | ||
37 | + # Mark the org.onosproject.drivers app active by default | ||
38 | + touch $ONOS_STAGE/apps/org.onosproject.drivers/active | ||
39 | + | ||
40 | + # Patch-in proper Karaf version into the startup script | ||
41 | + sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \ | ||
42 | + $ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service | ||
43 | + sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \ | ||
44 | + $ONOS_ROOT/tools/package/bin/onos-client > bin/onos | ||
45 | + chmod a+x bin/onos-service bin/onos | ||
46 | + | ||
47 | + # Stage the ONOS bundles, but only those that match the version | ||
48 | + mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject | ||
49 | + find $M2_REPO/org/onosproject -type f -path "*/$ONOS_POM_VERSION/*" \ | ||
50 | + -name '*.jar' -o -name '*.pom' -o -name '*-features.xml' \ | ||
51 | + | grep -v -Ee '-tests.jar|-[0-9]{8}.[0-9]{6}-' \ | ||
52 | + | while read src; do | ||
53 | + dst=$ONOS_STAGE/$KARAF_DIST/system/${src#$M2_REPO/*} | ||
54 | + mkdir -p $(dirname $dst) | ||
55 | + cp $src $dst | ||
56 | + done | ||
57 | + | ||
58 | + # ONOS Patching ---------------------------------------------------------------- | ||
59 | + | ||
60 | + # Patch the Apache Karaf distribution file to add ONOS features repository | ||
61 | + perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \ | ||
62 | + $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg | ||
63 | + | ||
64 | + # Patch the Apache Karaf distribution file to load default ONOS boot features | ||
65 | + export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui" | ||
66 | + perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \ | ||
67 | + $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg | ||
68 | + | ||
69 | + # Patch the Apache Karaf distribution with ONOS branding bundle | ||
70 | + cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \ | ||
71 | + $ONOS_STAGE/$KARAF_DIST/lib | ||
72 | + | ||
73 | + # Patch in the ONOS version file | ||
74 | + echo $ONOS_VERSION > $ONOS_STAGE/VERSION | ||
75 | +} | ||
76 | + | ||
77 | +function build_compressed_package() { | ||
78 | + # Package up the ONOS tar file | ||
79 | + cd $ONOS_STAGE_ROOT | ||
80 | + rm -f $ONOS_TAR $ONOS_ZIP | ||
81 | + COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS | ||
82 | + | ||
83 | + # Figure out whether we should build ONOS zip file and if so, build it. | ||
84 | + which zip >/dev/null && [ -z "$ONOS_TAR_ONLY" ] && buildZip=true || unset buildZip | ||
85 | + [ -n "$buildZip" ] && zip -rq $ONOS_ZIP $ONOS_BITS | ||
86 | + | ||
87 | + # Report on the archives that were built and clean-up | ||
88 | + [ -n "$buildZip" ] && ls -lh $ONOS_TAR $ONOS_ZIP || ls -lh $ONOS_TAR | ||
89 | + rm -r $ONOS_STAGE | ||
90 | +} | ||
91 | + | ||
92 | +# Build a DEB package | ||
93 | +function build_deb() { | ||
94 | + echo "You need to be root in order to generate a proper DEB package." | ||
95 | + | ||
96 | + sudo rm -fr $ONOS_DEB_ROOT | ||
97 | + | ||
98 | + mkdir -p $ONOS_DEB_ROOT/DEBIAN | ||
99 | + mkdir -p $ONOS_DEB_ROOT/opt/ | ||
100 | + mkdir -p $ONOS_DEB_ROOT/etc/init | ||
101 | + | ||
102 | + { | ||
103 | + echo "Package: onos" | ||
104 | + echo "Architecture: all" | ||
105 | + echo "Maintainer: ONOS Project" | ||
106 | + echo "Depends: debconf (>= 0.5.00), default-jre-headless (>= 1.8) | openjdk-8-jre | oracle-java8-installer" | ||
107 | + echo "Priority: optional" | ||
108 | + echo "Version: $ONOS_POM_VERSION" | ||
109 | + echo "Description: Open Network Operating System (ONOS) is an" | ||
110 | + echo " opensource SDN controller." | ||
111 | + } > $ONOS_DEB_ROOT/DEBIAN/control | ||
112 | + | ||
113 | + cp -r $ONOS_STAGE $ONOS_DEB_ROOT/opt/onos | ||
114 | + cp $ONOS_ROOT/tools/package/debian/onos.conf $ONOS_DEB_ROOT/etc/init/ | ||
115 | + | ||
116 | + mkdir -p $ONOS_DEB_ROOT/opt/onos/var/ | ||
117 | + | ||
118 | + sudo chown -R root:root $ONOS_DEB_ROOT | ||
119 | + | ||
120 | + sudo dpkg-deb --build $ONOS_DEB_ROOT > /dev/null && | ||
121 | + sudo mv $ONOS_STAGE_ROOT/deb.deb $ONOS_DEB && ls -l $ONOS_DEB | ||
122 | +} | ||
123 | + | ||
124 | +# Script entry point | ||
6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 | 125 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
7 | . $ONOS_ROOT/tools/build/envDefaults | 126 | . $ONOS_ROOT/tools/build/envDefaults |
8 | 127 | ||
9 | # Bail on any errors | 128 | # Bail on any errors |
10 | set -e | 129 | set -e |
11 | 130 | ||
12 | -rm -fr $ONOS_STAGE # Remove this when package script is completed | 131 | +# Before starting make sure the environment is clan - delete onos staging folder |
13 | - | 132 | +rm -fr $ONOS_STAGE |
14 | -# Make sure we have the original apache karaf bits first | 133 | + |
15 | -[ ! -d $M2_REPO ] && echo "M2 repository $M2_REPO not found" && exit 1 | 134 | +# If there are parameters check if we want to build a deb - otherwise build tar.gz |
16 | -[ -d $ONOS_STAGE ] && echo "ONOS stage $ONOS_STAGE already exists" && exit 1 | 135 | +case ${1:---tar} in |
17 | - | 136 | + "--tar") build_stage_dir |
18 | -# Create the stage directory and warp into it | 137 | + build_compressed_package |
19 | -mkdir -p $ONOS_STAGE | 138 | + ;; |
20 | -cd $ONOS_STAGE | 139 | + "--deb") build_stage_dir |
21 | - | 140 | + build_deb |
22 | -# Check if Apache Karaf bits are available and if not, fetch them. | 141 | + ;; |
23 | -if [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ]; then | 142 | + *) echo "usage: $(basename $0) [--tar|--deb]" >&2 && exit 1 |
24 | - echo "Downloading $KARAF_TAR..." | 143 | + ;; |
25 | - curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR | 144 | +esac |
26 | -fi | ||
27 | -[ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \ | ||
28 | - echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1 | ||
29 | - | ||
30 | -# Unroll the Apache Karaf bits, prune them and make ONOS top-level directories. | ||
31 | -[ -f $KARAF_ZIP ] && unzip -q $KARAF_ZIP && rm -rf $ONOS_STAGE/$KARAF_DIST/demos | ||
32 | -[ -f $KARAF_TAR ] && tar zxf $KARAF_TAR && rm -rf $ONOS_STAGE/$KARAF_DIST/demos | ||
33 | -mkdir bin | ||
34 | - | ||
35 | -# Stage the ONOS admin scripts and patch in Karaf service wrapper extras | ||
36 | -cp -r $ONOS_ROOT/tools/package/bin . | ||
37 | -cp -r $ONOS_ROOT/tools/package/debian $ONOS_STAGE/debian | ||
38 | -cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc | ||
39 | - | ||
40 | -# Stage all builtin ONOS apps for factory install | ||
41 | -onos-stage-apps $ONOS_STAGE/apps $ONOS_STAGE/$KARAF_DIST/system | ||
42 | - | ||
43 | -# Mark the org.onosproject.drivers app active by default | ||
44 | -touch $ONOS_STAGE/apps/org.onosproject.drivers/active | ||
45 | - | ||
46 | -# Patch-in proper Karaf version into the startup script | ||
47 | -sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \ | ||
48 | - $ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service | ||
49 | -sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \ | ||
50 | - $ONOS_ROOT/tools/package/bin/onos-client > bin/onos | ||
51 | -chmod a+x bin/onos-service bin/onos | ||
52 | - | ||
53 | -# Stage the ONOS bundles, but only those that match the version | ||
54 | -mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject | ||
55 | -find $M2_REPO/org/onosproject -type f -path "*/$ONOS_POM_VERSION/*" \ | ||
56 | - -name '*.jar' -o -name '*.pom' -o -name '*-features.xml' \ | ||
57 | - | grep -v -Ee '-tests.jar|-[0-9]{8}.[0-9]{6}-' \ | ||
58 | - | while read src; do | ||
59 | - dst=$ONOS_STAGE/$KARAF_DIST/system/${src#$M2_REPO/*} | ||
60 | - mkdir -p $(dirname $dst) | ||
61 | - cp $src $dst | ||
62 | -done | ||
63 | - | ||
64 | -# ONOS Patching ---------------------------------------------------------------- | ||
65 | - | ||
66 | -# Patch the Apache Karaf distribution file to add ONOS features repository | ||
67 | -perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \ | ||
68 | - $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg | ||
69 | - | ||
70 | -# Patch the Apache Karaf distribution file to load default ONOS boot features | ||
71 | -export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui" | ||
72 | -perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \ | ||
73 | - $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg | ||
74 | - | ||
75 | -# Patch the Apache Karaf distribution with ONOS branding bundle | ||
76 | -cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \ | ||
77 | - $ONOS_STAGE/$KARAF_DIST/lib | ||
78 | - | ||
79 | -# Patch in the ONOS version file | ||
80 | -echo $ONOS_VERSION > $ONOS_STAGE/VERSION | ||
81 | - | ||
82 | -# Now package up the ONOS tar file | ||
83 | -cd $ONOS_STAGE_ROOT | ||
84 | -rm -f $ONOS_TAR $ONOS_ZIP | ||
85 | -COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS | ||
86 | - | ||
87 | -# Figure out whether we should build ONOS zip file and if so, build it. | ||
88 | -which zip >/dev/null && [ -z "$ONOS_TAR_ONLY" ] && buildZip=true || unset buildZip | ||
89 | -[ -n "$buildZip" ] && zip -rq $ONOS_ZIP $ONOS_BITS | ||
90 | - | ||
91 | -# Report on the archives that were built and clean-up | ||
92 | -[ -n "$buildZip" ] && ls -lh $ONOS_TAR $ONOS_ZIP || ls -lh $ONOS_TAR | ||
93 | -rm -r $ONOS_STAGE | ... | ... |
-
Please register or login to post a comment