Skip to content

Commit

Permalink
treewide: fix lint suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Packet Please <[email protected]>
  • Loading branch information
pktpls committed May 28, 2024
1 parent 3014aa5 commit 6d525c9
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 217 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ shfmt:
shellcheck:
# The excluded cases are supported by Busybox but not POSIX.
# TODO update to shellcheck 0.10 for busybox sh support
grep -rIzl '^#![[:blank:]]*/bin/sh' ./packages ./luci | xargs shellcheck -S warning
grep -rIzl '^#![[:blank:]]*/bin/sh' ./packages ./luci | xargs shellcheck -S warning -e SC3003,SC3014,SC3018,SC3020,SC3030,SC3039,SC3043,SC3054,SC3060
.PHONY: shellcheck

luacheck:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ MAC=$(uci -q get network.${IFACE}_dev.macaddr)
if [ $? -eq 1 ]; then
# start with b6 for Berliner 6ackbone
MAC="b6"
for byte in 2 3 4 5 6; do
for _byte in 2 3 4 5 6; do
MAC=$MAC`dd if=/dev/urandom bs=1 count=1 2> /dev/null | hexdump -e '1/1 ":%02x"'`
done
fi

UUID=$(uci -q get tunneldigger.${IFACE}.uuid)
if [ $? -eq 1 ]; then
UUID=$MAC
for byte in 7 8 9 10; do
for _byte in 7 8 9 10; do
UUID=$UUID`dd if=/dev/urandom bs=1 count=1 2> /dev/null | hexdump -e '1/1 ":%02x"'`
done
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ NET_STATE=$?

ONLINE_SSIDS=$(get_interfaces)
CHK_SSID=$(echo "$ONLINE_SSIDS" | cut -d' ' -f 1) # makes checking easier
CHANGE=0

if [ $NET_STATE = 0 ]; then # router online: switch to online, if not present already
# abort if SSID is "online" already
Expand All @@ -64,7 +63,6 @@ if [ $NET_STATE = 0 ]; then # router online: switch to online, if not present al
for ONLINE_SSID in $ONLINE_SSIDS; do
log "Internet was reached. Change SSID back to online..."
sed -i "s~^ssid=$OFFLINE_SSID~ssid=$ONLINE_SSID~" "$HOSTAPD"
CHANGE=1
done
done
else # router offline: adjust ssid accordingly, if needed
Expand Down
23 changes: 14 additions & 9 deletions packages/falter-berlin-tunneldigger/files/tunneldigger.hotplug
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ tunnel_is_up() {

interface_disabled() {
local iface=$1
local disabled=$(uci -q get network.${iface}.disabled)
local disabled
disabled="$(uci -q get network.${iface}.disabled)"
[ -z $disabled ] && disabled=0
echo "${disabled}"
}
Expand All @@ -29,13 +30,16 @@ srv_lookup() {
local i
local srvlist=""
for i in $srv; do
local lookup=$(nslookup -q=SRV $i | grep $i | cut -d "=" -f 2)
local lookup
lookup="$(nslookup -q=SRV $i | grep $i | cut -d "=" -f 2)"
local OLDIFS=$IFS
IFS=$'\n'
local j
for j in $lookup; do
local host=$(echo $j | cut -d ' ' -f 5)
local port=$(echo $j | cut -d ' ' -f 4)
local host
local port
host="$(echo $j | cut -d ' ' -f 5)"
port="$(echo $j | cut -d ' ' -f 4)"
append srvlist "${host}:${port}"
done
IFS=$OLDIFS
Expand Down Expand Up @@ -78,9 +82,9 @@ handle_td_ifup() {
[ ! -z ${bind_interface} ] && \
[ "$INTERFACE" != "${bind_interface}" ] && \
[ "$INTERFACE" != "${interface}" ] && return
[ $(interface_disabled ${interface}) == "1" ] && \
[ "$(interface_disabled ${interface})" == "1" ] && \
logger -t td-client "Not starting tunneldiger \"${cfg}\", interface ${interface} disabled" && return
[ $(tunnel_is_up ${interface}) == "1" ] && return
[ "$(tunnel_is_up ${interface})" == "1" ] && return

local broker_opts=""

Expand Down Expand Up @@ -145,17 +149,18 @@ handle_td_ifdown() {
[ ! -z ${bind_interface} ] && [ "$INTERFACE" != "${bind_interface}" ] && \
return

[ $(tunnel_is_up ${interface}) != "1" ] && return
[ "$(tunnel_is_up ${interface})" != "1" ] && return

local PIDFILE=${PIDPATH}/tunneldigger.${interface}.pid
local PID="$(cat ${PIDFILE})"
local PID
PID="$(cat ${PIDFILE})"
logger -t td-client "Stopping tunneldigger \"$cfg\" on ${interface} PIDFILE=${PIDFILE}"
/sbin/start-stop-daemon -K -q -p $PIDFILE
while test -d "/proc/${PID}"; do
logger -t td-client " waiting for tunneldigger to stop"
sleep 1
done
$(rm -f ${PIDFILE})
rm -f "${PIDFILE}"
logger -t td-client " tunneldigger stopped"
}

Expand Down
38 changes: 22 additions & 16 deletions packages/falter-berlin-tunneldigger/files/tunneldigger.init
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/sh /etc/rc.common

# shellcheck disable=SC2044
# shellcheck disable=SC2068

. $IPKG_INSTROOT/lib/functions/network.sh

# Comment out the START declaration to prevent the init file from
Expand All @@ -23,7 +26,8 @@ tunnel_is_up() {

interface_disabled() {
local iface=$1
local disabled=$(uci -q get network.${iface}.disabled)
local disabled
disabled="$(uci -q get network.${iface}.disabled)"
[ -z $disabled ] && disabled=0
echo "${disabled}"
}
Expand All @@ -33,13 +37,16 @@ srv_lookup() {
local i
local srvlist=""
for i in $srv; do
local lookup=$(nslookup -q=SRV $i | grep $i | cut -d "=" -f 2)
local lookup
lookup="$(nslookup -q=SRV $i | grep $i | cut -d "=" -f 2)"
local OLDIFS=$IFS
IFS=$'\n'
local j
for j in $lookup; do
local host=$(echo $j | cut -d ' ' -f 5)
local port=$(echo $j | cut -d ' ' -f 4)
local host
local port
host="$(echo $j | cut -d ' ' -f 5)"
port="$(echo $j | cut -d ' ' -f 4)"
append srvlist "${host}:${port}"
done
IFS=$OLDIFS
Expand All @@ -53,14 +60,14 @@ missing() {
}

handle_td() {
local cfg=$1; shift
local cfg="$1"; shift
# determine if we should start only this instance
local sections=$@
local argn=$#
local sections=("$@")
local argn="$#"
local skip=0
if [ $argn -ne 0 ]; then
skip=1
for section in $sections; do
for section in "${sections[@]}"; do
if [ "$cfg" == "$section" ]; then
skip=0
break
Expand All @@ -79,7 +86,6 @@ handle_td() {
local group
local limit_bw_down
local hook_script
local bind_interface
local broker_selection

config_get_bool enabled "$cfg" enabled 1
Expand All @@ -90,15 +96,14 @@ handle_td() {
config_get group "$cfg" group
config_get limit_bw_down "$cfg" limit_bw_down
config_get hook_script "$cfg" hook_script
config_get bind_interface "$cfg" bind_interface
config_get broker_selection "$cfg" broker_selection

let tunnel_id++

[ $enabled -eq 0 ] && return
[ $(interface_disabled ${interface}) == "1" ] && \
[ "$(interface_disabled ${interface})" == "1" ] && \
echo "Not starting tunneldigger \"${cfg}\", interface ${interface} disabled" && return
[ $(tunnel_is_up ${interface}) == "1" ] && \
[ "$(tunnel_is_up ${interface})" == "1" ] && \
echo "Not starting tunneldigger \"${cfg}\", already started" && return

local broker_opts=""
Expand Down Expand Up @@ -156,7 +161,7 @@ start() {
# to stop all tunneldigger sections. With arguements, only the listed tunneldigger
# sections are stopped
stop() {
local sections=$@
local sections=("$@")
local argn=$#
for PIDFILE in `find ${PIDPATH}/ -name "tunneldigger\.*\.pid"`; do
PID="$(cat ${PIDFILE})"
Expand All @@ -165,8 +170,9 @@ stop() {
local skip=0
if [ $argn -ne 0 ]; then
skip=1
for section in $sections; do
local section_iface=$(uci get tunneldigger.${section}.interface)
for section in "${sections[@]}"; do
local section_iface
section_iface="$(uci get tunneldigger.${section}.interface)"
if [ $IFACE = $section_iface ]; then
skip=0
break
Expand All @@ -182,7 +188,7 @@ stop() {
echo " waiting for tunneldigger to stop"
sleep 1
done
$(rm -f ${PIDFILE})
rm -f ${PIDFILE}
echo " tunneldigger stopped"
done
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

THIS_UPLINKNAME="notunnel"

. /lib/functions/freifunk-berlin-network.sh
. /lib/functions/freifunk-berlin-network.sh
. /lib/functions/guard.sh
. /lib/functions.sh

Expand Down Expand Up @@ -48,21 +48,22 @@ uci set network.ffuplink_dev.macaddr=$macaddr
uci commit network.ffuplink_dev

# add ffuplink_dev to the br-wan bridge if not there
devname=$(uci get network.wan.device)
handle_wan_device() {
local config=$1
local name=""
local ports=""
local wandev=$(uci -q get network.wan.device)
local _ports=""
local wandev

wandev="$(uci -q get network.wan.device)"
if [ -z $wandev ]; then
return
return
fi

config_get name $config name
if [ "X${name}X" == "Xbr-wanX" ]; then
config_get ports $config ports
list_contains ports ffuplink_wan || uci add_list network.${config}.ports="ffuplink_wan"
uci commit network.${config}
config_get _ports $config _ports
list_contains _ports ffuplink_wan || uci add_list network.${config}.ports="ffuplink_wan"
uci commit network.${config}
fi
}

Expand All @@ -71,6 +72,6 @@ config_load network
config_foreach handle_wan_device device

uci set network.ffuplink.proto=dhcp
uci set network.ffuplink.hostname=freifunk-$(echo $macaddr|tr -d :)-uplink
uci set network.ffuplink.hostname="freifunk-$(echo $macaddr|tr -d :)-uplink"
uci commit network.ffuplink

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

THIS_UPLINKNAME="tunnelberlin_tunneldigger"

. /lib/functions/freifunk-berlin-network.sh
. /lib/functions/freifunk-berlin-network.sh
. /lib/functions/guard.sh
. /lib/functions/system.sh

Expand Down Expand Up @@ -48,7 +48,7 @@ uci commit network.ffuplink
UUID=$(uci -q get tunneldigger.ffuplink.uuid)
if [ $? -eq 1 ]; then
UUID=$macaddr
for byte in 7 8 9 10; do
for _byte in 7 8 9 10; do
UUID=$UUID`dd if=/dev/urandom bs=1 count=1 2> /dev/null | hexdump -e '1/1 ":%02x"'`
done
fi
Expand Down
2 changes: 1 addition & 1 deletion packages/falter-common/files/etc/rc.local
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh /etc/rc.common

# shellcheck disable=SC2034
# shellcheck disable=SC1090

[ -d /etc/rc.local.d ] && {
for file in /etc/rc.local.d/*; do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
proto="4"
#[ -f /proc/net/ipv6_route ] && proto="4 6"

enable=""
zones=""
strict=""
config_load freifunk-policyrouting
config_get enable pr enable
config_get fallback pr fallback
config_get strict pr strict
config_get zones pr zones

Expand All @@ -25,9 +27,9 @@ if [ "$ACTION" = "ifup" ] && [ "$enable" = "1" ]; then
#network_get_subnet6 net6 $INTERFACE
;;esac

if [ "$net" != "" -a -n "${DEVICE}" ]; then
eval $(/bin/ipcalc.sh $net)
if [ "$PREFIX" != "0" -a "$NETWORK" != "127.0.0.0" ]; then
if [ "$net" != "" ] && [ -n "${DEVICE}" ]; then
eval "$(/bin/ipcalc.sh $net)"
if [ "$PREFIX" != "0" ] && [ "$NETWORK" != "127.0.0.0" ]; then
if [ ! "$(ip route show table localnets |grep "$NETWORK/$PREFIX dev")" ]; then
cmd="ip route add $NETWORK/$PREFIX dev ${DEVICE} table localnets"
$cmd
Expand All @@ -51,7 +53,7 @@ if [ "$ACTION" = "ifup" ] && [ "$enable" = "1" ]; then

if [ -n "$net6" ]; then
cmd="ip -6 route add $net6 dev ${DEVICE} table localnets"
$cmd 2>&1 > /dev/null
$cmd >/dev/null 2>&1
if [ "$?" = 0 ]; then
logger -s -t policyrouting "Add route: $cmd (IPv6)"
fi
Expand Down
Loading

0 comments on commit 6d525c9

Please sign in to comment.