Skip to content

Commit fa21403

Browse files
authored
Merge pull request #2613 from Squidly271/patch-12
Fix: Handle CRLF in syslinux and grub configs
2 parents bec8f0b + 6d809b8 commit fa21403

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

emhttp/plugins/dynamix/scripts/manage_boot_params.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ parse_append_line() {
263263

264264
# Extract append line for specific label
265265
# Matches from "label $label" to the next "label" or end of file
266-
awk -v label="$label" '
266+
# Normalize CRLF to LF for parsing (DOS-edited syslinux.cfg)
267+
tr -d '\r' < "$cfg_file" | awk -v label="$label" '
267268
BEGIN { label=tolower(label) }
268269
/^label / {
269270
line=tolower($0)
@@ -278,7 +279,7 @@ parse_append_line() {
278279
print
279280
exit
280281
}
281-
' "$cfg_file"
282+
'
282283
}
283284

284285
#############################################
@@ -288,7 +289,8 @@ parse_grub_linux_args() {
288289
local label="$1"
289290
local cfg_file="${2:-$GRUB_CFG}"
290291

291-
awk -v label="$label" '
292+
# Normalize CRLF to LF for parsing (DOS-edited grub.cfg)
293+
tr -d '\r' < "$cfg_file" | awk -v label="$label" '
292294
$0 ~ /^menuentry / {
293295
in_section = (index($0, "\"" label "\"") > 0 || index($0, "\x27" label "\x27") > 0)
294296
}
@@ -303,7 +305,7 @@ parse_grub_linux_args() {
303305
}
304306
exit
305307
}
306-
' "$cfg_file"
308+
'
307309
}
308310

309311
#############################################
@@ -349,7 +351,7 @@ extract_grub_timeout() {
349351
local cfg_file="${1:-$GRUB_CFG}"
350352

351353
if [[ -f "$cfg_file" ]]; then
352-
grep "^set timeout=" "$cfg_file" | awk -F'=' '{print $2}' | tr -d '\r' | head -n 1
354+
tr -d '\r' < "$cfg_file" | grep "^set timeout=" | awk -F'=' '{print $2}' | head -n 1
353355
else
354356
echo ""
355357
fi
@@ -748,16 +750,16 @@ validate_config() {
748750
return 1
749751
fi
750752

751-
# Check required labels exist
752-
if ! grep -qi "^label unraid OS$" "$cfg_file"; then
753+
# Check required labels exist (strip CR so ^/$ match CRLF files)
754+
if ! tr -d '\r' < "$cfg_file" | grep -qi "^label unraid OS$"; then
753755
return 1
754756
fi
755757

756-
if ! grep -qi "^label unraid OS GUI Mode$" "$cfg_file"; then
758+
if ! tr -d '\r' < "$cfg_file" | grep -qi "^label unraid OS GUI Mode$"; then
757759
return 1
758760
fi
759761

760-
if ! grep -qi "^label unraid OS Safe Mode" "$cfg_file"; then
762+
if ! tr -d '\r' < "$cfg_file" | grep -qi "^label unraid OS Safe Mode"; then
761763
return 1
762764
fi
763765

@@ -1098,6 +1100,9 @@ write_config_grub() {
10981100

10991101
local temp_file=$(mktemp -p "$(dirname "$GRUB_CFG")")
11001102
cp "$GRUB_CFG" "$temp_file"
1103+
# Strip CR from CRLF so awk/grep/sed in update_grub_* match Unix line endings
1104+
local temp_lf="${temp_file}.lf"
1105+
tr -d '\r' < "$temp_file" > "$temp_lf" && mv "$temp_lf" "$temp_file"
11011106

11021107
if [[ "${APPLY_TO_UNRAID_OS}" == "1" ]]; then
11031108
update_grub_entry "Unraid OS" "$new_args" "$temp_file"

0 commit comments

Comments
 (0)