Commit ba3fce82 authored by Jouke Witteveen's avatar Jouke Witteveen
Browse files

Minor refactoring

parent e578eeec
......@@ -21,22 +21,8 @@ network_status() {
fi
}
ensure_root netctl
# Ensure we are not in a transient directory
cd /
if [[ $# -eq 2 && $1 == @(start|stop) ]]; then
# Expose the profile name
Profile=$2
load_profile "$Profile"
load_interface_config "$Interface"
elif [[ $# -ne 1 || $1 != "wait-online" ]]; then
exit_error "Usage: $0 {start|stop|wait-online} [profile]"
fi
case $1 in
start)
## Start the loaded profile
network_start() {
report_notice "Starting network profile '$Profile'..."
if is_interface "$Interface" && interface_is_up "$Interface" && \
! is_yes "${ForceConnect:-no}"; then
......@@ -57,8 +43,10 @@ case $1 in
fi
network_status "online"
report_notice "Started network profile '$Profile'"
;;
stop)
}
## Stop the loaded profile
network_stop() {
report_notice "Stopping network profile '$Profile'..."
# Sandbox the eval
if ! ( do_debug eval "$ExecDownPre" ); then
......@@ -77,17 +65,34 @@ case $1 in
exit 1
fi
report_notice "Stopped network profile '$Profile'"
;;
wait-online)
}
## Wait for all enabled profiles to come online within a single timeout
network_wait_online() {
mapfile -t Profiles < <(list_profiles)
i=0
# Wait for all enabled profiles to come online within a single timeout
timeout_wait "${TIMEOUT_ONLINE:-120}" \
'! until [[ $(sd_call is-enabled "${Profiles[i]}") == "enabled" &&
$(sd_status_text "${Profiles[i]}") != "online" ]]; do
(( ++i < ${#Profiles[@]} )) || return 0; done'
;;
esac
}
ensure_root netctl
# Ensure we are not in a transient directory
cd /
if [[ $# -eq 1 && $1 == wait-online ]]; then
network_wait_online
elif [[ $# -eq 2 && $1 == @(start|stop) ]]; then
# Expose the profile name
Profile=$2
load_profile "$Profile"
load_interface_config "$Interface"
"network_$1"
else
exit_error "Usage: $0 {start|stop|wait-online} [profile]"
fi
# vim: ft=sh ts=4 et sw=4:
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