From 027c4d1bce99fc0666361a83762670bc0ef687da Mon Sep 17 00:00:00 2001 From: Louie S Date: Sat, 6 Jan 2024 15:23:01 -0500 Subject: Allow for specifying configuration location --- .gitignore | 3 ++- config.template/romlist.template | 2 ++ config/.gitignore | 4 ---- config/romlist.template | 2 -- config/systems/.example | 6 ------ config/systems/.gitignore | 3 --- rom-desktop-entry-generator.sh | 41 ++++++++++++++++++++++++++++++++++------ 7 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 config.template/romlist.template delete mode 100644 config/.gitignore delete mode 100644 config/romlist.template delete mode 100644 config/systems/.example delete mode 100644 config/systems/.gitignore diff --git a/.gitignore b/.gitignore index 86a2245..d650fe2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ * !.gitignore !rom-desktop-entry-generator.sh -!config +!config.template +!config.template/* diff --git a/config.template/romlist.template b/config.template/romlist.template new file mode 100644 index 0000000..15c5ee1 --- /dev/null +++ b/config.template/romlist.template @@ -0,0 +1,2 @@ +# Name of file should be romlist_[SYSTEM NAME] (i.e., romlist_nes) for each system +# "NAME" "PATH" "SYSTEM NAME" diff --git a/config/.gitignore b/config/.gitignore deleted file mode 100644 index c2b1351..0000000 --- a/config/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -* -!.gitignore -!romlist.template -!systems diff --git a/config/romlist.template b/config/romlist.template deleted file mode 100644 index 15c5ee1..0000000 --- a/config/romlist.template +++ /dev/null @@ -1,2 +0,0 @@ -# Name of file should be romlist_[SYSTEM NAME] (i.e., romlist_nes) for each system -# "NAME" "PATH" "SYSTEM NAME" diff --git a/config/systems/.example b/config/systems/.example deleted file mode 100644 index f1381e7..0000000 --- a/config/systems/.example +++ /dev/null @@ -1,6 +0,0 @@ -# This is an example system script -# It is a shell script which should define a launcher and optionally any flags -# Example for an nes system config: - -launcher="/usr/bin/nes" -flags="--fullscreen" diff --git a/config/systems/.gitignore b/config/systems/.gitignore deleted file mode 100644 index 19a8c43..0000000 --- a/config/systems/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -* -!.example -!.gitignore diff --git a/rom-desktop-entry-generator.sh b/rom-desktop-entry-generator.sh index e53976e..3c6d357 100755 --- a/rom-desktop-entry-generator.sh +++ b/rom-desktop-entry-generator.sh @@ -7,6 +7,7 @@ STDERR_LOG=/dev/stderr # BASEDIR is used to treat this script as a portable application BASEDIR="$(dirname "$0")" SCRIPTNAME="$(basename "$0" .sh)" +CONFIG_DIR="" DESKTOP_ENTRY_OUTPUT_DIR="$BASEDIR/output" DESKTOP_ENTRY_INSTALL_DIR="$HOME/.local/share/applications/$SCRIPTNAME" ICON_SOURCE_DIR="$BASEDIR/icon" @@ -87,10 +88,21 @@ clean_wrapper() { rmdir --ignore-fail-on-non-empty "$DESKTOP_ENTRY_OUTPUT_DIR" } +# checks for config location +# Usage: get_config_dir +get_config_dir() { + for path in "$HOME/.config/$SCRIPTNAME" "$HOME/.$SCRIPTNAME" "/etc/$SCRIPTNAME"; do + if [ -d "$path" ]; then + CONFIG_DIR="$path" + return + fi + done +} + # help message # Usage: help help() { - echo "Usage: $0 [OPTION]... [TARGET]..." >> "$STDERR_LOG" + echo "Usage: $0 [OPTION]... TARGET..." >> "$STDERR_LOG" echo "Generate desktop entries for video game roms" >> "$STDERR_LOG" echo >> "$STDERR_LOG" echo "Targets:" >> "$STDERR_LOG" @@ -100,8 +112,9 @@ help() { echo " uninstall uninstall desktop entries from $DESKTOP_ENTRY_INSTALL_DIR" >> "$STDERR_LOG" echo >> "$STDERR_LOG" echo "Options" >> "$STDERR_LOG" + echo " -c, --config specify a configuration directory (default is $HOME/.config/$SCRIPTNAME)" >> "$STDERR_LOG" echo " -h, --help print this help message and exit" >> "$STDERR_LOG" - echo " --icon-dir [DIR] specify an icon source directory (default is $ICON_SOURCE_DIR)" >> "$STDERR_LOG" + echo " -i, --icon-dir [DIR] specify an icon source directory (default is $ICON_SOURCE_DIR)" >> "$STDERR_LOG" echo " -q, --quiet do not print to stdout" >> "$STDERR_LOG" echo " -s, --system [SYSTEM] specify a system, or comma-separated list of systems. Default is all systems" >> "$STDERR_LOG" } @@ -158,7 +171,7 @@ install_wrapper() { } parse_config() { - CONFIG_PATH="$1" + CONFIG_DIR="$1" while read -r line; do # Skip comments and empty lines @@ -170,7 +183,7 @@ parse_config() { fi eval "build_desktop_file $line" - done < "$CONFIG_PATH" + done < "$CONFIG_DIR" } # Usage: uninstall_wrapper TARGET_SYSTEMS... @@ -196,7 +209,7 @@ uninstall_wrapper() { } # Read arguments -GETOPT=$(getopt -o 'hqs:' --long 'help,icon-dir:,quiet,system:' -n "$(basename "$0")" -- "$@") +GETOPT=$(getopt -o 'c:hi:qs:' --long 'config:,help,icon-dir:,quiet,system:' -n "$(basename "$0")" -- "$@") # Terminate if getopt goes wrong if [ $? -ne 0 ]; then @@ -209,11 +222,17 @@ unset GETOPT while true; do case "$1" in + '-c'|'--config') + shift + CONFIG_DIR="$1" + shift + continue + ;; '-h'|'--help') help exit ;; - '--icon-dir') + 'i'|'--icon-dir') shift ICON_SOURCE_DIR="$1" shift @@ -240,6 +259,16 @@ while true; do esac done +# Set CONFIG_DIR if not already set by flags +if [ -z "$CONFIG_DIR" ]; then + get_config_dir +fi +# Check that CONFIG_DIR is real +if [ ! -d "$CONFIG_DIR" ]; then + echo "Error: could not load configuration at '$CONFIG_DIR'; directory does not exist" >> "$STDERR_LOG" + exit 1 +fi + # By default, build, but do not install if [ -z "$1" ]; then build_wrapper -- cgit