makebranch.sh: use -SNAPSHOT instead of -CURRENT for untagged branch builds
[buildbot.git] / phase1 / makebranch.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 " [-u <Download base url>] -n <codename> -v <version>"
18 echo ""
19 echo "-i"
20 echo "Exit successfully if branch already exists"
21 echo ""
22 echo "-a Git author [$git_author]"
23 echo "Override the author name used for automated Git commits"
24 echo ""
25 echo "-e Git email [$git_email]"
26 echo "Override the email used for automated Git commits"
27 echo ""
28 echo "-u Download base url [$base_url]"
29 echo "Use the given URL as base for download repositories"
30 echo ""
31 exit 1
32 } >&2
33 }
34
35 while getopts "a:e:iu:n:v:" opt; do
36 case "$opt" in
37 a) git_author="$OPTARG" ;;
38 e) git_email="$OPTARG" ;;
39 i) ignore_existing=1 ;;
40 u) base_url="${OPTARG%/}" ;;
41 n) codename="$OPTARG" ;;
42 v)
43 case "$OPTARG" in
44 [0-9]*.[0-9]*)
45 version="$(echo "$OPTARG" | cut -d. -f1-2)"
46 ;;
47 *)
48 echo "Unexpected version format: $OPTARG" >&2
49 exit 1
50 ;;
51 esac
52 ;;
53 \?)
54 echo "Unexpected option: -$OPTARG" >&2
55 usage
56 ;;
57 :)
58 echo "Missing argument for option: -$OPTARG" >&2
59 usage
60 ;;
61 esac
62 done
63
64 [ -n "$codename" -a -n "$version" ] || usage
65
66 if git rev-parse "lede-${version}^{tree}" >/dev/null 2>/dev/null; then
67 if [ -z "$ignore_existing" ]; then
68 echo "Branch lede-${version} already exists!" >&2
69 exit 1
70 fi
71
72 exit 0
73 fi
74
75 revnum="$(./scripts/getver.sh)"
76 githash="$(git log --format=%h -1)"
77
78 prev_branch="$(git symbolic-ref -q HEAD)"
79
80 if [ "$prev_branch" != "refs/heads/master" ]; then
81 echo "Expecting current branch name to be \"master\"," \
82 "but it is \"${prev_branch#refs/heads/}\" - aborting."
83
84 exit 1
85 fi
86
87 export GIT_AUTHOR_NAME="$git_author"
88 export GIT_AUTHOR_EMAIL="$git_email"
89 export GIT_COMMITTER_NAME="$git_author"
90 export GIT_COMMITTER_EMAIL="$git_email"
91
92 git checkout -b "lede-$version"
93
94 while read type name url; do
95 case "$type" in
96 src-git)
97 case "$url" in
98 *^*|*\;*) : ;;
99 *)
100 ref="$(git ls-remote "$url" "lede-$version")"
101
102 if [ -z "$ref" ]; then
103 echo "WARNING: Feed \"$name\" provides no" \
104 "\"lede-$version\" branch - using master!" >&2
105 else
106 url="$url;lede-$version"
107 fi
108 ;;
109 esac
110 echo "$type $name $url"
111 ;;
112 src-*)
113 echo "$type $name $url"
114 ;;
115 esac
116 done < feeds.conf.default > feeds.conf.branch && \
117 mv feeds.conf.branch feeds.conf.default
118
119 sed -e 's!^RELEASE:=.*!RELEASE:='"$codename"'!g' \
120 -e 's!\(VERSION_NUMBER:=\$(if .*\),[^,]*)!\1,'"$version-SNAPSHOT"')!g' \
121 -e 's!\(VERSION_REPO:=\$(if .*\),[^,]*)!\1,'"$base_url/$version-SNAPSHOT"')!g' \
122 include/version.mk > include/version.branch && \
123 mv include/version.branch include/version.mk
124
125 sed -e 's!http://downloads.lede-project.org/[^"]*!'"$base_url/$version-SNAPSHOT"'!g' \
126 package/base-files/image-config.in > package/base-files/image-config.branch && \
127 mv package/base-files/image-config.branch package/base-files/image-config.in
128
129 git commit -sm "LEDE v$version: set branch defaults" \
130 feeds.conf.default \
131 include/version.mk \
132 package/base-files/image-config.in
133
134 git --no-pager log -p -1
135 git push origin "refs/heads/lede-$version:refs/heads/lede-$version"
136 git checkout "${prev_branch#refs/heads/}"