summaryrefslogtreecommitdiff
path: root/support/rewrite-hooks.sh
blob: 1d0542ef69323c0bf364eb54edf7f43035d74410 (plain)
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
#!/bin/bash

# $1 is an optional argument specifying the location of the repositories directory.
# Defaults to /home/git/repositories if not provided

home_dir="/home/git"
src=${1:-"$home_dir/repositories"}

for dir in `ls "$src/"`
do
  if [ -d "$src/$dir" ]; then

    if [ "$dir" = "gitolite-admin.git" ]
    then
      continue 
    fi

    if [[ "$dir" =~ ^.*\.git$ ]]
    then
      project_hook="$src/$dir/hooks/post-receive"
      gitolite_hook="$home_dir/gitlab-shell/hooks/post-receive"
      ln -s -f $gitolite_hook $project_hook

      project_hook="$src/$dir/hooks/update"
      gitolite_hook="$home_dir/gitlab-shell/hooks/update"
      ln -s -f $gitolite_hook $project_hook
    else
      for subdir in `ls "$src/$dir/"`
      do
        if [ -d "$src/$dir/$subdir" ] && [[ "$subdir" =~ ^.*\.git$ ]]; then
          project_hook="$src/$dir/$subdir/hooks/post-receive"
          gitolite_hook="$home_dir/gitlab-shell/hooks/post-receive"
          ln -s -f $gitolite_hook $project_hook

          project_hook="$src/$dir/$subdir/hooks/update"
          gitolite_hook="$home_dir/gitlab-shell/hooks/update"
          ln -s -f $gitolite_hook $project_hook
        fi
      done
    fi
  fi
done