aboutsummaryrefslogtreecommitdiffstats
path: root/git2redcrew.sh
blob: 964e6e1bbf29c07914c1190bf77acd53a3496474 (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
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
#!/bin/sh

set -ue

SUBDIR=""
PRIVATE=0

REMHOST="redcrew"

while getopts ":d:p" opt; do
  case $opt in
    d)
      SUBDIR="/${OPTARG}"
      ;;
    p)
      PRIVATE=1
      ;;
    \?)
      echo "Invalid option: -$OPTARG"
      exit 1
      ;;
    :)
      echo "Option -$OPTARG requires an argument."
      exit 1
      ;;
  esac
done

# Shift past the last option parsed by getopts
shift $((OPTIND-1))

if [ -d .git ] ; then
    git gc --aggressive --prune=now
    REPO="$(basename "$(git rev-parse --show-toplevel)")"
    cd ..
else
    [ -n "$1" ] || exit 1
    REPO="$1"
    (cd "$REPO"
      git gc --aggressive --prune=now
    )
fi

GITDIR="$(readlink -f "${REPO}").git"
git clone --bare "$REPO" "${GITDIR}"
(cd "${GITDIR}"
  # shellcheck disable=SC3045
  read -r -e -p "Describe the repository:" DESC
  echo "$DESC" >description
  touch git-daemon-export-ok
  git config --add gitweb.owner 'Matěj Cepl <mcepl@cepl.eu>'
  git remote rm origin || /bin/true
)

if [ $PRIVATE -eq 1 ] ; then
    TARGET="private_git${SUBDIR}"
    URL_BASE="${REMHOST}:${TARGET}"
else
    TARGET="/srv/git${SUBDIR}"
    URL_BASE="https://git.cepl.eu/cgit${SUBDIR}"
fi

rsync -avz "${GITDIR}" "${REMHOST}:${TARGET}/"
rm -rf "${GITDIR}"
cd "$REPO"
git remote add myrepo "${URL_BASE}/${REPO}"
if [ $PRIVATE -ne 1 ] ; then
    git remote set-url --push myrepo "${REMHOST}:${TARGET}/${REPO}.git"
fi
# if git remote show gitlab >/dev/null 2>&1 ; then
#     git remote remove gitlab
# fi
git remote update
git push --all -u myrepo