Commit 711c4645 authored by Jouke Witteveen's avatar Jouke Witteveen
Browse files

Improve array handling

When interpreted as an array, the empty string represents a 1-element
array consisting of the empty string. This is actually very reasonable.

Reported by: Thomas Bächler <thomas@archlinux.org>
parent 2587acda
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
. "$SUBR_DIR/ip" . "$SUBR_DIR/ip"
: ${IFENSLAVE:=ifenslave} : ${IFENSLAVE:=ifenslave}
: ${BindsToInterfaces=} declare -a BindsToInterfaces
bond_up() { bond_up() {
if is_interface "$Interface"; then if is_interface "$Interface"; then
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
. "$SUBR_DIR/ip" . "$SUBR_DIR/ip"
: ${BRCTL:=brctl} : ${BRCTL:=brctl}
: ${BindsToInterfaces=} declare -a BindsToInterfaces
bridge_up() { bridge_up() {
if is_interface "$Interface"; then if is_interface "$Interface"; then
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
. "$SUBR_DIR/ip" . "$SUBR_DIR/ip"
: ${BindsToInterfaces=} declare -a BindsToInterfaces
tunnel_up() { tunnel_up() {
if is_interface "$Interface"; then if is_interface "$Interface"; then
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
. "$SUBR_DIR/ip" . "$SUBR_DIR/ip"
: ${BindsToInterfaces=} declare -a BindsToInterfaces
tuntap_up() { tuntap_up() {
if is_interface "$Interface"; then if is_interface "$Interface"; then
......
...@@ -78,7 +78,7 @@ timeout_wait() { ...@@ -78,7 +78,7 @@ timeout_wait() {
local timeout=$1 local timeout=$1
(( timeout *= 5 )) (( timeout *= 5 ))
shift shift
while ! eval "$*"; do until eval "$*"; do
(( timeout-- > 0 )) || return 1 (( timeout-- > 0 )) || return 1
sleep 0.2 sleep 0.2
done done
......
...@@ -51,14 +51,12 @@ ip_set() { ...@@ -51,14 +51,12 @@ ip_set() {
esac esac
;; ;;
static) static)
if [[ $Address ]]; then for addr in "${Address[@]}"; do
for addr in "${Address[@]}"; do if ! do_debug ip addr add "$addr" brd + dev "$Interface"; then
if ! do_debug ip addr add "$addr" brd + dev "$Interface"; then report_error "Could not add address '$addr' to interface '$Interface'"
report_error "Could not add address '$addr' to interface '$Interface'" return 1
return 1 fi
fi done
done
fi
if [[ $Gateway ]]; then if [[ $Gateway ]]; then
if ! do_debug ip route add default via "$Gateway" dev "$Interface"; then if ! do_debug ip route add default via "$Gateway" dev "$Interface"; then
report_error "Could not set gateway '$Gateway' on interface '$Interface'" report_error "Could not set gateway '$Gateway' on interface '$Interface'"
...@@ -74,8 +72,8 @@ ip_set() { ...@@ -74,8 +72,8 @@ ip_set() {
;; ;;
esac esac
# Add static IP routes if [[ $IP ]]; then
if [[ $IP && $Routes ]]; then # Add static IP routes
for route in "${Routes[@]}"; do for route in "${Routes[@]}"; do
if ! do_debug ip route add $route dev "$Interface"; then if ! do_debug ip route add $route dev "$Interface"; then
report_error "Could not add route '$route' to interface '$Interface'" report_error "Could not add route '$route' to interface '$Interface'"
...@@ -121,13 +119,11 @@ ip_set() { ...@@ -121,13 +119,11 @@ ip_set() {
sysctl -q -w "net.ipv6.conf.$interface_sysctl.accept_ra=0" sysctl -q -w "net.ipv6.conf.$interface_sysctl.accept_ra=0"
;;& ;;&
stateless|static) stateless|static)
if [[ -n $Address6 ]]; then for addr in "${Address6[@]}"; do
for addr in "${Address6[@]}"; do if ! do_debug ip -6 addr add $addr dev "$Interface"; then
if ! do_debug ip -6 addr add $addr dev "$Interface"; then report_error "Could not add address '$addr' to interface '$Interface'"
report_error "Could not add address '$addr' to interface '$Interface'" fi
fi done
done
fi
;; ;;
esac esac
...@@ -139,14 +135,12 @@ ip_set() { ...@@ -139,14 +135,12 @@ ip_set() {
fi fi
# Add static IPv6 routes # Add static IPv6 routes
if [[ $Routes6 ]]; then for route in "${Routes6[@]}"; do
for route in "${Routes6[@]}"; do if ! do_debug ip -6 route add $route dev "$Interface"; then
if ! do_debug ip -6 route add $route dev "$Interface"; then report_error "Could not add route '$route' to interface '$Interface'"
report_error "Could not add route '$route' to interface '$Interface'" return 1
return 1 fi
fi done
done
fi
# Set a custom gateway after DAD has finished # Set a custom gateway after DAD has finished
if [[ $IP6 == @(stateless|static) && $Gateway6 ]]; then if [[ $IP6 == @(stateless|static) && $Gateway6 ]]; then
...@@ -157,14 +151,12 @@ ip_set() { ...@@ -157,14 +151,12 @@ ip_set() {
fi fi
fi fi
if [[ $IPCustom ]]; then for line in "${IPCustom[@]}"; do
for line in "${IPCustom[@]}"; do if ! do_debug ip $line; then
if ! do_debug ip $line; then report_error "Could not configure interface ($line)"
report_error "Could not configure interface ($line)" return 1
return 1 fi
fi done
done
fi
if [[ $Hostname ]]; then if [[ $Hostname ]]; then
if ! do_debug hostnamectl set-hostname "$Hostname"; then if ! do_debug hostnamectl set-hostname "$Hostname"; then
......
...@@ -109,14 +109,15 @@ unit_enable() { ...@@ -109,14 +109,15 @@ unit_enable() {
echo ".include @systemdsystemunitdir@/netctl@.service" > "$unit" echo ".include @systemdsystemunitdir@/netctl@.service" > "$unit"
echo -e "\n[Unit]" >> "$unit" echo -e "\n[Unit]" >> "$unit"
[[ -n $Description ]] && echo "Description=$Description" >> "$unit" [[ -n $Description ]] && echo "Description=$Description" >> "$unit"
if [[ -n ${BindsToInterfaces=$Interface} ]]; then [[ -v BindsToInterfaces ]] || BindsToInterfaces=$Interface
if (( ${#BindsToInterfaces[@]} )); then
: ${InterfaceRoot=sys/subsystem/net/devices/} : ${InterfaceRoot=sys/subsystem/net/devices/}
printf "BindsTo=$(sd_escape "$InterfaceRoot")%s.device\n" \ printf "BindsTo=$(sd_escape "$InterfaceRoot")%s.device\n" \
$(sd_escape "${BindsToInterfaces[@]}") >> "$unit" $(sd_escape "${BindsToInterfaces[@]}") >> "$unit"
printf "After=$(sd_escape "$InterfaceRoot")%s.device\n" \ printf "After=$(sd_escape "$InterfaceRoot")%s.device\n" \
$(sd_escape "${BindsToInterfaces[@]}") >> "$unit" $(sd_escape "${BindsToInterfaces[@]}") >> "$unit"
fi fi
if [[ -n $After ]]; then if (( ${#After[@]} )); then
printf 'After="netctl@%s.service"\n' \ printf 'After="netctl@%s.service"\n' \
$(sd_escape "${After[@]}") >> "$unit" $(sd_escape "${After[@]}") >> "$unit"
fi fi
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment