File: install-hooks

package info (click to toggle)
farstream-0.2 0.2.8-4.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,972 kB
  • sloc: ansic: 43,088; sh: 12,143; perl: 3,071; python: 1,921; makefile: 803; xml: 692
file content (97 lines) | stat: -rw-r--r-- 2,187 bytes parent folder | download | duplicates (2)
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
90
91
92
93
94
95
96
97
#!/bin/bash
#
# install-hooks
#
# install hooks on git server
#
# usage: install-hooks [GIT_REPOSITORY_DIR]

set -e

HOOKS="update post-receive"

# if directory where git repositories are is specified, change into that
if ! test -z $1 ; then
  cd $1;
fi

# save it
gitrepodir=`pwd`

# make backup of previous hooks
timestamp=`date +%F-%H%M%S`
for hook in $HOOKS; do
  if [ -e $hook ]; then
    cp $hook $hook.backup-$timestamp
  fi
done

# now check out the common module with the latest hooks
tmpdir=`mktemp -d`
if test -z $tmpdir; then
  echo "Failed to create temp dir"
  exit 1;
fi

pushd $tmpdir >/dev/null
git clone --branch=master $gitrepodir/common

# copy over latest hooks into directory with git repositories
for hook in $HOOKS; do
  cp -v common/hooks/$hook.hook $gitrepodir/$hook
done

# now switch back to directory where the git repositories are
popd >/dev/null

# clean up temp checkout of common dir
rm -rf $tmpdir

# remove backup again if it is identical to the new one
for hook in $HOOKS; do
  if cmp $hook $hook.backup-$timestamp; then
    rm $hook.backup-$timestamp
  fi
done

# sanity check if there are any git repositories in here
if ! ls *.git */*.git 2>/dev/null >&2 ; then
  echo "No git repositories in $(pwd) ?!"
  exit;
fi

echo "git repository base dir: $gitrepodir"

for repo in *.git */*.git ; do
  if test "$repo" = "sdk/glib.git"; then
    echo "Skipping $repo"
    continue
  fi
  echo "Updating hooks in $repo"
  for hook in $HOOKS; do
    # make sure target hook script actually exists
    if ! test -e $hook ; then
      echo "Hook '$hook' does not exist in $gitrepodir. Aborting.";
      exit 1;
    fi
    # create new hook
    rm -f $repo/hooks/$hook.new
    pushd $repo/hooks >/dev/null
    if [ -e "../../$hook" ] ; then
      ln -s "../../$hook" $hook.new
    elif [ -e "../../../$hook" ] ; then
      ln -s "../../../$hook" $hook.new
    else
      echo "could not find hook script in parent directories ?!"
      exit 1
    fi
    # put new hook in place atomically
    #echo "installing $repo/hooks/$hook"
    mv $hook.new $hook
    # test it to make sure all is good
    cat $hook >/dev/null
    popd >/dev/null
  done
done

echo "Done"