Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
37 changes: 31 additions & 6 deletions plugin/source/dynamix.unraid.net/install/doinst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,41 @@ 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

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

# makepkg appends generated symlink actions to this script when building the TXZ.
# Keep those actions after the cleanup above.
# 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 )
55 changes: 55 additions & 0 deletions plugin/tests/test-txz-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

set -euo pipefail

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

cleanup() {
rm -rf "$TEMP_ROOT"
}
trap cleanup EXIT

COMPONENT_DIR="$TEMP_ROOT/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components"
mkdir -p \
"$TEMP_ROOT/etc/rc.d/rc6.d" \
"$TEMP_ROOT/var/lib/pkgtools/packages" \
"$TEMP_ROOT/usr/local/bin" \
"$TEMP_ROOT/usr/local/sbin" \
"$TEMP_ROOT/usr/bin" \
"$TEMP_ROOT/usr/local/unraid-api/dist" \
"$COMPONENT_DIR/standalone"

touch \
"$TEMP_ROOT/usr/local/unraid-api/dist/cli.js" \
"$TEMP_ROOT/usr/local/unraid-api/dist/main.js"
printf '%s\n' production > "$TEMP_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"
cat > "$TEMP_ROOT/var/lib/pkgtools/packages/dynamix.unraid.net-test" <<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/
usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/standalone/current.js
EOF
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

(
cd "$TEMP_ROOT"
sh "$DOINST_SCRIPT"
)

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

if [ -e "$COMPONENT_DIR/standalone/old.js" ] || [ -e "$COMPONENT_DIR/.stale" ]; then
echo "Package file cleanup left stale components" >&2
exit 1
fi

echo "TXZ install cleanup test passed"
Loading