[arch-projects] [netctl][PATCH] Use drop-in directories instead of .include statements

Jouke Witteveen j.witteveen at gmail.com
Sat Jul 28 21:22:22 UTC 2018


The .include directive in systemd unit files has effectively been
deprecated since systemd v210. Its functionality is subsumed by
drop-in directories.
---
 src/netctl.in | 46 +++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/src/netctl.in b/src/netctl.in
index b5da594..6aeed7e 100644
--- a/src/netctl.in
+++ b/src/netctl.in
@@ -90,43 +90,43 @@ switch_to() {
 }
 
 unit_enable() {
-    local unit="@systemdsystemconfdir@/netctl@$(systemd-escape "$1").service"
-    if [[ -e $unit ]]; then
-        report_error "A unit file for profile '$1' already exists"
+    local unit=$(systemd-escape --template=netctl at .service "$1") target
+    load_profile "$1"
+
+    target="@systemdsystemconfdir@/multi-user.target.wants/$unit"
+    if [[ -e $target ]]; then
+        report_error "The profile '$1' is already enabled"
         return 1
     fi
-    load_profile "$1"
-    do_readable touch "$unit"
-    echo ".include @systemdsystemunitdir@/netctl at .service" > "$unit"
-    echo -e "\n[Unit]" >> "$unit"
-    [[ $Description ]] && echo "Description=$Description" >> "$unit"
+    do_readable mkdir -p "$(dirname "$target")"
+    ln -vs "@systemdsystemunitdir@/netctl at .service" "$target"
+
+    target="@systemdsystemconfdir@/$unit.d/profile.conf"
+    do_readable mkdir -p "$(dirname "$target")"
+    do_readable touch "$target"
+    echo "[Unit]" > "$target"
+    if [[ $Description ]]; then
+        echo "Description=$Description" >> "$target"
+    fi
     declare -p BindsToInterfaces &> /dev/null || BindsToInterfaces=$Interface
     if (( ${#BindsToInterfaces[@]} )); then
         : ${InterfaceRoot=sys/subsystem/net/devices/}
         printf "BindsTo=$(systemd-escape "$InterfaceRoot")%s.device\n" \
-               $(systemd-escape "${BindsToInterfaces[@]}") >> "$unit"
+               $(systemd-escape "${BindsToInterfaces[@]}") >> "$target"
         printf "After=$(systemd-escape "$InterfaceRoot")%s.device\n" \
-               $(systemd-escape "${BindsToInterfaces[@]}") >> "$unit"
+               $(systemd-escape "${BindsToInterfaces[@]}") >> "$target"
     fi
     if (( ${#After[@]} )); then
         printf 'After=netctl@%s.service\n' \
-               $(systemd-escape "${After[@]}") >> "$unit"
+               $(systemd-escape "${After[@]}") >> "$target"
     fi
-    mkdir -p "@systemdsystemconfdir@/multi-user.target.wants"
-    echo "ln -s '$unit' '${unit/system\//system/multi-user.target.wants/}'"
-    ln -s "$unit" "${unit/system\//system/multi-user.target.wants/}"
+    report_notice "generated '$target'"
 }
 
 unit_disable() {
-    local unit="@systemdsystemconfdir@/netctl@$(systemd-escape "$1").service"
-    if sd_call "is-enabled --quiet" "$1" &> /dev/null; then
-        sd_call disable "$1"
-    fi
-    if [[ ! -f $unit ]]; then
-        report_error "No regular unit file found for profile '$1'"
-        return 1
-    fi
-    do_debug rm "$unit"
+    local unit=$(systemd-escape --template=netctl at .service "$1")
+    rm -vfd "@systemdsystemconfdir@"{/multi-user.target.wants,}"/$unit" \
+            "@systemdsystemconfdir@/$unit.d"{/profile.conf,}
 }
 
 wait_online() {
-- 
2.18.0


More information about the arch-projects mailing list