From 2ea131a96d5257be855070c91442f435d3cc1429 Mon Sep 17 00:00:00 2001 From: ZachIR Date: Wed, 10 Sep 2025 06:43:34 -0500 Subject: Add update function to install.sh --- install.sh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'install.sh') diff --git a/install.sh b/install.sh index 197ea0d..3ab3271 100755 --- a/install.sh +++ b/install.sh @@ -15,15 +15,18 @@ 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:" o; do case "${o}" in +while getopts "cdhsSu:U" o; do case "${o}" in c) unset SCRIPT_DIRS ;; d) [ -n "$SCRIPT_DIRS" ] && SCRIPT_DIRS="$SCRIPT_DIRS\n$OPTARG" @@ -35,9 +38,23 @@ while getopts "cdhsSu:" o; do case "${o}" in 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" @@ -56,5 +73,9 @@ clone_dir () { echo "$SCRIPT_DIRS" | while read -r i; do [ -z "$i" ] && continue - clone_dir "$i" "$___USE_SSH" + if [ "$UPDATE" = "y" ]; then + update_dir "$i" + else + clone_dir "$i" "$___USE_SSH" + fi done -- cgit v1.2.3