#!/bin/sh

if [ $# -lt 3 ]; then
    echo "Usage: $0 cmd type group <system>?"
    exit 1
fi

cmd=$1
provider_type=$2
group_name=$3
stype=$4
params=

if [ "$stype" == "system" ]; then
    params="--system";
fi

lib_dir=/usr/lib/statefs
scripts_dir=$lib_dir/scripts
loader_dir=$scripts_dir/$provider_type
script_name=$loader_dir/on-$group_name

if [ "$cmd" == "register" ]; then
    order=03
    if [ "$provider_type" == "loader" ]; then
        order=02
    fi
    # add-oneshot is used only if there is oneshot available,
    # otherwise it is replaced with alternative command
    echo "Register $group_name"
    add-oneshot --now statefs-$order-register-$group_name || :
else
    echo "$cmd $params"
    $script_name $cmd $params || :
fi
