diff options
author | Aaron LI <aly@aaronly.me> | 2018-04-18 16:41:27 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2018-04-18 16:44:09 +0800 |
commit | 053cd1b7fe10f746792e0d1353fad4ad04e8ebe9 (patch) | |
tree | 93137af7af0b073383e0db5ae91cbe301f9bcdd1 /roles/git/files/git-shell-commands/create | |
parent | f448bcbdf07cf988ab50950df95d822f359041db (diff) | |
download | ansible-dfly-vps-053cd1b7fe10f746792e0d1353fad4ad04e8ebe9.tar.bz2 |
Add git role: host git repos and share repos via cgit
* Host git repositories
* Share git repositories through web interface via cgit
* The static resources used by cgit is also managed/deployed by a git repo ^_^
Diffstat (limited to 'roles/git/files/git-shell-commands/create')
-rw-r--r-- | roles/git/files/git-shell-commands/create | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/roles/git/files/git-shell-commands/create b/roles/git/files/git-shell-commands/create new file mode 100644 index 0000000..21cacc1 --- /dev/null +++ b/roles/git/files/git-shell-commands/create @@ -0,0 +1,42 @@ +#!/bin/sh +# +# ~/git-shell-commands/create +# +# An interactive command to create a new repository. The `.git` extension +# is automatically added if missing, in order to let `list` command find +# this repository. +# +# Credit: +# * Hosting an admin-friendly git server with git-shell +# http://planzero.org/blog/2012/10/24/hosting_an_admin-friendly_git_server_with_git-shell +# +# Aaron LI +# 2017-06-18 +# + +if [ $# -eq 0 ]; then + echo "Usage: create <project.git> [ description ]" + exit 1 +fi + +# Set the project name, adding `.git` extension if missing +project="${1%.[gG][iI][tT]}.git" +shift + +if [ -d "${HOME}/${project}" ]; then + echo "ERROR: repository '${project}' already exists!" + exit 2 +fi + +# Create and initialise the project +mkdir "${HOME}/${project}" && \ + cd "${HOME}/${project}" && \ + git --bare init + +description="$@" +if [ -n "${description}" ]; then + echo "${description}" > ${HOME}/${project}/description +fi + +echo "Created Git repository: ${project}" +echo "Description: $(cat ${HOME}/${project}/description)" |