From 2c22e95941b8997535b441efccd8566d7ce3155c Mon Sep 17 00:00:00 2001 From: syui Date: Sat, 17 Feb 2024 17:35:49 +0900 Subject: [PATCH] add scpt cron --- README.md | 8 ++++++++ test/ai.zsh | 5 +++++ test/cron.zsh | 7 +++++++ test/env | 26 +++++--------------------- test/token.zsh | 12 ++++++++++++ 5 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 test/cron.zsh diff --git a/README.md b/README.md index 0a0a8dc..1aa3a0f 100644 --- a/README.md +++ b/README.md @@ -96,3 +96,11 @@ $ cp -rf ~/.config/ai ./.config/ $ docker compose up ``` + +### cron + +```sh +$ sudo pacman -S fcron +$ fcrontab -e +* * * * * $HOME/bot/test/ai.zsh c +``` diff --git a/test/ai.zsh b/test/ai.zsh index 5743479..d53abc1 100755 --- a/test/ai.zsh +++ b/test/ai.zsh @@ -8,11 +8,13 @@ case $OSTYPE in ;; esac d=${0:a:h} + source $d/env source $d/refresh.zsh source $d/token.zsh source $d/reply.zsh source $d/notify.zsh +source $d/cron.zsh case $1 in refresh|r) @@ -27,4 +29,7 @@ case $1 in notify|n) notify ;; + cron|c) + cron + ;; esac diff --git a/test/cron.zsh b/test/cron.zsh new file mode 100644 index 0000000..43e99c4 --- /dev/null +++ b/test/cron.zsh @@ -0,0 +1,7 @@ +function cron() { + t=`docker ps |grep "ai bot"` + if [ -z "$t" ];then + docker compose up -d + fi + exit +} diff --git a/test/env b/test/env index 75a6471..863b1c5 100644 --- a/test/env +++ b/test/env @@ -1,26 +1,10 @@ cfg=~/.config/ai/test.json -if [ ! -f $cfg ] || ! cat $cfg|jq . || [ "`cat $cfg|jq .host`" = "null" ] || [ -z "`cat $cfg`" ];then - mkdir -p ~/.config/ai - echo server: - read host - - echo password: - read pass - - echo handle: - read handle - - echo "{ \"host\":\"$host\", \"password\":\"$pass\", \"handle\":\"$handle\" }" >> $cfg -fi - -host=`cat $cfg|jq -r .host` -handle=`cat $cfg|jq -r .handle` -pass=`cat $cfg|jq -r .password` -date=`date --iso-8601=seconds` - -if [ ! -f $cfg.t ];then - $d/token.zsh +if [ -f $cfg ];then + host=`cat $cfg|jq -r .host` + handle=`cat $cfg|jq -r .handle` + pass=`cat $cfg|jq -r .password` + date=`date --iso-8601=seconds` fi if [ -f $cfg.t ];then diff --git a/test/token.zsh b/test/token.zsh index 0e5fda6..c9a5d24 100755 --- a/test/token.zsh +++ b/test/token.zsh @@ -1,4 +1,16 @@ function token() { + mkdir -p ~/.config/ai + echo server: + read host + + echo password: + read pass + + echo handle: + read handle + + echo "{ \"host\":\"$host\", \"password\":\"$pass\", \"handle\":\"$handle\" }" >> $cfg + url=https://$host/xrpc/com.atproto.server.createSession j=`curl -sL -X POST -H "Content-Type: application/json" -d "{\"identifier\":\"$handle\",\"password\":\"$pass\"}" $url` echo $j