Skip to content

Commit 71ce45b

Browse files
committed
New: add pre-commit hooks and CI improvements
- Add comprehensive pre-commit configuration - Trailing whitespace trimming - End-of-file fixing - Mixed line ending fixes (LF) - Executable shebangs validation - Private key detection - ShellCheck validation - Bash syntax checking - Update GitHub Actions workflow - Add bash syntax check step - Set ShellCheck severity to warning - Fix ShellCheck warnings in dupe.sh - SC2155: Separate declaration and assignment - Add shellcheck disable comments for intentional word splitting - Fix ShellCheck SC2207 in sonarr_dupefinder.sh - Make dupefinder scripts executable - Update jdupes command path to /usr/local/bin/jdupes - Add xseed.sh to .gitignore
1 parent 340fa91 commit 71ce45b

File tree

8 files changed

+55
-8
lines changed

8 files changed

+55
-8
lines changed

.github/workflows/shellcheck.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ jobs:
1313
- name: Install ShellCheck
1414
run: sudo apt-get install -y shellcheck
1515

16+
- name: Bash Syntax Check
17+
run: find . -type f -name "*.sh" -exec bash -n {} \;
18+
1619
- name: Run ShellCheck
17-
run: find . -type f -name "*.sh" -exec shellcheck {} +
20+
run: find . -type f -name "*.sh" -exec shellcheck --severity=warning {} +

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,4 @@ MigrationBackup/
351351

352352
# Ignore .env
353353
.env
354+
xseed.sh

.pre-commit-config.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
name: trim trailing whitespace
7+
- id: end-of-file-fixer
8+
name: fix end of files
9+
- id: check-added-large-files
10+
name: check for added large files
11+
- id: check-merge-conflict
12+
name: check for merge conflicts
13+
- id: detect-private-key
14+
name: detect private key
15+
- id: mixed-line-ending
16+
name: mixed line ending
17+
args: ['--fix=lf']
18+
- id: check-executables-have-shebangs
19+
name: check executables have shebangs
20+
- id: check-shebang-scripts-are-executable
21+
name: check shebang scripts are executable
22+
23+
- repo: https://github.com/shellcheck-py/shellcheck-py
24+
rev: v0.10.0.1
25+
hooks:
26+
- id: shellcheck
27+
name: shellcheck
28+
args: ['--severity=warning']
29+
exclude: '^\.env'
30+
31+
- repo: local
32+
hooks:
33+
- id: bash-syntax
34+
name: bash syntax check
35+
entry: bash -n
36+
language: system
37+
types: [shell]
38+
exclude: '^\.env'

.secrets.baseline

Whitespace-only changes.

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"hashdb",
44
"zfsburn"
55
]
6-
}
6+
}

dupe.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ JDUPES_OUTPUT_LOG=${JDUPES_OUTPUT_LOG:-"/mnt/data/jdupes.log"}
2424
JDUPES_SOURCE_DIR=${JDUPES_SOURCE_DIR:-"/mnt/data/media/"}
2525
JDUPES_DESTINATION_DIR=${JDUPES_DESTINATION_DIR:-"/mnt/data/torrents/"}
2626
JDUPES_HASH_DB=${JDUPES_HASH_DB:-"/.config/jdupes_hashdb"}
27-
JDUPES_COMMAND=${JDUPES_COMMAND:-"/usr/bin/jdupes"}
27+
JDUPES_COMMAND=${JDUPES_COMMAND:-"/usr/local/bin/jdupes"}
2828
JDUPES_EXCLUDE_DIRS=${JDUPES_EXCLUDE_DIRS:-"-X nostr:.RecycleBin -X nostr:.trash"}
2929
JDUPES_INCLUDE_EXT=${JDUPES_INCLUDE_EXT:-"mp4,mkv,avi"}
3030
DEBUG=${DEBUG:-"false"}
3131

3232
find_duplicates() {
3333
local log_file="$JDUPES_OUTPUT_LOG"
34-
local start_time=$(date +%s)
34+
local start_time
35+
start_time=$(date +%s)
3536
echo "[$(date +"%Y-%m-%d %H:%M:%S")] Duplicate search started" | tee -a "$log_file"
3637

3738
if [ "$DEBUG" == "true" ]; then
@@ -40,9 +41,11 @@ find_duplicates() {
4041
fi
4142

4243
local results
44+
# shellcheck disable=SC2086
4345
results=$("$JDUPES_COMMAND" $JDUPES_EXCLUDE_DIRS -X onlyext:"$JDUPES_INCLUDE_EXT" -r -M -y "$JDUPES_HASH_DB" "$JDUPES_SOURCE_DIR" "$JDUPES_DESTINATION_DIR")
4446

4547
if [[ $results != *"No duplicates found."* ]]; then
48+
# shellcheck disable=SC2086
4649
"$JDUPES_COMMAND" $JDUPES_EXCLUDE_DIRS -X onlyext:"$JDUPES_INCLUDE_EXT" -r -L -y "$JDUPES_HASH_DB" "$JDUPES_SOURCE_DIR" "$JDUPES_DESTINATION_DIR" >>"$log_file"
4750
fi
4851

@@ -51,7 +54,8 @@ find_duplicates() {
5154
fi
5255

5356
parse_jdupes_output "$results" "$log_file"
54-
local finish_time=$(date +%s)
57+
local finish_time
58+
finish_time=$(date +%s)
5559
local run_time=$((finish_time - start_time))
5660
echo "[$(date +"%Y-%m-%d %H:%M:%S")] Duplicate search completed in ${run_time}s" | tee -a "$log_file"
5761
}

radarr_dupefinder.sh

100644100755
File mode changed.

sonarr_dupefinder.sh

100644100755
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ directory=${1:-.} # Use provided directory or default to current directory
44

55
find "$directory" -type d | while read -r dir; do
66
# Extract all matching filenames in the directory
7-
files=($(find "$dir" -maxdepth 1 -type f -regextype posix-extended \
8-
\( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.avi" -o -iname "*.mov" -o -iname "*.wmv" -o -iname "*.flv" -o -iname "*.webm" -o -iname "*.mpg" -o -iname "*.mpeg" \) \
9-
-regex ".*\([0-9]{4}\).*S[0-9]{2}E([0-9]{2}).*" | sed -E 's/.*E([0-9]{2}).*/\1/'))
7+
# shellcheck disable=SC2207
8+
files=($(find "$dir" -maxdepth 1 -type f -regextype posix-extended \
9+
\( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.avi" -o -iname "*.mov" -o -iname "*.wmv" -o -iname "*.flv" -o -iname "*.webm" -o -iname "*.mpg" -o -iname "*.mpeg" \) \
10+
-regex ".*\([0-9]{4}\).*S[0-9]{2}E([0-9]{2}).*" | sed -E 's/.*E([0-9]{2}).*/\1/'))
1011

1112
# Count occurrences of each episode number
1213
declare -A ep_count

0 commit comments

Comments
 (0)