diff options
author | Dmitry Ilvokhin <d@ilvokhin.com> | 2024-03-03 14:11:45 +0000 |
---|---|---|
committer | Dmitry Ilvokhin <d@ilvokhin.com> | 2024-03-03 14:11:45 +0000 |
commit | 9920d404374275ef80b21421ae3a1ab8211fd88d (patch) | |
tree | 57b32073b91ea2f2071c63d80a9ec8978a5a516e /roles/gitserver/files/init-git-repo.sh | |
parent | dda24d15031f6ca179bede64beef9ff3f6e7d6eb (diff) | |
download | infra-9920d404374275ef80b21421ae3a1ab8211fd88d.tar.gz infra-9920d404374275ef80b21421ae3a1ab8211fd88d.tar.bz2 infra-9920d404374275ef80b21421ae3a1ab8211fd88d.zip |
Rename git role to gitserver
Diffstat (limited to 'roles/gitserver/files/init-git-repo.sh')
-rwxr-xr-x | roles/gitserver/files/init-git-repo.sh | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/roles/gitserver/files/init-git-repo.sh b/roles/gitserver/files/init-git-repo.sh new file mode 100755 index 0000000..881ee55 --- /dev/null +++ b/roles/gitserver/files/init-git-repo.sh @@ -0,0 +1,58 @@ +#! /usr/bin/env bash + +# Usage examples +# +# Init private repository and mirror it to github. +# ./init-git-repo.sh --private --mirror repo.git + +private=0 +mirror=0 +repo="" + +while [[ $# -gt 0 ]]; do + case $1 in + -p|--private) + private=1 + shift + ;; + -m|--mirror) + mirror=1 + shift + ;; + -*|--*) + echo "Unknown option $1" 1>&2 + exit 1 + ;; + *) + repo=$1 + shift + ;; + esac +done + +if [ -z $repo ]; then + echo "Provide repository name!" 1>&2 + exit 1 +fi + +mkdir $repo +cd $repo +git init --bare + +if [ $private -eq 0 ]; then + touch git-daemon-export-ok +fi + +if [ $mirror -eq 1 ]; then + git remote add --mirror github git@github.com:ilvokhin/$repo + + cat > hooks/post-receive <<EOF +#! /bin/sh + +git push --quiet github & +EOF + + chmod +x hooks/post-receive +fi + +cd .. |