-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathupdate-version.sh
executable file
·89 lines (74 loc) · 2.9 KB
/
update-version.sh
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
#!/bin/sh
LANG=C
export LANG
faketty() {
if uname -a | grep -q Darwin; then
script -q /dev/null $@
else
$@
fi
}
if [ -z "$1" ] || [ -z "$2" ]; then
echo "usage: $0 version message"
echo "current version: "`grep ^Version syncer/SPECS/atomiadns-nameserver.spec | cut -d " " -f 2`
exit 1
fi
version_to_number() {
major=`echo "$1" | cut -d . -f 1`
minor=`echo "$1" | cut -d . -f 2`
patch=`echo "$1" | cut -d . -f 3`
expr "$major" "*" 1000 + "$minor" "*" 100 + "$patch"
}
version="$1"
message="$2"
version_num=`version_to_number "$version"`
current_version=`grep ^Version syncer/SPECS/atomiadns-nameserver.spec | cut -d " " -f 2`
current_version_num=`version_to_number "$current_version"`
if [ -z "$version_num" ] || [ -z "$current_version_num" ]; then
echo "error: calculating version number for $version or $current_version"
exit 1
fi
if [ ! "$version_num" -gt "$current_version_num" ]; then
echo "error: current version $current_version is not lower than $version"
exit 1
fi
author_realname=`git config user.name`
author_email=`git config user.email`
if [ -z "$author_realname" ] || [ -z "$author_email" ]; then
author="Jimmy Bergman <[email protected]>"
else
author="$author_realname <$author_email>"
fi
# Update *.spec
find dyndns syncer server powerdns_sync bind_sync webapp -name "*.spec" -type f | while read f; do
version_subs="%%s/^Version: .*/Version: $version/"
require_subs="%%s/^Requires: atomiadns-api >= .* atomiadns-database >= .*/Requires: atomiadns-api >= $version atomiadns-database >= $version/"
goto_changelog="/^%%changelog/+1i"
change_header="* $(date +"%a %b %d %Y") $author - ${version}-1"
ed_script=`printf "$version_subs\n$require_subs\n$goto_changelog\n$change_header\n- $message\n.\nw\nq\n"`
echo "$ed_script" | faketty ed "$f"
done
# Update */Makefile.PL
find dyndns syncer server zonefileimporter powerdns_sync bind_sync webapp -name "Makefile.PL" | while read f; do
version_subs="%%s/'VERSION' => '.*',/'VERSION' => '$version',/"
ed_script=`printf "$version_subs\nw\nq\n"`
echo "$ed_script" | faketty ed "$f"
done
# Update */control
find dyndns syncer server zonefileimporter powerdns_sync bind_sync webapp -name "control" | while read f; do
version_subs='%%s/\\\\(atomiadns-[a-z]*\\\\) (>= [^)]*)/\\\\1 (>= '"$version"')/g'
ed_script=`printf "$version_subs\nw\nq\n"`
echo "$ed_script" | faketty ed "$f"
done
# Update */changelog
find dyndns syncer server zonefileimporter powerdns_sync bind_sync webapp -name "changelog" | while read f; do
date=`date +"%a, %-d %b %Y %T %z"`
package=`grep " hardy; " "$f" | head -n 1 | cut -d " " -f 1`
changelog=`printf "%s (%s) hardy; urgency=low\n\n * %s\n\n -- $author %s" "$package" "$version" "$message" "$date"`
ed_script=`printf "1i\n%s\n\n.\nw\nq\n" "$changelog"`
if ! grep -q "[(]$version[)]" "$f"; then
echo "$ed_script" | faketty ed "$f"
fi
done
# Update package.json
sed -i.bak 's/\("version": "\)[^"]*"/\1'"$version"'"/' */package.json