Skip to content

Commit 3c1b797

Browse files
committed
chore: fix shellcheck and other errors
1 parent 0427c14 commit 3c1b797

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

plugin/docs/migration/progress.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,23 @@ This document tracks our progress in migrating the Unraid plugin to a native Sla
9595
- DNS resolution checks are unnecessary and should be removed from the plugin file
9696
- Plugin staging conflict check is outdated and no longer needed
9797
- Full SlackBuild script is not necessary since we're not compiling code; direct use of `makepkg` is simpler
98-
- Version compatibility checks should remain in the plugin file since they need to run before installation
98+
- Version compatibility checks should remain in the plugin file since they need to run before installation
99+
100+
## Recent Improvements
101+
- Enhanced Firefox configuration in file_patches.sh:
102+
- Replaced hardcoded Firefox profile path with dynamic profile detection
103+
- Added fallback handling when Firefox profile cannot be found
104+
- Improved user feedback with status messages about configuration changes
105+
- Made the script more resilient to Firefox profile directory changes in future Unraid versions
106+
- Improved POSIX and shellcheck compliance in cleanup.sh:
107+
- Fixed SC2046 warning in process termination code by properly handling pidof with no results
108+
- Improved ps/grep/kill pattern to safely handle cases with no matching processes
109+
- Prevented non-zero exit codes during cleanup process to ensure smooth uninstallation
110+
- Enhanced reliability of the script in edge cases like when no processes are running
111+
- Fixed base64 encoding to prevent line wrapping in HTTP POST data by piping through tr -d '\n'
112+
113+
## Bug Fixes
114+
- Fixed malformed sed pattern in cleanup.sh:
115+
- Changed `sed -i '#robots.txt any origin/d'` to use standard slash delimiters
116+
- Replaced with `sed -i '/#robots.txt any origin/d'` to correctly match and delete the pattern
117+
- This ensures the robots.txt origin line is properly removed from rc.nginx during cleanup

plugin/source/dynamix.unraid.net/install/scripts/file_patches.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if grep -q "SAMEORIGIN" "${FILE}" >/dev/null 2>&1; then
88
cp "$FILE" "$FILE-"
99
OLD="add_header X-Frame-Options 'SAMEORIGIN';"
1010
NEW="add_header Content-Security-Policy \"frame-ancestors 'self' https://connect.myunraid.net/\";"
11-
sed -i "s#${OLD}#${NEW}#" "${FILE}"
11+
sed -i "s/${OLD}/${NEW}/" "${FILE}"
1212
NGINX_CHANGED=1
1313
fi
1414

@@ -43,13 +43,22 @@ if [ -f "${FILE}" ] && grep -q "top.Shadowbox" "${FILE}" >/dev/null 2>&1; then
4343
fi
4444

4545
# Relax restrictions on built-in Firefox
46-
FILE=/usr/share/mozilla/firefox/9n35r0i1.default/user.js
47-
if [ -f "$FILE" ]; then
48-
cp -f "$FILE" "$FILE-"
49-
# Append settings if they don't exist
50-
grep -q "privacy.firstparty.isolate" "$FILE" || echo 'user_pref("privacy.firstparty.isolate", false);' >> "$FILE"
51-
grep -q "javascript.options.asmjs" "$FILE" || echo 'user_pref("javascript.options.asmjs", true);' >> "$FILE"
52-
grep -q "javascript.options.wasm" "$FILE" || echo 'user_pref("javascript.options.wasm", true);' >> "$FILE"
46+
FIREFOX_DIR=/usr/share/mozilla/firefox
47+
# Find the default profile directory (may change in future versions)
48+
PROFILE_DIR=$(find "$FIREFOX_DIR" -name "*.default" -type d 2>/dev/null | head -n 1)
49+
50+
if [ -z "$PROFILE_DIR" ]; then
51+
echo "Firefox default profile directory not found, skipping Firefox configuration"
52+
else
53+
FILE="$PROFILE_DIR/user.js"
54+
if [ -f "$FILE" ]; then
55+
cp -f "$FILE" "$FILE-"
56+
# Append settings if they don't exist
57+
grep -q "privacy.firstparty.isolate" "$FILE" || echo 'user_pref("privacy.firstparty.isolate", false);' >> "$FILE"
58+
grep -q "javascript.options.asmjs" "$FILE" || echo 'user_pref("javascript.options.asmjs", true);' >> "$FILE"
59+
grep -q "javascript.options.wasm" "$FILE" || echo 'user_pref("javascript.options.wasm", true);' >> "$FILE"
60+
echo "Updated Firefox preferences in $FILE"
61+
fi
5362
fi
5463

5564
# Move settings on flash drive

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ perform_connect_cleanup() {
100100
regfile=$(grep "regFILE" "/var/local/emhttp/var.ini" | cut -d= -f2)
101101
if [ -n "$regfile" ] && [ -f "$regfile" ]; then
102102
# Base64 encode the key file and send to server
103-
encoded_key=$(base64 "$regfile")
103+
encoded_key=$(base64 "$regfile" | tr -d '\n')
104104
if [ -n "$encoded_key" ]; then
105105
curl -s -X POST "https://keys.lime-technology.com/account/server/unregister" \
106106
-d "keyfile=$encoded_key" >/dev/null 2>&1
@@ -132,9 +132,11 @@ perform_full_cleanup() {
132132
# Stop newer clients
133133
unraid-api stop
134134
# Kill any processes
135-
kill -9 $(pidof unraid-api) >/dev/null 2>&1
135+
pid_list=$(pidof unraid-api 2>/dev/null) || true
136+
[ -n "$pid_list" ] && kill -9 $pid_list
136137
# Find all PIDs referencing main.js and kill them
137-
ps aux | grep "node /usr/local/unraid-api/dist/main.js" | grep -v grep | awk '{print $2}' | xargs -r kill -9
138+
node_pids=$(pgrep -f "node /usr/local/unraid-api/dist/main.js" 2>/dev/null) || true
139+
[ -n "$node_pids" ] && echo "$node_pids" | xargs kill -9
138140
# Clean up files
139141
rm -rf /usr/local/unraid-api
140142
rm -rf /var/run/unraid-api.sock
@@ -173,7 +175,7 @@ perform_full_cleanup() {
173175
# Clean up our optional makestate modifications in rc.nginx (on 6.9 and 6.10.0-rc[12])
174176
sed -i '/scripts\/makestate/d' /etc/rc.d/rc.nginx
175177
# Clean up extra origin for robots.txt
176-
sed -i '#robots.txt any origin/d' /etc/rc.d/rc.nginx
178+
sed -i '/#robots.txt any origin/d' /etc/rc.d/rc.nginx
177179

178180
# Clean up temporary flag file
179181
rm -f /tmp/restore-files-dynamix-unraid-net

0 commit comments

Comments
 (0)