From ccf6e69054978ac8fa15ef2d3897f49c97c1147f Mon Sep 17 00:00:00 2001 From: Hyperling Date: Mon, 21 Sep 2026 18:41:15 -0700 Subject: [PATCH] install, fix a few bugs, add aias for all names, and test the global source deletion. --- cli/install.sh | 71 +++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/cli/install.sh b/cli/install.sh index fd1965b..1d20af6 100755 --- a/cli/install.sh +++ b/cli/install.sh @@ -8,7 +8,7 @@ DIR="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" PROJ="$(cd "$DIR"/.. &>/dev/null && pwd)" PROG="$(basename -- "${BASH_SOURCE[0]}")" LOCAL=~/bin -GLOBAL="$(npm prefix -g)" +GLOBAL="/usr/local" GLOBAL_BIN="$GLOBAL/bin" GLOBAL_SRC="$GLOBAL/src" @@ -21,29 +21,32 @@ name_abs="weather-list" function usage { cat <<- EOF - $PROG [-h] [-g] [a|l|s] [-r] + $PROG [-h] [-g] [a: b|l|s] [-r] Install $name_local to the system. Can be local, global, or removed. Parameters) h) Display this message. g) Install globally ($GLOBAL), otherwise local ($LOCAL). - a) Abstract name, unrelated to being nomadic. ($name_abs) - l) Long name, the full name of the project. ($name_long) + a) All names / pseudonyms, rather than choosing from below. + b) Basic name, unrelated to being nomadic. ($name_abs) + l) Long name, the full name of the project. ($name_long) [Default] s) Short name, the full name of the project. ($name_short) r) Remove / uninstall the project according to the above flags. Examples) - - Install to the local user with the abstract name. + - Install to the local user with the default name. $PROG - Install to all users with all names. - $PROG -alsg + $PROG -ga - Remove all instances. - $PROG -alsr && $PROG -alsrg + $PROG -ra && $PROG -gra Happy weather watching! :) ~ Hyperling + + https://git.hyperling.com/me/nomadic-weather EOF exit $1 } @@ -68,42 +71,47 @@ done ## Parameters ## -while getopts ":gslarh" arg; do +while getopts ":gslabrh" arg; do case $arg in g) global="Y" ;; s) short="Y" ;; l) long="Y" ;; - a) abstract="Y" ;; + b) abstract="Y" ;; + a) all="Y" ;; r) remove="Y" ;; h) usage ;; *) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;; esac done -## Processing ## - name="" -if [[ "$short" == "Y" ]]; then - name="$name $name_short" -fi -if [[ "$long" == "Y" ]]; then - name="$name $name_long" -fi -if [[ "$abstract" == "Y" || ( -z "$short" && -z "$long" ) ]]; then +if [[ "$all" == "Y" || "$abstract" == "Y" ]]; then name="$name $name_abs" fi +if [[ "$all" == "Y" || "$short" == "Y" ]]; then + name="$name $name_short" +fi +if [[ "$all" == "Y" || "$long" == "Y" || -z "$name" ]]; then + name="$name $name_long" +fi + +termux_check="/sdcard" +if [[ "$global" == "Y" && -e "$termux_check" ]]; then + echo "Detected $termux_check, assuming we are on Termux, global flag disabled." + global="N" +fi + +## Processing ## cmd="" dir="$LOCAL" src="$PROJ" if [[ "$global" == "Y" ]]; then - dir="$GLOBAL_BIN" cmd="sudo" + dir="$GLOBAL_BIN" + src="$GLOBAL_SRC/`basename "$PROJ"`" echo "Requesting sudo privileges... " sudo echo "Success!" - mkdir -pv /usr/local/src - sudo cp -Rv "$PROJ" "$GLOBAL_SRC"/ - src="$GLOBAL_SRC/`basename "$PROJ"`" fi if [[ -z "$remove" ]]; then @@ -114,15 +122,20 @@ fi ## Main ## -# Untested -#if [[ "$global" == "Y" && "$remove" == "Y" ]]; then -# sudo rm -rfv "$src" -#fi +# Global Source Code: Install / Removal +if [[ "$global" == "Y" ]]; then + if [[ "$remove" == "Y" ]]; then + sudo rm -rfv "$src" + else + mkdir -pv "$GLOBAL_SRC" + sudo cp -Rv "$PROJ" "$GLOBAL_SRC"/ + fi +fi +# Program: Install / Removal for prog in $name; do - # fix spaces to tabs - if [[ ! -d "$dir" ]]; then - mkdir -pv "$dir" + if [[ ! -d "$dir" ]]; then + mkdir -pv "$dir" fi $cmd "$dir/$prog" done