Skip to content

Commit 1d3413b

Browse files
committed
fix: rc.unraid-api now cleans up older dependencies
1 parent 574d572 commit 1d3413b

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

plugin/source/dynamix.unraid.net/etc/rc.d/rc.unraid-api

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,23 @@ case "$1" in
111111
;;
112112
'ensure')
113113
if [ -x "$scripts_dir/dependencies.sh" ]; then
114+
# First clean up old dependencies
115+
"$scripts_dir/dependencies.sh" cleanup
116+
# Then ensure new dependencies are installed
114117
"$scripts_dir/dependencies.sh" ensure "$2"
115118
else
116119
echo "Error: dependencies.sh script not found or not executable"
117120
exit 1
118121
fi
119122
;;
123+
'cleanup-dependencies')
124+
if [ -x "$scripts_dir/dependencies.sh" ]; then
125+
"$scripts_dir/dependencies.sh" cleanup
126+
else
127+
echo "Error: dependencies.sh script not found or not executable"
128+
exit 1
129+
fi
130+
;;
120131
'archive-dependencies')
121132
if [ -x "$scripts_dir/dependencies.sh" ]; then
122133
"$scripts_dir/dependencies.sh" archive

plugin/source/dynamix.unraid.net/usr/local/share/dynamix.unraid.net/scripts/dependencies.sh

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,54 @@ source "${SCRIPT_DIR}/api_utils.sh"
1010
# Default paths
1111
DEPENDENCIES_DIR="/usr/local/unraid-api/node_modules"
1212

13+
# Function to cleanup old dependency archives
14+
# Removes all node_modules archives except the one for the current API version
15+
cleanup() {
16+
local info
17+
local api_version=""
18+
local vendor_store_path=""
19+
local vendor_dir=""
20+
local current_archive=""
21+
22+
# Get archive information
23+
if ! mapfile -t info < <(get_archive_information); then
24+
echo "Error: Failed to get vendor archive information. Cannot proceed with cleanup." >&2
25+
return 1
26+
fi
27+
28+
api_version="${info[0]}"
29+
vendor_store_path="${info[2]}"
30+
31+
echo "Cleaning up node_modules archives that don't match current API version: $api_version"
32+
33+
# Extract the directory path from the full vendor_store_path
34+
vendor_dir="$(dirname "$vendor_store_path")"
35+
36+
# Extract the filename from the full vendor_store_path - this is our current archive
37+
current_archive="$(basename "$vendor_store_path")"
38+
39+
# Check if vendor directory exists
40+
if [ ! -d "$vendor_dir" ]; then
41+
echo "Vendor directory $vendor_dir does not exist. Nothing to clean up."
42+
return 0
43+
fi
44+
45+
echo "Current archive to keep: $current_archive"
46+
47+
# Find and remove all node_modules archives except the current one
48+
find "$vendor_dir" -name "node_modules-for-*.tar.xz" | while read -r archive; do
49+
if [ "$(basename "$archive")" != "$current_archive" ]; then
50+
echo "Removing archive: $archive"
51+
rm -f "$archive"
52+
else
53+
echo "Keeping current archive: $archive"
54+
fi
55+
done
56+
57+
echo "Cleanup completed."
58+
return 0
59+
}
60+
1361
# Function to attempt redownload of vendor archive if missing
1462
# Args:
1563
# $1 - Path to vendor archive to download (ignored, kept for backward compatibility)
@@ -228,6 +276,10 @@ case "$1" in
228276
ensure "$2"
229277
exit $?
230278
;;
279+
'cleanup')
280+
cleanup
281+
exit $?
282+
;;
231283
'redownload')
232284
# The path argument is ignored but kept for backward compatibility
233285
if downloaded_archive=$(redownload_vendor_archive) && [ -n "$downloaded_archive" ]; then
@@ -239,7 +291,7 @@ case "$1" in
239291
fi
240292
;;
241293
*)
242-
echo "Usage: $0 {restore|archive|ensure|redownload}"
294+
echo "Usage: $0 {restore|archive|ensure|cleanup|redownload}"
243295
exit 1
244296
;;
245297
esac

0 commit comments

Comments
 (0)