Commit a371f35f authored by Diego Pasqualin's avatar Diego Pasqualin
Browse files

jenkins_continuous_integration.sh: Move createPackage() to its own script


Signed-off-by: default avatarDiego Pasqualin <dpasqualin@c3sl.ufpr.br>
parent e17839c6
#!/bin/bash
PREFIX="$(dirname $0)"
REPOROOT="$PREFIX/.."
PACKAGESDEST="$REPOROOT/pkgs"
function showHelp() {
echo "$0 <package> [major|minor|revision]"
echo ""
echo -n "Generate <package> passed as argument, increment the package version "
echo "according to the second argument. The version is 'major.minor.revision'."
echo "If the second argument is empty, revision is assumed."
echo "The generated packages will be stored in $PACKAGESDEST"
}
# Generate a debian package for $pkg ($1), updating the version based on
# $kind ($2), where $kind can be revision, minor, or major.
function createPackage() {
local pkg=$1
local kind=$2
local version=""
local newVersion=""
local major=""
local minor=""
local revision=""
local controlFile="$REPOROOT/$pkg/pacote/DEBIAN/control"
local ret=""
version=$(grep "^Version:" $controlFile | awk '{print $2}')
major=$(echo $version | cut -d. -f1)
minor=$(echo $version | cut -d. -f2)
revision=$(echo $version | cut -d. -f3)
case $kind in
major)
((major++))
minor=0
revision=0
;;
minor)
((minor++))
revision=0
;;
*)
((revision++))
;;
esac
newVersion="${major}.${minor}.${revision}"
sed -i -e "s/Version:.*/Version: $newVersion/" $controlFile
fakeroot dpkg -b $REPOROOT/$pkg/pacote/ $PACKAGESDEST/
ret=$?
if test $ret -ne 0; then
git checkout $controlFile
return $ret
fi
return 0
}
# ------------- main
# Check arguments
if test $# -lt 1 -o $# -gt 2; then
showHelp
exit 1
fi
# Globals
PKG="$1"
KIND="$2"
if ! test -d $REPOROOT/$PKG; then
echo "Package $PKG not found in $REPOROOT"
exit 2
fi
if ! mkdir -p $PACKAGESDEST; then
echo "Error while creating directory to store packages ($PACKAGESDEST)"
exit 3
fi
createPackage "$PKG" "$KIND"
exit $?
...@@ -33,6 +33,7 @@ PREFIX="$(dirname $0)" ...@@ -33,6 +33,7 @@ PREFIX="$(dirname $0)"
REPOROOT="$PREFIX/.." REPOROOT="$PREFIX/.."
REPOCONFIGFILE="$REPOROOT/.git/config" REPOCONFIGFILE="$REPOROOT/.git/config"
PUBLISHSCRIPT="$PREFIX/le-publish.sh" PUBLISHSCRIPT="$PREFIX/le-publish.sh"
CREATEPACKAGESCRIPT="$PREFIX/create_package.sh"
PACKAGESDEST="$REPOROOT/pkgs" PACKAGESDEST="$REPOROOT/pkgs"
JENKINSUSER="Jenkins <jenkins@c3sl.ufpr.br>" JENKINSUSER="Jenkins <jenkins@c3sl.ufpr.br>"
...@@ -106,56 +107,7 @@ function publish() { ...@@ -106,56 +107,7 @@ function publish() {
return $? return $?
} }
# Generate a debian package for $pkg ($1), updating the version based on # Print program help
# $kind ($2), where $kind can be revision, minor, or major.
function createPackage() {
local pkg=$1
local kind=$2
local version=""
local newVersion=""
local major=""
local minor=""
local revision=""
local controlFile="$REPOROOT/$pkg/pacote/DEBIAN/control"
local ret=""
version=$(grep "^Version:" $controlFile | awk '{print $2}')
major=$(echo $version | cut -d. -f1)
minor=$(echo $version | cut -d. -f2)
revision=$(echo $version | cut -d. -f3)
case $kind in
major)
((major++))
minor=0
revision=0
;;
minor)
((minor++))
revision=0
;;
*)
((revision++))
;;
esac
newVersion="${major}.${minor}.${revision}"
sed -i -e "s/Version:.*/Version: $newVersion/" $controlFile
fakeroot dpkg -b $REPOROOT/$pkg/pacote/ $PACKAGESDEST
ret=$?
if test $ret -ne 0; then
git checkout $controlFile
return $ret
fi
return 0
}
function showHelp() { function showHelp() {
echo "$0 OPTION... <previous commit> [current commit]" echo "$0 OPTION... <previous commit> [current commit]"
echo "" echo ""
...@@ -243,7 +195,7 @@ for pkg in $pkgs; do ...@@ -243,7 +195,7 @@ for pkg in $pkgs; do
# Generate Package # Generate Package
# TODO: allow user to change minor and major too # TODO: allow user to change minor and major too
echo "Generating package $pkg" echo "Generating package $pkg"
if ! createPackage $pkg revision; then if ! $CREATEPACKAGESCRIPT $pkg "revision"; then
echo ERROR creating package $pkg. echo ERROR creating package $pkg.
exit 1 exit 1
fi fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment