Luca Prete

Adding debian packaging.

Change-Id: I01cc2b9e3503c9c1621f5428f65b0c8d5ef1abc5
...@@ -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 -[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 6 +# Build the staging directory used to produce the packages
7 -. $ONOS_ROOT/tools/build/envDefaults 7 +function build_stage_dir() {
8 - 8 + # Make sure we have the original apache karaf bits first
9 -# Bail on any errors 9 + [ ! -d $M2_REPO ] && echo "M2 repository $M2_REPO not found" && exit 1
10 -set -e 10 + [ -d $ONOS_STAGE ] && echo "ONOS stage $ONOS_STAGE already exists" && exit 1
11 -
12 -rm -fr $ONOS_STAGE # Remove this when package script is completed
13 11
14 -# Make sure we have the original apache karaf bits first 12 + # Create the stage directory and warp into it
15 -[ ! -d $M2_REPO ] && echo "M2 repository $M2_REPO not found" && exit 1 13 + mkdir -p $ONOS_STAGE
16 -[ -d $ONOS_STAGE ] && echo "ONOS stage $ONOS_STAGE already exists" && exit 1 14 + cd $ONOS_STAGE
17 15
18 -# Create the stage directory and warp into it 16 + # Check if Apache Karaf bits are available and if not, fetch them.
19 -mkdir -p $ONOS_STAGE 17 + if [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ]; then
20 -cd $ONOS_STAGE
21 -
22 -# Check if Apache Karaf bits are available and if not, fetch them.
23 -if [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ]; then
24 echo "Downloading $KARAF_TAR..." 18 echo "Downloading $KARAF_TAR..."
25 curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR 19 curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR
26 -fi 20 + fi
27 -[ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \ 21 + [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \
28 echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1 22 echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1
29 23
30 -# Unroll the Apache Karaf bits, prune them and make ONOS top-level directories. 24 + # 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 25 + [ -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 26 + [ -f $KARAF_TAR ] && tar zxf $KARAF_TAR && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
33 -mkdir bin 27 + mkdir bin
34 28
35 -# Stage the ONOS admin scripts and patch in Karaf service wrapper extras 29 + # Stage the ONOS admin scripts and patch in Karaf service wrapper extras
36 -cp -r $ONOS_ROOT/tools/package/bin . 30 + cp -r $ONOS_ROOT/tools/package/bin .
37 -cp -r $ONOS_ROOT/tools/package/debian $ONOS_STAGE/debian 31 + cp -r $ONOS_ROOT/tools/package/debian $ONOS_STAGE/debian
38 -cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc 32 + cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc
39 33
40 -# Stage all builtin ONOS apps for factory install 34 + # Stage all builtin ONOS apps for factory install
41 -onos-stage-apps $ONOS_STAGE/apps $ONOS_STAGE/$KARAF_DIST/system 35 + onos-stage-apps $ONOS_STAGE/apps $ONOS_STAGE/$KARAF_DIST/system
42 36
43 -# Mark the org.onosproject.drivers app active by default 37 + # Mark the org.onosproject.drivers app active by default
44 -touch $ONOS_STAGE/apps/org.onosproject.drivers/active 38 + touch $ONOS_STAGE/apps/org.onosproject.drivers/active
45 39
46 -# Patch-in proper Karaf version into the startup script 40 + # Patch-in proper Karaf version into the startup script
47 -sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \ 41 + sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
48 $ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service 42 $ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service
49 -sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \ 43 + sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
50 $ONOS_ROOT/tools/package/bin/onos-client > bin/onos 44 $ONOS_ROOT/tools/package/bin/onos-client > bin/onos
51 -chmod a+x bin/onos-service bin/onos 45 + chmod a+x bin/onos-service bin/onos
52 46
53 -# Stage the ONOS bundles, but only those that match the version 47 + # Stage the ONOS bundles, but only those that match the version
54 -mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject 48 + mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject
55 -find $M2_REPO/org/onosproject -type f -path "*/$ONOS_POM_VERSION/*" \ 49 + find $M2_REPO/org/onosproject -type f -path "*/$ONOS_POM_VERSION/*" \
56 -name '*.jar' -o -name '*.pom' -o -name '*-features.xml' \ 50 -name '*.jar' -o -name '*.pom' -o -name '*-features.xml' \
57 | grep -v -Ee '-tests.jar|-[0-9]{8}.[0-9]{6}-' \ 51 | grep -v -Ee '-tests.jar|-[0-9]{8}.[0-9]{6}-' \
58 | while read src; do 52 | while read src; do
59 dst=$ONOS_STAGE/$KARAF_DIST/system/${src#$M2_REPO/*} 53 dst=$ONOS_STAGE/$KARAF_DIST/system/${src#$M2_REPO/*}
60 mkdir -p $(dirname $dst) 54 mkdir -p $(dirname $dst)
61 cp $src $dst 55 cp $src $dst
62 -done 56 + done
63 57
64 -# ONOS Patching ---------------------------------------------------------------- 58 + # ONOS Patching ----------------------------------------------------------------
65 59
66 -# Patch the Apache Karaf distribution file to add ONOS features repository 60 + # 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|" \ 61 + 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 62 $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
69 63
70 -# Patch the Apache Karaf distribution file to load default ONOS boot features 64 + # 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" 65 + 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|" \ 66 + perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \
73 $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg 67 $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
74 68
75 -# Patch the Apache Karaf distribution with ONOS branding bundle 69 + # Patch the Apache Karaf distribution with ONOS branding bundle
76 -cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \ 70 + cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \
77 $ONOS_STAGE/$KARAF_DIST/lib 71 $ONOS_STAGE/$KARAF_DIST/lib
78 72
79 -# Patch in the ONOS version file 73 + # Patch in the ONOS version file
80 -echo $ONOS_VERSION > $ONOS_STAGE/VERSION 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."
81 95
82 -# Now package up the ONOS tar file 96 + sudo rm -fr $ONOS_DEB_ROOT
83 -cd $ONOS_STAGE_ROOT
84 -rm -f $ONOS_TAR $ONOS_ZIP
85 -COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS
86 97
87 -# Figure out whether we should build ONOS zip file and if so, build it. 98 + mkdir -p $ONOS_DEB_ROOT/DEBIAN
88 -which zip >/dev/null && [ -z "$ONOS_TAR_ONLY" ] && buildZip=true || unset buildZip 99 + mkdir -p $ONOS_DEB_ROOT/opt/
89 -[ -n "$buildZip" ] && zip -rq $ONOS_ZIP $ONOS_BITS 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
125 +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
126 +. $ONOS_ROOT/tools/build/envDefaults
127 +
128 +# Bail on any errors
129 +set -e
90 130
91 -# Report on the archives that were built and clean-up 131 +# Before starting make sure the environment is clan - delete onos staging folder
92 -[ -n "$buildZip" ] && ls -lh $ONOS_TAR $ONOS_ZIP || ls -lh $ONOS_TAR 132 +rm -fr $ONOS_STAGE
93 -rm -r $ONOS_STAGE 133 +
134 +# If there are parameters check if we want to build a deb - otherwise build tar.gz
135 +case ${1:---tar} in
136 + "--tar") build_stage_dir
137 + build_compressed_package
138 + ;;
139 + "--deb") build_stage_dir
140 + build_deb
141 + ;;
142 + *) echo "usage: $(basename $0) [--tar|--deb]" >&2 && exit 1
143 + ;;
144 +esac
......