maketag.sh: use the output of getver.sh verbatim
[buildbot.git] / phase1 / maketag.sh
1 #!/usr/bin/env bash
2
3 git_author="Release Management"
4 git_email="lede-dev@lists.infradead.org"
5
6 base_url="http://downloads.lede-project.org/releases"
7
8 [ -f "./feeds.conf.default" ] || {
9 echo "Please execute as ./${0##*/}" >&2
10 exit 1
11 }
12
13 usage() {
14 {
15 echo ""
16 echo "Usage: $0 [-i] [-a <Git author>] [-e <Git email>] \\"
17 echo " [-k <GPG key id>] [-p <GPG passphrase file>] \\"
18 echo " [-u <Download base url>] -v <version>"
19 echo ""
20 echo "-i"
21 echo "Exit successfully if tag already exists"
22 echo ""
23 echo "-a Git author [$git_author]"
24 echo "Override the author name used for automated Git commits"
25 echo ""
26 echo "-e Git email [$git_email]"
27 echo "Override the email used for automated Git commits"
28 echo ""
29 echo "-k GPG key id [none]"
30 echo "Enable GPG signing of tags with given GPG key id"
31 echo ""
32 echo "-p GPG passphrase file [none]"
33 echo "Use the passphrase stored in the given file for signing"
34 echo ""
35 echo "-u Download base url [$base_url]"
36 echo "Use the given URL as base for download repositories"
37 echo ""
38 exit 1
39 } >&2
40 }
41
42 while getopts "a:e:ik:p:u:v:" opt; do
43 case "$opt" in
44 a) git_author="$OPTARG" ;;
45 e) git_email="$OPTARG" ;;
46 i) ignore_existing=1 ;;
47 k) gpg_keyid="${OPTARG#0x}" ;;
48 p) gpg_passfile="${OPTARG}" ;;
49 u) base_url="${OPTARG%/}" ;;
50 v)
51 case "$OPTARG" in
52 [0-9]*.[0-9]*.[0-9]*)
53 version="$OPTARG"
54 basever="$(echo "$version" | cut -d. -f1-2)"
55 ;;
56 *)
57 echo "Unexpected version format: $OPTARG" >&2
58 exit 1
59 ;;
60 esac
61 ;;
62 \?)
63 echo "Unexpected option: -$OPTARG" >&2
64 usage
65 ;;
66 :)
67 echo "Missing argument for option: -$OPTARG" >&2
68 usage
69 ;;
70 esac
71 done
72
73 [ -n "$version" ] || usage
74
75 if git rev-parse "v${version}^{tag}" >/dev/null 2>/dev/null; then
76 if [ -z "$ignore_existing" ]; then
77 echo "Tag v${version} already exists!" >&2
78 exit 1
79 fi
80
81 exit 0
82 fi
83
84 revnum="$(./scripts/getver.sh)"
85
86 prev_branch="$(git symbolic-ref -q HEAD)"
87
88 case "$prev_branch" in
89 *-$basever) : ;;
90 *)
91 echo "Expecting current branch name to end in \"-$basever\"," \
92 "but it is \"${prev_branch#refs/heads/}\" - aborting."
93
94 exit 1
95 ;;
96 esac
97
98 export GIT_AUTHOR_NAME="$git_author"
99 export GIT_AUTHOR_EMAIL="$git_email"
100 export GIT_COMMITTER_NAME="$git_author"
101 export GIT_COMMITTER_EMAIL="$git_email"
102
103 git checkout -b "release-$version"
104
105 while read type name url; do
106 case "$type" in
107 src-git)
108 case "$url" in
109 *^*) sha1="${url##*^}" ;;
110 *\;*) sha1="$(git ls-remote "${url%;*}" "${url##*;}")" ;;
111 *) sha1="$(git ls-remote "$url" "master")" ;;
112 esac
113 echo "$type $name ${url%[;^]*}${sha1:+^${sha1:0:40}}"
114 ;;
115 src-svn)
116 case "$url" in
117 *\;*) rev="${url##*;}" ;;
118 *) rev="$(svn log -l 1 "$url" | sed -ne '2s/ .*$//p')" ;;
119 esac
120 echo "$type $name ${url%;*}${rev:+;$rev}"
121 ;;
122 src-*)
123 echo "$type $name $url"
124 ;;
125 esac
126 done < feeds.conf.default > feeds.conf.tagged && \
127 mv feeds.conf.tagged feeds.conf.default
128
129 sed -e 's!\(VERSION_NUMBER:=\$(if .*\),[^,]*)!\1,'"$version"')!g' \
130 -e 's!\(VERSION_CODE:=\$(if .*\),[^,]*)!\1,'"$revnum"')!g' \
131 -e 's!\(VERSION_REPO:=\$(if .*\),[^,]*)!\1,'"$base_url/$version"')!g' \
132 include/version.mk > include/version.tagged && \
133 mv include/version.tagged include/version.mk
134
135 sed -e 's!http://downloads.lede-project.org/[^"]*!'"$base_url/$version"'!g' \
136 package/base-files/image-config.in > package/base-files/image-config.tagged && \
137 mv package/base-files/image-config.tagged package/base-files/image-config.in
138
139 git commit -sm "LEDE v$version: adjust config defaults" \
140 feeds.conf.default \
141 include/version.mk \
142 package/base-files/image-config.in
143
144
145 if [ -n "$gpg_keyid" -a -n "$gpg_passfile" ]; then
146 gpg_script="$(tempfile)"
147
148 cat <<-EOT > "$gpg_script"
149 #!/usr/bin/env bash
150 exec $(which gpg) --batch --passphrase-file $gpg_passfile "\$@"
151 EOT
152
153 chmod 0700 "$gpg_script"
154 fi
155
156 git ${gpg_script:+-c "gpg.program=$gpg_script"} tag \
157 -a "v$version" \
158 -m "LEDE v$version Release" \
159 ${gpg_keyid:+-s -u "$gpg_keyid"}
160
161 [ -n "$gpg_script" ] && rm -f "$gpg_script"
162
163 git checkout "${prev_branch#refs/heads/}"
164 git branch -D "release-$version"
165
166 git --no-pager show "v$version"
167 git push --follow-tags origin "refs/tags/v$version:refs/tags/v$version"