Commit 9b70046f authored by Jouke Witteveen's avatar Jouke Witteveen
Browse files

Add verify subcommand to netctl

The name of the subcommand mirrors the same subcommand of systemd-analyze.

Verification before restarting would be useful. However, verification
requires the profile file to be readable by the current user. The current
user may be a regular user with permission to control systemd, so
restarting does not require the profile file to be readable. Therefore, we
do not attempt verification before restarting.
parent ca58db4f
...@@ -82,7 +82,11 @@ The following commands are understood: ...@@ -82,7 +82,11 @@ The following commands are understood:
*edit [+PROFILE+]*:: *edit [+PROFILE+]*::
Open the file of the specified profile in an editor. This does not Open the file of the specified profile in an editor. This does not
reenable or restart any profiles. reenable, restart, or verify any profiles.
*verify [+PROFILE+]*::
Check the file of the specified profile for syntax errors. If no
errors are found, no output is produced.
*wait-online [+PROFILE+]*:: *wait-online [+PROFILE+]*::
Wait until the interface of the profile has a routable IP address of Wait until the interface of the profile has a routable IP address of
......
...@@ -109,6 +109,12 @@ list_profiles() { ...@@ -109,6 +109,12 @@ list_profiles() {
find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name $'*\n*' -not -name '*.action' -not -name '*.conf' -not -name '*.service' -printf '%f\n' find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name $'*\n*' -not -name '*.action' -not -name '*.conf' -not -name '*.service' -printf '%f\n'
} }
## Exit if a profile file is not syntactically correct
# $1: profile name
verify_profile() {
/bin/bash -n "$PROFILE_DIR/$1" || exit 1
}
## Sources all hooks and a profile (but no interface configuration) ## Sources all hooks and a profile (but no interface configuration)
# $1: profile name # $1: profile name
load_profile() { load_profile() {
......
...@@ -23,7 +23,8 @@ Commands: ...@@ -23,7 +23,8 @@ Commands:
disable [PROFILE] Disable the systemd unit for a profile disable [PROFILE] Disable the systemd unit for a profile
reenable [PROFILE] Reenable the systemd unit for a profile reenable [PROFILE] Reenable the systemd unit for a profile
is-enabled [PROFILE] Check whether a profile is enabled is-enabled [PROFILE] Check whether a profile is enabled
edit [PROFILE] Edit a profile edit [PROFILE] Edit a profile file
verify [PROFILE] Check the syntax of a profile file
wait-online [PROFILE] Wait for a profile to finish connecting wait-online [PROFILE] Wait for a profile to finish connecting
END END
} }
...@@ -71,9 +72,6 @@ stop_all() { ...@@ -71,9 +72,6 @@ stop_all() {
switch_to() { switch_to() {
cd "$PROFILE_DIR" cd "$PROFILE_DIR"
if [[ ! -r $1 ]]; then
exit_error "Profile '$1' does not exist or is not readable"
fi
# We assume interface names are not quoted # We assume interface names are not quoted
# Using read removes leading whitespace # Using read removes leading whitespace
read InterfaceLine < \ read InterfaceLine < \
...@@ -129,6 +127,11 @@ unit_disable() { ...@@ -129,6 +127,11 @@ unit_disable() {
"@systemdsystemconfdir@/$unit.d"{/profile.conf,} "@systemdsystemconfdir@/$unit.d"{/profile.conf,}
} }
unit_reenable() {
unit_disable "$1"
unit_enable "$1"
}
wait_online() { wait_online() {
local profile="$1" local profile="$1"
if sd_call "is-active --quiet" "$profile"; then if sd_call "is-active --quiet" "$profile"; then
...@@ -163,22 +166,21 @@ case $# in ...@@ -163,22 +166,21 @@ case $# in
sd_call "$1" "$2";; sd_call "$1" "$2";;
switch-to) switch-to)
ensure_root "$(basename "$0")" ensure_root "$(basename "$0")"
verify_profile "$2"
switch_to "$2";; switch_to "$2";;
enable|disable) enable|disable|reenable)
ensure_root "$(basename "$0")" ensure_root "$(basename "$0")"
if [[ $1 != "disable" ]]; then
verify_profile "$2"
fi
"unit_$1" "$2" "unit_$1" "$2"
if systemd-notify --booted; then if systemd-notify --booted; then
systemctl daemon-reload systemctl daemon-reload
fi;; fi;;
reenable)
ensure_root "$(basename "$0")"
unit_disable "$2"
unit_enable "$2"
if systemd-notify --booted; then
systemctl daemon-reload
fi;;
edit) edit)
exec ${EDITOR:-nano} "$PROFILE_DIR/$2";; exec ${EDITOR:-nano} "$PROFILE_DIR/$2";;
verify)
verify_profile "$2";;
wait-online) wait-online)
wait_online "$2";; wait_online "$2";;
*) *)
......
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