Skip to content

Commit

Permalink
falter-common: apply shellcheck-fixes
Browse files Browse the repository at this point in the history
exclude hna.lua from linter.

Signed-off-by: Martin Hübner <martin.hubner@web.de>
  • Loading branch information
Akira25 committed Jun 11, 2023
1 parent dc14f70 commit b26a772
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 64 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ jobs:
# Change to 'master' if your main branch differs
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FILTER_REGEX_EXCLUDE: ".*/usr/bin/hna\\.lua$"
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/sh

# shellcheck disable=SC1091
# shellcheck disable=SC2154

. /lib/functions.sh
. /lib/functions/network.sh

Expand All @@ -19,20 +22,20 @@ config_get zones pr zones
if [ "$ACTION" = ifup ]; then
logger -t ff-userlog "ffuplink interface is up"
logger -t ff-userlog "creating ffuplink ip-rules"
ifaces=$(uci -q get firewall.zone_freifunk.network)
ifaces=$(uci -q get firewall.zone_freifunk.network)
network_get_subnet uplink_net ffuplink
if [ -z $uplink_net ]; then
if [ -z "$uplink_net" ]; then
logger -t ff-userlog "UCI did not return a valid IP-net for ffuplink; querying directly with ip-tool"
uplink_net=$(ip -4 -o addr show dev ffuplink|awk '{print $4}')
fi
if [ -z $uplink_net ]; then
if [ -z "$uplink_net" ]; then
logger -t ff-userlog "no valid IP-net found for ffuplink; TRAFFIC FOR UPLINK-NETWORK WILL NOT BE BLOCKED"
fi
eval $(/bin/ipcalc.sh $uplink_net)
eval "$(/bin/ipcalc.sh "$uplink_net")"
for iface in $ifaces; do
network_get_physdev netdev $iface
[ ! '0.0.0.0' = $NETWORK ] && ip rule add prio 19989 to $NETWORK/$PREFIX iif $netdev prohibit
ip rule add prio 19990 iif $netdev lookup ffuplink
network_get_physdev netdev "$iface"
[ ! '0.0.0.0' = "$NETWORK" ] && ip rule add prio 19989 to "$NETWORK/$PREFIX" iif "$netdev" prohibit
ip rule add prio 19990 iif "$netdev" lookup ffuplink
done
logger -t ff-userlog "ffuplink-interface is setup"
fi
Expand Down
3 changes: 2 additions & 1 deletion packages/falter-common/files/etc/init.d/ff_dnsmasq_reload
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh /etc/rc.common

# shellcheck disable=SC2034

START=88

boot() {
Expand All @@ -11,4 +13,3 @@ boot() {

/etc/init.d/cron restart &
}

3 changes: 3 additions & 0 deletions packages/falter-common/files/etc/init.d/freifunk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Freifunk Init
# $Id$

# shellcheck disable=SC2034
# shellcheck disable=SC1090

START=99

boot() {
Expand Down
7 changes: 6 additions & 1 deletion packages/falter-common/files/etc/profile.d/10_dynbanner.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#!/bin/sh

# shellcheck shell=bash
# shellcheck disable=SC2059

# Get dynamic information and print them under the banner.
#
# This script originates from Freifunk Berlin

HOSTNAME=$(uci -q get system.@system[0].hostname)".olsr"
IPADDR=$(uci -q get network.dhcp.ipaddr)
UPTIME=$(uptime | cut -d ',' -f 0 | cut -d ' ' -f 4-) 2&> /dev/null
FREEFL=$(df -h | grep " /overlay" | sed -E -e s/[[:space:]]+/\;/g | cut -d';' -f4 ) 2&> /dev/null
SYS_LOAD=$(cat /proc/loadavg | cut -d' ' -f 1-3) 2&> /dev/null
SYS_LOAD=$(cut -d' ' -f 1-3 < /proc/loadavg ) 2&> /dev/null
CLIENTS=$(wc -l /tmp/dhcp.leases | cut -d' ' -f1) 2&> /dev/null

printf \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@
# see https://github.com/freifunk-berlin/firmware/issues/381
#

[ ! $(command -v iwinfo) ] && exit 0
# shellcheck shell=dash
# shellcheck disable=SC2181
# shellcheck disable=SC1091

[ ! "$(command -v iwinfo)" ] && exit 0
iwinfo|grep -q 'NanoStation M2\|NanoStation Loco M2' || exit 0


. /lib/functions/guard.sh
guard "NSm2_txpower"

set_default_txpower() {
echo "setting txpower value to $1 dBm"
uci set wireless.radio0.txpower=$1
uci set wireless.radio0.txpower="$1"
uci commit wireless
}

MAX_TX_2G=20
# get "TX offset" of 1st interface, if this is unknown set it to 0dB
# then only return the numerical value
ANT_GAIN=$(iwinfo |grep -m 1 "TX power offset:" |sed -e "s/unknown/0 dB/" |tr -dc '0-9')
NEW_TX=$(echo $(($MAX_TX_2G - $ANT_GAIN)))
NEW_TX=$((MAX_TX_2G - ANT_GAIN))

CURR_TX=$(uci -q get wireless.radio0.txpower)
# check if txpower is defined in config
if [ $? -ne 0 ]; then
echo -n "txpower not defined - "
set_default_txpower $NEW_TX
elif [ $CURR_TX -gt $NEW_TX ]; then
elif [ "$CURR_TX" -gt $NEW_TX ]; then
set_default_txpower $NEW_TX
fi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

# shellcheck disable=SC1091

. /lib/functions/guard.sh
guard "dhcp"

Expand All @@ -11,7 +13,7 @@ uci set dhcp.@dnsmasq[0].quietdhcp=1
uci add_list dhcp.@dnsmasq[0].notinterface='wan'

# on IPv6-islands we also should give a default-route to the clients,
# so they can also reach IPv6-neighbours.
# so they can also reach IPv6-neighbours.
uci set dhcp.lan.ra_default=1

# add dns entry frei.funk
Expand All @@ -23,7 +25,7 @@ uci set dhcp.frei_funk.ip=192.168.42.1
router_ula=$(uci get network.globals.ula_prefix | sed -e 's/\/48/1/')
uci set dhcp.frei_funk_ipv6=domain
uci set dhcp.frei_funk_ipv6.name=frei.funk
uci set dhcp.frei_funk_ipv6.ip=$router_ula
uci set dhcp.frei_funk_ipv6.ip="$router_ula"

# don't send default-route to clients to prevent them sending pakets
# to us, that we can't forward now
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/sh

# shellcheck disable=SC1091


. /lib/functions/freifunk-berlin-network.sh
. /lib/functions/guard.sh
guard "ffberlin_uplink"
Expand All @@ -17,4 +20,3 @@ uci commit ffberlin-uplink
create_ffuplink
uci set network.ffuplink.disabled=1
uci commit network.ffuplink

Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/bin/sh

# shellcheck disable=SC1091


. /lib/functions/guard.sh
guard "network"

# change default ip to avoid collision with user's local network
uci set network.lan.ipaddr=192.168.42.1

WANDEV=$(uci -q get network.wan.device)
echo ${WANDEV} | grep ^br- > /dev/null
echo "$WANDEV" | grep ^br- > /dev/null
BRIDGECHECK=$?

# setup wan as a bridge
Expand All @@ -17,8 +20,8 @@ if [ "X${WANDEV}X" = "XX" ]; then
# port device from the client network to wan. This is also needed
# in the case where the user decides to use the "notunnel" variant
NEWDEV=$(uci add network device)
uci set network.$NEWDEV.type="bridge"
uci set network.$NEWDEV.name="br-wan"
uci set "network.$NEWDEV.type=bridge"
uci set "network.$NEWDEV.name=br-wan"

# create a wan interface, even if it can't do anything
uci set network.wan=interface
Expand All @@ -37,15 +40,15 @@ elif [ $BRIDGECHECK = "0" ]; then
else
# The wan device is not a bridge. Change it to a bridge
NEWDEV=$(uci add network device)
uci set network.$NEWDEV.type="bridge"
uci set network.$NEWDEV.name="br-wan"
uci add_list network.$NEWDEV.ports=${WANDEV}
uci set "network.$NEWDEV.type=bridge"
uci set "network.$NEWDEV.name=br-wan"
uci add_list "network.$NEWDEV.ports=$WANDEV"

uci set network.wan.device="br-wan"
uci set network.wan6.device="br-wan"
fi

# do not use dns servers provided by dhcp - we maintain a static list of
# do not use dns servers provided by dhcp - we maintain a static list of
# dns servers instead
uci set network.wan.peerdns=0
uci set network.wan6.peerdns=0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

# shellcheck disable=SC1091

. /lib/functions/guard.sh
guard "iproute"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/sh

# shellcheck disable=SC1091
# shellcheck disable=SC2086

. /lib/functions/guard.sh
guard "olsrd"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

# shellcheck disable=SC1091

. /lib/functions.sh

# remove the sta interface, leaving only wan
Expand All @@ -12,4 +14,3 @@ uci set pingcheck.@default\[0\].host=livecheck.berlin.freifunk.net
uci set pingcheck.@default\[0\].timeout=60

uci commit pingcheck

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/sh

# shellcheck disable=SC1091
# shellcheck disable=SC1083

. /lib/functions/guard.sh
guard "luci_statistics"

Expand All @@ -8,7 +11,7 @@ uci import luci_statistics <<EOF
EOF

# mod_ping and collectd_rrdtool use a lot of RAM, disable on 32MB routers
if [ "$(cat /proc/meminfo |grep MemTotal:|awk {'print $2'})" -gt "65536" ]; then
if [ "$(grep MemTotal: < /proc/meminfo | awk {'print $2'})" -gt "65536" ]; then
HAVE_PLENTY_RAM=1
else
HAVE_PLENTY_RAM=0
Expand Down Expand Up @@ -74,8 +77,8 @@ uci set luci_statistics.collectd_uptime=statistics
uci set luci_statistics.collectd_uptime.enable=1

# network - push data to monitor server
NETWORK="$(uci add luci_statistics collectd_network_server)"
uci set luci_statistics.$NETWORK.host=monitor.berlin.freifunk.net
NETWORK="$(uci add luci_statistics collectd_network_server)"
uci set "luci_statistics.$NETWORK.host=monitor.berlin.freifunk.net"
uci set luci_statistics.collectd_network=statistics
uci set luci_statistics.collectd_network.enable=1

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/sh

# shellcheck disable=SC1091

. /lib/functions/guard.sh

# change default hostname
if [ $(uci get system.@system[0].hostname) = OpenWrt ]; then
if [ "$(uci get system.@system[0].hostname)" = OpenWrt ]; then
uci set system.@system[0].hostname=gib-mir-einen-namen
uci commit system
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

# shellcheck disable=SC1091

. /lib/functions/guard.sh
guard "uhttpd"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
## the first wizard run
#

# shellcheck disable=SC1091
# shellcheck disable=SC3043

. /lib/functions.sh
. /lib/config/uci.sh
. /lib/functions/system.sh
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
#!/bin/sh

# shellcheck shell=dash
# shellcheck disable=SC2034
# shellcheck disable=SC1091

. /lib/functions/guard.sh

create_ffuplink() {
uci -q delete network.ffuplink
# create a very basic ffuplink interface
uci set network.ffuplink=interface
uci set network.ffuplink.device=ffuplink
uci set network.ffuplink.peerdns=0
# see https://github.com/freifunk-berlin/firmware/issues/561
uci set network.ffuplink.ip4table=ffuplink
uci set network.ffuplink.ip6table=ffuplink
# the following options need to be set by the individual uplink-package
uci set network.ffuplink.proto=none
uci commit network.ffuplink
uci -q delete network.ffuplink
# create a very basic ffuplink interface
uci set network.ffuplink=interface
uci set network.ffuplink.device=ffuplink
uci set network.ffuplink.peerdns=0
# see https://github.com/freifunk-berlin/firmware/issues/561
uci set network.ffuplink.ip4table=ffuplink
uci set network.ffuplink.ip6table=ffuplink
# the following options need to be set by the individual uplink-package
uci set network.ffuplink.proto=none
uci commit network.ffuplink

guard_delete notunnel
guard_delete tunnelberlin_openvpn
guard_delete tunnelberlin_tunneldigger
guard_delete vpn03_openvpn
guard_delete notunnel
guard_delete tunnelberlin_openvpn
guard_delete tunnelberlin_tunneldigger
guard_delete vpn03_openvpn
}

generate_random_mac_hex() {
local prefix=$1
local prefix="$1"

[ -n "$prefix" ] || return
local macaddr
# Create a static macaddr starting with "prefix" for ffuplink devices
# See the website https://www.itwissen.info/MAC-Adresse-MAC-address.html
for byte in 2 3 4 5 6; do
macaddr=$macaddr`dd if=/dev/urandom bs=1 count=1 2> /dev/null | hexdump -e '1/1 ":%02x"'`
done
[ -n "$prefix" ] || return
local macaddr
# Create a static macaddr starting with "prefix" for ffuplink devices
# See the website https://www.itwissen.info/MAC-Adresse-MAC-address.html
for byte in 2 3 4 5 6; do
macaddr=$macaddr$(dd if=/dev/urandom bs=1 count=1 2>/dev/null | hexdump -e '1/1 ":%02x"')
done

echo $prefix$macaddr
echo "$prefix$macaddr"
}
12 changes: 6 additions & 6 deletions packages/falter-common/files/lib/functions/guard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ guard() {
OPTION=$1

[ ! -f $CFG_FILE ] && touch $CFG_FILE && uci set $CFG.$NAME=$SECTION
[ "$(uci -q get $CFG.$NAME.$OPTION)" == "1" ] && exit 0
uci set $CFG.$NAME.$OPTION=1
[ "$(uci -q get "$CFG.$NAME.$OPTION")" = "1" ] && exit 0
uci set "$CFG.$NAME.$OPTION=1"
uci commit $CFG
}

Expand All @@ -20,15 +20,15 @@ guard_rename() {
DEST=$2

# get current setting or exit when not defined
cur_set=$(uci -q get $CFG.$NAME.$SRC) || return 0
uci delete $CFG.$NAME.$SRC
uci set $CFG.$NAME.$DEST=$cur_set
cur_set=$(uci -q get "$CFG.$NAME.$SRC") || return 0
uci delete "$CFG.$NAME.$SRC"
uci set "$CFG.$NAME.$DEST=$cur_set"
uci commit $CFG
}

guard_delete() {
OPTION=$1

uci -q delete $CFG.$NAME.$OPTION || return 0
uci -q delete "$CFG.$NAME.$OPTION" || return 0
uci commit $CFG
}
Loading

0 comments on commit b26a772

Please sign in to comment.