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)"
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