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 | |
| 31 | # Stage the ONOS admin scripts and patch in Karaf service wrapper extras |
| 32 | cp -r $ONOS_ROOT/tools/package/bin . |
| 33 | cp -r $ONOS_ROOT/tools/package/debian $ONOS_STAGE/debian |
| 34 | cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc |
| 35 | |
| 36 | # Stage all builtin ONOS apps for factory install |
| 37 | onos-stage-apps $ONOS_STAGE/apps $ONOS_STAGE/$KARAF_DIST/system |
| 38 | |
| 39 | # Mark the org.onosproject.drivers app active by default |
| 40 | touch $ONOS_STAGE/apps/org.onosproject.drivers/active |
| 41 | |
| 42 | # Patch-in proper Karaf version into the startup script |
| 43 | sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \ |
| 44 | $ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service |
| 45 | sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \ |
| 46 | $ONOS_ROOT/tools/package/bin/onos-client > bin/onos |
| 47 | chmod a+x bin/onos-service bin/onos |
| 48 | |
| 49 | # Stage the ONOS bundles, but only those that match the version |
| 50 | mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject |
| 51 | find $M2_REPO/org/onosproject -type f -path "*/$ONOS_POM_VERSION/*" \ |
| 52 | -name '*.jar' -o -name '*.pom' -o -name '*-features.xml' \ |
| 53 | | grep -v -Ee '-tests.jar|-[0-9]{8}.[0-9]{6}-' \ |
| 54 | | while read src; do |
| 55 | dst=$ONOS_STAGE/$KARAF_DIST/system/${src#$M2_REPO/*} |
| 56 | mkdir -p $(dirname $dst) |
| 57 | cp $src $dst |
| 58 | done |
| 59 | |
| 60 | # ONOS Patching ---------------------------------------------------------------- |
| 61 | |
| 62 | # Patch the Apache Karaf distribution file to add ONOS features repository |
| 63 | perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \ |
| 64 | $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg |
| 65 | |
| 66 | # Patch the Apache Karaf distribution file to load default ONOS boot features |
| 67 | export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui" |
| 68 | perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \ |
| 69 | $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg |
| 70 | |
| 71 | # Patch the Apache Karaf distribution with ONOS branding bundle |
| 72 | cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \ |
| 73 | $ONOS_STAGE/$KARAF_DIST/lib |
| 74 | |
| 75 | # Patch in the ONOS version file |
| 76 | echo $ONOS_VERSION > $ONOS_STAGE/VERSION |
| 77 | } |
| 78 | |
| 79 | function build_compressed_package() { |
| 80 | # Package up the ONOS tar file |
| 81 | cd $ONOS_STAGE_ROOT |
| 82 | rm -f $ONOS_TAR $ONOS_ZIP |
| 83 | COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS |
| 84 | |
| 85 | # Figure out whether we should build ONOS zip file and if so, build it. |
| 86 | which zip >/dev/null && [ -z "$ONOS_TAR_ONLY" ] && buildZip=true || unset buildZip |
| 87 | [ -n "$buildZip" ] && zip -rq $ONOS_ZIP $ONOS_BITS |
| 88 | |
| 89 | # Report on the archives that were built and clean-up |
| 90 | [ -n "$buildZip" ] && ls -lh $ONOS_TAR $ONOS_ZIP || ls -lh $ONOS_TAR |
| 91 | rm -r $ONOS_STAGE |
| 92 | } |
| 93 | |
| 94 | # Build a DEB package |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 95 | function build_deb() { |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 96 | echo "You need to be root in order to generate a proper DEB package." |
| 97 | |
| 98 | sudo rm -fr $ONOS_DEB_ROOT |
| 99 | |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 100 | mkdir -p $ONOS_DEB_ROOT/{DEBIAN,opt,etc/init} |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 101 | |
| 102 | { |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 103 | echo "Package: ONOS" |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 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 |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 119 | |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 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 | |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 124 | # Build an RPM package |
| 125 | function build_rpm() { |
| 126 | read -r -p "WARN: rpm-build utility and root priviledges are need to build the package. Do you want to continue? [Y/n] " response |
| 127 | case $response in |
| 128 | [nN][oO]) |
| 129 | exit 0 |
| 130 | ;; |
| 131 | *) |
| 132 | sudo rm -fr $ONOS_RPM_ROOT |
| 133 | |
| 134 | sudo yum -y install rpm-build |
| 135 | |
| 136 | mkdir -p $ONOS_RPM_ROOT/{BUILD,RPMS,SOURCES/ONOS-$ONOS_RPM_VERSION/{etc/init,opt},SPECS,SRPMS} |
| 137 | |
| 138 | cp -r $ONOS_STAGE $ONOS_RPM_ROOT/SOURCES/ONOS-$ONOS_RPM_VERSION/opt/onos |
| 139 | cp $ONOS_ROOT/tools/package/debian/onos.conf $ONOS_RPM_ROOT/SOURCES/ONOS-$ONOS_RPM_VERSION/etc/init/ |
| 140 | |
| 141 | cd $ONOS_RPM_ROOT/SOURCES |
| 142 | COPYFILE_DISABLE=1 tar zcf ONOS-$ONOS_RPM_VERSION.tar.gz ONOS-$ONOS_RPM_VERSION |
| 143 | |
| 144 | { |
| 145 | echo "Name: ONOS" |
| 146 | echo "Version: $ONOS_RPM_VERSION" |
| 147 | echo "Release: 1" |
| 148 | echo "Summary: Open Networking Operating System (ONOS)" |
| 149 | echo "Vendor: ONOS Project" |
| 150 | echo "Packager: ONOS Project" |
| 151 | echo "Group: Applications/Engineering" |
| 152 | echo "Requires: jre >= 1:8" |
| 153 | echo "License: Apache 2.0" |
| 154 | echo "URL: http://www.onosproject.org" |
| 155 | echo "Source0: ONOS-$ONOS_RPM_VERSION.tar.gz" |
| 156 | echo "BuildArch: noarch" |
| 157 | echo "BuildRoot: %{_tmppath}/%{name}-buildroot" |
| 158 | echo "%description" |
| 159 | echo "Open Network Operating System (ONOS) is an opensource SDN controller." |
| 160 | echo -e "\n" |
| 161 | echo "%prep" |
| 162 | echo "%setup -q" |
| 163 | echo -e "\n" |
| 164 | echo "%install" |
| 165 | echo "mkdir -p %{buildroot}" |
| 166 | echo "cp -R * %{buildroot}" |
| 167 | echo -e "\n" |
| 168 | echo "%clean" |
| 169 | echo "rm -rf %{buildroot}" |
| 170 | echo -e "\n" |
| 171 | echo "%files" |
| 172 | echo "%defattr(-,root,root,-)" |
| 173 | echo "/etc/init/onos.conf" |
| 174 | echo "/opt/onos/" |
| 175 | echo -e "\n" |
| 176 | echo "%post" |
| 177 | echo "echo ONOS successfully installed at /opt/onos" |
| 178 | } > $ONOS_RPM_ROOT/SPECS/onos.spec |
| 179 | |
| 180 | rpmbuild --define "_topdir $ONOS_RPM_ROOT" -bb $ONOS_RPM_ROOT/SPECS/onos.spec |
| 181 | |
| 182 | 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 |
| 183 | ;; |
| 184 | esac |
| 185 | } |
| 186 | |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 187 | # Script entry point |
tom | 5c25570 | 2014-09-18 06:57:39 -0700 | [diff] [blame] | 188 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 189 | . $ONOS_ROOT/tools/build/envDefaults |
tom | 4d0c663 | 2014-09-15 23:27:01 -0700 | [diff] [blame] | 190 | |
| 191 | # Bail on any errors |
| 192 | set -e |
| 193 | |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 194 | # Before starting make sure the environment is clan - delete onos staging folder |
| 195 | rm -fr $ONOS_STAGE |
tom | 4d0c663 | 2014-09-15 23:27:01 -0700 | [diff] [blame] | 196 | |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 197 | # If there are parameters check if we want to build a deb - otherwise build tar.gz |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 198 | case ${1:---tar} in |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 199 | "--tar" | "-T") build_stage_dir |
| 200 | build_compressed_package |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 201 | ;; |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 202 | "--deb" | "-D") build_stage_dir |
| 203 | build_deb |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 204 | ;; |
Luca Prete | f2049d1 | 2015-08-01 14:48:01 -0700 | [diff] [blame] | 205 | "--rpm" | "-R") build_stage_dir |
| 206 | build_rpm |
| 207 | ;; |
| 208 | *) echo "usage: $(basename $0) [--tar|--deb|--rpm]" >&2 && exit 1 |
Luca Prete | e618375 | 2015-07-29 01:55:50 -0700 | [diff] [blame] | 209 | ;; |
| 210 | esac |