Repository navigation
Expand file tree
/
Copy pathincVersion.sh
More file actions
executable file
·131 lines (112 loc) · 4.5 KB
/
Copy pathincVersion.sh
File metadata and controls
executable file
·131 lines (112 loc) · 4.5 KB
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
27
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#! /bin/bash
# set -x
# usage...
if [ ! $# -eq 3 ] ; then
echo "Usage: $0 distribution VERSION=[version] REPOSITORY=[repository]" && exit 1
fi
if svn list > /dev/null 2>&1 ; then
VCS="svn"
else
VCS="git"
fi
USER=seb # FIXME
DCH=$(mktemp /tmp/dch-XXXXX)
rm -f debian/changelog.dch
# CL args
distribution=${1}
version=${2/VERSION=}
versionGiven=$version
repository=${3/REPOSITORY=}
[ -z "${repository}" ] && repository=`$0/getPlatform.sh`
osdist=unknown
case $repository in
sarge|etch|lenny|sid) osdist=debian ;;
feisty|gutsy|intrepid|hardy) osdist=ubuntu ;;
esac
previousVersion=`dpkg-parsechangelog 2> /dev/null | awk '/Version: / { print $2 }'`
previousUpstreamVersion=`dpkg-parsechangelog 2> /dev/null | awk '/Version: / { gsub(/-.*/, "", $2) ; print $2 }'`
if [ -z "$version" ] ; then
# not exactly kosher, but I'll contend that incVersion.sh is only
# called from the Makefile :>
versionFile=`dirname $0`/resources/VERSION
# get some values from VCS: branch, last changed revision, timestamp
# for the current directory
case $VCS in
svn)
VCS_INFO="svn info --recursive"
VCS_STATUS="svn status"
url=`$VCS_INFO . | awk '/^URL:/{print $2}'` #FIXME
case $url in
*branch/*) branch=`echo $url | perl -pe 's|.*/branch/(.*?)/.*|\1| ; s/-//g'` ;;
*) branch=main ;;
esac
revision=`$VCS_INFO . | awk '/Last Changed Rev: / { print $4 }' | sort -n | tail -1`
[ -z "$revision" ] && revision=100000
timestamp=`$VCS_INFO . | awk '/Last Changed Date:/ { gsub(/-/, "", $4) ; gsub(/:/, "", $5) ; print $4 "T" $5 }' | sort -n | tail -1`
# this is how we figure out if we're up-to-date or not
hasLocalChanges=`$VCS_STATUS | grep -v -E '^([X?!]|Fetching external item into|Performing status on external item at|$)'`
;;
git)
# new-style source package are not directly under version
# control, but their parent dir is
[[ $(pwd) == */ngfw_upstream/* ]] && d=.. || d=.
revision=$(git log -n 1 --format="%h" -- $d)
# older git versions don't have --date=iso-strict-local, so we
# use --date=local (to convert to local timezone) with %ad,
# which yields something like "Tue Sep 13 23:46:56 PDT 2016"
timestamp="$(git log -n 1 --date=local --format='%ad' -- $d)"
# ... then we convert that to something like
# "2016-09-13T23:46:56-0700"
timestamp=$(date -d"$timestamp" --iso-8601=seconds)
# ... and finally to "20160913T234656"
timestamp=$(echo $timestamp | perl -pe 's/[-+]\d{4}$// ; s/[-:]//g')
hasLocalChanges=$(git diff-index --name-only HEAD -- .)
;;
esac
# this is the base version; it will be tweaked a bit if need be:
# - append a local modification marker is we're not up to date
# - prepend the upstream version if UNTANGLE-KEEP-UPSTREAM-VERSION exists
baseVersion=$(cat $versionFile).${timestamp}.${revision}
if [ -f UNTANGLE-KEEP-UPSTREAM-VERSION ] ; then
baseVersion=${previousUpstreamVersion}+${baseVersion}
elif [ -f UNTANGLE-FORCE-UPSTREAM-VERSION ] ; then
# if we find UNTANGLE-FORCE-UPSTREAM-VERSION, do nothing as it
# means we want to build an upstream package without modifying it
# at all.
baseVersion=${previousVersion}
fi
if [ -z "$hasLocalChanges" ] ; then
version=$baseVersion
else
echo -e "The changes were:\n$hasLocalChanges"
version=${baseVersion}+$USER`date +"%Y%m%dT%H%M%S"`
distribution=$USER
fi
if [ ! -f UNTANGLE-FORCE-UPSTREAM-VERSION ] ; then # FIXME: ugly, but will do for now
version=${version}-1
fi
else # force version
if [ -f UNTANGLE-KEEP-UPSTREAM-VERSION ] ; then
previousUpstreamVersion=`dpkg-parsechangelog | awk '/Version: / { gsub(/-.*/, "", $2) ; print $2 }'`
version=${previousUpstreamVersion}+${version}
fi
case "$version" in
*-*) ;; # the user did supply a Debian revision
*) version=${version}-1 ;;
esac
fi
version=${version}${repository}
dchargs="--preserve -v ${version} -D ${distribution}"
## dch is called outside the chroot...
#if [ "$osdist" = ubuntu ]; then
# dchargs="$dchargs --distributor Untangle"
#fi
/bin/cp -f /usr/bin/dch $DCH
chmod 755 $DCH
sed -i -e '/garbage/d' $DCH
echo "Setting version to \"${version}\", distribution to \"$distribution\""
DEBEMAIL="${DEBEMAIL:-${USER}@untangle.com}" $DCH $dchargs "auto build" 2> /dev/null
# check changelog back in if version was forced; FIXME: disabled for now
#[ -n "$versionGiven" ] && [ ! -f UNTANGLE-KEEP-UPSTREAM-VERSION ] && $SVN commit debian/changelog -m "Forcing version to $version"
rm -f $DCH
echo " done."