*** Rebased towards latest Fuel stable/6.0 ***
[genesis.git] / fuel / build / opendaylight / make-odl-deb.sh
1 #!/bin/bash
2 set -e
3 ##############################################################################
4 # Copyright (c) 2015 Ericsson AB and others.
5 # stefan.k.berg@ericsson.com
6 # jonas.bjurel@ericsson.com
7 # All rights reserved. This program and the accompanying materials
8 # are made available under the terms of the Apache License, Version 2.0
9 # which accompanies this distribution, and is available at
10 # http://www.apache.org/licenses/LICENSE-2.0
11 ##############################################################################
12
13 ##############################################################################
14 # Default variable declarations
15
16 COMMAND=
17 PACKAGE_NAME=
18 PACKAGE_SHORT_NAME=
19 PACKAGE_VERSION=
20 TARGET_BUILD_PATH=
21 DEPENDENCIES=
22 MAINTAINER=
23 ARCH="amd64"
24 BUILD_HISTORY=".odl-build-history"
25
26 ##############################################################################
27 # subroutine: usage
28 # Description: Prints out usage of this script
29
30 usage ()
31 {
32 cat <<EOF
33 usage: $0 options
34
35 $0 creates a ${PACKAGE_NAME} Debian package
36
37 OPTIONS:
38   -n Package shoer name
39   -N Package name
40   -v Version
41   -t Tag
42   -p Target build path, the path where the built tar ball is to be fetched
43   -m Maintainer
44   -d Package dependencies
45   -h Prints this message
46   -C Clean
47
48 E.g.: $0 -n my/deb/src/dest/path -N my-package -v 1.0-1 -t myTag -p path/to/the/source -m "Main Tainer <main.tainer.exampe.org> -d myJavaDependence
49 EOF
50 }
51
52 ##############################################################################
53 # subroutine: clean
54 # Description: Cleans up all artifacts from earlier builds
55
56 clean ()
57 {
58 if [ -e $BUILD_HISTORY ]; then
59     while read line
60     do
61         rm -rf $line
62     done < $BUILD_HISTORY
63     rm ${BUILD_HISTORY}
64     exit 0
65 fi
66 }
67
68 ##############################################################################
69 # make-DEBIAN_control
70 # Description: constructs the Debian pack control file
71
72 make-DEBIAN_control ()
73 {
74 cat <<EOF
75 Package: $PACKAGE_SHORT_NAME
76 Version: $PACKAGE_VERSION
77 Section: base
78 Priority: optional
79 Architecture: $ARCH
80 Depends: $DEPENDENCIES
81 Maintainer: $MAINTAINER
82 Description: OpenDaylight deamon
83  This is a daemon for the opendaylight/odl controller service.
84 EOF
85 }
86
87 ##############################################################################
88 # subroutine: make-DEBIAN_conffiles
89 # Description: Constructs the Debian package config files assignment
90
91 make-DEBIAN_conffiles ()
92 {
93 cat <<EOF
94 /etc/odl/etc/all.policy
95 /etc/odl/etc/config.properties
96 /etc/odl/etc/custom.properties
97 /etc/odl/etc/distribution.info
98 /etc/odl/etc/equinox-debug.properties
99 /etc/odl/etc/java.util.logging.properties
100 /etc/odl/etc/jmx.acl.cfg
101 /etc/odl/etc/jmx.acl.java.lang.Memory.cfg
102 /etc/odl/etc/jmx.acl.org.apache.karaf.bundle.cfg
103 /etc/odl/etc/jmx.acl.org.apache.karaf.config.cfg
104 /etc/odl/etc/jmx.acl.org.apache.karaf.security.jmx.cfg
105 /etc/odl/etc/jmx.acl.osgi.compendium.cm.cfg
106 /etc/odl/etc/jre.properties
107 /etc/odl/etc/keys.properties
108 /etc/odl/etc/org.apache.felix.fileinstall-deploy.cfg
109 /etc/odl/etc/org.apache.karaf.command.acl.bundle.cfg
110 /etc/odl/etc/org.apache.karaf.command.acl.config.cfg
111 /etc/odl/etc/org.apache.karaf.command.acl.feature.cfg
112 /etc/odl/etc/org.apache.karaf.command.acl.jaas.cfg
113 /etc/odl/etc/org.apache.karaf.command.acl.kar.cfg
114 /etc/odl/etc/org.apache.karaf.command.acl.shell.cfg
115 /etc/odl/etc/org.apache.karaf.command.acl.system.cfg
116 /etc/odl/etc/org.apache.karaf.features.cfg
117 /etc/odl/etc/org.apache.karaf.features.obr.cfg
118 /etc/odl/etc/org.apache.karaf.features.repos.cfg
119 /etc/odl/etc/org.apache.karaf.jaas.cfg
120 /etc/odl/etc/org.apache.karaf.kar.cfg
121 /etc/odl/etc/org.apache.karaf.log.cfg
122 /etc/odl/etc/org.apache.karaf.management.cfg
123 /etc/odl/etc/org.apache.karaf.shell.cfg
124 /etc/odl/etc/org.ops4j.pax.logging.cfg
125 /etc/odl/etc/org.ops4j.pax.url.mvn.cfg
126 /etc/odl/etc/regions-config.xml
127 /etc/odl/etc/shell.init.script
128 /etc/odl/etc/startup.properties
129 /etc/odl/etc/system.properties
130 /etc/odl/etc/users.properties
131 /etc/odl/configuration/context.xml
132 /etc/odl/configuration/logback.xml
133 /etc/odl/configuration/tomcat-logging.properties
134 /etc/odl/configuration/tomcat-server.xml
135 EOF
136 }
137
138 ##############################################################################
139 # subroutine: make-DEBIAN_postinst
140 # Description: Constructs the Debian package post installation script
141
142 make-DEBIAN_postinst ()
143 {
144 cat <<EOF
145 #!/bin/bash -e
146 ln -s /etc/${PACKAGE_SHORT_NAME}/* ${TARGET_INSTALL_PATH}
147 echo "OpenDaylight $TAG version $PACKAGE_VERSION has been installed"
148 EOF
149 }
150
151 ##############################################################################
152 # subroutine: make-DEBIAN_bin
153 # Description: Constructs the bin script (normally under /usr/bin)
154
155 make-DEBIAN_bin ()
156 {
157 cat <<EOF
158 #!/bin/bash -e
159 ${TARGET_INSTALL_PATH}bin/karaf $@
160 EOF
161 }
162
163 ##############################################################################
164 # subroutine: make-DEBIAN_copyright
165 # Description: Constructs the copyright text (normally under /usr/share/doc...)
166
167 make-DEBIAN_copyright ()
168 {
169 cat <<EOF
170 OpenDaylight - an open source SDN controller
171 Licensed to the Apache Software Foundation (ASF) under one or more
172 contributor license agreements.  See the NOTICE file distributed with
173 this work for additional information regarding copyright ownership.
174 The ASF licenses this file to You under the Apache License, Version 2.0
175 (the "License"); you may not use this file except in compliance with
176 the License.  You may obtain a copy of the License at
177
178 http://www.apache.org/licenses/LICENSE-2.0
179
180 Unless required by applicable law or agreed to in writing, software
181 distributed under the License is distributed on an "AS IS" BASIS,
182 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183 See the License for the specific language governing permissions and
184 limitations under the License.
185 EOF
186 }
187
188 ##############################################################################
189 # subroutine: make-DEBIAN_changelog
190 # Description: Constructs the changelog text (normally under /usr/share/doc...)
191
192 make-DEBIAN_changelog ()
193 {
194 cat <<EOF
195 $PACKAGE_SHORT_NAME ($PACKAGE_VERSION) precise-proposed; urgency=low
196
197   * Derived from $PACKAGE_NAME $PACHAGE_VERSION
198
199  -- $MAINTAINER  $(date)
200 EOF
201 }
202
203 ##############################################################################
204 # MAIN
205
206 while getopts "N:n:v:d:Chm:t:p:" OPTION
207 do
208     case $OPTION in
209         h)
210             usage
211             exit 0
212             ;;
213
214         N)
215             PACKAGE_NAME=$OPTARG
216             COMMAND+="-N ${PACKAGE_NAME} "
217             ;;
218
219         n)
220             PACKAGE_SHORT_NAME=$OPTARG
221             COMMAND+="-n ${PACKAGE_SHORT_NAME} "
222             ;;
223
224         v)
225             PACKAGE_VERSION=$OPTARG
226             COMMAND+="-v ${PACKAGE_VERSION} "
227             ;;
228
229         p)
230             TARGET_BUILD_PATH=$OPTARG
231             COMMAND+="-p ${TARGET_BUILD_PATH} "
232             ;;
233
234         t)
235             TAG=$OPTARG
236             COMMAND+="-t ${TAG} "
237             ;;
238
239         m)
240             MAINTAINER=$OPTARG
241             COMMAND+="-m ${MAINTAINER} "
242             ;;
243
244         d)
245             DEPENDENCIES=$OPTARG
246             COMMAND+="-d ${DEPENDENCIES} "
247             ;;
248
249         A)
250             ARCH=$OPTARG
251             COMMAND+="-A ${ARCH} "
252             ;;
253
254         C)
255             COMMAND+="-C "
256             clean
257             exit 0
258             ;;
259     esac
260 done
261
262 # Constructing script variables
263 DEB_PACK_BASE_PATH="f_${PACKAGE_SHORT_NAME}/${PACKAGE_NAME}_${PACKAGE_VERSION}/"
264 echo ${DEB_PACK_BASE_PATH} >> "$BUILD_HISTORY"
265 TARGET_INSTALL_PATH="/usr/share/java/${PACKAGE_SHORT_NAME}/"
266 DEB_PACK_CONTENT_PATH="${DEB_PACK_BASE_PATH}usr/share/java/${PACKAGE_SHORT_NAME}/"
267 DEB_PACK_CONFIG_PATH="${DEB_PACK_BASE_PATH}etc/${PACKAGE_SHORT_NAME}"
268 TARGET_TAR=$(ls ${TARGET_BUILD_PATH}*.tar.gz)
269 TARGET_TAR="${TARGET_TAR##*/}"
270 TAR_PATH="${TARGET_TAR%.*}"
271 TAR_PATH="${TAR_PATH%.*}"
272 if [ -e $DEB_PACK_BASE_PATH ]; then
273     rm -R $DEB_PACK_BASE_PATH
274 fi
275
276 # Create Deb pack content and configuration
277 mkdir -p ${DEB_PACK_CONTENT_PATH}
278 cp ${TARGET_BUILD_PATH}${TARGET_TAR} ${DEB_PACK_CONTENT_PATH}
279 tar -xzf ${DEB_PACK_CONTENT_PATH}${TARGET_TAR} -C ${DEB_PACK_CONTENT_PATH}
280 rm ${DEB_PACK_CONTENT_PATH}${TARGET_TAR}
281 mv ${DEB_PACK_CONTENT_PATH}${TAR_PATH}/* ${DEB_PACK_CONTENT_PATH}.
282 rm -R ${DEB_PACK_CONTENT_PATH}${TAR_PATH}
283
284 # Crate and populate Deb pack config target
285 mkdir -p ${DEB_PACK_CONFIG_PATH}/etc
286 mv ${DEB_PACK_CONTENT_PATH}etc/* ${DEB_PACK_CONFIG_PATH}/etc/
287 rm -R ${DEB_PACK_CONTENT_PATH}etc
288 mkdir -p ${DEB_PACK_CONFIG_PATH}/configuration
289 mv ${DEB_PACK_CONTENT_PATH}configuration/* ${DEB_PACK_CONFIG_PATH}/configuration/
290 rm -R ${DEB_PACK_CONTENT_PATH}configuration
291
292 # Set package permisions
293 find ${DEB_PACK_CONTENT_PATH} -type d -print -exec chmod 755 {} \;
294 find ${DEB_PACK_CONFIG_PATH}/etc/ -type f -print -exec chmod 644 {} \;
295 find ${DEB_PACK_CONFIG_PATH}/etc/ -type d -print -exec chmod 755 {} \;
296
297 # Create package usr/bin odl script
298 mkdir  "${DEB_PACK_BASE_PATH}usr/bin"
299 chmod 755 "${DEB_PACK_BASE_PATH}usr/bin"
300 make-DEBIAN_bin > "${DEB_PACK_BASE_PATH}usr/bin/odl"
301 chmod 755 "${DEB_PACK_BASE_PATH}usr/bin/odl"
302
303 # Create Deb pack install meta-data
304 mkdir "${DEB_PACK_BASE_PATH}DEBIAN"
305 make-DEBIAN_control > "${DEB_PACK_BASE_PATH}DEBIAN/control"
306 make-DEBIAN_conffiles > "${DEB_PACK_BASE_PATH}DEBIAN/conffiles"
307 mkdir -p "${DEB_PACK_BASE_PATH}usr/share/doc/${PACKAGE_SHORT_NAME}"
308 make-DEBIAN_copyright > "${DEB_PACK_BASE_PATH}usr/share/doc/${PACKAGE_SHORT_NAME}/copyright"
309 make-DEBIAN_changelog > "${DEB_PACK_BASE_PATH}usr/share/doc/${PACKAGE_SHORT_NAME}/changelog.Debian"
310
311 # Create Deb pack post install symlinks and usr/bin scripts
312 make-DEBIAN_postinst > "${DEB_PACK_BASE_PATH}DEBIAN/postinst"
313 chmod 755  "${DEB_PACK_BASE_PATH}DEBIAN/postinst"
314 mkdir -p "${DEB_PACK_BASE_PATH}usr/bin"