From 1844268b0a3df5959e216372da21f1191f9eebd5 Mon Sep 17 00:00:00 2001 From: Dennis Herbrich Date: Wed, 13 Nov 2013 11:45:26 +0100 Subject: [PATCH] Remove CR from all source input files When netctl profiles or other sourced files contain DOS line endings, profiles fail to be brought up, because netctl cannot read the file paths constructed from the variables with a trailing carriage return. This patch uses sed to transparently remove any \r at the end of lines in any 'source'd file without altering the original file, thus improving overall robustness. Signed-off-by: Dennis Herbrich --- src/ifplugd.action | 2 +- src/lib/globals | 8 ++++---- src/netctl-auto | 6 +++--- src/wifi-menu | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ifplugd.action b/src/ifplugd.action index c87ac0c..8248415 100755 --- a/src/ifplugd.action +++ b/src/ifplugd.action @@ -19,7 +19,7 @@ case "$2" in while read -r profile; do ( echo "Reading profile '$profile'" - source "$PROFILE_DIR/$profile" + source <(sed 's/\r$//' "$PROFILE_DIR/$profile") [[ "$Interface" == "$1" && "$Connection" == "ethernet" ]] || continue is_yes "${AutoWired:-no}" && exit 1 # user preferred AUTO profile [[ "$IP" == "dhcp" ]] && exit 2 # dhcp profile diff --git a/src/lib/globals b/src/lib/globals index f31beac..f6d83bd 100644 --- a/src/lib/globals +++ b/src/lib/globals @@ -111,9 +111,9 @@ load_profile() { exit_error "Profile '$1' does not exist or is not readable" fi while read -r hook; do - source "$hook" + source <(sed 's/\r$//' "$hook") done < <(find -L "$PROFILE_DIR/hooks" -maxdepth 1 -type f -executable -not -name '.*' -not -name '*~' | sort -u) - source "$PROFILE_DIR/$1" + source <(sed 's/\r$//' "$PROFILE_DIR/$1") if [[ -z $Interface ]]; then exit_error "Profile '$1' does not specify an interface" fi @@ -121,9 +121,9 @@ load_profile() { exit_error "Profile '$1' does not specify a valid connection" fi if [[ -x "$PROFILE_DIR/interfaces/$Interface" ]]; then - source "$PROFILE_DIR/interfaces/$Interface" + source <(sed 's/\r$//' "$PROFILE_DIR/interfaces/$Interface") fi - source "$CONN_DIR/$Connection" + source <(sed 's/\r$//' "$CONN_DIR/$Connection") } diff --git a/src/netctl-auto b/src/netctl-auto index 5cf104b..bcb7cf3 100755 --- a/src/netctl-auto +++ b/src/netctl-auto @@ -174,7 +174,7 @@ start() { exit_error "The interface ($interface) is already in use" fi if [[ -x "$PROFILE_DIR/interfaces/$interface" ]]; then - source "$PROFILE_DIR/interfaces/$interface" + source <(sed 's/\r$//' "$PROFILE_DIR/interfaces/$interface") fi if [[ $RFKill ]]; then rf_enable "$interface" "$RFKill" || return 1 @@ -190,7 +190,7 @@ start() { list_profiles | while read -r profile; do report_debug "Examining profile '$profile'" ( - source "$PROFILE_DIR/$profile" + source <(sed 's/\r$//' "$PROFILE_DIR/$profile") [[ $Interface == "$interface" ]] || continue is_yes "${ExcludeAuto:-no}" && exit 1 [[ $Connection != "wireless" ]] && exit 1 @@ -223,7 +223,7 @@ stop() { [[ -e "$pidfile" ]] && kill "$(< "$pidfile")" if [[ -x "$PROFILE_DIR/interfaces/$interface" ]]; then - source "$PROFILE_DIR/interfaces/$interface" + source <(sed 's/\r$//' "$PROFILE_DIR/interfaces/$interface") fi timeout_wait 1 '! wpa_is_active "$interface"' || wpa_stop "$interface" ip link set dev "$interface" down diff --git a/src/wifi-menu b/src/wifi-menu index 455cdc9..2fe9fc2 100755 --- a/src/wifi-menu +++ b/src/wifi-menu @@ -27,7 +27,7 @@ init_profiles() while read profile; do essid=$( unset INTERFACE ESSID - source "$PROFILE_DIR/$profile" > /dev/null + source <(sed 's/\r$//' "$PROFILE_DIR/$profile") > /dev/null if [[ "$Interface" = "$1" && -n "$ESSID" ]]; then printf "%s" "$ESSID" if [[ "$Description" =~ "Automatically generated" ]]; then -- 1.8.4.2