Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
"env:validate": "test -f .env || (echo 'Error: .env file missing. Run npm run env:init first' && exit 1)",
"env:clean": "rm -f .env",
"// Testing": "",
"test": "vitest && pnpm run test:extractor && pnpm run test:shell-detection",
"test": "vitest && pnpm run test:extractor && pnpm run test:shell-detection && pnpm run test:txz-install",
"test:extractor": "bash ./tests/test-extractor.sh",
"test:shell-detection": "bash ./tests/test-shell-detection.sh"
"test:shell-detection": "bash ./tests/test-shell-detection.sh",
"test:txz-install": "bash ./tests/test-txz-install.sh"
},
"devDependencies": {
"http-server": "14.1.1",
Expand Down
41 changes: 28 additions & 13 deletions plugin/source/dynamix.unraid.net/install/doinst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,31 @@ ln -sf ../local/bin/unraid-api usr/bin/unraid-api
backup_file_if_exists usr/local/unraid-api/.env
cp usr/local/unraid-api/.env.production usr/local/unraid-api/.env

# auto-generated actions from makepkg:
( cd usr/local/bin ; rm -rf corepack )
( cd usr/local/bin ; ln -sf ../lib/node_modules/corepack/dist/corepack.js corepack )
( cd usr/local/bin ; rm -rf npm )
( cd usr/local/bin ; ln -sf ../lib/node_modules/npm/bin/npm-cli.js npm )
( cd usr/local/bin ; rm -rf npx )
( cd usr/local/bin ; ln -sf ../lib/node_modules/npm/bin/npx-cli.js npx )
( cd usr/local/bin ; rm -rf corepack )
( cd usr/local/bin ; ln -sf ../lib/node_modules/corepack/dist/corepack.js corepack )
( cd usr/local/bin ; rm -rf npm )
( cd usr/local/bin ; ln -sf ../lib/node_modules/npm/bin/npm-cli.js npm )
( cd usr/local/bin ; rm -rf npx )
( cd usr/local/bin ; ln -sf ../lib/node_modules/npm/bin/npx-cli.js npx )
remove_stale_component_files() {
component_dir="usr/local/emhttp/plugins/dynamix.my.servers/unraid-components"
[ -d "$component_dir" ] || return 0

package_db=""
for candidate in var/lib/pkgtools/packages/dynamix.unraid.net-* var/log/packages/dynamix.unraid.net-*; do
if [ -f "$candidate" ]; then
package_db="$candidate"
break
fi
done

if [ -z "$package_db" ]; then
echo "Warning: Cannot find the installed package file list; keeping component files"
return 0
fi

find "$component_dir" -type f -print | while IFS= read -r file; do
if ! grep -Fqx "$file" "$package_db"; then
echo "Removing stale component file: $file"
rm -f "$file"
fi
done

find "$component_dir" -depth -type d -empty -delete 2>/dev/null || true
}

remove_stale_component_files
106 changes: 106 additions & 0 deletions plugin/tests/test-txz-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOINST_SCRIPT="$SCRIPT_DIR/../source/dynamix.unraid.net/install/doinst.sh"

prepare_root() {
local root="$1"
local component_dir="$root/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components"

mkdir -p \
"$root/etc/rc.d/rc6.d" \
"$root/var/lib/pkgtools/packages" \
"$root/var/log/packages" \
"$root/usr/local/bin" \
"$root/usr/local/sbin" \
"$root/usr/bin" \
"$root/usr/local/unraid-api/dist" \
"$component_dir/standalone"

touch \
"$root/usr/local/unraid-api/dist/cli.js" \
"$root/usr/local/unraid-api/dist/main.js"
printf '%s\n' production > "$root/usr/local/unraid-api/.env.production"
printf '%s\n' current > "$component_dir/standalone/current.js"
printf '%s\n' stale > "$component_dir/standalone/old.js"
printf '%s\n' stale > "$component_dir/.stale"
}

write_manifest() {
local manifest_path="$1"
local current_file="$2"
local stale_file="${3:-}"

cat > "$manifest_path" <<EOF
PACKAGE NAME: dynamix.unraid.net-test
FILE LIST:
./
usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/
usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/standalone/
$current_file
$stale_file
EOF
}

run_case() {
local case_name="$1"
local manifest_location="$2"
local root
local component_dir

root="$(mktemp -d)"
component_dir="$root/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components"
prepare_root "$root"
Comment thread
coderabbitai[bot] marked this conversation as resolved.

case "$manifest_location" in
primary)
write_manifest \
"$root/var/lib/pkgtools/packages/dynamix.unraid.net-primary" \
"usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/standalone/current.js"
write_manifest \
"$root/var/log/packages/dynamix.unraid.net-legacy" \
"usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/standalone/old.js"
;;
legacy)
write_manifest \
"$root/var/log/packages/dynamix.unraid.net-legacy" \
"usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/standalone/current.js"
;;
none)
;;
*)
echo "Unknown manifest location: $manifest_location" >&2
exit 1
;;
esac

(
cd "$root"
sh "$DOINST_SCRIPT"
)

if [ ! -f "$component_dir/standalone/current.js" ]; then
echo "$case_name removed a current component" >&2
exit 1
fi

if [ "$manifest_location" = "none" ]; then
if [ ! -f "$component_dir/standalone/old.js" ] || [ ! -f "$component_dir/.stale" ]; then
echo "$case_name deleted files without a package manifest" >&2
exit 1
fi
elif [ -e "$component_dir/standalone/old.js" ] || [ -e "$component_dir/.stale" ]; then
echo "$case_name left stale components" >&2
exit 1
fi

rm -rf "$root"
echo "$case_name passed"
}

run_case "Primary manifest" primary
run_case "Legacy manifest fallback" legacy
run_case "Missing manifest fail-open" none
echo "TXZ install cleanup tests passed"
Loading