From 5b1bf2b3d59d739912b2d17b0521e44e69b70da7 Mon Sep 17 00:00:00 2001 From: mercury Date: Thu, 21 Mar 2024 01:19:19 +0400 Subject: [PATCH] switch branches after update --- app/bot.php | 45 +++++++++++++++++++++++++++++++++++++ app/{ => webapp}/login.html | 0 config/mtprotodomain | 0 docker-compose.yml | 4 ++-- dockerfile/php.dockerfile | 1 + update/update.sh | 5 +++++ 6 files changed, 53 insertions(+), 2 deletions(-) rename app/{ => webapp}/login.html (100%) create mode 100644 config/mtprotodomain diff --git a/app/bot.php b/app/bot.php index d7392c1..3ce15a7 100644 --- a/app/bot.php +++ b/app/bot.php @@ -140,6 +140,12 @@ class Bot case preg_match('~^/updatebot$~', $this->input['callback'], $m): $this->updatebot(); break; + case preg_match('~^/branches$~', $this->input['callback'], $m): + $this->branches(); + break; + case preg_match('~^/changeBranch (\d+)$~', $this->input['callback'], $m): + $this->changeBranch($m[1]); + break; case preg_match('~^/getMirror$~', $this->input['callback'], $m): $this->getMirror(); break; @@ -3783,7 +3789,13 @@ DNS-over-HTTPS with IP: 'callback_data' => "/debug", ], ]; + exec('git -C / branch', $m); + $track = trim(file_get_contents('/update/branch')); $data[] = [ + [ + 'text' => "{$m[0]} => $track", + 'callback_data' => "/branches", + ], [ 'text' => $this->i18n('update bot'), 'callback_data' => "/updatebot", @@ -3801,6 +3813,39 @@ DNS-over-HTTPS with IP: ]; } + public function branches() + { + exec('git -C / branch -r', $m); + array_shift($m); + foreach ($m as $k => $v) { + $data[] = [ + [ + 'text' => $v, + 'callback_data' => "/changeBranch $k", + ] + ]; + } + $data[] = [ + [ + 'text' => $this->i18n('back'), + 'callback_data' => "/menu config", + ] + ]; + $this->update($this->input['from'], $this->input['message_id'], 'branches', $data); + } + + public function changeBranch($i) + { + exec('git -C / branch -r', $m); + array_shift($m); + foreach ($m as $k => $v) { + if ($i == $k) { + file_put_contents('/update/branch', trim(str_replace('origin/', '', $v))); + } + } + $this->menu('config'); + } + public function logs() { foreach (scandir('/logs/') as $k => $v) { diff --git a/app/login.html b/app/webapp/login.html similarity index 100% rename from app/login.html rename to app/webapp/login.html diff --git a/config/mtprotodomain b/config/mtprotodomain new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yml b/docker-compose.yml index 2ec6524..37ea67e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -74,7 +74,6 @@ services: - ./config/sshd_config:/etc/ssh/sshd_config - ./logs/:/logs/ - ./app/webapp:/app - - ./app/login.html:/app/login.html ports: - 80:80 hostname: nginx @@ -96,7 +95,7 @@ services: ipv4_address: 10.10.1.2 logging: *default-logging php: - image: mercurykd/vpnbot-php:1.2 + image: mercurykd/vpnbot-php:1.3 build: dockerfile: dockerfile/php.dockerfile args: @@ -117,6 +116,7 @@ services: - ./mirror:/mirror - ./.env:/mirror/.env - ./update:/update + - ./.git:/.git environment: IP: ${IP} VER: ${VER} diff --git a/dockerfile/php.dockerfile b/dockerfile/php.dockerfile index 80078f8..8c81a0a 100644 --- a/dockerfile/php.dockerfile +++ b/dockerfile/php.dockerfile @@ -19,6 +19,7 @@ RUN apk add --no-cache --update php81 \ openssh \ openssl \ curl \ + git \ py3-qt5 \ && wget https://github.com/ameshkov/dnslookup/releases/download/v1.9.1/dnslookup-linux-amd64-v1.9.1.tar.gz \ && tar -xf dnslookup-linux-amd64-v1.9.1.tar.gz \ diff --git a/update/update.sh b/update/update.sh index 46f0fe5..3938dc0 100644 --- a/update/update.sh +++ b/update/update.sh @@ -6,11 +6,16 @@ echo "$$" > $pwd/update/update_pid while true do cmd=$(cat $pwd/update/pipe) + branch=$(cat $pwd/update/branch 2>/dev/null) if [[ -n "$cmd" ]] then docker compose down --remove-orphans git reset --hard git pull > ./update/message + if [[ -n "$branch" ]] + then + git checkout -t origin/$branch || git checkout $branch + fi IP=$(curl https://ipinfo.io/ip) VER=$(git describe --tags) docker compose up -d --force-recreate bash $pwd/update/update.sh & exit 0