Skip to content

Commit

Permalink
fix(shellcheck): problems with env and script syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkarry committed Jul 23, 2024
1 parent 8be79b6 commit 4c84cfe
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
21 changes: 17 additions & 4 deletions dupe.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
#!/bin/bash

# Load environment variables from .env file
# Load environment variables from .env file if it exists
if [ -f ".env" ]; then
# in the same directory as this bash script

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENV_PATH="$SCRIPT_DIR/.env"
if [ -f "$ENV_PATH" ]; then
# shellcheck source=.env
source ".env"
echo "using .env file"
echo "Loading environment variables from $ENV_PATH file"
# shellcheck disable=SC1090 # shellcheck sucks
source "$ENV_PATH"
if [ $? -eq 0 ]; then
echo "Environment variables loaded successfully"
else
echo "Error loading environment variables" >&2
exit 1
fi
else
echo ".env file not found in script directory ($ENV_PATH)"
fi

# Variables
JDUPES_OUTPUT_LOG=${JDUPES_OUTPUT_LOG:-"/mnt/data/jdupes.log"}
JDUPES_SOURCE_DIR=${JDUPES_SOURCE_DIR:-"/mnt/data/media/"}
Expand Down
9 changes: 7 additions & 2 deletions merge_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import logging

# Setup logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)


def merge_directories(src, dst):
"""
Expand All @@ -12,7 +15,7 @@ def merge_directories(src, dst):
for item in os.listdir(src):
src_path = os.path.join(src, item)
dst_path = os.path.join(dst, item)

if os.path.isdir(src_path):
# If it's a directory, recurse into it
if not os.path.exists(dst_path):
Expand All @@ -28,6 +31,7 @@ def merge_directories(src, dst):
else:
logging.info(f"File skipped (already exists): {dst_path}")


def atomic_moves(source_directories, target_directory):
"""
Handles atomic moving from multiple source directories to a single target directory.
Expand All @@ -40,6 +44,7 @@ def atomic_moves(source_directories, target_directory):
except Exception as e:
logging.error(f"Error during moving process from {src}: {e}")


# Example use case (commented out for safety - remove "# " to uncomment):
# source_dirs = ['/mnt/data/media/tv-slade', '/mnt/data/media/tv-tmp']
# target_dir = '/mnt/data/media/tv'
Expand Down
19 changes: 17 additions & 2 deletions qbm-qbit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,23 @@ if ! command -v lockfile &>/dev/null; then
fi

# Load environment variables from .env file if it exists
if [ -f ".env" ]; then
source ".env"
# in the same directory as this bash script

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENV_PATH="$SCRIPT_DIR/.env"
if [ -f "$ENV_PATH" ]; then
# shellcheck source=.env
echo "Loading environment variables from $ENV_PATH file"
# shellcheck disable=SC1090 # shellcheck sucks
source "$ENV_PATH"
if [ $? -eq 0 ]; then
echo "Environment variables loaded successfully"
else
echo "Error loading environment variables" >&2
exit 1
fi
else
echo ".env file not found in script directory ($ENV_PATH)"
fi

# Use environment variables with descriptive default values
Expand Down
2 changes: 2 additions & 0 deletions xseed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ ENV_PATH="$SCRIPT_DIR/.env"
if [ -f "$ENV_PATH" ]; then
# shellcheck source=.env
echo "Loading environment variables from $ENV_PATH file"
# shellcheck disable=SC1090 # shellcheck sucks

source "$ENV_PATH"
if [ $? -eq 0 ]; then
echo "Environment variables loaded successfully"
Expand Down
22 changes: 17 additions & 5 deletions zfsburn.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
#!/bin/bash

# Load .env file
set -o allexport
if [ -f ".env" ]; then
# Load environment variables from .env file if it exists
# in the same directory as this bash script

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENV_PATH="$SCRIPT_DIR/.env"
if [ -f "$ENV_PATH" ]; then
# shellcheck source=.env
source ".env"
echo "Loading environment variables from $ENV_PATH file"
# shellcheck disable=SC1090 # shellcheck sucks
source "$ENV_PATH"
if [ $? -eq 0 ]; then
echo "Environment variables loaded successfully"
else
echo "Error loading environment variables" >&2
exit 1
fi
else
echo ".env file not found in script directory ($ENV_PATH)"
fi
set +o allexport0

VERBOSE=${VERBOSE:-1}
MAX_FREQ=${MAX_FREQ:-4}
Expand Down

0 comments on commit 4c84cfe

Please sign in to comment.