Moved sdv-mods to its own repository.

in-use
Emily Frost 7 years ago
parent 4d7420f7b3
commit 71b2d1fd7b
No known key found for this signature in database
GPG Key ID: FD1FA524668FB1FA

@ -1,100 +0,0 @@
#!/bin/bash
# sdv-mods
### Manage Stardew Valley mods with nginx-style x-available and x-enabled folders.
game_dir="${HOME}/sdv-manager-test"
game_dir="${HOME}/.local/share/Steam/steamapps/common/Stardew Valley"
mods_available_dir="${game_dir}/mods-available"
mods_enabled_dir="${game_dir}/mods-enabled"
declare -A mod_state
function get_mod_state {
for available_mod_dir in "$mods_available_dir"/*; do
available_mod_name="$(basename "$available_mod_dir")"
mod_state[$available_mod_name]='disabled'
done
# TODO: Probably remove broken links and untracked files.
for enabled_mod_dir in "$mods_enabled_dir"/*; do
enabled_mod_name="$(basename "$enabled_mod_dir")"
if printf '%s\n' "${!mod_state[@]}" | grep -qx "${enabled_mod_name}"; then
mod_state[$enabled_mod_name]='enabled'
fi
done
}
function mod_is_available {
mod_name="$1"
get_mod_state
if [[ $mod_name == '' ]]; then
echo "Mod name not given."
return 1
elif printf '%s\n' "${!mod_state[@]}" | grep -qx "$mod_name"; then
return 0
else
return 1
fi
}
case "$1" in
'list')
# TODO: Make this printing prettier.
echo 'Listing available mods.'
get_mod_state
for mod in "${!mod_state[@]}"; do
echo "$mod --- ${mod_state[$mod]}"
done
;;
'install')
echo 'Implement install.'
# Check if $2 is an existing directory
# If it is, check if a mod with the same name is already installed.
# If not, copy the directory to mods-available
;;
'enable')
mod_name="$2"
if mod_is_available "$mod_name"; then
if [[ ${mod_state[$mod_name]} == 'disabled' ]]; then
echo "Enabling $mod_name."
ln -s "${mods_available_dir}/${mod_name}" "${mods_enabled_dir}/${mod_name}"
else
echo "Mod $mod_name is already enabled."
fi
fi
;;
'disable')
mod_name="$2"
if mod_is_available "$mod_name"; then
if [[ ${mod_state[$mod_name]} == 'enabled' ]]; then
echo "Disabling $mod_name."
rm "${mods_enabled_dir}/${mod_name}"
else
echo "Mod $mod_name is already disabled."
fi
fi
;;
'init')
# TODO: This needs to be a lot more careful. Cases to handle:
# sdv-manager is already set up
echo "Initializing sdv-manager at ${game_dir}."
SMAPI_mods_dir="${game_dir}/Mods"
mkdir -p "$mods_available_dir" "$mods_enabled_dir"
for mod_dir in "${SMAPI_mods_dir}"/*; do
mod_name="$(basename "$mod_dir")"
echo "$mod_dir"
echo "$mod_name"
mv "${mod_dir}" "$mods_available_dir"
ln -s "${mods_available_dir}/${mod_name}" "${mods_enabled_dir}"
done
rmdir "${SMAPI_mods_dir}"
ln -s "${game_dir}/mods-enabled" "${SMAPI_mods_dir}"
;;
*)
echo "$1 is not a recognized command."
echo "Available commands are enable, disable, install, and init."
;;
esac
Loading…
Cancel
Save