[LEDE-DEV] [PATCH v2] nvram: fix globbing, word splitting and arithmetic variables

Jan-Tarek Butt tarek at ring0.de
Wed Oct 5 03:39:29 PDT 2016


Double quote to prevent globbing and word splitting.
$/${} is unnecessary on arithmetic variables.
Remove unused variables

Signed-off-by: Jan-Tarek Butt <tarek at ring0.de>
---
 package/utils/nvram/files/nvram.init | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/package/utils/nvram/files/nvram.init b/package/utils/nvram/files/nvram.init
index 467ab28..4a50a22 100755
--- a/package/utils/nvram/files/nvram.init
+++ b/package/utils/nvram/files/nvram.init
@@ -4,10 +4,10 @@
 # This file handles the NVRAM quirks of various hardware.
 
 START=02
-alias debug=${DEBUG:-:}
+alias debug="${DEBUG:-:}"
 
 nvram_default() {
-	[ -z "$(nvram get $1)" ] && nvram set "$1=$2"
+	[ -z "$(nvram get "$1")" ] && nvram set "$1=$2"
 }
 
 nvram_set() { # for the linksys fixup part
@@ -20,12 +20,11 @@ nvram_set() { # for the linksys fixup part
 fixup_linksys() {
 	# work around braindead CFE defaults in linksys routers
 	boardtype=$(nvram get boardtype)
-	boardnum=$(nvram get boardnum)
 	boardflags=$(($(nvram get boardflags)))
-	adm_switch="$(( ($boardflags & 0x80) >> 7 ))"
+	adm_switch="$(( (boardflags & 0x80) >> 7 ))"
 
 	[ -n "$(nvram get vxkilled)" ] && boardtype=0 # don't mess with the ram settings on the hacked cfe
-	case "$(( $boardtype ))" in
+	case "$(( boardtype ))" in
 		"1800") #0x708
 			if [ "$adm_switch" = 0 ]; then
 				nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))"
@@ -53,10 +52,10 @@ fixup_linksys() {
 		;;
 		"1071") #0x042f
 			# do sanity check first! max 0x0011 = 128mb
-			SDRAM_INIT=$(printf %d $(/usr/sbin/nvram get sdram_init))
-			[ "$SDRAM_INIT" -lt "9" -o "$SDRAM_INIT" -gt "17" ] && {
+			SDRAM_INIT=$(printf %d "$(/usr/sbin/nvram get sdram_init)")
+			[ "$SDRAM_INIT" -lt "9" ] || [ "$SDRAM_INIT" -gt "17" ] && {
 				# set this to default: 0x09 only if value is invaild like 16MB on Asus WL-500GP
-				echo "sdram_init is invaild: $(printf 0x%04x $SDRAM_INIT), force to default!"
+				echo "sdram_init is invaild: $(printf 0x%04x "$SDRAM_INIT"), force to default!"
 				nvram_set sdram_init 0x0009
 			}
 			# on WRT54G3GV2 set flag, so checksum errors of firmware image 2 don't stop the boot process
@@ -83,15 +82,15 @@ start() {
 
 	[ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && {
 		# if default wifi mac, set two higher than the lan mac
-		nvram set il0macaddr=$(nvram get et0macaddr|
-		awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}')
+		nvram set il0macaddr="$(nvram get et0macaddr|
+		awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}')"
 	}
 
 	[ "$(nvram get et0macaddr)" = "00:90:4c:c0:00:08" ] && {
 		# OvisLink WL-1600GL mac workaround
-		nvram set et0macaddr=$(hexdump -n 6 -s 130976 -e '5/1 "%02x:" "%02x" ' /dev/mtd/0)
-		nvram set il0macaddr=$(nvram get et0macaddr|
-		awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}')
+		nvram set et0macaddr="$(hexdump -n 6 -s 130976 -e '5/1 "%02x:" "%02x" ' /dev/mtd/0)"
+		nvram set il0macaddr="$(nvram get et0macaddr|
+		awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}')"
 	}
 
 	[ "$COMMIT" = "1" ] && nvram commit
-- 
2.10.0




More information about the Lede-dev mailing list