Skip to content

Commit

Permalink
Simplify more conditonals, use local assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaky committed Aug 19, 2023
1 parent 27e6042 commit b643e04
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions portacl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ split_comma()
# Lookup port in /etc/services if it is not numeric
resolve_port()
{
local port proto lookup

port=$1
proto=$2
local lookup
local port="$1"
local proto="$2"

echo_numeric "${port}" && return

Expand Down Expand Up @@ -109,16 +108,12 @@ resolve_port()
}

resolve_id() {
local id flag kind lookup

kind=$1
id=$2
local lookup
local kind="$1"
local id="$2"
local flag="-u"

if [ "${kind}" = "user" ]; then
flag="-u"
else
flag="-g"
fi
[ "${kind}" = "group" ] && flag="-g"

echo_numeric "${id}" && return

Expand All @@ -134,15 +129,11 @@ resolve_id() {

generate_ruleset_for()
{
local key sid ids id rules proto ports port
local id ids port ports proto rules sid
local kind="$1"
local key="uid"

kind=$1

if [ "${kind}" = "user" ]; then
key="uid"
else
key="gid"
fi
[ "${kind}" = "group" ] && key="gid"

eval ids="\${${name}_${kind}s}"
for sid in ${ids}
Expand Down

0 comments on commit b643e04

Please sign in to comment.