summaryrefslogtreecommitdiff
path: root/install.sh
blob: f5b6f61762b39318d8ca3c5d03f8207e30cf8576 (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
48
49
50
51
52
53
54
#!/bin/sh

# adds my other script paths (except volsv)

SSH_BASE_URL="git@git.zachir.xyz:zachir/"
HTTP_BASE_URL="https://git.zachir.xyz/"

SCRIPT_DIRS="$(<<EOF
generics
scripts
shortcmds
sp
EOF


printhelp () {
  printf "install.sh | Used to add my other script repos as submodules. Feel free to modfy it to clone yours as well.\n"
  printf "  -s) clone repos using ssh\n"
  printf "  -S) clone repos using https\n"
  printf "  -h) prints this help message\n"
  printf "  -u X )  will clone using X as the URL\n"
}

while getopts "cdhsSu:" o; do case "${o}" in
  c) unset SCRIPT_DIRS ;;
  d)
    [ -n "$SCRIPT_DIRS" ] && SCRIPT_DIRS="$SCRIPT_DIRS\n$OPTARG"
    [ -z "$SCRIPT_DIRS" ] && SCRIPT_DIRS="$OPTARG"
    ;;
  s) ___USE_SSH=y ;;
  S) unset ___USE_SSH ;;
  u) URL="$OPTARG" ;;
  *) printhelp ;;
esac done

clone_dir () {
  if [ -d "$1" ]; then
    printf "%s already exists as dir; not adding.\n" "$1"
  elif [ -f "$1" ]; then
    printf "%s already exists, but not as a dir; not adding.\n" "$1"
  else
    if [ -n "$2" ]; then
      printf "Cloning %s %s using ssh; will be read-write\nNote: only my ssh key will clone it\n" "$1"
      git clone "$SSH_BASE_URL$1.git" "$1"
    else
      printf "Cloning %s using http; will be read-only\n" "$1"
      git clone "$HTTP_BASE_URL$1.git" "$1"
    fi
  fi
}

echo "$SCRIPT_DIRS" | while read i; do
  clone_dir "$i"  "$___USE_SSH"
done