From 903d3f805f1f74df8ed2808d75fe266e2ebc400c Mon Sep 17 00:00:00 2001
From: Julien Bonjean <julien@bonjean.info>
Date: Fri, 29 May 2009 12:34:12 -0400
Subject: [PATCH] [#1317] Cleaning

---
 .../distributions/build-packages.sh           | 87 +++++++++++++++++++
 tools/build-system/distributions/globals      | 52 ++++-------
 ...opensuse.sh => build-packages-opensuse.sh} | 50 +++++++----
 ...age-ubuntu.sh => build-packages-ubuntu.sh} | 24 +----
 tools/build-system/launch-build-machine.sh    |  8 +-
 tools/build-system/sfl-git-dch.sh             |  2 +-
 6 files changed, 147 insertions(+), 76 deletions(-)
 create mode 100755 tools/build-system/distributions/build-packages.sh
 rename tools/build-system/distributions/opensuse/{build-package-opensuse.sh => build-packages-opensuse.sh} (61%)
 rename tools/build-system/distributions/ubuntu/{build-package-ubuntu.sh => build-packages-ubuntu.sh} (88%)

diff --git a/tools/build-system/distributions/build-packages.sh b/tools/build-system/distributions/build-packages.sh
new file mode 100755
index 0000000000..fc86f34e21
--- /dev/null
+++ b/tools/build-system/distributions/build-packages.sh
@@ -0,0 +1,87 @@
+#!/bin/bash
+#####################################################
+# File Name: build-packages.sh
+#
+# Purpose :
+#
+# Author: Julien Bonjean (julien@bonjean.info) 
+#
+# Creation Date: 2009-05-29
+# Last Modified: 2009-05-29 12:27:50 -0400
+#####################################################
+
+. ./globals
+
+if [ "$?" -ne 0 ]; then
+	echo "!! Cannot source global file"
+	exit -1
+fi
+
+cd ${PACKAGING_DIR}
+
+if [ ! ${PACKAGING_DIR} ];then
+	echo "!! Cannot go to working directory"
+	exit -1
+fi
+
+# check if version is ok
+if [ ! ${VERSION} ]; then
+        echo "!! Cannot detect current version"
+        exit -1
+fi
+
+# open log file
+exec 3<>${LOG_FILE}
+
+# redirect outputs (stdout & stderr)
+exec 1>&3
+exec 2>&3
+
+echo "SFLPhone version is ${VERSION}"
+
+# check user
+if [ "${WHOAMI}" != "${USER}" ]; then
+        echo "!! Please use user ${USER} to run this script"
+        exit -1;
+fi
+
+if [ ${RELEASE_MODE} ]; then
+        echo "Release mode : ${RELEASE_MODE}"
+else
+        echo "Snapshot mode"
+fi
+
+# decompress repository
+echo "Untar repository"
+cd ${BUILD_DIR} && tar xf ${REPOSITORY_ARCHIVE}
+
+if [ "$?" -ne "0" ]; then
+        echo " !! Cannot untar repository"
+        exit -1
+fi
+
+# launch distribution specific script
+if [ "${DISTRIBUTION}" = "ubuntu" ];then
+	echo "Launch packaging for Ubuntu (hardy/intrepid/jaunty)"
+	cd ${UBUNTU_DIR} && ./build-packages-ubuntu.sh $*
+
+elif [ "${DISTRIBUTION}" = "opensuse" ]; then
+	echo "Launch packaging for openSUSE 11"
+	cd ${OPENSUSE_DIR} && ./build-packages-opensuse.sh $*
+
+else
+	echo "!! Cannot detect distribution"
+	exit -1
+fi
+
+if [ "$?" -ne 0 ]; then
+	echo "!! Error in subprocess"
+	exit -1
+fi
+
+echo "All done"
+
+# close file descriptor
+exec 3>&-
+
+exit 0
diff --git a/tools/build-system/distributions/globals b/tools/build-system/distributions/globals
index a4b19bf8b1..19417669f9 100644
--- a/tools/build-system/distributions/globals
+++ b/tools/build-system/distributions/globals
@@ -9,58 +9,42 @@
 # Last Modified: 2009-05-28 15:55:14 -0400
 #####################################################
 
+# general
+RELEASE_MODE="$1"
 ROOT_DIR="/home/sflphone"
 PACKAGING_DIR="${ROOT_DIR}/sflphone-packaging"
 
+# distributions
 UBUNTU_DIR="${PACKAGING_DIR}/ubuntu"
-OPENSUSE="${PACKAGING_DIR}/opensuse"
+OPENSUSE_DIR="${PACKAGING_DIR}/opensuse"
 
+# where packaging will be donne
 BUILD_DIR="${PACKAGING_DIR}/build"
-DIST_DIR="${PACKAGING_DIR}/dists"
 REPOSITORY_ARCHIVE="${BUILD_DIR}/sflphone.tar.gz"
 REPOSITORY_DIR="${BUILD_DIR}/sflphone"
-REPOSITORY_SFLPHONE_COMMON_DIR="${REPOSITORY_DIR}/sflphone-common"
-REPOSITORY_SFLPHONE_CLIENT_KDE_DIR="${REPOSITORY_DIR}/sflphone-client-kde"
-REPOSITORY_SFLPHONE_CLIENT_GNOME_DIR="${REPOSITORY_DIR}/sflphone-client-gnome"
 
+# target directories
+DIST_DIR="${PACKAGING_DIR}/dists"
+
+# system information
 ARCH_FLAG=`getconf -a|grep LONG_BIT | sed -e 's/LONG_BIT\s*//'`
 OS_VERSION=`lsb_release -d -s -c | sed -e '1d'`
+DISTRIBUTION=`lsb_release -s -d | sed 's/"//g' | tr 'A-Z' 'a-z' | cut -d " " -f1`
 VERSION=`cat ${BUILD_DIR}/VERSION` 
 
-if [ ! ${VERSION} ]; then
-        echo "!! Cannot detect current version"
-        exit -1
-fi
-
+# other stuff
 EDITOR=echo
 export EDITOR
 RELEASE_MODE=$1
 USER="sflphone"
+WHOAMI=`whoami`
 
-#PACKAGES=('sflphone-common' 'sflphone-client-gnome' 'sflphone-client-kde')
+# packages we will build
 PACKAGES=('sflphone-common sflphone-client-gnome')
 
-GLOBAL_LOG=${PACKAGING_DIR}/sflphone-${OS_VERSION}-${ARCH_FLAG}.log
-
-# open log file
-exec 3<>${GLOBAL_LOG}
-
-# redirect outputs (stdout & stderr)
-exec 1>&3
-exec 2>&3
-
-echo "SFLPhone version is ${VERSION}"
-
-WHO=`whoami`
-
-if [ "${WHO}" != "${USER}" ]; then
-        echo "!! Please use user ${USER} to run this script"
-        exit -1;
+# log file
+LOG_ID="${OS_VERSION}"
+if [ "${LOG_ID}" = "" ]; then
+	LOG_ID="${DISTRIBUTION}"
 fi
-
-if [ ${RELEASE_MODE} ]; then
-        echo "Release mode : ${RELEASE_MODE}"
-else
-        echo "Snapshot mode"
-fi
-
+LOG_FILE=${PACKAGING_DIR}/sflphone-${LOG_ID}-${ARCH_FLAG}.log
diff --git a/tools/build-system/distributions/opensuse/build-package-opensuse.sh b/tools/build-system/distributions/opensuse/build-packages-opensuse.sh
similarity index 61%
rename from tools/build-system/distributions/opensuse/build-package-opensuse.sh
rename to tools/build-system/distributions/opensuse/build-packages-opensuse.sh
index 636076c90b..41f1acbd81 100755
--- a/tools/build-system/distributions/opensuse/build-package-opensuse.sh
+++ b/tools/build-system/distributions/opensuse/build-packages-opensuse.sh
@@ -1,25 +1,25 @@
 #!/bin/bash
 #####################################################
-# File Name: build-package-opensuse.sh
+# File Name: build-packages-opensuse.sh
 #
 # Purpose :
 #
 # Author: Julien Bonjean (julien@bonjean.info) 
 #
 # Creation Date: 2009-05-27
-# Last Modified: 2009-05-28 16:32:54 -0400
+# Last Modified: 2009-05-29 12:15:08 -0400
 #####################################################
 
-BUILD_DIR=/tmp/sflphone
-SRC_DIR=${HOME}/sflphone-packaging/build/sflphone
-WORKING_DIR=${HOME}/sflphone-packaging
-VERSION=`cat ${SRC_DIR}/sflphone-common/VERSION`
+. ../globals
 
-if [ ! ${VERSION} ]; then
-	echo "!! Cannot detect current version"
-	exit -1
+cd ${OPENSUSE_DIR}
+
+if [ "$?" -ne "0" ]; then
+        echo " !! Cannot cd to openSUSE directory"
+        exit -1
 fi
 
+# create build directories
 echo "Create directories"
 mkdir -p ${BUILD_DIR}/BUILD
 mkdir -p ${BUILD_DIR}/RPMS
@@ -27,6 +27,7 @@ mkdir -p ${BUILD_DIR}/SOURCES
 mkdir -p ${BUILD_DIR}/SPECS
 mkdir -p ${BUILD_DIR}/SRPMS
 
+# create rpm macros
 echo "Create RPM macros"
 cat > ~/.rpmmacros << STOP
 %packager               Julien Bonjean (julien.bonjean@savoirfairelinux.com)
@@ -44,29 +45,48 @@ cat > ~/.rpmmacros << STOP
 %_srcrpmdir		%{_topdir}/SRPMS
 STOP
 
-
+# create packages
 for PACKAGE in ${PACKAGES[@]}
 do
 	echo "Prepare ${PACKAGE}"
 
-	cd ${SRC_DIR}
+	cd ${REPOSITORY_DIR}
 
 	echo " -> create source archive"
-	mv ${PACKAGE} ${PACKAGE}-${VERSION} 2>/dev/null
-	tar cf ${PACKAGE}.tar.gz ${PACKAGE}-${VERSION}
+	mv ${PACKAGE} ${PACKAGE}-${VERSION} 2>/dev/null && \
+	tar cf ${PACKAGE}.tar.gz ${PACKAGE}-${VERSION} && \
 	mv ${PACKAGE}-${VERSION} ${PACKAGE}
 	
+	if [ "$?" -ne "0" ]; then
+		echo "!! Cannot create source archive"
+		exit -1
+	fi
+	
 	echo " -> move archive to source directory"
 	mv ${PACKAGE}.tar.gz ${BUILD_DIR}/SOURCES
 
-	cd ${WORKING_DIR}
+	if [ "$?" -ne "0" ]; then
+                echo "!! Cannot move archive"
+                exit -1
+        fi
+
+	cd ${PACKAGING_DIR}
 
 	echo " -> update spec file"
 	sed "s/VERSION/${VERSION}/g" ${PACKAGE}.spec > ${BUILD_DIR}/SPECS/${PACKAGE}.spec
+
+	if [ "$?" -ne "0" ]; then
+                echo "!! Cannot update spec file"
+                exit -1
+        fi
 done
 
+# launch build
 echo "Launch build"
 rpmbuild -ba ${BUILD_DIR}/SPECS/*.spec
 
-exit 0
+if [ "$?" -ne "0" ]; then
+	echo "!! Cannot build packages"
+	exit -1
+fi
 
diff --git a/tools/build-system/distributions/ubuntu/build-package-ubuntu.sh b/tools/build-system/distributions/ubuntu/build-packages-ubuntu.sh
similarity index 88%
rename from tools/build-system/distributions/ubuntu/build-package-ubuntu.sh
rename to tools/build-system/distributions/ubuntu/build-packages-ubuntu.sh
index 3e73f349bd..4fc7954591 100755
--- a/tools/build-system/distributions/ubuntu/build-package-ubuntu.sh
+++ b/tools/build-system/distributions/ubuntu/build-packages-ubuntu.sh
@@ -7,11 +7,6 @@
 
 . ../globals
 
-if [ ! ${PACKAGING_DIR} ];then
-	echo "!! Cannot source globals file"
-	exit -1
-fi
-
 cd ${UBUNTU_DIR}
 
 if [ "$?" -ne "0" ]; then
@@ -20,7 +15,7 @@ if [ "$?" -ne "0" ]; then
 fi
 
 PACKAGE_SYSVER="0ubuntu1"
-FULL_VERSION="${VERSION}-0ubuntu1"
+FULL_VERSION="${VERSION}-${PACKAGE_SYSVER}"
 
 #########################
 # BEGIN
@@ -39,21 +34,13 @@ echo "Do updates"
 sudo apt-get update >/dev/null
 sudo apt-get upgrade -y >/dev/null
 
-# decompress repository
-echo "Untar repository"
-cd ${BUILD_DIR} && tar xf ${REPOSITORY_ARCHIVE}
-
-if [ "$?" -ne "0" ]; then
-        echo " !! Cannot untar repository"
-        exit -1
-fi
 
 for PACKAGE in ${PACKAGES[@]}
 do
         echo "Process ${PACKAGE}"
 
 	echo " -> prepare debian directories"
-	mv ${UBUNTU_DIR}/debian-${PACKAGE} ${REPOSITORY_DIR}/${PACKAGE}/
+	mv ${UBUNTU_DIR}/debian-${PACKAGE} ${REPOSITORY_DIR}/${PACKAGE}/debian
 
 	# generate the changelog
 	echo " -> generate changelog"
@@ -114,10 +101,3 @@ if [ "$?" -ne "0" ]; then
         exit -1
 fi
 
-echo "All done"
-
-# close file descriptor
-exec 3>&-
-
-exit 0
-
diff --git a/tools/build-system/launch-build-machine.sh b/tools/build-system/launch-build-machine.sh
index ebaa0ac48c..7500dcdbec 100755
--- a/tools/build-system/launch-build-machine.sh
+++ b/tools/build-system/launch-build-machine.sh
@@ -7,7 +7,7 @@
 # Author: Julien Bonjean (julien@bonjean.info) 
 #
 # Creation Date: 2009-04-20
-# Last Modified: 2009-05-28 18:30:17 -0400
+# Last Modified: 2009-05-29 12:29:27 -0400
 #####################################################
 
 #
@@ -228,7 +228,7 @@ if [ ${DO_PREPARE} ]; then
 			VERSION="${VERSION}~${RELEASE_MODE}"
 		fi
 	else
-		VERSION="${VERSION}-snapshot-${SNAPSHOT_TAG}"
+		VERSION="${VERSION}~snapshot${SNAPSHOT_TAG}"
 	fi
 	echo "Version is : ${VERSION}"
 
@@ -265,7 +265,7 @@ if [ ${DO_PREPARE} ]; then
 	# generate the changelog, according to the distribution and the git commit messages
 	echo "Update debian changelogs (2/2)"
 	cd ${REPOSITORY_DIR}
-	${SCRIPTS_DIR}/sfl-git-dch.sh ${RELEASE_MODE}
+	${SCRIPTS_DIR}/sfl-git-dch.sh ${VERSION} ${RELEASE_MODE}
 	
 	if [ "$?" -ne "0" ]; then
 		echo "!! Cannot update debian changelogs"
@@ -333,7 +333,7 @@ if [ ${DO_MAIN_LOOP} ]; then
 	        fi
 
 		echo "Launch remote build"
-		${SSH_BASE} "cd ${REMOTE_DEPLOY_DIR}/ubuntu/ && ./build-package-ubuntu.sh ${RELEASE_MODE}"
+		${SSH_BASE} "cd ${REMOTE_DEPLOY_DIR} && ./build-packages.sh ${RELEASE_MODE}"
 
 		if [ "$?" -ne "0" ]; then
 	                echo " !! Error during remote packaging process"
diff --git a/tools/build-system/sfl-git-dch.sh b/tools/build-system/sfl-git-dch.sh
index c6ea370334..4263ff4cc9 100755
--- a/tools/build-system/sfl-git-dch.sh
+++ b/tools/build-system/sfl-git-dch.sh
@@ -7,7 +7,7 @@
 # Author: Julien Bonjean (julien@bonjean.info) 
 #
 # Creation Date: 2009-05-13
-# Last Modified: 2009-05-28 18:24:53 -0400
+# Last Modified: 2009-05-29 10:51:33 -0400
 #####################################################
 
 # set -x
-- 
GitLab