From 306049abddcc0fb990fcd3a90545c7edcf5de1ec Mon Sep 17 00:00:00 2001 From: MasterDraco Date: Wed, 5 Mar 2025 09:47:29 +0000 Subject: [PATCH] Fix config directory handling in install script - Ensure CONFIG_DIR exists during installation - Create proper symlink from INSTALL_DIR/config.json to CONFIG_DIR/config.json - Use CONFIG_DIR instead of INSTALL_DIR for configuration files - Add code to move existing config file to CONFIG_DIR if needed This fixes the issue where the config.json file was not being created in /etc/transmission-rss-manager, even though the directory was created. --- modules/utils-module.sh | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/utils-module.sh b/modules/utils-module.sh index 3c59bdb..c40ad32 100644 --- a/modules/utils-module.sh +++ b/modules/utils-module.sh @@ -104,6 +104,26 @@ function finalize_setup() { mkdir -p "$INSTALL_DIR/logs" log "INFO" "Created logs directory: $INSTALL_DIR/logs" + # Ensure CONFIG_DIR exists + if [ ! -d "$CONFIG_DIR" ]; then + mkdir -p "$CONFIG_DIR" + log "INFO" "Created configuration directory: $CONFIG_DIR" + chown -R "$USER:$USER" "$CONFIG_DIR" + fi + + # Check if the config symlink exists, create it if not + if [ ! -L "$INSTALL_DIR/config.json" ] || [ ! -e "$INSTALL_DIR/config.json" ]; then + # If there's a real file at INSTALL_DIR/config.json (not a symlink), move it to CONFIG_DIR + if [ -f "$INSTALL_DIR/config.json" ] && [ ! -L "$INSTALL_DIR/config.json" ]; then + log "INFO" "Moving existing config.json to $CONFIG_DIR" + mv "$INSTALL_DIR/config.json" "$CONFIG_DIR/config.json" + fi + + # Create the symlink + ln -sf "$CONFIG_DIR/config.json" "$INSTALL_DIR/config.json" + log "INFO" "Created symlink from $INSTALL_DIR/config.json to $CONFIG_DIR/config.json" + fi + # Set proper ownership for the installation directory chown -R $USER:$USER $INSTALL_DIR @@ -124,7 +144,7 @@ function finalize_setup() { cd $INSTALL_DIR && npm install # Handle configuration file - if ! update_config_file "$INSTALL_DIR/config.json" "$IS_UPDATE"; then + if ! update_config_file "$CONFIG_DIR/config.json" "$IS_UPDATE"; then log "INFO" "Creating default configuration file..." # Create the users array content for JSON @@ -133,7 +153,10 @@ function finalize_setup() { USER_JSON="{ \"username\": \"${ADMIN_USERNAME}\", \"password\": \"${ADMIN_PASSWORD}\", \"role\": \"admin\" }" fi - cat > $INSTALL_DIR/config.json << EOF + # Make sure CONFIG_DIR exists + mkdir -p "$CONFIG_DIR" + + cat > $CONFIG_DIR/config.json << EOF { "version": "1.2.0", "transmissionConfig": { @@ -188,7 +211,12 @@ function finalize_setup() { "logLevel": "info" } EOF - chown $USER:$USER $INSTALL_DIR/config.json + # Set ownership for the config file + chown $USER:$USER $CONFIG_DIR/config.json + + # Ensure symlink exists from INSTALL_DIR to CONFIG_DIR + ln -sf "$CONFIG_DIR/config.json" "$INSTALL_DIR/config.json" + log "INFO" "Created symlink from $INSTALL_DIR/config.json to $CONFIG_DIR/config.json" log "INFO" "Default configuration created successfully" fi