3 #=======================================================================
5 # File ID: 7075da30-98d2-11de-b3de-00248cd5cf1e
7 # Compile and install git(1).
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
26 " -n "$progname" -- "$@
")"
27 test "$?" = "0" ||
exit 1
36 -h|
--help) opt_help
=1; shift ;;
37 --no-net) opt_no_net
=1; shift ;;
38 -q|
--quiet) opt_quiet
=$
(($opt_quiet + 1)); shift ;;
39 -v|
--verbose) opt_verbose
=$
(($opt_verbose + 1)); shift ;;
40 --version) echo $progname $VERSION; exit 0 ;;
42 *) echo $progname: Internal error
>&2; exit 1 ;;
45 opt_verbose
=$
(($opt_verbose - $opt_quiet))
47 if test "$opt_help" = "1"; then
48 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
51 Compile and install git(1). Default action is to build from the newest
52 revision on 'master'. Another branch or tag can be specified as first
55 Usage: $progname [options] [branch]
62 Don't fetch or push, use what's present in the local repo.
64 Be more quiet. Can be repeated to increase silence.
66 Increase level of verbosity. Can be repeated.
68 Print version information.
74 lockdir
=$HOME/.Build-git.LOCK
77 rmdir $lockdir ||
echo $progname: $lockdir: Cannot remove lockdir
>&2
81 trap "myexit 1" INT TERM
83 echo $progname: $lockdir: Cannot create lockdir
>&2
87 rcfile
=$HOME/.build-gitrc
88 origin_url
=git
://git.kernel.org
/pub
/scm
/git
/git.git
90 # Directory where the git build happens
91 builddir
=$HOME/src
/other
/git
/build-git
93 # Prefix to directory tree where git will be installed. You can change
94 # it to for example $HOME/local if you don’t have root access.
97 # If you don’t have sudo rights or you don’t need it at the location in
98 # the file system, clear the value of the $sudo variable
101 # Local name of remote master
104 # Name of remote master
105 remote_master
=origin
/master
107 # Set to 0 to skip ./configure and use Makefile in git.git instead
117 [ -e $rcfile ] && .
$rcfile
123 is_official_branch
() {
124 echo -n $1 |
grep -Eq '^(master|maint|next|pu|todo)$' &&
129 git remote |
grep -q '^origin$' || git remote add origin
$origin_url
130 git remote |
grep -q '^kernelorg$' ||
131 git remote add kernelorg git
://git.kernel.org
/pub
/scm
/git
/git.git
132 git remote |
grep -q '^gitster$' ||
{
133 git remote add gitster git
://github.com
/gitster
/git.git
134 git config
--add remote.gitster.fetch
+refs
/notes
/*:refs
/notes
/*
136 git remote |
grep -q '^gitlab$' ||
137 git remote add gitlab git@gitlab.com
:oyvholm
/git.git
138 git remote |
grep -q '^peff$' ||
139 git remote add peff git
://github.com
/peff
/git.git
140 git remote |
grep -q '^sunbase$' ||
141 git remote add sunbase \
142 sunny@sunbase.org
:/home
/sunny
/repos
/Git-other
/git.git
143 if test "$opt_no_net" = "0"; then
144 echo ================= git fetch
=================
145 echo ===== origin
=====
146 until git fetch origin
; do
147 echo $progname: Fetch error from origin
, retrying
>&2
150 # git fetch --all arrived in v1.6.6, and that’s too recent to use.
151 for f
in $
(git remote |
grep -v '^origin$'); do
155 for f
in maint master next pu todo
; do
156 git branch | cut
-c 3- |
grep -q ^
$f\$ || git branch
$f origin
/$f
162 git log
--color --graph --pretty=format
:'%Cred%h %Cblue%p%Creset '\
163 '-%C(yellow)%d%Creset %s %Cgreen(%cd %Cblue%an%Cgreen)%Creset' \
168 until $sudo echo Password OK |
grep -q "Password OK"; do
174 if test "$opt_no_net" = "0"; then
175 for f
in bellmann loc-repo passp sunbase gitlab rsync-net
; do
176 git remote |
grep -q "^$f\$" && {
177 echo ==== push changes to
$f ====
178 git push
-f $f master maint next pu todo
181 for f
in loc-repo passp sunbase rsync-net
; do
182 git remote |
grep -q "^$f\$" && {
183 echo ==== push tags to
$f ====
187 echo ==== push finished
====
193 date +"%Y-%m-%d %H:%M:%S%z"
197 git checkout $
(git log
-1 --format=%H
) 2>/dev
/null
198 echo -n "master: " >&2
199 git push . origin
/master
:master ||
{
200 echo $progname: master branch did not fast-forward
, aborting
>&2
204 for f
in maint next pu todo
; do
206 git push
-f . origin
/$f:$f
208 git checkout
-f $local_master
212 [ -f $HOME/src
/git
/lpar
/git.lpar
] && lpar
215 [ -z "`git --version | grep '^git version '`" ] && {
216 echo $progname: You need to have git installed to use this
script.
>&2
220 rmdir $builddir 2>/dev
/null
221 if [ ! -d $builddir/.
]; then
222 mkdir
-p $builddir ||
{
223 echo $progname: $builddir: Cannot create directory
227 echo ================= git clone
=================
228 git clone
$origin_url $builddir
229 cd $builddir ||
{ echo $progname: $builddir: Cannot chdir
>&2; myexit
1; }
230 git config lpar.name git
231 for f
in maint next pu todo
; do
232 git branch
-t $f origin
/$f ||
{
233 echo $progname: $f: Could not create branch
>&2
238 cd $builddir ||
{ echo $progname: $builddir: Cannot chdir
>&2; myexit
1; }
239 GIT_PAGER
=cat git status
--porcelain |
grep .
&& {
240 echo $progname: $builddir is not clean
, aborting
>&2
245 (git tag |
grep compiled-
$hname-2 |
tail -1) ||
echo UNKNOWN
252 echo "curr_git_ver = \"$curr_git_ver\" ($(
254 git describe --long --match 'v[12]*' $curr_git_ver
256 echo "rcfile = \"$rcfile\" ($([ -e $rcfile ] || echo -n "not
")found)"
257 echo "builddir = \"$builddir\""
258 echo "pref = \"$pref\""
259 echo "sudo = \"$sudo\""
260 echo "local_master = \"$local_master\""
261 echo "remote_master = \"$remote_master\""
262 echo "makeflags = \"$makeflags\""
263 echo "make_doc = \"$make_doc\""
264 echo "make_info = \"$make_info\""
265 echo "hname = \"$hname\""
266 echo "use_configure = \"$use_configure\""
267 echo "configure_opts = \"$configure_opts\""
270 git checkout
$local_master ||
{ echo Cannot check out branch
>&2; myexit
1; }
271 if [ ! -e GIT-VERSION-GEN
]; then
273 echo $progname: Didn’t
find GIT-VERSION-GEN. That’s strange
, aborting.
277 is_official_branch
$local_master &&
278 destbranch
=origin
/$local_master || destbranch
=$local_master
280 if [ -n "$curr_git_ver" ]; then
281 echo ================= git status
in `pwd` =================
282 GIT_PAGER
=cat git status
286 until [ "$choice" = "y" ]; do
289 echo $
(git log
--format=oneline
$curr_git_ver..
$destbranch |
wc -l) \
290 "new commits available in range $curr_git_ver..$destbranch"
291 echo Going to compile git $
(
292 git describe
--long --match 'v[12]*' $destbranch
295 echo If that looks okay to you
, press
\'y
\' to start the build
, or
:
297 echo \'ds
\' to
diff --stat
298 echo \'dw
\' to word-diff
299 echo \'l
\' to list log
300 echo \'lp\' to list log with
patch
301 echo \'lt
\' to list log with commit tree
302 echo \'lw
\' to list log with
patch using word
diff
304 echo \'p
\' to push new commits
305 echo \'t
\' to show commit tree
307 [ "$choice" = "d" ] && git
diff $curr_git_ver $destbranch
308 [ "$choice" = "ds" ] && git
diff --stat $curr_git_ver $destbranch
309 [ "$choice" = "dw" ] && git
diff --word-diff $curr_git_ver $destbranch
310 [ "$choice" = "l" ] && git log
--stat $curr_git_ver..
$destbranch
311 [ "$choice" = "lp" ] && git log
--patch $curr_git_ver..
$destbranch
312 [ "$choice" = "lt" ] &&
313 git log
--graph --stat $curr_git_ver..
$destbranch
314 [ "$choice" = "lw" ] &&
315 git log
--patch --word-diff $curr_git_ver..
$destbranch
316 [ "$choice" = "n" ] && myexit
0
317 [ "$choice" = "p" ] && {
318 if test "$opt_no_net" = "0"; then
322 echo $progname: --no-net was specified
, will not push
>&2
325 [ "$choice" = "t" ] && commit_tree
$curr_git_ver..
$destbranch
329 until [ "$choice" = "y" ]; do
330 echo -n Press
\'y
\' to start the build
, or
\'n
\' to abort...
332 [ "$choice" = "n" ] && myexit
0
336 echo ================= git clean
=================
338 echo ================= Update all branches
=================
340 vername
=git.
$local_master.
`git describe --long --match 'v[12]*'`
341 dest
=$pref/varprg
/$vername
344 echo "Sorry, no new git(1) for you this time."
345 echo You’ll have to stick with
`git --version` for now.
350 if [ "$use_configure" = "1" ]; then
351 echo $progname: Creating .
/configure
353 echo ==== .
/configure
--prefix=$dest $configure_opts
354 .
/configure
--prefix=$dest $configure_opts
356 if [ "$make_doc" = "1" ]; then
358 inst_doc_str
="install-doc install-html"
363 if [ "$make_info" = "1" ]; then
365 inst_info_str
=install-info
370 echo Compiling
$vername
371 echo "==== make prefix=$dest $makeflags all" \
372 "$make_doc_str $make_info_str \|\| myexit"
373 make prefix
=$dest $makeflags all
$make_doc_str $make_info_str || myexit
374 if test "$run_tests" = "1"; then
375 echo ==== make $makeflags test
379 echo Ready to
install $
(.
/git
--version) from branch
\"$local_master\"
381 until test "$choice" = "y"; do
384 echo -n If all tests succeeded
, press y to
continue...
388 echo "==== $sudo make prefix=$dest" \
389 "$makeflags install $inst_doc_str $inst_info_str"
390 $sudo make prefix
=$dest $makeflags install $inst_doc_str $inst_info_str
391 echo ================= make install finished
=================
392 $sudo mkdir
-p $pref/{bin
,prg
,varprg
}
393 $sudo rm $pref/prg
/git
394 $sudo ln -svf ..
/varprg
/$vername $pref/prg
/git
395 $sudo ln -sv /etc
$pref/prg
/git
/etc
397 echo $progname: $pref/bin
: Cannot chdir
, aborting
>&2
400 $sudo ln -svf ..
/prg
/git
/bin
/* .
401 echo ================= Check that the thing works
=================
403 localgit
=`./git --version`
404 globalgit
=`git --version`
405 if [ "$localgit" = "$globalgit" ]; then
406 echo Congratulations with your shiny new
$globalgit
407 cd $builddir ||
{ echo $progname: $builddir: Cannot chdir
>&2; myexit
1; }
408 git tag compiled-
$hname-$
(date -u +"%Y%m%dT%H%M%SZ")
409 test "$opt_no_net" = "0" && git push
--tags sunbase
411 echo Uhm
, something went wrong.
412 echo Current version of git
: $globalgit
413 echo Expected version of git
: $localgit
417 echo ================= symlink manpages
=================
418 cd $pref/prg
/git
/share
/man
420 for f
in $mansects; do
421 $sudo mkdir
-p $pref/share
/man
/$f
422 cd $pref/share
/man
/$f ||
{
423 echo $progname: $pref/share
/man
/$f: Could not chdir
, aborting
>&2
427 $sudo ln -sf ..
/..
/..
/prg
/git
/share
/man
/$f/* .
429 if [ -d $pref/.git
/.
]; then
430 echo ================= git commit the symlink
=================
432 echo $progname installed
$globalgit on $
(hostname
)
434 suuid
-t commit
,$progname
440 $sudo git commit
-m "$commitmsg"
441 test "$opt_no_net" = "0" && git pa