From d68f074f0ae1fd29a452164988dce957ac18982f Mon Sep 17 00:00:00 2001 From: Mubashshir Date: Sun, 17 Sep 2023 20:30:08 +0600 Subject: scripts: Rename scripts Signed-off-by: Mubashshir --- data/scripts/common | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ data/scripts/common.sh | 50 ------------------------------------------- data/scripts/log-sync | 36 ------------------------------- data/scripts/sync-logs | 37 ++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 86 deletions(-) create mode 100644 data/scripts/common delete mode 100644 data/scripts/common.sh delete mode 100755 data/scripts/log-sync create mode 100755 data/scripts/sync-logs (limited to 'data') diff --git a/data/scripts/common b/data/scripts/common new file mode 100644 index 0000000..d1c3047 --- /dev/null +++ b/data/scripts/common @@ -0,0 +1,58 @@ +#!/bin/bash + +SERVER_URL="https://frypan.jadupc.com" #"dev.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 hour + 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" "$@" + ;; + hourly) + month="$1" + day="$2" + hour="$3" + shift 3 + set -- -d "month=$month" -d "day=$day" -d "hour=$hour" "$@" + ;; + esac + + [[ "${type%%/*}" != "user" ]] || set -- -d "user=$USER" "$@" + curl --disable -Ls \ + -d "type=${type%%/*}" -d "wlmac=$wlmac" \ + -d "enmac=$enmac" -d "year=$year" "$@" \ + "$SERVER_URL$endpoint" +} diff --git a/data/scripts/common.sh b/data/scripts/common.sh deleted file mode 100644 index 0fbaa45..0000000 --- a/data/scripts/common.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -SERVER_URL="https://frypan.jadupc.com" #"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 --disable -Ls \ - -d "type=${type%%/*}" -d "wlmac=$wlmac" \ - -d "enmac=$enmac" -d "year=$year" -d "user=$USER" "$@" \ - "$SERVER_URL$endpoint" -} diff --git a/data/scripts/log-sync b/data/scripts/log-sync deleted file mode 100755 index 7459a7b..0000000 --- a/data/scripts/log-sync +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -source "${BASH_ARGV0%/*}"/common.sh -RAW_DATA_PATH="${XDG_CACHE_HOME:-$HOME/.cache}/Watcher" - -enmac="$(getaddr "$(getiface "net/e")")" -wlmac="$(getaddr "$(getiface "net/w")")" - -get_logs() -{ - find "$RAW_DATA_PATH/$1" -type f -exec basename -a '{}' + \ - | grep -oE "$2" -} - -# shellcheck disable=SC2031,SC2030 -if [[ $1 == "weekly" ]]; then - watcher -ws 2> /dev/null >&2 - - get_logs Analysis '[0-9]+-[0-9]+' \ - | while IFS=- read -r week year; do - ! communicate "/whack/a/mole" user/weekly "$wlmac" "$enmac" "$year" "$week" --silent --fail || continue - - echo "Uploading log: Week $week, $year" >&2 - communicate "/puss/in/boots" user/weekly "$wlmac" "$enmac" "$year" "$week" \ - -# --data-urlencode "data@$RAW_DATA_PATH/Analysis/W$week-$year.csv" - done -else - get_logs daily_data '[0-9]{4}(-[0-9]{2}){2}' \ - | while IFS=- read -r year month day; do - ! [[ $(date --rfc-3339=date) == "$year-$month-$day" ]] || continue - ! communicate "/whack/a/mole" user/daily "$wlmac" "$enmac" "$year" "$month" "$day" --silent --fail || continue - - echo "Uploading log: $year-$month-$day" >&2 - communicate "/puss/in/boots" user/daily "$wlmac" "$enmac" "$year" "$month" "$day" \ - -# --data-urlencode "data@$RAW_DATA_PATH/daily_data/$year-$month-$day.csv" - done -fi diff --git a/data/scripts/sync-logs b/data/scripts/sync-logs new file mode 100755 index 0000000..adbe1a0 --- /dev/null +++ b/data/scripts/sync-logs @@ -0,0 +1,37 @@ +#!/bin/bash +source "${BASH_ARGV0%/*}"/common +RAW_DATA_PATH="${XDG_CACHE_HOME:-$HOME/.cache}/Watcher" + +enmac="$(getaddr "$(getiface "net/e")")" +wlmac="$(getaddr "$(getiface "net/w")")" + +get_logs() +{ + find "$RAW_DATA_PATH/$1" -type f -exec basename -a '{}' + \ + | grep -oE "$2" +} + +# shellcheck disable=SC2031,SC2030 +if [[ $1 == "weekly" ]]; then + watcher -ws 2> /dev/null >&2 + + get_logs Analysis '[0-9]+-[0-9]+' \ + | while IFS=- read -r week year; do + ! communicate "/whack/a/mole" user/weekly "$wlmac" "$enmac" "$year" "$week" --silent --fail || continue + + echo "Uploading log: Week $week, $year" >&2 + communicate "/puss/in/boots" user/weekly "$wlmac" "$enmac" "$year" "$week" \ + -# --data-urlencode "data@$RAW_DATA_PATH/Analysis/W$week-$year.csv" + done +else + get_logs daily_data '[0-9]{4}(-[0-9]{2}){2}' \ + | while IFS=- read -r year month day; do + ! [[ $(date --rfc-3339=date) == "$year-$month-$day" ]] || continue + ! communicate "/whack/a/mole" user/daily "$wlmac" "$enmac" "$year" "$month" "$day" --silent --fail \ + || continue + + echo "Uploading log: $year-$month-$day" >&2 + communicate "/puss/in/boots" user/daily "$wlmac" "$enmac" "$year" "$month" "$day" \ + -# --data-urlencode "data@$RAW_DATA_PATH/daily_data/$year-$month-$day.csv" + done +fi -- cgit v1.2.3