tom | 4d0c663 | 2014-09-15 23:27:01 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 2 | # ----------------------------------------------------------------------------- |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 3 | # Packages ONOS distributable into onos.tar.gz, onos.zip or a deb file |
Pavlin Radoslavov | 9141379 | 2014-10-15 11:00:32 -0700 | [diff] [blame] | 4 | # ----------------------------------------------------------------------------- |
tom | 4d0c663 | 2014-09-15 23:27:01 -0700 | [diff] [blame] | 5 | |
Thomas Vachuska | 6066dff | 2016-10-26 13:57:36 -0700 | [diff] [blame] | 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 7 | cd $ONOS_ROOT && onos-buck build onos --show-output && onos-check-bits |
| 8 | exit $? |
| 9 | |
| 10 | #============================================================================= |
| 11 | |
| 12 | # FIXME: This needs to be refactored using Buck; for now it is disabled |
| 13 | # FIXME: .deb, .rpm, .zip need to be re-implemented |
| 14 | # FIXME: SM-ONOS packaging flavour needs to be re-implemented |
| 15 | |
Brian O'Connor | f5d9363 | 2015-09-04 20:18:31 -0700 | [diff] [blame] | 16 | set -e |
| 17 | |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 18 | # Build the staging directory used to produce the packages |
| 19 | function build_stage_dir() { |
| 20 | # Make sure we have the original apache karaf bits first |
| 21 | [ ! -d $M2_REPO ] && echo "M2 repository $M2_REPO not found" && exit 1 |
| 22 | [ -d $ONOS_STAGE ] && echo "ONOS stage $ONOS_STAGE already exists" && exit 1 |
| 23 | |
| 24 | # Create the stage directory and warp into it |
| 25 | mkdir -p $ONOS_STAGE |
| 26 | cd $ONOS_STAGE |
| 27 | |
| 28 | # Check if Apache Karaf bits are available and if not, fetch them. |
| 29 | if [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ]; then |
| 30 | echo "Downloading $KARAF_TAR..." |
| 31 | curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR |
| 32 | fi |
| 33 | [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \ |
| 34 | echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1 |
| 35 | |
| 36 | # Unroll the Apache Karaf bits, prune them and make ONOS top-level directories. |
| 37 | [ -f $KARAF_ZIP ] && unzip -q $KARAF_ZIP && rm -rf $ONOS_STAGE/$KARAF_DIST/demos |
| 38 | [ -f $KARAF_TAR ] && tar zxf $KARAF_TAR && rm -rf $ONOS_STAGE/$KARAF_DIST/demos |
| 39 | mkdir bin |
| 40 | |
Thomas Vachuska | 08ab6a6 | 2015-09-23 16:55:45 -0700 | [diff] [blame] | 41 | # Patch the log-file size in place to increase it to 10 MB |
| 42 | perl -pi.old -e "s/maxFileSize=1MB/maxFileSize=10MB/g" \ |
| 43 | $ONOS_STAGE/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg |
| 44 | |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 45 | # Stage the ONOS admin scripts and patch in Karaf service wrapper extras |
| 46 | cp -r $ONOS_ROOT/tools/package/bin . |
Brian O'Connor | 0eed29e | 2015-09-16 11:38:33 -0700 | [diff] [blame] | 47 | cp -r $ONOS_ROOT/tools/package/init $ONOS_STAGE/init |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 48 | cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc |
| 49 | |
| 50 | # Stage all builtin ONOS apps for factory install |
| 51 | onos-stage-apps $ONOS_STAGE/apps $ONOS_STAGE/$KARAF_DIST/system |
| 52 | |
| 53 | # Mark the org.onosproject.drivers app active by default |
| 54 | touch $ONOS_STAGE/apps/org.onosproject.drivers/active |
| 55 | |
| 56 | # Patch-in proper Karaf version into the startup script |
| 57 | sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \ |
| 58 | $ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 59 | chmod a+x bin/onos-service bin/onos |
| 60 | |
Thomas Vachuska | 8c9ee81 | 2015-11-24 17:29:37 -0800 | [diff] [blame] | 61 | if [ -d $ONOS_ROOT/tools/package/karaf-assembly/target/repo ]; then |
| 62 | cp -r $ONOS_ROOT/tools/package/karaf-assembly/target/repo/* $ONOS_STAGE/$KARAF_DIST/system |
Brian O'Connor | eca5bbc | 2015-12-05 00:55:58 -0800 | [diff] [blame] | 63 | #FIXME we need to add onos-features manually |
| 64 | mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject/onos-features/$ONOS_POM_VERSION |
| 65 | cp $M2_REPO/org/onosproject/onos-features/$ONOS_POM_VERSION/onos-features* \ |
| 66 | $ONOS_STAGE/$KARAF_DIST/system/org/onosproject/onos-features/$ONOS_POM_VERSION |
Thomas Vachuska | 8c9ee81 | 2015-11-24 17:29:37 -0800 | [diff] [blame] | 67 | else |
| 68 | # TODO: Deprecated so remove when confident staging works. |
| 69 | # Stage the ONOS bundles, but only those that match the version |
| 70 | mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject |
| 71 | find $M2_REPO/org/onosproject -type f -path "*/$ONOS_POM_VERSION/*" \ |
| 72 | \( -name '*.jar' -o -name '*.pom' -o -name '*-features.xml' \) \ |
| 73 | | grep -v -Ee '-tests.jar|-[0-9]{8}.[0-9]{6}-' \ |
| 74 | | while read src; do |
| 75 | dst=$ONOS_STAGE/$KARAF_DIST/system/${src#$M2_REPO/*} |
| 76 | mkdir -p $(dirname $dst) |
| 77 | cp $src $dst |
| 78 | done |
| 79 | fi |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 80 | |
| 81 | # ONOS Patching ---------------------------------------------------------------- |
| 82 | |
Brian O'Connor | dfe13c8 | 2015-09-01 22:02:52 -0700 | [diff] [blame] | 83 | export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui" |
| 84 | |
| 85 | [ "$ONOS_SECURITY_MODE" = true ] && enable_security_mode |
| 86 | |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 87 | # Patch the Apache Karaf distribution file to add ONOS features repository |
| 88 | perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \ |
| 89 | $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg |
| 90 | |
| 91 | # Patch the Apache Karaf distribution file to load default ONOS boot features |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 92 | perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \ |
| 93 | $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg |
| 94 | |
| 95 | # Patch the Apache Karaf distribution with ONOS branding bundle |
| 96 | cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \ |
| 97 | $ONOS_STAGE/$KARAF_DIST/lib |
| 98 | |
| 99 | # Patch in the ONOS version file |
| 100 | echo $ONOS_VERSION > $ONOS_STAGE/VERSION |
| 101 | } |
| 102 | |
Brian O'Connor | dfe13c8 | 2015-09-01 22:02:52 -0700 | [diff] [blame] | 103 | function clean_stage_dir() { |
| 104 | [ -d "$ONOS_STAGE" ] && rm -r $ONOS_STAGE || : |
| 105 | } |
| 106 | |
| 107 | function enable_security_mode() { |
| 108 | echo "Enabling security mode ONOS..." |
| 109 | |
| 110 | # SM-ONOS step 1: downgrade felix config admin |
| 111 | FELIX_CFG_ADMIN=${FELIX_CFG_ADMIN:-~/Downloads/org.apache.felix.configadmin-1.6.0.jar} |
| 112 | if [ ! -f $FELIX_CFG_ADMIN ]; then |
| 113 | echo "Downloading $FELIX_CFG_ADMIN..." |
| 114 | curl -sL http://archive.apache.org/dist/felix/org.apache.felix.configadmin-1.6.0.jar > $FELIX_CFG_ADMIN |
| 115 | fi |
| 116 | [ ! -f $FELIX_CFG_ADMIN ] && \ |
| 117 | echo "Felix config admin not found: $FELIX_CFG_ADMIN" && exit 1 |
| 118 | |
| 119 | mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/apache/felix/org.apache.felix.configadmin/1.6.0 |
| 120 | cp $FELIX_CFG_ADMIN $ONOS_STAGE/$KARAF_DIST/system/org/apache/felix/org.apache.felix.configadmin/1.6.0 |
Changhoon Yoon | a68e6f9 | 2016-05-02 15:36:43 +0900 | [diff] [blame] | 121 | perl -pi.old -e "s|^(.*org.apache.felix.configadmin.*)|mvn\\\\:org.apache.felix/org.apache.felix.configadmin/1.6.0 = 10|" \ |
Brian O'Connor | dfe13c8 | 2015-09-01 22:02:52 -0700 | [diff] [blame] | 122 | $ONOS_STAGE/$KARAF_DIST/etc/startup.properties |
| 123 | |
| 124 | # SM-ONOS step 2: stage ONOS Felix framework security (this is already done by karaf assembly); end |
| 125 | |
| 126 | # SM-ONOS step 3.1: configure karaf |
| 127 | perl -pi.old -e "s|#java.security.policy|java.security.policy|" \ |
| 128 | $ONOS_STAGE/$KARAF_DIST/etc/system.properties |
| 129 | perl -pi.old -e "s|#org.osgi.framework.security|org.osgi.framework.security|" \ |
| 130 | $ONOS_STAGE/$KARAF_DIST/etc/system.properties |
| 131 | |
| 132 | # SM-ONOS step 3.2: update featuresBoot |
| 133 | export BOOT_FEATURES="onos-security,$BOOT_FEATURES" |
| 134 | } |
| 135 | |
| 136 | function build_compressed_zip() { |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 137 | cd $ONOS_STAGE_ROOT |
Brian O'Connor | dfe13c8 | 2015-09-01 22:02:52 -0700 | [diff] [blame] | 138 | rm -f $ONOS_ZIP |
| 139 | which zip >/dev/null && zip -rq $ONOS_ZIP $ONOS_BITS && ls -lh $ONOS_ZIP |
| 140 | } |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 141 | |
Brian O'Connor | dfe13c8 | 2015-09-01 22:02:52 -0700 | [diff] [blame] | 142 | function build_compressed_tar() { |
| 143 | cd $ONOS_STAGE_ROOT |
| 144 | rm -f $ONOS_TAR |
| 145 | COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS && ls -lh $ONOS_TAR |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | # Build a DEB package |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 149 | function build_deb() { |
Brian O'Connor | 8a0c20e | 2015-09-16 22:54:24 -0700 | [diff] [blame] | 150 | echo "This command may ask for your password to run commands as sudo," |
| 151 | echo " because you need to be root in order to generate a proper DEB package." |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 152 | |
| 153 | sudo rm -fr $ONOS_DEB_ROOT |
| 154 | |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 155 | mkdir -p $ONOS_DEB_ROOT/{DEBIAN,opt,etc/init} |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 156 | |
Brian O'Connor | 8a0c20e | 2015-09-16 22:54:24 -0700 | [diff] [blame] | 157 | # Copy the debian directory and fill in version |
| 158 | cp -r $ONOS_ROOT/tools/package/deb/* $ONOS_DEB_ROOT/DEBIAN/ |
| 159 | sed -i'' -E "s/@ONOS_POM_VERSION/$ONOS_POM_VERSION/" $ONOS_DEB_ROOT/DEBIAN/control |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 160 | |
| 161 | cp -r $ONOS_STAGE $ONOS_DEB_ROOT/opt/onos |
Brian O'Connor | 0eed29e | 2015-09-16 11:38:33 -0700 | [diff] [blame] | 162 | cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_DEB_ROOT/etc/init/ |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 163 | |
| 164 | mkdir -p $ONOS_DEB_ROOT/opt/onos/var/ |
| 165 | |
| 166 | sudo chown -R root:root $ONOS_DEB_ROOT |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 167 | |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 168 | sudo dpkg-deb --build $ONOS_DEB_ROOT > /dev/null && |
| 169 | sudo mv $ONOS_STAGE_ROOT/deb.deb $ONOS_DEB && ls -l $ONOS_DEB |
Brian O'Connor | 8a0c20e | 2015-09-16 22:54:24 -0700 | [diff] [blame] | 170 | |
| 171 | #TODO run lintian on .deb |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 174 | # Build an RPM package |
| 175 | function build_rpm() { |
| 176 | read -r -p "WARN: rpm-build utility and root priviledges are need to build the package. Do you want to continue? [Y/n] " response |
Brian O'Connor | ac32244 | 2015-09-17 23:49:17 -0700 | [diff] [blame] | 177 | [[ "$response" =~ ^[Nn] ]] && exit 0 |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 178 | |
Brian O'Connor | ac32244 | 2015-09-17 23:49:17 -0700 | [diff] [blame] | 179 | sudo rm -fr $ONOS_RPM_ROOT |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 180 | |
Brian O'Connor | ac32244 | 2015-09-17 23:49:17 -0700 | [diff] [blame] | 181 | sudo yum -y install rpm-build |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 182 | |
Brian O'Connor | ac32244 | 2015-09-17 23:49:17 -0700 | [diff] [blame] | 183 | mkdir -p $ONOS_RPM_ROOT/{BUILD,RPMS,SOURCES/onos-$ONOS_RPM_VERSION/{etc/init,opt},SPECS,SRPMS} |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 184 | |
Brian O'Connor | ac32244 | 2015-09-17 23:49:17 -0700 | [diff] [blame] | 185 | cp -r $ONOS_STAGE $ONOS_RPM_ROOT/SOURCES/onos-$ONOS_RPM_VERSION/opt/onos |
| 186 | cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_RPM_ROOT/SOURCES/onos-$ONOS_RPM_VERSION/etc/init/ |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 187 | |
Brian O'Connor | ac32244 | 2015-09-17 23:49:17 -0700 | [diff] [blame] | 188 | cd $ONOS_RPM_ROOT/SOURCES |
| 189 | COPYFILE_DISABLE=1 tar zcf onos-$ONOS_RPM_VERSION.tar.gz onos-$ONOS_RPM_VERSION |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 190 | |
Brian O'Connor | ac32244 | 2015-09-17 23:49:17 -0700 | [diff] [blame] | 191 | cp $ONOS_ROOT/tools/package/rpm/onos.spec $ONOS_RPM_ROOT/SPECS/ |
| 192 | sed -i'' -E "s/@ONOS_RPM_VERSION/$ONOS_RPM_VERSION/g" $ONOS_RPM_ROOT/SPECS/onos.spec |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 193 | |
Brian O'Connor | ac32244 | 2015-09-17 23:49:17 -0700 | [diff] [blame] | 194 | rpmbuild --define "_topdir $ONOS_RPM_ROOT" -bb $ONOS_RPM_ROOT/SPECS/onos.spec |
| 195 | |
| 196 | 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 |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 199 | # Script entry point |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 200 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 201 | . $ONOS_ROOT/tools/build/envDefaults |
tom | 4d0c663 | 2014-09-15 23:27:01 -0700 | [diff] [blame] | 202 | |
| 203 | # Bail on any errors |
| 204 | set -e |
| 205 | |
Brian O'Connor | dfe13c8 | 2015-09-01 22:02:52 -0700 | [diff] [blame] | 206 | [[ $# == 0 ]] && ONOS_PACKAGE_TAR_arg=true |
| 207 | while [[ $# > 0 ]]; do |
| 208 | case $1 in |
| 209 | -t|--tar) |
| 210 | ONOS_PACKAGE_TAR_arg=true |
| 211 | ;; |
| 212 | -z|--zip) |
| 213 | ONOS_PACKAGE_ZIP_arg=true |
| 214 | ;; |
| 215 | -d|--deb) |
| 216 | ONOS_PACKAGE_DEB_arg=true |
| 217 | ;; |
| 218 | -r|--rpm) |
| 219 | ONOS_PACKAGE_RPM_arg=true |
| 220 | ;; |
| 221 | -s|--secure) |
| 222 | ONOS_SECURITY_MODE=true |
| 223 | ;; |
| 224 | *) |
| 225 | # unknown option |
| 226 | echo "Unknown options: $1" |
| 227 | echo "usage: $(basename $0) [--tar] [--zip] [--deb] [--rpm] [--secure]" >&2 && exit 1 |
| 228 | ;; |
| 229 | esac |
| 230 | shift |
| 231 | done |
| 232 | |
Brian O'Connor | 37c486f | 2015-12-14 20:28:48 -0800 | [diff] [blame] | 233 | #TODO consider moving this block to build_stage_dir |
Thomas Vachuska | 8208205 | 2015-12-04 16:12:45 -0800 | [diff] [blame] | 234 | # Run karaf assembly to collect artifacts for off-line installations. |
| 235 | aux=/tmp/assembly-$$.log |
| 236 | trap "rm -f $aux 2>/dev/null" EXIT |
Brian O'Connor | 37c486f | 2015-12-14 20:28:48 -0800 | [diff] [blame] | 237 | #TODO possibly merge with MAVEN_OPTS, also M2_REPO must be set for the reasons |
| 238 | [ -n "$M2_REPO" ] && args="-Dmaven.repo.local=$M2_REPO" || args="" |
| 239 | cd $ONOS_ROOT/tools/package/karaf-assembly && |
| 240 | mvn $args clean install > $aux 2>&1 || |
Brian O'Connor | 68498e2 | 2016-01-04 14:02:03 -0800 | [diff] [blame] | 241 | ( cat $aux && |
| 242 | printf "\nFailed to run karaf-assembly, which stages artifacts for offline deployments.\n" && |
| 243 | exit 1 ) |
Thomas Vachuska | 8208205 | 2015-12-04 16:12:45 -0800 | [diff] [blame] | 244 | |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 245 | # Before starting make sure the environment is clan - delete onos staging folder |
Brian O'Connor | dfe13c8 | 2015-09-01 22:02:52 -0700 | [diff] [blame] | 246 | clean_stage_dir |
tom | 4d0c663 | 2014-09-15 23:27:01 -0700 | [diff] [blame] | 247 | |
Brian O'Connor | dfe13c8 | 2015-09-01 22:02:52 -0700 | [diff] [blame] | 248 | build_stage_dir |
| 249 | [ "$ONOS_PACKAGE_TAR_arg" = true ] && build_compressed_tar |
| 250 | [ "$ONOS_PACKAGE_ZIP_arg" = true ] && build_compressed_zip |
| 251 | [ "$ONOS_PACKAGE_DEB_arg" = true ] && build_deb |
| 252 | [ "$ONOS_PACKAGE_RPM_arg" = true ] && build_rpm |
| 253 | clean_stage_dir |