feat: prevent the same mod from being installed multiple times (#14)

* prevent the same mod from being installed multiple times

* use flag instead of variable for exit check
This commit is contained in:
Luca Saalfeld
2025-02-05 15:59:00 +01:00
committed by GitHub
parent 9f622ca130
commit a2b904caa2
+11
View File
@@ -63,9 +63,13 @@ function get_mod_name_and_index() {
fi fi
if [[ -z "$entry" || -z "$mod_index" || -z "$mod_name" ]]; then if [[ -z "$entry" || -z "$mod_index" || -z "$mod_name" ]]; then
if [[ "$1" == "--do-not-exit" ]]; then
mod_index=-1
else
echo -e "${RED}Error${NC}: Mod not found." >&2 echo -e "${RED}Error${NC}: Mod not found." >&2
exit 1 exit 1
fi fi
fi
status=$(echo "$entry" | awk -F, '{print $2}') status=$(echo "$entry" | awk -F, '{print $2}')
} }
@@ -662,6 +666,13 @@ function mod_install() {
# verify minimum information required # verify minimum information required
[[ -z "$mod_name" || ${#mod_files[@]} -eq 0 ]] && { echo -e "${RED}Error${NC}: Mod name and files are required." >&2; exit 1; } [[ -z "$mod_name" || ${#mod_files[@]} -eq 0 ]] && { echo -e "${RED}Error${NC}: Mod name and files are required." >&2; exit 1; }
get_mod_name_and_index "--do-not-exit" "$mod_name" "$do_not_exit"
if [[ $mod_index -ne -1 ]]; then
echo -e "${RED}Error${NC}: The mod '$mod_name' is already installed.";
exit 1;
fi
# verify mod files exist # verify mod files exist
for file in "${mod_files[@]}"; do for file in "${mod_files[@]}"; do
[[ ! -f "$file" ]] && { echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2; exit 1; } [[ ! -f "$file" ]] && { echo -e "${RED}Error${NC}: Mod file $file does not exist." >&2; exit 1; }