summaryrefslogtreecommitdiffstats
path: root/bin/setup-repo
blob: 1651534e14d58f1325a1168ee2186bc8e3f8208d (plain) (blame)
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/sh
#
# Set up a clone of the security-tracker git repo

set -e

## variables
if [ -d .git ]; then
  GIT_HOOKS_DIR=".git/hooks"
elif [ -e .git ]; then
  GIT_DIR=$(awk '/gitdir:/ { print $2 }' .git)
  GIT_HOOKS_DIR="$GIT_DIR/hooks"
else
  echo "ERROR: Not in the top-level directory of the git repository." >&2
  exit 1
fi

SRC=$(realpath --relative-to "$GIT_HOOKS_DIR" conf/pre-commit)
HOOK="$GIT_HOOKS_DIR"/pre-commit

install_pre_commit_hook() {
  if [ -L "${HOOK}" ] && [ "$(readlink ${HOOK})" = "${SRC}" ]; then
      echo "pre-commit hook already set up"
      return
  fi

  if [ -e "${HOOK}" ] || [ -L "${HOOK}" ]; then
    echo "Moving old pre-commit hook"
     mv -f "${HOOK}" "${HOOK}.$(date '+%s')"
  fi

  echo "Installing pre-commit hook"
  ln -s "${SRC}" "${HOOK}"
}


if [ "$(git rev-parse --show-cdup)" != '' ] || [ -d data/CVE/list ]; then
     echo "This does not look like the git repo of the security tracker" 1>&2
     exit 1
fi

install_pre_commit_hook

© 2014-2024 Faster IT GmbH | imprint | privacy policy