Skip to content

Commit eb4c07a

Browse files
zakkarrybakerboy448
authored andcommitted
fix(shellcheck): problems with env and script syntax
1 parent 7cc2160 commit eb4c07a

File tree

9 files changed

+79
-42
lines changed

9 files changed

+79
-42
lines changed

backup_config.sh

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,18 @@ EXCLUDE_PATTERNS=(
2020
'--exclude=plexmediaserver/*'
2121
)
2222

23-
# Create the archive in /tmp
24-
tar -czvf "$TEMP_BACKUP_DIR/$ARCHIVE_NAME" "${EXCLUDE_PATTERNS[@]}" -C "$SOURCE_DIR" . > "$LOG_FILE" 2>&1
23+
# Create the archive in /tmp and check if the archive was created successfully
24+
if tar -czvf "$TEMP_BACKUP_DIR/$ARCHIVE_NAME" "${EXCLUDE_PATTERNS[@]}" -C "$SOURCE_DIR" . >"$LOG_FILE" 2>&1; then
25+
echo "Archive created successfully: $TEMP_BACKUP_DIR/$ARCHIVE_NAME" >>"$LOG_FILE"
2526

26-
# Check if the archive was created successfully
27-
if [[ $? -eq 0 ]]; then
28-
echo "Archive created successfully: $TEMP_BACKUP_DIR/$ARCHIVE_NAME" >> "$LOG_FILE"
29-
3027
# Sync the archive to the remote backup directory
31-
rsync -av "$TEMP_BACKUP_DIR/$ARCHIVE_NAME" "$REMOTE_BACKUP_DIR" >> "$LOG_FILE" 2>&1
32-
33-
if [[ $? -eq 0 ]]; then
34-
echo "Backup synced successfully: $REMOTE_BACKUP_DIR/$ARCHIVE_NAME" >> "$LOG_FILE"
28+
if rsync -av "$TEMP_BACKUP_DIR/$ARCHIVE_NAME" "$REMOTE_BACKUP_DIR" >>"$LOG_FILE" 2>&1; then
29+
echo "Backup synced successfully: $REMOTE_BACKUP_DIR/$ARCHIVE_NAME" >>"$LOG_FILE"
3530
# Optionally, remove the local archive after successful sync
3631
rm "$TEMP_BACKUP_DIR/$ARCHIVE_NAME"
3732
else
38-
echo "Failed to sync the backup to the remote server" >> "$LOG_FILE"
33+
echo "Failed to sync the backup to the remote server" >>"$LOG_FILE"
3934
fi
4035
else
41-
echo "Failed to create the archive" >> "$LOG_FILE"
36+
echo "Failed to create the archive" >>"$LOG_FILE"
4237
fi

dupe.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
#!/bin/bash
22

3-
# Load environment variables from .env file
43
# Load environment variables from .env file if it exists
5-
if [ -f ".env" ]; then
4+
# in the same directory as this bash script
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
ENV_PATH="$SCRIPT_DIR/.env"
8+
if [ -f "$ENV_PATH" ]; then
69
# shellcheck source=.env
7-
source ".env"
8-
echo "using .env file"
10+
echo "Loading environment variables from $ENV_PATH file"
11+
# shellcheck disable=SC1090 # shellcheck sucks
12+
if source "$ENV_PATH"; then
13+
echo "Environment variables loaded successfully"
14+
else
15+
echo "Error loading environment variables" >&2
16+
exit 1
17+
fi
18+
else
19+
echo ".env file not found in script directory ($ENV_PATH)"
920
fi
21+
1022
# Variables
1123
JDUPES_OUTPUT_LOG=${JDUPES_OUTPUT_LOG:-"/mnt/data/jdupes.log"}
1224
JDUPES_SOURCE_DIR=${JDUPES_SOURCE_DIR:-"/mnt/data/media/"}

f2b-dump.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ temp_file=$(mktemp)
55

66
# Function to add content to the temporary file
77
add_content() {
8+
# shellcheck disable=SC2129
89
echo -e "\n$1\n" >>"$temp_file"
910
cat "$2" >>"$temp_file" 2>/dev/null
1011
echo -e "\n" >>"$temp_file"
@@ -34,7 +35,7 @@ done
3435

3536
# Upload to termbin
3637
echo "Uploading to Termbin..." >>"$temp_file"
37-
cat "$temp_file" | nc termbin.com 9999
38+
nc termbin.com 9999 <"$temp_file"
3839

3940
# Cleanup
4041
rm "$temp_file"

merge_folders.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import logging
44

55
# Setup logging
6-
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
6+
logging.basicConfig(
7+
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
8+
)
9+
710

811
def merge_directories(src, dst):
912
"""
@@ -12,7 +15,7 @@ def merge_directories(src, dst):
1215
for item in os.listdir(src):
1316
src_path = os.path.join(src, item)
1417
dst_path = os.path.join(dst, item)
15-
18+
1619
if os.path.isdir(src_path):
1720
# If it's a directory, recurse into it
1821
if not os.path.exists(dst_path):
@@ -28,6 +31,7 @@ def merge_directories(src, dst):
2831
else:
2932
logging.info(f"File skipped (already exists): {dst_path}")
3033

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

47+
4348
# Example use case (commented out for safety - remove "# " to uncomment):
4449
# source_dirs = ['/mnt/data/media/tv-slade', '/mnt/data/media/tv-tmp']
4550
# target_dir = '/mnt/data/media/tv'

pic-update.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ CURRENT_UID=$(id -u)
1616
# Check if Plex-Image-Cleanup is installed and the current user owns it
1717
check_pic_installation() {
1818
if [ -d "$PIC_PATH" ]; then
19-
local pic_repo_owner=$(stat -c '%u' "$PIC_PATH")
19+
local pic_repo_owner
20+
pic_repo_owner=$(stat -c '%u' "$PIC_PATH")
2021
if [ "$pic_repo_owner" != "$CURRENT_UID" ]; then
2122
echo "You do not own the Plex-Image-Cleanup repo. Please run this script as the user that owns the repo [$pic_repo_owner]."
2223
exit 1

qbm-qbit.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,22 @@ if ! command -v lockfile &>/dev/null; then
77
fi
88

99
# Load environment variables from .env file if it exists
10-
if [ -f ".env" ]; then
11-
source ".env"
10+
# in the same directory as this bash script
11+
12+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13+
ENV_PATH="$SCRIPT_DIR/.env"
14+
if [ -f "$ENV_PATH" ]; then
15+
# shellcheck source=.env
16+
echo "Loading environment variables from $ENV_PATH file"
17+
# shellcheck disable=SC1090 # shellcheck sucks
18+
if source "$ENV_PATH"; then
19+
echo "Environment variables loaded successfully"
20+
else
21+
echo "Error loading environment variables" >&2
22+
exit 1
23+
fi
24+
else
25+
echo ".env file not found in script directory ($ENV_PATH)"
1226
fi
1327

1428
# Use environment variables with descriptive default values

xseed.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ ENV_PATH="$SCRIPT_DIR/.env"
1414
if [ -f "$ENV_PATH" ]; then
1515
# shellcheck source=.env
1616
echo "Loading environment variables from $ENV_PATH file"
17-
source "$ENV_PATH"
18-
if [ $? -eq 0 ]; then
17+
# shellcheck disable=SC1090 # shellcheck sucks
18+
if source "$ENV_PATH"; then
1919
echo "Environment variables loaded successfully"
2020
else
2121
echo "Error loading environment variables" >&2
@@ -31,6 +31,7 @@ USENET_CLIENT_NAME=${USENET_CLIENT_NAME:-SABnzbd}
3131
XSEED_HOST=${XSEED_HOST:-crossseed}
3232
XSEED_PORT=${XSEED_PORT:-8080}
3333
LOG_FILE=${LOG_FILE:-/config/xseed.log}
34+
# shellcheck disable=SC2269
3435
XSEED_APIKEY=${XSEED_APIKEY}
3536

3637
# Function to log messages

xseed_qbit_cat_filter.sh

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ FILTERED_CAT="CAT1|CAT2|CAT3"
2929
# Ex) tracker.announce.com|tracker.announce2.com
3030
FILTERED_TRACKER="tracker1.announce.com|tracker2.announce.com"
3131

32-
3332
log() {
3433
echo -e "${0##*/}: $1"
3534
}
@@ -39,13 +38,13 @@ log_err() {
3938
}
4039

4140
cross_seed_request() {
42-
local data="$1"
43-
local headers=(-X POST "$XSEED_URL" --data-urlencode "$data")
44-
if [ -n "$XSEED_API_KEY" ]; then
45-
headers+=(-H "X-Api-Key: $XSEED_API_KEY")
46-
fi
47-
response=$(curl --silent --output /dev/null --write-out "%{http_code}" "${headers[@]}")
48-
echo "$response"
41+
local data="$1"
42+
local headers=(-X POST "$XSEED_URL" --data-urlencode "$data")
43+
if [ -n "$XSEED_API_KEY" ]; then
44+
headers+=(-H "X-Api-Key: $XSEED_API_KEY")
45+
fi
46+
response=$(curl --silent --output /dev/null --write-out "%{http_code}" "${headers[@]}")
47+
echo "$response"
4948
}
5049

5150
if [[ -z "$TORRENT_PATH" ]]; then
@@ -56,14 +55,12 @@ elif [[ -z "$TORRENT_CAT" ]]; then
5655
log_err "Category not specified for $TORRENT_PATH"
5756
fi
5857

59-
60-
6158
if [[ -n "$FILTERED_CAT" ]] && [[ "$TORRENT_CAT" =~ ^($FILTERED_CAT)$ ]]; then
6259
log "[\033[1m$TORRENT_NAME\033[0m] [$TORRENT_CAT]"
63-
xseed_resp=$(cross_seed_request "infoHash=$TORRENT_INFOHASH");
64-
[ "$xseed_resp" != "204" ] && sleep 30 && xseed_resp=$(cross_seed_request "path=$TORRENT_PATH")
60+
xseed_resp=$(cross_seed_request "infoHash=$TORRENT_INFOHASH")
61+
[ "$xseed_resp" != "204" ] && sleep 30 && xseed_resp=$(cross_seed_request "path=$TORRENT_PATH")
6562
elif [[ -n "$FILTERED_TRACKER" ]] && [[ "$TORRENT_TRACKER" =~ ($FILTERED_TRACKER) ]]; then
6663
log "[\033[1m$TORRENT_NAME\033[0m] [$TORRENT_TRACKER]"
67-
xseed_resp=$(cross_seed_request "infoHash=$TORRENT_INFOHASH");
64+
xseed_resp=$(cross_seed_request "infoHash=$TORRENT_INFOHASH")
6865
[ "$xseed_resp" != "204" ] && sleep 30 && xseed_resp=$(cross_seed_request "path=$TORRENT_PATH")
6966
fi

zfsburn.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
#!/bin/bash
22

3-
# Load .env file
4-
set -o allexport
5-
if [ -f ".env" ]; then
3+
# Load environment variables from .env file if it exists
4+
# in the same directory as this bash script
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
ENV_PATH="$SCRIPT_DIR/.env"
8+
if [ -f "$ENV_PATH" ]; then
69
# shellcheck source=.env
7-
source ".env"
10+
echo "Loading environment variables from $ENV_PATH file"
11+
# shellcheck disable=SC1090 # shellcheck sucks
12+
if source "$ENV_PATH"; then
13+
echo "Environment variables loaded successfully"
14+
else
15+
echo "Error loading environment variables" >&2
16+
exit 1
17+
fi
18+
else
19+
echo ".env file not found in script directory ($ENV_PATH)"
820
fi
9-
set +o allexport0
1021

1122
VERBOSE=${VERBOSE:-1}
1223
MAX_FREQ=${MAX_FREQ:-4}

0 commit comments

Comments
 (0)