Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add(ci): shellcheck and syntax/error fixes #13

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: ShellCheck

on: [push, pull_request]

jobs:
shellcheck:
name: Run ShellCheck
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install ShellCheck
run: sudo apt-get install -y shellcheck

- name: Run ShellCheck
run: find . -type f -name "*.sh" -exec shellcheck {} +
19 changes: 7 additions & 12 deletions backup_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@ EXCLUDE_PATTERNS=(
'--exclude=plexmediaserver/*'
)

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

# Check if the archive was created successfully
if [[ $? -eq 0 ]]; then
echo "Archive created successfully: $TEMP_BACKUP_DIR/$ARCHIVE_NAME" >> "$LOG_FILE"

# Sync the archive to the remote backup directory
rsync -av "$TEMP_BACKUP_DIR/$ARCHIVE_NAME" "$REMOTE_BACKUP_DIR" >> "$LOG_FILE" 2>&1

if [[ $? -eq 0 ]]; then
echo "Backup synced successfully: $REMOTE_BACKUP_DIR/$ARCHIVE_NAME" >> "$LOG_FILE"
if rsync -av "$TEMP_BACKUP_DIR/$ARCHIVE_NAME" "$REMOTE_BACKUP_DIR" >>"$LOG_FILE" 2>&1; then
echo "Backup synced successfully: $REMOTE_BACKUP_DIR/$ARCHIVE_NAME" >>"$LOG_FILE"
# Optionally, remove the local archive after successful sync
rm "$TEMP_BACKUP_DIR/$ARCHIVE_NAME"
else
echo "Failed to sync the backup to the remote server" >> "$LOG_FILE"
echo "Failed to sync the backup to the remote server" >>"$LOG_FILE"
fi
else
echo "Failed to create the archive" >> "$LOG_FILE"
echo "Failed to create the archive" >>"$LOG_FILE"
fi
20 changes: 16 additions & 4 deletions dupe.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
#!/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
if source "$ENV_PATH"; 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
3 changes: 2 additions & 1 deletion f2b-dump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ temp_file=$(mktemp)

# Function to add content to the temporary file
add_content() {
# shellcheck disable=SC2129
echo -e "\n$1\n" >>"$temp_file"
cat "$2" >>"$temp_file" 2>/dev/null
echo -e "\n" >>"$temp_file"
Expand Down Expand Up @@ -34,7 +35,7 @@ done

# Upload to termbin
echo "Uploading to Termbin..." >>"$temp_file"
cat "$temp_file" | nc termbin.com 9999
nc termbin.com 9999 <"$temp_file"

# Cleanup
rm "$temp_file"
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
3 changes: 2 additions & 1 deletion pic-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ CURRENT_UID=$(id -u)
# Check if Plex-Image-Cleanup is installed and the current user owns it
check_pic_installation() {
if [ -d "$PIC_PATH" ]; then
local pic_repo_owner=$(stat -c '%u' "$PIC_PATH")
local pic_repo_owner
pic_repo_owner=$(stat -c '%u' "$PIC_PATH")
if [ "$pic_repo_owner" != "$CURRENT_UID" ]; then
echo "You do not own the Plex-Image-Cleanup repo. Please run this script as the user that owns the repo [$pic_repo_owner]."
exit 1
Expand Down
18 changes: 16 additions & 2 deletions qbm-qbit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,22 @@ 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
if source "$ENV_PATH"; 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
5 changes: 3 additions & 2 deletions xseed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ ENV_PATH="$SCRIPT_DIR/.env"
if [ -f "$ENV_PATH" ]; then
# shellcheck source=.env
echo "Loading environment variables from $ENV_PATH file"
source "$ENV_PATH"
if [ $? -eq 0 ]; then
# shellcheck disable=SC1090 # shellcheck sucks
if source "$ENV_PATH"; then
echo "Environment variables loaded successfully"
else
echo "Error loading environment variables" >&2
Expand All @@ -31,6 +31,7 @@ USENET_CLIENT_NAME=${USENET_CLIENT_NAME:-SABnzbd}
XSEED_HOST=${XSEED_HOST:-crossseed}
XSEED_PORT=${XSEED_PORT:-8080}
LOG_FILE=${LOG_FILE:-/config/xseed.log}
# shellcheck disable=SC2269
XSEED_APIKEY=${XSEED_APIKEY}

# Function to log messages
Expand Down
23 changes: 10 additions & 13 deletions xseed_qbit_cat_filter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ FILTERED_CAT="CAT1|CAT2|CAT3"
# Ex) tracker.announce.com|tracker.announce2.com
FILTERED_TRACKER="tracker1.announce.com|tracker2.announce.com"


log() {
echo -e "${0##*/}: $1"
}
Expand All @@ -39,13 +38,13 @@ log_err() {
}

cross_seed_request() {
local data="$1"
local headers=(-X POST "$XSEED_URL" --data-urlencode "$data")
if [ -n "$XSEED_API_KEY" ]; then
headers+=(-H "X-Api-Key: $XSEED_API_KEY")
fi
response=$(curl --silent --output /dev/null --write-out "%{http_code}" "${headers[@]}")
echo "$response"
local data="$1"
local headers=(-X POST "$XSEED_URL" --data-urlencode "$data")
if [ -n "$XSEED_API_KEY" ]; then
headers+=(-H "X-Api-Key: $XSEED_API_KEY")
fi
response=$(curl --silent --output /dev/null --write-out "%{http_code}" "${headers[@]}")
echo "$response"
}

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



if [[ -n "$FILTERED_CAT" ]] && [[ "$TORRENT_CAT" =~ ^($FILTERED_CAT)$ ]]; then
log "[\033[1m$TORRENT_NAME\033[0m] [$TORRENT_CAT]"
xseed_resp=$(cross_seed_request "infoHash=$TORRENT_INFOHASH");
[ "$xseed_resp" != "204" ] && sleep 30 && xseed_resp=$(cross_seed_request "path=$TORRENT_PATH")
xseed_resp=$(cross_seed_request "infoHash=$TORRENT_INFOHASH")
[ "$xseed_resp" != "204" ] && sleep 30 && xseed_resp=$(cross_seed_request "path=$TORRENT_PATH")
elif [[ -n "$FILTERED_TRACKER" ]] && [[ "$TORRENT_TRACKER" =~ ($FILTERED_TRACKER) ]]; then
log "[\033[1m$TORRENT_NAME\033[0m] [$TORRENT_TRACKER]"
xseed_resp=$(cross_seed_request "infoHash=$TORRENT_INFOHASH");
xseed_resp=$(cross_seed_request "infoHash=$TORRENT_INFOHASH")
[ "$xseed_resp" != "204" ] && sleep 30 && xseed_resp=$(cross_seed_request "path=$TORRENT_PATH")
fi
21 changes: 16 additions & 5 deletions zfsburn.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#!/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
if source "$ENV_PATH"; 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