aboutsummaryrefslogtreecommitdiff
path: root/data/scripts/common.sh
diff options
context:
space:
mode:
authorLibravatar Mubashshir <ahm@jadupc.com>2023-03-23 17:01:08 +0600
committerLibravatar Mubashshir <ahm@jadupc.com>2023-03-23 17:02:05 +0600
commit171af59c7c1589eb7f16118ddd28e3a55f9cf0d1 (patch)
tree974fc505ee2b351e5f39b244b7019d8be02b99cc /data/scripts/common.sh
parentb3ccd6b08b908e60fd452bcfaf520e92e7b6f232 (diff)
downloadshopno-os-log-sync-171af59c7c1589eb7f16118ddd28e3a55f9cf0d1.tar.gz
shopno-os-log-sync-171af59c7c1589eb7f16118ddd28e3a55f9cf0d1.zip
Implement Log uploader
Signed-off-by: Mubashshir <ahm@jadupc.com>
Diffstat (limited to 'data/scripts/common.sh')
-rw-r--r--data/scripts/common.sh51
1 files changed, 51 insertions, 0 deletions
diff --git a/data/scripts/common.sh b/data/scripts/common.sh
new file mode 100644
index 0000000..faa6b03
--- /dev/null
+++ b/data/scripts/common.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+SERVER_URL="https://frypan.jadupc.com" #"builder.jadupc.com"
+SERVER_URL="https://builder.jadupc.com/logs" #"builder.jadupc.com"
+
+if [[ $DEBUG ]]; then
+ SERVER_URL="http://log-server.local"
+fi
+
+function getiface
+{
+ printf '%s\n' "/sys/class/$1"*/ | head -n1
+}
+
+function getaddr
+{
+ if [[ -d $1 ]]; then
+ tr ':' '-' < "$1/address"
+ else
+ echo '00-00-00-00-00-00'
+ fi
+}
+
+function communicate
+{
+ local endpoint type wlmac enmac year week day month
+ endpoint="$1"
+ type="$2"
+ wlmac="$3"
+ enmac="$4"
+ year="$5"
+ shift 5
+ case "${type#*/}" in
+ weekly)
+ week="$1"
+ shift 1
+ set -- -d "week=$week" "$@"
+ ;;
+ daily)
+ month="$1"
+ day="$2"
+ shift 2
+ set -- -d "month=$month" -d "day=$day" "$@"
+ ;;
+ esac
+
+ curl \
+ -d "type=${type%%/*}" -d "wlmac=$wlmac" \
+ -d "enmac=$enmac" -d "year=$year" "$@" \
+ "$SERVER_URL$endpoint"
+}