Updating onos-package for debian packaging
Change-Id: Icc3899b3a35ba0a02a97f5eddebfbe51ff6c1638
diff --git a/tools/build/onos-package b/tools/build/onos-package
index a1264c6..f47f5b6 100755
--- a/tools/build/onos-package
+++ b/tools/build/onos-package
@@ -93,22 +93,16 @@
# Build a DEB package
function build_deb() {
- echo "You need to be root in order to generate a proper DEB package."
+ echo "This command may ask for your password to run commands as sudo,"
+ echo " because you need to be root in order to generate a proper DEB package."
sudo rm -fr $ONOS_DEB_ROOT
mkdir -p $ONOS_DEB_ROOT/{DEBIAN,opt,etc/init}
- {
- echo "Package: ONOS"
- echo "Architecture: all"
- echo "Maintainer: ONOS Project"
- echo "Depends: debconf (>= 0.5.00), default-jre-headless (>= 1.8) | openjdk-8-jre | oracle-java8-installer"
- echo "Priority: optional"
- echo "Version: $ONOS_POM_VERSION"
- echo "Description: Open Network Operating System (ONOS) is an"
- echo " opensource SDN controller."
- } > $ONOS_DEB_ROOT/DEBIAN/control
+ # Copy the debian directory and fill in version
+ cp -r $ONOS_ROOT/tools/package/deb/* $ONOS_DEB_ROOT/DEBIAN/
+ sed -i'' -E "s/@ONOS_POM_VERSION/$ONOS_POM_VERSION/" $ONOS_DEB_ROOT/DEBIAN/control
cp -r $ONOS_STAGE $ONOS_DEB_ROOT/opt/onos
cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_DEB_ROOT/etc/init/
@@ -119,6 +113,8 @@
sudo dpkg-deb --build $ONOS_DEB_ROOT > /dev/null &&
sudo mv $ONOS_STAGE_ROOT/deb.deb $ONOS_DEB && ls -l $ONOS_DEB
+
+ #TODO run lintian on .deb
}
# Build an RPM package
diff --git a/tools/package/deb/control b/tools/package/deb/control
new file mode 100644
index 0000000..c581ac2
--- /dev/null
+++ b/tools/package/deb/control
@@ -0,0 +1,8 @@
+Package: onos
+Architecture: all
+Maintainer: ONOS Project
+Depends: debconf (>= 0.5.00), default-jre-headless (>= 1.8) | openjdk-8-jre | oracle-java8-installer
+Priority: optional
+Version: @ONOS_POM_VERSION
+Description: Open Network Operating System (ONOS)
+ Open Network Operating System (ONOS) is an opensource SDN controller.
diff --git a/tools/package/deb/copyright b/tools/package/deb/copyright
new file mode 100644
index 0000000..09ec05e
--- /dev/null
+++ b/tools/package/deb/copyright
@@ -0,0 +1,20 @@
+Upstream-Name: onos
+Source: http://github.com/opennetworkinglab/onos
+
+Files: *
+Copyright: 2014-2015 Open Networking Laboratory
+License: Apache 2.0
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ .
+ http://www.apache.org/licenses/LICENSE-2.0
+ .
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ .
+ On Debian systems, the complete text of the Apache License 2.0 can
+ be found in "/usr/share/common-licenses/Apache-2.0"
diff --git a/tools/package/deb/postinst b/tools/package/deb/postinst
new file mode 100755
index 0000000..60de14a
--- /dev/null
+++ b/tools/package/deb/postinst
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+ONOS_USER=sdn
+
+# Check to see if user exists, and if not, create a service account
+getent passwd $ONOS_USER >/dev/null 2&>1 || ( useradd -M $ONOS_USER && usermod -L $ONOS_USER )
+
+# Create ONOS options file
+[ ! -f /opt/onos/options ] && cat << EOF > /opt/onos/options
+export ONOS_OPTS=server
+export ONOS_USER="$ONOS_USER"
+EOF
+
+# Change permissions for onos directory
+[ -d /opt/onos ] && chown -R $ONOS_USER.$ONOS_USER /opt/onos
+
diff --git a/tools/package/deb/prerm b/tools/package/deb/prerm
new file mode 100755
index 0000000..5e8ace3
--- /dev/null
+++ b/tools/package/deb/prerm
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+# Check if onos is running; if it is, stop onos
+[ -z "$(status onos 2>/dev/null | grep start)" ] && echo "onos is not running." || (
+ stop onos
+
+ # Wait for onos to stop up to 5 seconds
+ for i in $(seq 1 5); do
+ [ -z "$(ps -ef | grep karaf.jar | grep -v grep)" ] && break
+ sleep 1
+ done
+ [ -z "$(ps -ef | grep karaf.jar | grep -v grep)" ] && echo 'Stopped onos service' || echo 'Failed to stop onos'
+ ps -ef | grep karaf.jar | grep -v grep
+)
+
+# Clean up onos runtime directories
+# TODO don't hardcode karaf version
+rm -rf /opt/onos/apache-karaf-3.0.3/
+rm -rf /opt/onos/var/*
+rm -rf /opt/onos/config
+rm -rf /opt/onos/options
+rm -rf /opt/onos/log
+
+#TODO consider removing the sdn user if we created it
diff --git a/tools/package/init/onos.conf b/tools/package/init/onos.conf
index f415f8e..779df90 100644
--- a/tools/package/init/onos.conf
+++ b/tools/package/init/onos.conf
@@ -13,9 +13,12 @@
env LANG=en_US.UTF-8
pre-start script
+ [ -f /opt/onos/options ] && . /opt/onos/options
+ ONOS_USER=${ONOS_USER:-root}
+
# Ensure that the environment is initialized
- [ -d /opt/onos ] && mkdir -p /opt/onos/var
- [ -d /opt/onos ] && mkdir -p /opt/onos/config
+ [ -d /opt/onos ] && mkdir /opt/onos/var 2>/dev/null && chown $ONOS_USER.$ONOS_USER /opt/onos/var
+ [ -d /opt/onos ] && mkdir /opt/onos/config 2>/dev/null && chown $ONOS_USER.$ONOS_USER /opt/onos/config
# TODO make karaf version configurable
[ -d /opt/onos ] && [ ! -h /opt/onos/log ] \
&& ln -s /opt/onos/apache-karaf-3.0.3/data/log /opt/onos/log || :