Skip to content

Commit 1bbf39b

Browse files
BaukeZwartTRaSH-
andauthored
feat(downloaders): Add update check and notifications for the mover-tuner scripts (#2547)
* feat(downloaders): Add update check and notifications for the mover-tuner scripts Introduce update checking, version notification, and disable controls for mover-tuner start and end scripts; bump versions to 1.0.0 and adjust configuration with cache-mount support and updated log path New Features: Add automated version-check and notification functionality for both start and end mover-tuner scripts Add configuration update check for mover-tuning.cfg in the start script Allow disabling update checks via ENABLE_VERSION_CHECK setting Enhancements: Bump scripts and configuration to version 1.0.0 and set raw URLs for remote fetching Add cache-mount option to the qBittorrent resume command in the end script Update default LOG_PATH in the configuration file * fixed: Wrong line endings or no final newline * Move the version variable to top of the scripts Move the version variable to top of the scripts for easy edit. * Added information how to fix issues because of CRLF vs LF line endings --------- Co-authored-by: TRaSH <[email protected]>
1 parent 76afd3d commit 1bbf39b

File tree

4 files changed

+259
-31
lines changed

4 files changed

+259
-31
lines changed

docs/Downloaders/qBittorrent/Tips/How-to-run-the-unRaid-mover-for-qBittorrent.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,30 @@ chmod +x /mnt/user/appdata/qbt-mover/mover-tuning-start.sh
121121
chmod +x /mnt/user/appdata/qbt-mover/mover-tuning-end.sh
122122
```
123123

124+
#### Fixing Run Errors
125+
126+
After editing the scripts, make sure they use LF line endings (Unix format). If you edited the files on Windows, they may have CRLF line endings, which can cause errors.
127+
128+
Run the following command to convert all `.sh` files to the correct format:
129+
130+
```bash
131+
for file in *.sh; do [ -f "$file" ] && sed -i 's/\r$//' "$file" && echo "Converted $file"; done
132+
```
133+
134+
**How to use this command:**
135+
136+
1. Open the unRAID terminal
137+
2. Navigate to the directory containing your mover-tuning scripts:
138+
139+
```bash
140+
cd /mnt/user/appdata/qbt-mover/
141+
```
142+
143+
3. Paste the command above
144+
4. Press ++enter++
145+
146+
This converts all `.sh` files from CRLF (Windows line endings) to LF (Unix line endings) in the current directory.
147+
124148
---
125149

126150
### Mover Tuning Settings

includes/downloaders/mover-tuning-end.sh

Lines changed: 99 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ set -euo pipefail # Exit on error, undefined variables, and pipe failures
33

44
# =====================================
55
# Script: qBittorrent Cache Mover - End
6-
# Updated: 20251112
6+
# Version: 1.0.0
7+
# Updated: 20251121
78
# =====================================
89

10+
# Script version and update check URLs
11+
readonly SCRIPT_VERSION="1.0.0"
12+
readonly SCRIPT_RAW_URL="https://raw.githubusercontent.com/TRaSH-Guides/Guides/refs/heads/master/includes/downloaders/mover-tuning-end.sh"
13+
914
# Get the directory where the script is located
1015
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1116

@@ -39,6 +44,64 @@ notify() {
3944
fi
4045
}
4146

47+
# ================================
48+
# VERSION CHECK FUNCTION
49+
# ================================
50+
check_script_version() {
51+
log "Checking for script updates..."
52+
53+
# Check if version check is enabled
54+
if [[ "${ENABLE_VERSION_CHECK:-true}" != "true" ]]; then
55+
log "Version check disabled"
56+
return 0
57+
fi
58+
59+
# Check for curl or wget
60+
local fetch_cmd
61+
if command -v curl &> /dev/null; then
62+
fetch_cmd="curl -s"
63+
elif command -v wget &> /dev/null; then
64+
fetch_cmd="wget -qO-"
65+
else
66+
log "⚠ Cannot check version: curl or wget not found (continuing anyway)"
67+
return 0
68+
fi
69+
70+
# Fetch the latest version from the raw script URL
71+
local remote_content
72+
remote_content=$($fetch_cmd "$SCRIPT_RAW_URL" 2>/dev/null) || true
73+
74+
if [[ -z "$remote_content" ]]; then
75+
log "⚠ Could not fetch latest version from GitHub (continuing anyway)"
76+
return 0
77+
fi
78+
79+
# Extract version from the remote script
80+
local latest_version
81+
latest_version=$(echo "$remote_content" | grep -m1 "^readonly SCRIPT_VERSION=" | sed 's/readonly SCRIPT_VERSION="\(.*\)"/\1/' 2>/dev/null) || true
82+
83+
if [[ -z "$latest_version" ]]; then
84+
log "⚠ Could not parse version from remote script (continuing anyway)"
85+
return 0
86+
fi
87+
88+
log "Current version: $SCRIPT_VERSION"
89+
log "Latest version: $latest_version"
90+
91+
# Compare versions
92+
if [[ "$SCRIPT_VERSION" != "$latest_version" ]]; then
93+
# Simple version comparison (works for semantic versioning)
94+
if printf '%s\n' "$latest_version" "$SCRIPT_VERSION" | sort -V | head -n1 | grep -q "^$SCRIPT_VERSION$" 2>/dev/null || true; then
95+
log "⚠ New version available: $latest_version"
96+
notify "mover-tuning-end.sh Update" "Version $latest_version available (current: $SCRIPT_VERSION)<br><br>📖 Visit the TRaSH-Guides for the latest version"
97+
fi
98+
else
99+
log "✓ Script is up to date"
100+
fi
101+
102+
return 0
103+
}
104+
42105
# ================================
43106
# AUTO-INSTALLER FUNCTIONS
44107
# ================================
@@ -54,7 +117,7 @@ install_fclones_binary() {
54117
# Current installed version
55118
local CURRENT_VERSION=""
56119
if [[ -x "$FCLONES_BIN" ]]; then
57-
CURRENT_VERSION=$($FCLONES_BIN --version 2>/dev/null | awk '{print $2}')
120+
CURRENT_VERSION=$($FCLONES_BIN --version 2>/dev/null | awk '{print $2}') || true
58121
log "✓ Found fclones version $CURRENT_VERSION"
59122
else
60123
log "✗ fclones not found"
@@ -67,15 +130,15 @@ install_fclones_binary() {
67130
elif command -v wget >/dev/null 2>&1; then
68131
GITHUB_API_CMD="wget -qO- https://api.github.com/repos/pkolaczk/fclones/releases/latest"
69132
else
70-
log "✗ Neither curl nor wget is available"
71-
return 1
133+
log "✗ Neither curl nor wget is available (continuing anyway)"
134+
return 0
72135
fi
73136

74137
# Fetch latest release from GitHub
75138
local LATEST_VERSION
76-
LATEST_VERSION=$($GITHUB_API_CMD | grep -Po '"tag_name": "\K.*?(?=")')
139+
LATEST_VERSION=$($GITHUB_API_CMD 2>/dev/null | grep -Po '"tag_name": "\K.*?(?=")') || true
77140
if [[ -z "$LATEST_VERSION" ]]; then
78-
log "⚠ Could not fetch latest release, using default version $DEFAULT_VERSION"
141+
log "⚠ Could not fetch latest release, using default version $DEFAULT_VERSION (continuing anyway)"
79142
LATEST_VERSION="$DEFAULT_VERSION"
80143
else
81144
log "Latest fclones release: $LATEST_VERSION"
@@ -92,33 +155,36 @@ install_fclones_binary() {
92155
local VERSION_NO_V="${LATEST_VERSION#v}"
93156
local DOWNLOAD_URL="https://github.com/pkolaczk/fclones/releases/download/$LATEST_VERSION/fclones-$VERSION_NO_V-linux-glibc-x86_64.tar.gz"
94157

95-
wget -O "$TMP_DIR/fclones.tar.gz" "$DOWNLOAD_URL"
96-
if [[ $? -ne 0 ]]; then
97-
log "✗ Failed to download fclones from $DOWNLOAD_URL"
158+
if ! wget -O "$TMP_DIR/fclones.tar.gz" "$DOWNLOAD_URL" 2>/dev/null; then
159+
log "✗ Failed to download fclones from $DOWNLOAD_URL (continuing anyway)"
98160
rm -rf "$TMP_DIR"
99-
return 1
161+
return 0
162+
fi
163+
164+
if ! tar -xzf "$TMP_DIR/fclones.tar.gz" -C "$TMP_DIR" 2>/dev/null; then
165+
log "✗ Failed to extract fclones archive (continuing anyway)"
166+
rm -rf "$TMP_DIR"
167+
return 0
100168
fi
101169

102-
tar -xzf "$TMP_DIR/fclones.tar.gz" -C "$TMP_DIR"
103-
mkdir -p "$BOOT_DIR"
104-
cp "$TMP_DIR/usr/bin/fclones" "$BOOT_DIR/fclones"
105-
chmod +x "$BOOT_DIR/fclones"
170+
mkdir -p "$BOOT_DIR" || true
171+
cp "$TMP_DIR/usr/bin/fclones" "$BOOT_DIR/fclones" 2>/dev/null || true
172+
chmod +x "$BOOT_DIR/fclones" 2>/dev/null || true
106173

107174
# Copy to /usr/local/bin immediately
108-
cp "$BOOT_DIR/fclones" /usr/local/bin/fclones
109-
chmod +x /usr/local/bin/fclones
175+
cp "$BOOT_DIR/fclones" /usr/local/bin/fclones 2>/dev/null || true
176+
chmod +x /usr/local/bin/fclones 2>/dev/null || true
110177

111178
# Add boot-time copy and PATH setup if not already in /boot/config/go
112-
if ! grep -q "fclones boot-time setup" "$GO_FILE"; then
113-
if [ ! -w "$GO_FILE" ]; then
114-
log "✗ Cannot write to $GO_FILE. Please check permissions."
115-
rm -rf "$TMP_DIR"
116-
return 1
179+
if ! grep -q "fclones boot-time setup" "$GO_FILE" 2>/dev/null; then
180+
if [ -w "$GO_FILE" ]; then
181+
echo "" >> "$GO_FILE"
182+
echo "# fclones boot-time setup" >> "$GO_FILE"
183+
echo "export PATH=/usr/local/bin:\$PATH" >> "$GO_FILE"
184+
echo "cp $BOOT_DIR/fclones /usr/local/bin/fclones" >> "$GO_FILE"
185+
else
186+
log "⚠ Cannot write to $GO_FILE. Please check permissions. (continuing anyway)"
117187
fi
118-
echo "" >> "$GO_FILE"
119-
echo "# fclones boot-time setup" >> "$GO_FILE"
120-
echo "export PATH=/usr/local/bin:\$PATH" >> "$GO_FILE"
121-
echo "cp $BOOT_DIR/fclones /usr/local/bin/fclones" >> "$GO_FILE"
122188
fi
123189

124190
rm -rf "$TMP_DIR"
@@ -141,15 +207,15 @@ install_fclones_script() {
141207

142208
# Download script
143209
if command -v curl &> /dev/null; then
144-
curl -fsSL "$raw_script_url" -o "$script_path" || {
210+
if ! curl -fsSL "$raw_script_url" -o "$script_path" 2>/dev/null; then
145211
log "✗ Failed to download fclones.sh script"
146212
return 1
147-
}
213+
fi
148214
elif command -v wget &> /dev/null; then
149-
wget -q "$raw_script_url" -O "$script_path" || {
215+
if ! wget -q "$raw_script_url" -O "$script_path" 2>/dev/null; then
150216
log "✗ Failed to download fclones.sh script"
151217
return 1
152-
}
218+
fi
153219
else
154220
log "✗ Neither curl nor wget is available"
155221
return 1
@@ -180,7 +246,7 @@ check_and_install_fclones() {
180246
else
181247
# Check if update is needed
182248
if ! install_fclones_binary; then
183-
log "⚠ Failed to check/update fclones binary"
249+
log "⚠ Failed to check/update fclones binary (continuing anyway)"
184250
fi
185251
fi
186252

@@ -300,6 +366,9 @@ main() {
300366
log "Age range: $DAYS_FROM-$DAYS_TO days (from $date_str)"
301367
log "========================================"
302368

369+
# Check for script updates
370+
check_script_version
371+
303372
# Validate configuration
304373
validate_config || exit 1
305374

includes/downloaders/mover-tuning-start.sh

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ set -euo pipefail # Exit on error, undefined variables, and pipe failures
33

44
# =======================================
55
# Script: qBittorrent Cache Mover - Start
6-
# Updated: 20251112
6+
# Version: 1.0.0
7+
# Updated: 20251121
78
# =======================================
89

10+
# Script version and update check URLs
11+
readonly SCRIPT_VERSION="1.0.0"
12+
readonly SCRIPT_RAW_URL="https://raw.githubusercontent.com/TRaSH-Guides/Guides/refs/heads/master/includes/downloaders/mover-tuning-start.sh"
13+
readonly CONFIG_RAW_URL="https://raw.githubusercontent.com/TRaSH-Guides/Guides/refs/heads/master/includes/downloaders/mover-tuning.cfg"
14+
915
# Get the directory where the script is located
1016
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1117

@@ -51,6 +57,122 @@ set_ownership() {
5157
chown -R nobody:users "$1" 2>/dev/null || log "⚠ Warning: Could not set ownership for $1"
5258
}
5359

60+
# ================================
61+
# VERSION CHECK FUNCTION
62+
# ================================
63+
check_script_version() {
64+
log "Checking for script updates..."
65+
66+
# Check if version check is enabled
67+
if [[ "${ENABLE_VERSION_CHECK:-true}" != "true" ]]; then
68+
log "Version check disabled"
69+
return 0
70+
fi
71+
72+
# Check for curl or wget
73+
local fetch_cmd
74+
if command -v curl &> /dev/null; then
75+
fetch_cmd="curl -s"
76+
elif command -v wget &> /dev/null; then
77+
fetch_cmd="wget -qO-"
78+
else
79+
log "⚠ Cannot check version: curl or wget not found (continuing anyway)"
80+
return 0
81+
fi
82+
83+
# Fetch the latest version from the raw script URL
84+
local remote_content
85+
remote_content=$($fetch_cmd "$SCRIPT_RAW_URL" 2>/dev/null) || true
86+
87+
if [[ -z "$remote_content" ]]; then
88+
log "⚠ Could not fetch latest version from GitHub (continuing anyway)"
89+
return 0
90+
fi
91+
92+
# Extract version from the remote script
93+
local latest_version
94+
latest_version=$(echo "$remote_content" | grep -m1 "^readonly SCRIPT_VERSION=" | sed 's/readonly SCRIPT_VERSION="\(.*\)"/\1/' 2>/dev/null) || true
95+
96+
if [[ -z "$latest_version" ]]; then
97+
log "⚠ Could not parse version from remote script (continuing anyway)"
98+
return 0
99+
fi
100+
101+
log "Current version: $SCRIPT_VERSION"
102+
log "Latest version: $latest_version"
103+
104+
# Compare versions
105+
if [[ "$SCRIPT_VERSION" != "$latest_version" ]]; then
106+
# Simple version comparison (works for semantic versioning)
107+
if printf '%s\n' "$latest_version" "$SCRIPT_VERSION" | sort -V | head -n1 | grep -q "^$SCRIPT_VERSION$" 2>/dev/null || true; then
108+
log "⚠ New version available: $latest_version"
109+
notify "mover-tuning-start.sh Update" "Version $latest_version available (current: $SCRIPT_VERSION)<br><br>📖 Visit the TRaSH-Guides for the latest version"
110+
fi
111+
else
112+
log "✓ Script is up to date"
113+
fi
114+
115+
return 0
116+
}
117+
118+
check_config_version() {
119+
log "Checking for config file updates..."
120+
121+
# Check if version check is enabled
122+
if [[ "${ENABLE_VERSION_CHECK:-true}" != "true" ]]; then
123+
log "Config version check disabled"
124+
return 0
125+
fi
126+
127+
# Check for curl or wget
128+
local fetch_cmd
129+
if command -v curl &> /dev/null; then
130+
fetch_cmd="curl -s"
131+
elif command -v wget &> /dev/null; then
132+
fetch_cmd="wget -qO-"
133+
else
134+
log "⚠ Cannot check config version: curl or wget not found (continuing anyway)"
135+
return 0
136+
fi
137+
138+
# Fetch the latest config from GitHub
139+
local remote_config
140+
remote_config=$($fetch_cmd "$CONFIG_RAW_URL" 2>/dev/null) || true
141+
142+
if [[ -z "$remote_config" ]]; then
143+
log "⚠ Could not fetch latest config from GitHub (continuing anyway)"
144+
return 0
145+
fi
146+
147+
# Extract version from the remote config
148+
local remote_config_version
149+
remote_config_version=$(echo "$remote_config" | grep -m1 "^readonly CONFIG_VERSION=" | sed 's/readonly CONFIG_VERSION="\([^"]*\)".*/\1/' 2>/dev/null) || true
150+
151+
if [[ -z "$remote_config_version" ]]; then
152+
log "⚠ Could not parse version from remote config (continuing anyway)"
153+
return 0
154+
fi
155+
156+
# Get current config version (handle case where it might not be set)
157+
local current_config_version="${CONFIG_VERSION:-unknown}"
158+
159+
log "Current config version: $current_config_version"
160+
log "Latest config version: $remote_config_version"
161+
162+
# Compare versions
163+
if [[ "$current_config_version" != "$remote_config_version" ]]; then
164+
# Simple version comparison (works for semantic versioning)
165+
if printf '%s\n' "$remote_config_version" "$current_config_version" | sort -V | head -n1 | grep -q "^$current_config_version$" 2>/dev/null || true; then
166+
log "⚠ New config version available: $remote_config_version"
167+
notify "mover-tuning.cfg Update" "Config version <b>$remote_config_version</b> available<br>Current version: <b>$current_config_version</b><br><br>📖 Visit the TRaSH-Guides for the latest version"
168+
fi
169+
else
170+
log "✓ Config is up to date"
171+
fi
172+
173+
return 0
174+
}
175+
54176
# ================================
55177
# AUTO INSTALLER FUNCTION
56178
# ================================
@@ -203,6 +325,12 @@ main() {
203325
log "Date range: $DAYS_FROM-$DAYS_TO days (from $date_from)"
204326
log "========================================"
205327

328+
# Check for script updates
329+
check_script_version
330+
331+
# Check for config updates
332+
check_config_version
333+
206334
# Run auto installer if enabled
207335
[[ "$ENABLE_AUTO_INSTALLER" == true ]] && run_auto_installer
208336

includes/downloaders/mover-tuning.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# =============================================
2+
# <----- Update and version settings ----->
3+
# =============================================
4+
5+
readonly CONFIG_VERSION="1.0.0" # ONLY UPDATE THE VERSION NUMBER WHEN A CONFIGURATION FILE CHANGE HAS BEEN MADE
6+
readonly ENABLE_VERSION_CHECK=true # Set to false to disable all update checks and notifications (not recommended)
7+
18
# =============================================
29
# <----- mover-tuning start/end settings ----->
310
# =============================================

0 commit comments

Comments
 (0)