exit strategies
This commit is contained in:
54
core/dynr
54
core/dynr
@@ -1,19 +1,23 @@
|
||||
#!/bin/bash
|
||||
# -----------------------------------------------------------------------
|
||||
# Dynasty Revolution CLI Framework (dynr) - DYNAMIC CORE v2.3.3
|
||||
# Dynasty Revolution CLI Framework (dynr) - DYNAMIC CORE v2.3.4
|
||||
# Authors: Dynasty Revolution & SaavageBueno
|
||||
# -----------------------------------------------------------------------
|
||||
|
||||
VERSION="2.3.3"
|
||||
VERSION="2.3.4"
|
||||
BLUE='\033[38;5;45m'; PURPLE='\033[38;5;127m'; GOLD='\033[38;5;178m'; RED='\033[38;5;196m'; NC='\033[0m'
|
||||
REPO_RAW="https://git.dynastyrevolution.com/DYNR/DynastyRevolution-Scripts/raw/branch/main"
|
||||
MOD_DIR="/opt/dynr/modules"
|
||||
|
||||
# --- The Magic Loader ---
|
||||
load_and_run() {
|
||||
local mod=$1
|
||||
local remote="$REPO_RAW/modules/$mod"
|
||||
|
||||
# 1. Download if missing
|
||||
if [ ! -f "$MOD_DIR/$mod" ]; then
|
||||
echo -e "${GOLD}🐉 Seeking the '$mod' scroll in the archives...${NC}"
|
||||
# -f fails silently on 404 to allow custom error handling
|
||||
if curl -sSLf "$remote" -o "$MOD_DIR/$mod"; then
|
||||
chmod +x "$MOD_DIR/$mod"
|
||||
else
|
||||
@@ -21,45 +25,25 @@ load_and_run() {
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 2. Load the file
|
||||
source "$MOD_DIR/$mod"
|
||||
|
||||
# 3. Execute: run_<module_name> (Converts hyphens to underscores for Bash functions)
|
||||
# Example: 'system-info' becomes 'run_system_info'
|
||||
local func_name="run_${mod//-/_}"
|
||||
|
||||
if declare -f "$func_name" > /dev/null; then
|
||||
shift
|
||||
"$func_name" "$@"
|
||||
shift # Remove the module name from the argument list
|
||||
"$func_name" "$@" # Execute function with remaining args
|
||||
else
|
||||
echo -e "${RED}❌ Error: Function '$func_name' not defined in module '$mod'.${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
# --- Internal Router ---
|
||||
case "$1" in
|
||||
update)
|
||||
sudo curl -sSL "$REPO_RAW/core/dynr" -o /usr/local/bin/dynr
|
||||
sudo chmod +x /usr/local/bin/dynr
|
||||
echo -e "${GOLD}✨ Dynasty Core updated to v$VERSION.${NC}"
|
||||
;;
|
||||
refresh)
|
||||
if [ -z "$2" ]; then echo -e "${RED}Usage: dynr refresh <module-name>${NC}"
|
||||
else
|
||||
rm -f "$MOD_DIR/$2"
|
||||
load_and_run "$2"
|
||||
fi
|
||||
;;
|
||||
list)
|
||||
echo -e "${PURPLE}📜 Locally Manifested Scrolls:${NC}"
|
||||
ls "$MOD_DIR" 2>/dev/null | sed 's/^/ 🐉 /' || echo " (No modules yet)"
|
||||
;;
|
||||
purge)
|
||||
echo -e "${RED}🔥 Incinerate the Dynasty Framework? (y/n)${NC}"
|
||||
read -p "> " confirm
|
||||
[[ "$confirm" == "y" ]] && sudo rm -rf /opt/dynr /usr/local/bin/dynr && echo "Purged."
|
||||
;;
|
||||
*)
|
||||
if [ -z "$1" ]; then
|
||||
echo -e "${PURPLE}🐉 DYNASTY REVOLUTION DYNAMIC CLI v$VERSION${NC}"
|
||||
echo -e "Usage: ${BLUE}dynr <module-name>${NC}"
|
||||
echo -e "System: ${GOLD}update, refresh, list, purge${NC}"
|
||||
else
|
||||
load_and_run "$@"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
# Clean Exit Logic
|
||||
exit|quit)
|
||||
FAREWELLS=(
|
||||
"The
|
||||
Reference in New Issue
Block a user