Skip to content

Commit 0471f34

Browse files
committed
intercept and log ignored build scripts warning in prod
1 parent 3380148 commit 0471f34

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ pnpm_store_dir="/usr/.pnpm-store"
1212

1313
# Placeholder functions for plugin installation/uninstallation
1414
install() {
15-
true;
15+
true
1616
}
1717
uninstall() {
18-
true;
18+
true
1919
}
2020

2121
# Creates a backup of the global pnpm store directory
@@ -81,7 +81,7 @@ restore_pnpm_store() {
8181

8282
# Require 1.5x the backup size for safe extraction
8383
local required_space=$((backup_size + (backup_size / 2)))
84-
84+
8585
if [ "$dest_space" -lt "$required_space" ]; then
8686
echo "Error: Insufficient disk space in destination. Need at least $((required_space / 1024 / 1024))MB, have $((dest_space / 1024 / 1024))MB"
8787
return 1
@@ -91,7 +91,7 @@ restore_pnpm_store() {
9191
# Remove existing store directory if it exists and ensure its parent directory exists
9292
rm -rf "$pnpm_store_dir"
9393
mkdir -p "$(dirname "$pnpm_store_dir")"
94-
94+
9595
# Extract directly to final location
9696
if ! tar -xJf "$backup_file" -C "$(dirname "$pnpm_store_dir")" --preserve-permissions; then
9797
echo "Error: Failed to extract backup to final location."
@@ -102,6 +102,24 @@ restore_pnpm_store() {
102102
echo "pnpm store restored successfully."
103103
}
104104

105+
# Executes pnpm install with production dependencies and offline preference
106+
# Captures and logs build script warnings to a dedicated log file at /var/log/unraid-api/build-scripts.log
107+
# Args: none
108+
# Output: Streams install progress and logs build script warnings
109+
run_pnpm_install() {
110+
local log_file="/var/log/unraid-api/build-scripts.log"
111+
stdbuf -oL pnpm install --prod --prefer-offline 2>&1 | while IFS= read -r line; do
112+
if echo "$line" | grep -q "Ignored build scripts:"; then
113+
mkdir -p "$(dirname "$log_file")"
114+
echo "Note: The warning above is expected. Build scripts are intentionally ignored for security and performance reasons." > "$log_file"
115+
echo "$line" >> "$log_file"
116+
echo "Build scripts completed. See $log_file for details."
117+
else
118+
echo "$line"
119+
fi
120+
done
121+
}
122+
105123
# Installs production dependencies for the unraid-api using pnpm. Prefers offline mode.
106124
# Uses the api_base_directory variable or defaults to /usr/local/unraid-api
107125
# Returns:
@@ -123,10 +141,9 @@ pnpm_install_unraid_api() {
123141
echo "Executing 'pnpm install' in $unraid_api_dir"
124142
rm -rf /usr/local/unraid-api/node_modules
125143
# Run pnpm install in a subshell to prevent changing the current working directory of the script
126-
( cd "$unraid_api_dir" && pnpm install --prod --prefer-offline )
144+
(cd "$unraid_api_dir" && run_pnpm_install)
127145
}
128146

129-
130147
case "$1" in
131148
'install')
132149
install "$2"

0 commit comments

Comments
 (0)