Fix syntax errors in utils-module.sh

Fixed multiple syntax errors in utils-module.sh:
- Replaced compound commands with  syntax with clearer if statements
- This addresses issues with bash syntax in older versions of bash
- Improved error handling with explicit 2 checks

💡 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
MasterDraco 2025-03-07 11:43:28 +00:00
parent 3aee416cda
commit 5a1318bbf2

View File

@ -104,19 +104,21 @@ function ensure_npm_packages() {
# First ensure the installation directory exists
if [ ! -d "$install_dir" ]; then
log "INFO" "Creating installation directory: $install_dir"
mkdir -p "$install_dir" || {
mkdir -p "$install_dir"
if [ $? -ne 0 ]; then
log "ERROR" "Failed to create installation directory: $install_dir"
return 1
}
}
fi
fi
# Ensure data directory exists
if [ ! -d "$install_dir/data" ]; then
log "INFO" "Creating data directory: $install_dir/data"
mkdir -p "$install_dir/data" || {
mkdir -p "$install_dir/data"
if [ $? -ne 0 ]; then
log "ERROR" "Failed to create data directory: $install_dir/data"
return 1
}
fi
# Initialize empty data files
echo "[]" > "$install_dir/data/rss-feeds.json"
@ -127,10 +129,11 @@ function ensure_npm_packages() {
# Ensure package.json exists in the installation directory
if [ ! -f "$install_dir/package.json" ]; then
log "INFO" "Copying package.json to installation directory..."
cp "$SCRIPT_DIR/package.json" "$install_dir/package.json" || {
cp "$SCRIPT_DIR/package.json" "$install_dir/package.json"
if [ $? -ne 0 ]; then
log "ERROR" "Failed to copy package.json to installation directory"
return 1
}
fi
fi
# Install NPM packages if not already installed or if it's an update
@ -141,16 +144,18 @@ function ensure_npm_packages() {
local current_dir=$(pwd)
# Change to install directory and install packages
cd "$install_dir" || {
cd "$install_dir"
if [ $? -ne 0 ]; then
log "ERROR" "Failed to change to installation directory: $install_dir"
return 1
}
fi
npm install || {
npm install
if [ $? -ne 0 ]; then
log "ERROR" "NPM installation failed in $install_dir"
cd "$current_dir" # Return to original directory
return 1
}
fi
# Return to original directory
cd "$current_dir"