gluon-packages/net/brmldproxy/files/etc/init.d/brmldproxy

112 lines
2.9 KiB
Bash
Executable File

#!/bin/sh /etc/rc.common
# SPDX-License-Identifier: MIT
# Copyright (C) 2023 Linus Lüssing <linus.luessing@c0d3.blue>
USE_PROCD=1
START=19
STOP=90
brmldproxy_start() {
local cfg="$1"
local namespace="$2"
local disabled
local ifname
local family
local bridge
local includedports
local excludedports
local proxiedports
local includefilters
local excludefilters
config_get_bool disabled "$cfg" disabled 0
[ "$disabled" -gt 0 ] && return 0
config_get bridge "$cfg" "bridge"
config_get family "$cfg" "family"
config_get includedports "$cfg" "includedport"
config_get excludedports "$cfg" "excludedport"
config_get proxiedports "$cfg" "proxiedport"
config_get includefilters "$cfg" "includefilter"
config_get excludefilters "$cfg" "excludefilter"
[ -z "$bridge" ] && {
echo "Error: no bridge specified for $cfg" >&2
return 0
}
. /lib/functions/network.sh
if network_get_device ifname "$bridge" && [ -n "$ifname" ]; then
bridge="$ifname"
fi
[ -n "$excludedports" ] && excludedports=$(echo "$excludedports" | sed 's/[^ ]* */-e &/g')
[ -n "$includedports" ] && includedports=$(echo "$includedports" | sed 's/[^ ]* */-i &/g')
[ -n "$proxiedports" ] && proxiedports=$(echo "$proxiedports" | sed 's/[^ ]* */-p &/g')
[ -n "$includefilters" ] && includefilters=$(echo "$includefilters" | sed 's/[^ ]* */-I &/g')
[ -n "$excludefilters" ] && excludefilters=$(echo "$excludefilters" | sed 's/[^ ]* */-E &/g')
[ -z "$namespace" ] && namespace="brmldproxy"
procd_open_instance "$namespace.$cfg"
procd_set_param command /usr/sbin/brmldproxy
[ "${family}" = "ipv4" ] && procd_append_param command -4
[ "${family}" = "ipv6" ] && procd_append_param command -6
procd_append_param command -b "$bridge"
[ -n "$excludedports" ] && procd_append_param command $excludedports
[ -n "$includedports" ] && procd_append_param command $includedports
[ -n "$proxiedports" ] && procd_append_param command $proxiedports
[ -n "$includefilters" ] && procd_append_param command $includefilters
[ -n "$excludefilters" ] && procd_append_param command $excludefilters
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
procd_set_param stderr 1
procd_close_instance
}
start_service() {
local cfg="$1"
local namespace="$2"
local instance_found=0
. /lib/functions/network.sh
# no procd boot startup, via hotplug or manual only
[ $PPID -eq 1 ] && return 0
config_cb() {
local type="$1"
local name="$2"
if [ "$type" = "brmldproxy" ]; then
if [ -n "$cfg" -a "$cfg" = "$name" ]; then
instance_found=1
fi
fi
}
config_load brmldproxy
if [ -n "$cfg" ]; then
[ "$instance_found" -gt 0 ] || return
brmldproxy_start "$cfg" "$namespace"
else
config_foreach brmldproxy_start brmldproxy "$namespace"
fi
}
stop_service() {
local cfg="$1"
local namespace="$2"
[ -z "$namespace" ] && namespace="brmldproxy"
}
service_triggers() {
procd_add_reload_trigger brmldproxy
}