Skip to content
Snippets Groups Projects
Unverified Commit 091ced3f authored by Andreas Ziegler's avatar Andreas Ziegler Committed by GitHub
Browse files

Merge pull request #3471 from neocturne/lint-initscripts

Fix linting for initscripts
parents 60734d56 e94775f1
No related branches found
No related tags found
No related merge requests found
Showing
with 81 additions and 52 deletions
...@@ -6,6 +6,7 @@ START=10 ...@@ -6,6 +6,7 @@ START=10
start() { start() {
config_load gluon config_load gluon
config_get_bool reconfigure core reconfigure 0 config_get_bool reconfigure core reconfigure 0
# shellcheck disable=SC2154
if [ "$reconfigure" = 1 ]; then if [ "$reconfigure" = 1 ]; then
gluon-reconfigure gluon-reconfigure
fi fi
......
...@@ -7,7 +7,7 @@ STOP=90 ...@@ -7,7 +7,7 @@ STOP=90
start_service() { start_service() {
procd_open_instance procd_open_instance
procd_set_param command /usr/sbin/gluon-arp-limiter procd_set_param command /usr/sbin/gluon-arp-limiter
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
procd_set_param stderr 1 procd_set_param stderr 1
procd_close_instance procd_close_instance
......
...@@ -15,11 +15,9 @@ ...@@ -15,11 +15,9 @@
# Removing a specific rule file: # Removing a specific rule file:
# $ /etc/init.d/gluon-ebtables stop /lib/gluon/ebtables/100-mcast-chain # $ /etc/init.d/gluon-ebtables stop /lib/gluon/ebtables/100-mcast-chain
START=19 START=19
STOP=91 STOP=91
exec_file() { exec_file() {
local file="$1" local file="$1"
...@@ -37,12 +35,10 @@ exec_file() { ...@@ -37,12 +35,10 @@ exec_file() {
} }
exec_all() { exec_all() {
local sort_arg="$1"
local old_ifs="$IFS" local old_ifs="$IFS"
IFS=' IFS='
' '
for file in `find /lib/gluon/ebtables -type f | sort $sort_arg`; do for file in $(find /lib/gluon/ebtables -type f | sort "$@"); do
exec_file "$file" exec_file "$file"
done done
IFS="$old_ifs" IFS="$old_ifs"
...@@ -51,7 +47,9 @@ exec_all() { ...@@ -51,7 +47,9 @@ exec_all() {
start() { start() {
( (
# shellcheck disable=SC2030,SC2031,SC2089
export EBTABLES_RULE='"ebtables-tiny -t " .. table .. " -A " .. command' export EBTABLES_RULE='"ebtables-tiny -t " .. table .. " -A " .. command'
# shellcheck disable=SC2030,SC2031,SC2089
export EBTABLES_CHAIN='"ebtables-tiny -t " .. table .. " -N " .. name .. " -P " .. policy' export EBTABLES_CHAIN='"ebtables-tiny -t " .. table .. " -N " .. name .. " -P " .. policy'
# Contains /var/lib/ebtables/lock for '--concurrent' # Contains /var/lib/ebtables/lock for '--concurrent'
...@@ -59,7 +57,7 @@ start() { ...@@ -59,7 +57,7 @@ start() {
mkdir -p /var/lib/ebtables mkdir -p /var/lib/ebtables
if [ -z "$1" ]; then if [ -z "$1" ]; then
exec_all '' exec_all
else else
exec_file "$1" exec_file "$1"
fi fi
...@@ -68,11 +66,13 @@ start() { ...@@ -68,11 +66,13 @@ start() {
stop() { stop() {
( (
# shellcheck disable=SC2030,SC2031,SC2090
export EBTABLES_RULE='"ebtables-tiny -t " .. table .. " -D " .. command' export EBTABLES_RULE='"ebtables-tiny -t " .. table .. " -D " .. command'
# shellcheck disable=SC2030,SC2031,SC2090
export EBTABLES_CHAIN='"ebtables-tiny -t " .. table .. " -X " .. name' export EBTABLES_CHAIN='"ebtables-tiny -t " .. table .. " -X " .. name'
if [ -z "$1" ]; then if [ -z "$1" ]; then
exec_all '-r' exec_all -r
else else
exec_file "$1" exec_file "$1"
fi fi
......
...@@ -27,7 +27,7 @@ reload_service() { ...@@ -27,7 +27,7 @@ reload_service() {
for i in $(echotol3roamd "get_meshifs"| jsonfilter -e "@.mesh_interfaces[@]") for i in $(echotol3roamd "get_meshifs"| jsonfilter -e "@.mesh_interfaces[@]")
do do
if ! ubus call network.interface dump | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device"|grep -q $i if ! ubus call network.interface dump | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device" | grep -qxF "$i"
then then
echotol3roamd "del_meshif $i" echotol3roamd "del_meshif $i"
fi fi
...@@ -35,15 +35,17 @@ reload_service() { ...@@ -35,15 +35,17 @@ reload_service() {
} }
start_service () { start_service () {
local interfaces=$( local interfaces prefix4 prefix6 localip roamingprefix
interfaces=$(
for dev in $(gluon-list-mesh-interfaces); do echo " -m $dev"; done for dev in $(gluon-list-mesh-interfaces); do echo " -m $dev"; done
[ "$(ifstatus local_node | jsonfilter -e '@.up')" = 'true' ] && echo ' -i local-node' [ "$(ifstatus local_node | jsonfilter -e '@.up')" = 'true' ] && echo ' -i local-node'
) )
local prefix4="$(lua -e 'prefix4 = require("gluon.site").prefix4() if prefix4 then print(" -p " .. prefix4) end')" prefix4="$(lua -e 'prefix4 = require("gluon.site").prefix4() if prefix4 then print(" -p " .. prefix4) end')"
local prefix6="$(lua -e 'print(" -p " .. require("gluon.site").prefix6())')" prefix6="$(lua -e 'print(" -p " .. require("gluon.site").prefix6())')"
local localip="$(uci get network.loopback.ip6addr | cut -d/ -f1)" localip="$(uci get network.loopback.ip6addr | cut -d/ -f1)"
local roamingprefix="$(lua -e 'print(" -P " .. require("gluon.l3").node_client_prefix6())')" roamingprefix="$(lua -e 'print(" -P " .. require("gluon.l3").node_client_prefix6())')"
/sbin/sysctl -w net.ipv6.neigh.default.gc_thresh1=2 /sbin/sysctl -w net.ipv6.neigh.default.gc_thresh1=2
/sbin/sysctl -w net.ipv4.neigh.default.gc_thresh1=2 /sbin/sysctl -w net.ipv4.neigh.default.gc_thresh1=2
...@@ -51,14 +53,17 @@ start_service () { ...@@ -51,14 +53,17 @@ start_service () {
procd_open_instance procd_open_instance
procd_set_param stdout 1 procd_set_param stdout 1
procd_set_param stderr 1 procd_set_param stderr 1
procd_set_param respawn ${respawn_threshold:-3660} ${respawn_timeout:-5} ${respawn_retry:-0} procd_set_param respawn "${respawn_threshold:-3660}" "${respawn_timeout:-5}" "${respawn_retry:-0}"
procd_set_param command "$PROG" -s /var/run/l3roamd.sock $prefix4 $prefix6 $interfaces -t 254 -a $localip -b br-client $roamingprefix # shellcheck disable=SC2086
procd_set_param command "$PROG" -s /var/run/l3roamd.sock "$prefix4" "$prefix6" $interfaces -t 254 -a "$localip" -b br-client "$roamingprefix"
procd_close_instance procd_close_instance
} }
service_triggers() { service_triggers() {
local script=$(readlink "$initscript") local script name
local name=$(basename "${script:-$initscript}") # shellcheck disable=SC2154
script=$(readlink "$initscript")
name=$(basename "${script:-$initscript}")
procd_open_trigger procd_open_trigger
procd_add_raw_trigger 'interface.*' 0 "/etc/init.d/$name" reload procd_add_raw_trigger 'interface.*' 0 "/etc/init.d/$name" reload
......
...@@ -15,11 +15,13 @@ waitforsocket() { ...@@ -15,11 +15,13 @@ waitforsocket() {
start_service() { start_service() {
local interfaces=$(for dev in $(gluon-list-mesh-interfaces); do echo " -i $dev"; done) local interfaces
interfaces=$(for dev in $(gluon-list-mesh-interfaces); do echo " -i $dev"; done)
procd_open_instance procd_open_instance
procd_set_param command $DAEMON -s $SOCKET $interfaces # shellcheck disable=SC2086
procd_set_param respawn ${respawn_threshold:-60} ${respawn_timeout:-1} ${respawn_retry:-0} procd_set_param command "$DAEMON" -s "$SOCKET" $interfaces
procd_set_param respawn "${respawn_threshold:-60}" "${respawn_timeout:-1}" "${respawn_retry:-0}"
procd_set_param stderr 1 procd_set_param stderr 1
procd_set_param stdout 1 procd_set_param stdout 1
procd_close_instance procd_close_instance
...@@ -30,15 +32,15 @@ mmfd_get_interfaces() { ...@@ -30,15 +32,15 @@ mmfd_get_interfaces() {
} }
mmfd_has_interface() { mmfd_has_interface() {
mmfd_get_interfaces | grep -q "^$1$" mmfd_get_interfaces | grep -qxF "$1"
} }
addif() { addif() {
echo "add_meshif $@" | uc $SOCKET echo "add_meshif $1" | uc $SOCKET
} }
delif() { delif() {
echo "del_meshif $@" | uc $SOCKET echo "del_meshif $1" | uc $SOCKET
} }
reload_service() { reload_service() {
...@@ -46,22 +48,24 @@ reload_service() { ...@@ -46,22 +48,24 @@ reload_service() {
for i in $(ubus call network.interface dump | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device") for i in $(ubus call network.interface dump | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device")
do do
if ! mmfd_has_interface $i; then if ! mmfd_has_interface "$i"; then
addif $i addif "$i"
fi fi
done done
for i in $(mmfd_get_interfaces) for i in $(mmfd_get_interfaces)
do do
if ! ubus call network.interface dump | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device" | grep -q "^$i$"; then if ! ubus call network.interface dump | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device" | grep -qxF "$i"; then
delif $i delif "$i"
fi fi
done done
} }
service_triggers() { service_triggers() {
local script=$(readlink "$initscript") local script name
local name=$(basename "${script:-$initscript}") # shellcheck disable=SC2154
script=$(readlink "$initscript")
name=$(basename "${script:-$initscript}")
procd_open_trigger procd_open_trigger
procd_add_raw_trigger "interface.*" 0 "/etc/init.d/$name" reload procd_add_raw_trigger "interface.*" 0 "/etc/init.d/$name" reload
......
...@@ -5,11 +5,12 @@ START=50 ...@@ -5,11 +5,12 @@ START=50
DAEMON=/usr/sbin/gluon-radv-filterd DAEMON=/usr/sbin/gluon-radv-filterd
start_service() { start_service() {
local threshold="$(lua -e 'print(require("gluon.site").radv_filterd.threshold(20))')" local threshold
threshold="$(lua -e 'print(require("gluon.site").radv_filterd.threshold(20))')"
procd_open_instance procd_open_instance
procd_set_param command $DAEMON -i br-client -c RADV_FILTER -t $threshold procd_set_param command "$DAEMON" -i br-client -c RADV_FILTER -t "$threshold"
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
procd_set_param netdev br-client procd_set_param netdev br-client
procd_set_param stderr 1 procd_set_param stderr 1
procd_close_instance procd_close_instance
......
...@@ -7,8 +7,9 @@ start_service() { ...@@ -7,8 +7,9 @@ start_service() {
[ -x /lib/gluon/radvd/arguments ] || return 1 [ -x /lib/gluon/radvd/arguments ] || return 1
procd_open_instance procd_open_instance
# shellcheck disable=SC2046
procd_set_param command /usr/sbin/uradvd $(/lib/gluon/radvd/arguments) procd_set_param command /usr/sbin/uradvd $(/lib/gluon/radvd/arguments)
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
procd_set_param stderr 1 procd_set_param stderr 1
procd_close_instance procd_close_instance
} }
...@@ -7,21 +7,25 @@ DAEMON=/usr/bin/respondd ...@@ -7,21 +7,25 @@ DAEMON=/usr/bin/respondd
MAXDELAY=10 MAXDELAY=10
start_service() { start_service() {
local ifdump="$(ubus call network.interface dump)" local ifdump meshdevs clientdevs
ifdump="$(ubus call network.interface dump)"
local meshdevs=$(for dev in $(echo "$ifdump" | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device"); do echo " -i $dev";done;) meshdevs=$(for dev in $(echo "$ifdump" | jsonfilter -e "@.interface[@.proto='gluon_mesh' && @.up=true].device"); do echo " -i $dev"; done)
local clientdevs=$(for dev in $(echo "$ifdump" | jsonfilter -e "@.interface[@.interface='$(cat /lib/gluon/respondd/client.dev 2>/dev/null)' && @.up=true].device"); do echo " -i $dev -t $MAXDELAY";done;) clientdevs=$(for dev in $(echo "$ifdump" | jsonfilter -e "@.interface[@.interface='$(cat /lib/gluon/respondd/client.dev 2>/dev/null)' && @.up=true].device"); do echo " -i $dev -t $MAXDELAY"; done)
procd_open_instance procd_open_instance
procd_set_param command $DAEMON -d /usr/lib/respondd -p 1001 -g ff02::2:1001 $meshdevs -g ff05::2:1001 $clientdevs # shellcheck disable=SC2086
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} procd_set_param command "$DAEMON" -d /usr/lib/respondd -p 1001 -g ff02::2:1001 $meshdevs -g ff05::2:1001 $clientdevs
procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
procd_set_param stderr 1 procd_set_param stderr 1
procd_close_instance procd_close_instance
} }
service_triggers() { service_triggers() {
local script=$(readlink "$initscript") local script name
local name=$(basename ${script:-$initscript}) # shellcheck disable=SC2154
script=$(readlink "$initscript")
name=$(basename "${script:-$initscript}")
procd_open_trigger procd_open_trigger
procd_add_raw_trigger "interface.*" 0 "/etc/init.d/$name" reload procd_add_raw_trigger "interface.*" 0 "/etc/init.d/$name" reload
......
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
# shellcheck disable=SC1091
if [ -x /etc/init.d/urngd ] && /etc/init.d/urngd enabled; then if [ -x /etc/init.d/urngd ] && /etc/init.d/urngd enabled; then
. /etc/init.d/urngd . /etc/init.d/urngd
fi fi
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
START=15 START=15
boot() { boot() {
local enabled="$(uci -q get 'gluon-setup-mode.@setup_mode[0].enabled')" local enabled configured
local configured="$(uci -q get 'gluon-setup-mode.@setup_mode[0].configured')" enabled="$(uci -q get 'gluon-setup-mode.@setup_mode[0].enabled')"
configured="$(uci -q get 'gluon-setup-mode.@setup_mode[0].configured')"
uci set 'gluon-setup-mode.@setup_mode[0].enabled=0' uci set 'gluon-setup-mode.@setup_mode[0].enabled=0'
uci commit gluon-setup-mode uci commit gluon-setup-mode
if [ "$enabled" != 1 -a "$configured" = 1 ]; then if [ "$enabled" != 1 ] && [ "$configured" = 1 ]; then
# This can happen after an upgrade from a version before the config file was called gluon-setup-mode # This can happen after an upgrade from a version before the config file was called gluon-setup-mode
# We'll just reboot to return to the normal mode... # We'll just reboot to return to the normal mode...
/etc/init.d/done boot /etc/init.d/done boot
......
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
# shellcheck disable=SC1091
USE_PROCD=1 USE_PROCD=1
PROG=/usr/sbin/dropbear PROG=/usr/sbin/dropbear
NAME=dropbear NAME=dropbear
......
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
# shellcheck disable=SC1091,SC2154
START=96 START=96
start() { start() {
......
...@@ -3,7 +3,11 @@ ...@@ -3,7 +3,11 @@
set -e set -e
is_scriptfile() { is_scriptfile() {
echo "$1" | grep -qE '.*\.sh$' || head -n1 "$1" | grep -qE '^#.*(sh|bash)$' echo "$1" | grep -q '\.sh$' || head -n1 "$1" | grep -qE '^#!(.*\<bash|/bin/sh)$'
}
is_initscript() {
head -n1 "$1" | grep -qxF '#!/bin/sh /etc/rc.common'
} }
find contrib -type f | while read -r file; do find contrib -type f | while read -r file; do
...@@ -14,10 +18,13 @@ find contrib -type f | while read -r file; do ...@@ -14,10 +18,13 @@ find contrib -type f | while read -r file; do
done done
find package -type f | while read -r file; do find package -type f | while read -r file; do
is_scriptfile "$file" || continue if is_scriptfile "$file"; then
echo "Checking $file" echo "Checking $file"
shellcheck -f gcc -x -s sh -e SC2039,SC3043,SC3037,SC3057 "$file" shellcheck -f gcc -x -s sh -e SC2039,SC3043,SC3037,SC3057 "$file"
elif is_initscript "$file"; then
echo "Checking $file (initscript)"
shellcheck -f gcc -x -s sh -e SC2034,SC2039,SC3043,SC3037,SC3057 "$file"
fi
done done
find scripts -type f | while read -r file; do find scripts -type f | while read -r file; do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment