OSDN Git Service

maint: remove dead store code and declarations
[android-x86/external-parted.git] / build-aux / parted-release
1 #!/bin/bash
2
3 v=""
4 date=$(date +%F)
5 logfile="release.log"
6 parted_dir=""
7 key_id=""
8 stage_dir="$(pwd)/parted_release-$$"
9
10 usage()
11 {
12   echo "Script for releasing parted."
13   echo
14   echo "$0 --version VERSION [--key-id KEYID --stage-dir DIR]"
15   echo
16   echo "  --version VERSION   The version of parted to be released"
17   echo "  --key-id KEYID    Your GPG key id.  If not given, -s argument"
18   echo "            of gpg will be used"
19   echo "  --stage-dir       The directory that will be used to stage the"
20   echo "            release process"
21 }
22
23 # Get all the input values
24 while [ $# -gt 0 ] ; do
25   case $1 in
26
27     --key-id)
28       key_id="$2"
29       shift; shift
30     ;;
31
32     # The version that is to be released
33     --version)
34       v="$2"
35       shift; shift
36     ;;
37
38     --stage-dir)
39       stage_dir="$2"
40       shift; shift
41     ;;
42
43     --help)
44       usage
45       exit 0
46     ;;
47
48     # The default
49     *)
50       usage
51       exit 1
52     ;;
53
54   esac
55 done
56
57 _find_signingkey()
58 {
59   # If its already set, return.
60   if [ "x$key_id" != "x" ] ; then
61       return 0
62   fi
63
64   # Maybe the global git config has the key :)
65   key_id=$(git config user.signingkey)
66   if [ "x$key_id" != "x" ] ; then
67     return 0
68   fi
69
70   # Lets ask gpg using git config user.email.  We will choose the first
71   # one in case of multiple keys with the same email.
72   git_uemail=$(git config user.email)
73   if [ "x$git_uemail" != "x" ] ; then
74       key_id=$(gpg --list-keys --with-colons --fixed-list "$git_uemail" |
75                grep pub |
76                head -n 1 |
77                awk -F ':' '{print $5}' |
78                cut -c 9-)
79     if [ "x$key_id" != "x" ] ; then
80       return 0
81     fi
82   fi
83
84   # Lets try with the name.
85   git_uname=$(git config user.name)
86   if [ "x$git_uname" != "x" ] ; then
87       key_id=$(gpg --list-keys --with-colons --fixed-list "$git_uname" |
88                grep pub |
89                head -n 1 |
90                awk -F ':' '{print $5}' |
91                cut -c 9-)
92     if [ "x$key_id" != "x" ] ; then
93       return 0
94     fi
95   fi
96
97   # Don't know where else to look.
98   echo "There was an error finding the key needed to sing the release tag."
99   echo "Please use the --key-id argument when you execute $0 or set the"
100   echo "user.signingkey value in your ~/.gitconfig"
101   exit 1
102 }
103
104 _do_git_clone()
105 {
106   git clone git://git.debian.org/git/parted/parted.git || return 1
107   parted_dir="parted"
108 }
109
110 _require_git()
111 {
112   ( git --version ) > /dev/null 2>&1 ||
113   {
114     echo "Could not find git. Please install from http://git-scm.com/download."
115     exit 1
116   }
117 }
118
119 _do_sanity_check()
120 {
121   (cd $parted_dir
122     ./bootstrap && \
123     ./configure && \
124     make && \
125     make check && \
126     sudo make check RUN_VERY_EXPENSIVE_TESTS=yes RUN_EXPENSIVE_TESTS=yes && \
127     make distcheck && \
128     make maintainer-clean && \
129     return 0
130   ) >> $logfile 2>&1 || return 1
131 }
132
133 _do_release()
134 {
135   (cd $parted_dir
136     news_line="* Noteworthy changes in release $v ($date) [stable]"
137     commit_message="version $v\n\n* NEWS: Record release date.\n"
138     sed -e "s/^.*in release.* (????-??-??) .*/$news_line/" -i NEWS && \
139     printf "$commit_message" | git commit NEWS -F - && \
140     git tag -u $key_id -m "parted $v" v$v HEAD && \
141     ./bootstrap && \
142     ./configure && \
143     make && \
144     make major gpg_key_ID=$key_id && \
145     return 0
146   ) >> $logfile 2>&1 || return 1
147 }
148
149 _do_success()
150 {
151   echo "\
152 The release process has finished successfully.  You are encouraged to follow
153 these steps:"
154   cat $parted_dir/README-release
155   exit 0
156 }
157
158 _do_fail()
159 {
160   echo "\
161 The process has returned an error please check the $logfile for more
162 information.  Also check your global git configuration and network
163 configuration for possible overlooked issues.
164 "
165   exit 1
166 }
167
168 if [ "x$v" = "x" ] ; then
169   usage
170   exit 1
171 fi
172
173 if [ "x$key_id" = "x" ] ; then
174   _find_signingkey
175 fi
176
177 _require_git
178 echo "git is installed..."
179
180 mkdir -p "$stage_dir" || exit 1
181 cd "$stage_dir"
182
183 echo "Cloning parted (this might take a few minutes)..."
184 _do_git_clone || _do_fail
185 echo "parted cloned..."
186
187 echo "Sanity checking..."
188 _do_sanity_check || _do_fail
189
190 echo "Creating the release..."
191 _do_release || _do_fail
192
193 _do_success