summaryrefslogtreecommitdiffstats
path: root/package/base-files/files/lib/functions.sh
diff options
context:
space:
mode:
authorAdrian Schmutzler <freifunk@adrianschmutzler.de>2019-09-28 15:12:55 +0200
committerDavid Bauer <mail@david-bauer.net>2019-10-13 19:03:57 +0200
commitc1388a2deb00b65ee4a06c0a1d4c461f2194ef38 (patch)
treecb5d3c0aec1212d942d41b0315674110d37db528 /package/base-files/files/lib/functions.sh
parentbba6646b5cba591946b3fd0caaad79cb6ec78043 (diff)
downloadopenwrt-c1388a2deb00b65ee4a06c0a1d4c461f2194ef38.tar.gz
openwrt-c1388a2deb00b65ee4a06c0a1d4c461f2194ef38.tar.bz2
openwrt-c1388a2deb00b65ee4a06c0a1d4c461f2194ef38.zip
base-files: move xor() from caldata extraction to functions.sh
The xor() function is defined in each of the caldata extraction scripts for several targets. Move it to functions.sh to reduce duplicate code. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Diffstat (limited to 'package/base-files/files/lib/functions.sh')
-rwxr-xr-xpackage/base-files/files/lib/functions.sh16
1 files changed, 16 insertions, 0 deletions
diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh
index 860fc04510..81176431d1 100755
--- a/package/base-files/files/lib/functions.sh
+++ b/package/base-files/files/lib/functions.sh
@@ -17,6 +17,22 @@ NO_EXPORT=1
LOAD_STATE=1
LIST_SEP=" "
+# xor multiple hex values of the same length
+xor() {
+ local val
+ local ret="0x$1"
+ local retlen=${#1}
+
+ shift
+ while [ -n "$1" ]; do
+ val="0x$1"
+ ret=$((ret ^ val))
+ shift
+ done
+
+ printf "%0${retlen}x" "$ret"
+}
+
append() {
local var="$1"
local value="$2"