#!/bin/sh # Copyright Zach Smith, MIT (See LICENSE-MIT) # adds my other script paths (except volsv) SSH_BASE_URL="git@git.zachir.xyz:zachir/" HTTP_BASE_URL="https://git.zachir.xyz/" SCRIPT_DIRS="$(cat << 'EOF' generics scripts shortcmds sp volsv EOF )" UPDATE="" 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" printf " -U) updates the repos rather than clones\n" } while getopts "cdhsSu:U" 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) SSH_BASE_URL="$OPTARG" HTTP_BASE_URL="$OPTARG" ;; U) UPDATE="y" ;; *) printhelp ;; esac done update_dir () { if [ ! -d "$1" ]; then printf "%s does not exist; please clone first.\n" "$1" elif [ -f "$1" ]; then printf "%s already exists, but not as a dir; cannot update.\n" "$1" else printf "Updating %s...\n" "$1" cd "$1" git pull cd .. fi } 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 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 -r i; do [ -z "$i" ] && continue if [ "$UPDATE" = "y" ]; then update_dir "$i" else clone_dir "$i" "$___USE_SSH" fi done