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