diff options
author | Dmitry Ilvokhin <d@ilvokhin.com> | 2024-02-03 17:34:53 +0000 |
---|---|---|
committer | Dmitry Ilvokhin <d@ilvokhin.com> | 2024-02-03 17:34:53 +0000 |
commit | 98ed665f0db3ac9261f33ad259f64b8261256f95 (patch) | |
tree | 447d9410459b0e68df172f418fc41342cc33208b /roles/git/files | |
parent | ab0d9d56fb27f19b76fc7c3aba1f0d1936cd44bc (diff) | |
download | infra-98ed665f0db3ac9261f33ad259f64b8261256f95.tar.gz infra-98ed665f0db3ac9261f33ad259f64b8261256f95.tar.bz2 infra-98ed665f0db3ac9261f33ad259f64b8261256f95.zip |
Add init-git-repo.sh script to init new repos
Diffstat (limited to 'roles/git/files')
-rwxr-xr-x | roles/git/files/init-git-repo.sh | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/roles/git/files/init-git-repo.sh b/roles/git/files/init-git-repo.sh new file mode 100755 index 0000000..881ee55 --- /dev/null +++ b/roles/git/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 .. |