The previous script was missing a required function:

  Apr 18 13:45:29 hostname nm-dispatcher[28472]: 
/etc/NetworkManager/dispatcher.d/fwknop-server: 16: 
/etc/NetworkManager/dispatcher.d/fwknop-server: read_sysf: not found

Attached is the fixed script.

Francois

-- 
https://fmarier.org/
#!/bin/sh
# Copyright (c) 2019 Thomas Koch <linrunner at gmx.net>, Francois Marier 
<franc...@debian.org> and others.
# This software is licensed under the GPL v2 or later.

read_sysf () { # read and echo contents of sysfile
    # return 1 and echo default if read fails
    # $1: sysfile, $2: default; rc: 0=ok/1=error
    if ! cat "$1" 2> /dev/null; then
        printf "%s" "$2"
        return 1
    else
        return 0
    fi
}

save_iface_type () { # save interface type -- $1: interface; $2: type
    # rc: 0=saved/1=error
    [ -d $NETD/$1 ] && { printf '%s\n' "$2" > $RUNDIR/${1}.itype; } 2> /dev/null
    return $?
}

get_iface_type () { # get saved interface type -- $1: interface
    # rc: 0=saved state found/1=not found
    # retval: $itype
    local rc

    itype=$(read_sysf $RUNDIR/${1}.itype); rc=$?
    rm -f $RUNDIR/${1}.itype
    return $rc
}

# Get args
iface="$1"
action="$2"
itype=""


# Quit for invalid interfaces
[ -n "$iface" ] && [ "$iface" != "none" ] || exit 0

# Quit for actions other than "up" and "down"
[ "$action" = "up" ] || [ "$action" = "down" ] || exit 0

#  Quit for virtual interfaces (up action)
if [ "$action" = "up" ] && readlink "$NETD/$iface" | grep -q '/virtual/'; then
    # save type for down action where $NETD/$iface won't be there anymore
    save_iface_type $iface virtual
    exit 0
fi

# Get saved interface type (down action)
if [ "$action" = "down" ]; then
    get_iface_type $iface

    # quit for virtual interfaces
    if [ "$itype" = "virtual" ]; then
        exit 0
    fi
fi

case $action in
    up)
        /bin/systemctl start fwknop-server.service
        ;;

    down)
        /bin/systemctl stop fwknop-server.service
        ;;

esac

exit 0

Reply via email to