build_package.sh 2.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/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=""
27
    local controlFile="$REPOROOT/$pkg/package/DEBIAN/control"
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    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

55
    fakeroot dpkg -b $REPOROOT/$pkg/package/ $PACKAGESDEST/
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    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

74
75
76
77
78
if ! which fakeroot &>/dev/null; then
    echo "ERROR: make sure you have the fakeroot package installed."
    exit 1
fi

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# 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 $?