aboutsummaryrefslogtreecommitdiffstats
path: root/roles/git/files/git-shell-commands/make-public
blob: f1dfb1d291fd2581b7f5e981aad182593c1bfbcf (plain)
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
#!/bin/sh
#
# Copyright (c) 2017 Aaron LI <aly@aaronly.me>
# MIT License
#
# Make an existing Git repository public by linking it into
# `repos.public`, which is exported via `cgit`.
#
# 2017-06-19
#

. ${HOME}/vars.conf

if [ $# -ne 1 ]; then
    echo "usage: make-public <repository.git>"
    exit 1
fi

if [ ! -e "${PUBLIC}" ]; then
    echo "ERROR: public directory '${PUBLIC}' not exists!"
    exit 1
fi

project="${1%.[gG][iI][tT]}.git"

if [ ! -d "${project}" ]; then
    echo "ERROR: repository '${project}' not exists!"
    exit 3
elif [ -L "${PUBLIC}/${project}" ]; then
    echo "Repository '${project}' already made public."
    exit 0
else
    ln -sv ../${project} ${PUBLIC}/${project}
    echo "Made repository '${project}' public."
    exit 0
fi