install, fix a few bugs, add aias for all names, and test the global source deletion.

This commit is contained in:
me committed 2026-09-21 18:41:15 -07:00
1 parent 50ae6a0f66
commit ccf6e69054
1 file changed
+42 -29
+42 -29
View File
@@ -8,7 +8,7 @@ DIR="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
PROJ="$(cd "$DIR"/.. &>/dev/null && pwd)" PROJ="$(cd "$DIR"/.. &>/dev/null && pwd)"
PROG="$(basename -- "${BASH_SOURCE[0]}")" PROG="$(basename -- "${BASH_SOURCE[0]}")"
LOCAL=~/bin LOCAL=~/bin
GLOBAL="$(npm prefix -g)" GLOBAL="/usr/local"
GLOBAL_BIN="$GLOBAL/bin" GLOBAL_BIN="$GLOBAL/bin"
GLOBAL_SRC="$GLOBAL/src" GLOBAL_SRC="$GLOBAL/src"
@@ -21,29 +21,32 @@ name_abs="weather-list"
function usage { function usage {
cat <<- EOF 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. Install $name_local to the system. Can be local, global, or removed.
Parameters) Parameters)
h) Display this message. h) Display this message.
g) Install globally ($GLOBAL), otherwise local ($LOCAL). g) Install globally ($GLOBAL), otherwise local ($LOCAL).
a) Abstract name, unrelated to being nomadic. ($name_abs) a) All names / pseudonyms, rather than choosing from below.
l) Long name, the full name of the project. ($name_long) 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) s) Short name, the full name of the project. ($name_short)
r) Remove / uninstall the project according to the above flags. r) Remove / uninstall the project according to the above flags.
Examples) Examples)
- Install to the local user with the abstract name. - Install to the local user with the default name.
$PROG $PROG
- Install to all users with all names. - Install to all users with all names.
$PROG -alsg $PROG -ga
- Remove all instances. - Remove all instances.
$PROG -alsr && $PROG -alsrg $PROG -ra && $PROG -gra
Happy weather watching! :) Happy weather watching! :)
~ Hyperling ~ Hyperling
https://git.hyperling.com/me/nomadic-weather
EOF EOF
exit $1 exit $1
} }
@@ -68,42 +71,47 @@ done
## Parameters ## ## Parameters ##
while getopts ":gslarh" arg; do while getopts ":gslabrh" arg; do
case $arg in case $arg in
g) global="Y" ;; g) global="Y" ;;
s) short="Y" ;; s) short="Y" ;;
l) long="Y" ;; l) long="Y" ;;
a) abstract="Y" ;; b) abstract="Y" ;;
a) all="Y" ;;
r) remove="Y" ;; r) remove="Y" ;;
h) usage ;; h) usage ;;
*) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;; *) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;;
esac esac
done done
## Processing ##
name="" name=""
if [[ "$short" == "Y" ]]; then if [[ "$all" == "Y" || "$abstract" == "Y" ]]; then
name="$name $name_short"
fi
if [[ "$long" == "Y" ]]; then
name="$name $name_long"
fi
if [[ "$abstract" == "Y" || ( -z "$short" && -z "$long" ) ]]; then
name="$name $name_abs" name="$name $name_abs"
fi 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="" cmd=""
dir="$LOCAL" dir="$LOCAL"
src="$PROJ" src="$PROJ"
if [[ "$global" == "Y" ]]; then if [[ "$global" == "Y" ]]; then
dir="$GLOBAL_BIN"
cmd="sudo" cmd="sudo"
dir="$GLOBAL_BIN"
src="$GLOBAL_SRC/`basename "$PROJ"`"
echo "Requesting sudo privileges... " echo "Requesting sudo privileges... "
sudo echo "Success!" sudo echo "Success!"
mkdir -pv /usr/local/src
sudo cp -Rv "$PROJ" "$GLOBAL_SRC"/
src="$GLOBAL_SRC/`basename "$PROJ"`"
fi fi
if [[ -z "$remove" ]]; then if [[ -z "$remove" ]]; then
@@ -114,15 +122,20 @@ fi
## Main ## ## Main ##
# Untested # Global Source Code: Install / Removal
#if [[ "$global" == "Y" && "$remove" == "Y" ]]; then if [[ "$global" == "Y" ]]; then
# sudo rm -rfv "$src" if [[ "$remove" == "Y" ]]; then
#fi 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 for prog in $name; do
# fix spaces to tabs if [[ ! -d "$dir" ]]; then
if [[ ! -d "$dir" ]]; then mkdir -pv "$dir"
mkdir -pv "$dir"
fi fi
$cmd "$dir/$prog" $cmd "$dir/$prog"
done done