diff --git a/app/bot.php b/app/bot.php index f44bdf3..d84fa25 100644 --- a/app/bot.php +++ b/app/bot.php @@ -994,7 +994,8 @@ class Bot if (!empty($c['admin']) && (empty($this->time) || ((time() - $this->time) > 3600))) { $this->time = time(); $current = file_get_contents('/version'); - $last = file_get_contents('https://raw.githubusercontent.com/mercurykd/vpnbot/master/version'); + $b = exec('git -C / rev-parse --abbrev-ref HEAD'); + $last = file_get_contents("https://raw.githubusercontent.com/mercurykd/vpnbot/$b/version"); if (!empty($last) && $last != $this->last && $last != $current) { $this->last = $last; $diff = array_slice(explode("\n", $last), 0, count(explode("\n", $last)) - count(explode("\n", $current))); @@ -4417,6 +4418,12 @@ DNS-over-HTTPS with IP: $this->exportManual($this->update); $r = $this->send($this->input['from'], 'update...'); file_put_contents('/update/reload_message', "{$this->input['from']}:{$r['result']['message_id']}"); + file_put_contents('/update/key', $this->key); + file_put_contents('/update/curl', json_encode([ + 'chat_id' => $this->input['chat'], + 'message_id' => $r['result']['message_id'], + 'text' => '~t~' + ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); file_put_contents('/update/pipe', '1'); $this->delete($this->input['from'], $this->input['message_id']); } diff --git a/update/update.sh b/update/update.sh index 066fc65..81cc9cd 100644 --- a/update/update.sh +++ b/update/update.sh @@ -9,16 +9,25 @@ do branch=$(cat $pwd/update/branch 2>/dev/null) if [[ -n "$cmd" ]] then + key=$(cat $pwd/update/key) + curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "останавливаю бота"/')" docker compose down --remove-orphans + curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "очищаю директорию"/')" git reset --hard && git clean -fd + curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "скачиваю обновление"/')" git fetch if [[ -n "$branch" ]] then + curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "меняю ветку"/')" git checkout -t origin/$branch || git checkout $branch fi + curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "применяю обновления"/')" git pull > ./update/message + curl -H "Content-Type: application/json" -X POST https://api.telegram.org/bot$key/editMessageText -d "$(cat $pwd/update/curl | sed 's/"text":"~t~"/"text": "запускаю бота"/')" IP=$(curl https://ipinfo.io/ip) VER=$(git describe --tags) docker compose up -d --force-recreate bash $pwd/update/update.sh & + > $pwd/update/key + > $pwd/update/curl exit 0 fi sleep 1