aboutsummaryrefslogtreecommitdiff
path: root/repo.sh
blob: eb7db2f0d8763cfd90ad3a824d627de2aef496ef (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
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
set -e

repo_location="/srv/git/"

trimmed_repos=""
get_repos () {
    trimmed_repos=()
    repos=$(ssh marks.kitchen "ls -d $repo_location*.git")
    for repo in $repos 
    do
        repo_trim=$(basename $repo | cut -f 1 -d '.')
        trimmed_repos+="$repo_trim "
    done
}

create_repo () {
    dir="$repo_location$1.git"
    ssh git@marks.kitchen "mkdir $dir"
    ssh git@marks.kitchen "cd \"$dir\"; git init --bare; touch git-daemon-export-ok"
}

case $1 in 
    create) # init a git repo here and create one on the server
        create_repo $2
        dir="$repo_location$2.git"
        printf "git init\n"
        printf "git remote add origin git@marks.kitchen:/srv/git/$dir\n"
        printf "git push origin master\n"
        ;;
    list) # list repos on the server
        get_repos
        for repo in $trimmed_repos
        do
            printf "$repo\n"
        done
        ;;
    clone) # clone a repo from the list
        dir="$repo_location$2.git"
        git clone git@marks.kitchen:/srv/git/$dir
        cd $dir
        ;;
    *)
        printf "usage: ./repo [create|list|clone] args\n"
        ;;
esac