Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ff67856
ci: add linting via luacheck and shellcheck
a-gave Jun 29, 2026
6eb0b73
fix: luacheck: lime-system config.lua
a-gave Jul 17, 2026
8ea2bbe
fix: luacheck: lime-system firewall.lua
a-gave Jul 17, 2026
9906f7b
fix: luacheck: lime-system generic_config.lua
a-gave Jul 17, 2026
e626b54
fix: luacheck: lime-system modules.lua
a-gave Jul 17, 2026
2370ef0
fix: luacheck: lime-system network.lua
a-gave Jul 17, 2026
58fbd3d
fix: luacheck: lime-system system.lua
a-gave Jul 17, 2026
5a2d320
fix: luacheck: lime-system utils.lua
a-gave Jul 17, 2026
e1a7888
fix: luacheck: lime-system wireless.lua
a-gave Jul 17, 2026
1f049ea
fix: luacheck: lime-system protocols and tests; init .luacheckrc
a-gave Jul 19, 2026
5b635cc
fix: luacheck: tests
a-gave Jul 31, 2026
01249a4
fix: luacheck: lime-proto
a-gave Jul 31, 2026
695792c
fix: luacheck: lime-hwd
a-gave Jul 31, 2026
589264f
fix: luacheck: shared-state
a-gave Jul 31, 2026
e37c239
fix: luacheck: ubus-lime
a-gave Jul 31, 2026
527e758
fix: luacheck: prometheus
a-gave Jul 31, 2026
c71946f
fix: luacheck: lime-eth-config lime-smart-wifi
a-gave Jul 31, 2026
d6006a5
fix: luacheck: more packages
a-gave Jul 31, 2026
48aef90
fix: luacheck: first-boot-wizard
a-gave Jul 31, 2026
ba4f382
fix: luacheck: pirania
a-gave Jul 31, 2026
2e2040e
fix: shellcheck: tools
a-gave Jul 31, 2026
23c1268
fix: shellcheck: packages
a-gave Aug 4, 2026
eef0256
fix: lime-system comment function apply from protos and modules
a-gave Aug 5, 2026
597853c
fix: lua files: replace -- with --! in comments
a-gave Aug 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint

on:
push:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:

permissions:
contents: read

jobs:
lua:
name: Lua
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Dependencies
run: sudo apt-get -y update && sudo apt-get -y install lua-check
- name: Lint Lua code
run: ./tools/ci/lint/lua.sh

sh:
name: Shell
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Dependencies
run: sudo apt-get -y update && sudo apt-get -y install shellcheck
- name: Lint shell code
run: ./tools/ci/lint/sh.sh
70 changes: 70 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
-- Global defaults
std = "lua51"
max_line_length = 120

local include_lua_files = require("luacheck_helper")

local function tableConcat(t1, t2)
for i = 1, #t2 do
t1[#t1 + 1] = t2[i]
end
return t1
end

include_dot_lua_files = {
"packages/**/*.lua",
"tests/**/*.lua",
"tools/**/*.lua",
}

include_files = tableConcat(include_dot_lua_files, include_lua_files)

ignore = {
-- Allow calling nonstandard functions on globals, i.e.:
-- accessing undefined field 'searchers' of global package
"143",
}

exclude_files = {
-- Contains unknown functions like Map() and translate()
"packages/bmx7-mdns/*",
}

-- Test files: define test framework globals
files["**/tests/**"] = {
globals = {
"after_each",
"assert",
"before_each",
"describe",
"it",
"match",
"setup",
"spy",
"stub",
"teardown",
},
-- Shadowing an upvalue.
ignore = { "431" },
}

-- Apply --no-unused-args to modules
files["**/usr/lib/lua/lime/proto/**"] = {
-- 212 = unused argument
ignore = { "212" },
}

-- Ignore undefined variable 'metric' in prometheus-collectors
-- since it is made available by the package prometheus-node-exporter-lua
files["**/usr/lib/lua/prometheus-collectors/**"] = {
globals = {
"metric",
},
}

-- Ignore undefined global variable 'uhttpd' in pirania files
files["**/packages/pirania/**"] = {
globals = {
"uhttpd",
},
}
70 changes: 70 additions & 0 deletions luacheck_helper.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/lua

local lfs = require("lfs")

local function firstLine(path)
local f = io.open(path, "rb")
if not f then
return nil
end
local line = f:read("*l")
f:close()
return line
end

local function isLuaShebang(line)
if not line then
return false
end

if line == "#!/usr/bin/lua" then
return true
end

-- /usr/bin/env lua (with optional version suffix)
-- Examples:
-- #!/usr/bin/env lua
-- #!/usr/bin/env lua5.4
local envLua = line:match("^#!.*/env%s+lua[%d%.]*$")
if envLua then
return true
end

return false
end

local function endsWith(s, suffix)
return s:sub(-#suffix) == suffix
end

local function walk(dir, callback)
for entry in lfs.dir(dir) do
if entry ~= "." and entry ~= ".." then
local path = dir .. "/" .. entry
local attr = lfs.attributes(path)
if attr then
if attr.mode == "directory" then
walk(path, callback)
elseif attr.mode == "file" then
callback(path)
end
end
end
end
end

-- Change this to the directory you want to scan
local root = "packages"
local include_lua_files = {}

walk(root, function(path)
if not endsWith(path, ".lua") then
local line = firstLine(path)
if isLuaShebang(line) then
print(path)
table.insert(include_lua_files, path)
end
end
end)

return include_lua_files
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#!/bin/sh
# shellcheck disable=SC1091

[ "$ACTION" = "add" ] || exit 0

[ "$ACTION" == "add" ] || exit 0

logger $(env)
logger "$(env)"
PHYNBR=${DEVPATH##*/phy}

[ -n $PHYNBR ] || exit 0
[ -n "$PHYNBR" ] || exit 0

. /lib/functions.sh
. /lib/functions/system.sh

board=$(board_name)
# board=$(board_name)

function find_radio () {
find_radio () {
uci show wireless | grep -m 1 "$1" | sed 's/wireless.\(.*\).path=.*/\1/'
}

function find_wifi_ifaces () {
find_wifi_ifaces () {
uci show wireless | grep "\.device='$1'$" | sed 's/wireless.\(.*\).device=.*/\1/'
}

Expand All @@ -26,16 +27,16 @@ case "$DEVPATH" in
radioPath=${radioPath%%/ieee80211/*}
radio=$(find_radio "$radioPath")
for wifi_iface in $(find_wifi_ifaces "$radio"); do
uci delete wireless.${wifi_iface}
uci delete "wireless.${wifi_iface}"
done
uci set wireless.${radio}.disabled=0
uci set wireless.${radio}_auto_usb_wwan=wifi-iface
uci set wireless.${radio}_auto_usb_wwan.device="${radio}"
uci set wireless.${radio}_auto_usb_wwan.network='auto_usb_wwan'
uci set wireless.${radio}_auto_usb_wwan.mode='sta'
uci set wireless.${radio}_auto_usb_wwan.ssid='internet'
uci set wireless.${radio}_auto_usb_wwan.encryption='psk2'
uci set wireless.${radio}_auto_usb_wwan.key='internet'
uci set "wireless.${radio}.disabled=0"
uci set "wireless.${radio}_auto_usb_wwan=wifi-iface"
uci set "wireless.${radio}_auto_usb_wwan.device=${radio}"
uci set "wireless.${radio}_auto_usb_wwan.network='auto_usb_wwan'"
uci set "wireless.${radio}_auto_usb_wwan.mode='sta'"
uci set "wireless.${radio}_auto_usb_wwan.ssid='internet'"
uci set "wireless.${radio}_auto_usb_wwan.encryption='psk2'"
uci set "wireless.${radio}_auto_usb_wwan.key='internet'"
uci commit wireless
uci set network.auto_usb_wwan=interface
uci set network.auto_usb_wwan.proto=dhcp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# batman-adv gateway handling (DHCP mangling)
[ "$(uci -q get batman-adv.bat0.gw_mode)" == "client" ] || exit 0
[ "$(uci -q get batman-adv.bat0.gw_mode)" = "client" ] || exit 0
if grep -q "^=>" /sys/kernel/debug/batman_adv/bat0/gateways ; then
BATTYPE=gw BATACTION=add /etc/hotplug.d/net/99-batman-gw
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# batman-adv gateway handling (DHCP mangling)
[ "$(uci -q get batman-adv.bat0.gw_mode)" == "client" ] || exit 0
[ "$(uci -q get batman-adv.bat0.gw_mode)" = "client" ] || exit 0
if grep -q "^=>" /sys/kernel/debug/batman_adv/bat0/gateways ; then
BATTYPE=gw BATACTION=del /etc/hotplug.d/net/99-batman-gw
fi
Expand Down
7 changes: 4 additions & 3 deletions packages/bmx7-auto-gw-bw-mode/files/etc/init.d/bmx7-auto-bw
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ SAVE="/tmp/bmx7-internet-bw.log"

start() {
echo "Ensuring bmx7-auto-bw-test is run by cron"
local rnd
if ! ( grep -q "$BIN" "$CRONTAB" 2>/dev/null ) ; then
# run twice and random sleep for better entropy
local rnd=$(awk 'BEGIN{srand();print int(rand()*3)}')
sleep $rnd
# run twice and random sleep for better entropy
rnd=$(awk 'BEGIN{srand();print int(rand()*3)}')
sleep "$rnd"
rnd=$(awk 'BEGIN{srand();print int(rand()*60)}')
echo "$rnd */6 * * * SAVE=$SAVE $BIN" >> "$CRONTAB"
/etc/init.d/cron enable
Expand Down
20 changes: 11 additions & 9 deletions packages/bmx7-auto-gw-bw-mode/files/usr/sbin/bmx7-auto-bw-test
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/sh
# shellcheck disable=SC2034

TRIES=3

bw_test() {
local bw=""
local try=0
while [ -z "$bw" -a $try -lt $TRIES ]; do
test=$({ wget -T5 -q $1 -O- | pv -n -b -t >/dev/null; } 2>&1)
bw=$(echo $test | awk '{printf "%.0f",$NF/$(NF-1)*8}')
while [ -z "$bw" ] && [ $try -lt $TRIES ]; do
test=$({ wget -T5 -q "$1" -O- | pv -n -b -t >/dev/null; } 2>&1)
bw=$(echo "$test" | awk '{printf "%.0f",$NF/$(NF-1)*8}')
try=$((try+1))
done
echo $bw
echo "$bw"
}

random_test() {
Expand All @@ -27,16 +29,16 @@ random_test() {

rnd=$(awk 'BEGIN{srand();print int(rand()*11)}')
svid="sv$rnd"
sv=$(eval echo \$$svid)
sv=$(eval echo "\$$svid")
logger -t bmx7-auto-gw "Testing bandwidth [$sv]"
bw_test "$sv"
}

cat /var/run/bmx7/json/parameters | jsonfilter -e '@["OPTIONS"][*]' | grep tunIn | grep -q "0.0.0.0" && {
jsonfilter -e '@["OPTIONS"][*]' < /var/run/bmx7/json/parameters | grep tunIn | grep -q "0.0.0.0" && {
bw=$(random_test)
[ -n "$bw" -a $bw -gt 1000 ] && {
[ -n "$bw" ] && [ "$bw" -gt 1000 ] && {
logger -t bmx7-auto-gw "Got bandwidth of $bw bit/s"
bmx7 -c tunIn inet4 /b $bw /n 0.0.0.0/0
[ -n "$SAVE" ] && echo $(date +"%Y.%m.%d.%H.%M") $bw >> $SAVE
bmx7 -c tunIn inet4 /b "$bw" /n 0.0.0.0/0
[ -n "$SAVE" ] && echo "$(date +"%Y.%m.%d.%H.%M")" "$bw" >> "$SAVE"
}
}
Loading
Loading