From 23326259539a879c6ee0010dc05d57badc04a589 Mon Sep 17 00:00:00 2001 From: poka Date: Sun, 12 Jul 2020 03:36:24 +0200 Subject: [PATCH] fix stuff --- .gitignore | 3 +++ src/shell/.env.example | 2 ++ src/shell/functions.sh | 12 ++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/shell/.env.example diff --git a/.gitignore b/.gitignore index 916d476..59160a5 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,6 @@ package-lock.json # Memo memo.txt + +# BoG +src/shell/.env diff --git a/src/shell/.env.example b/src/shell/.env.example new file mode 100644 index 0000000..b741c7a --- /dev/null +++ b/src/shell/.env.example @@ -0,0 +1,2 @@ +API_TOKEN="" +API_ID="" diff --git a/src/shell/functions.sh b/src/shell/functions.sh index aaf946a..e6b5998 100755 --- a/src/shell/functions.sh +++ b/src/shell/functions.sh @@ -1,14 +1,22 @@ #!/bin/bash +MY_PATH="`dirname \"$0\"`" # relative +MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized + +[[ -n $MY_PATH/.env ]] && source $MY_PATH/.env || (echo "Please create $MY_PATH/.env as $MY_PATH/.env.example" && exit 1) + sendmsg() { chan="$1" msg="${@:2}" [[ ! $chan || ! $msg ]] && echo "Please select user and message." && exit 1 -curl -s -H "X-Auth-Token: 9aHo-EZ4ySYv9reV7rwcRLxuOSWeATmKlyKRvwebIXa" \ - -H "X-User-Id: HTuZCNhtoG4yQocCg" \ +curl -s -H "X-Auth-Token: $API_TOKEN" \ + -H "X-User-Id: $API_ID" \ -H "Content-type:application/json" \ http://192.168.9.6:10140/api/v1/chat.postMessage \ -d "{ \"channel\": \"$chan\", \"text\": \"$msg\" }" > /dev/null 2>&1 } + +$@ +