From 9b2731ea9cf16b5f0cddd89a2bcd3c4456c26b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 12 Nov 2025 04:39:19 +0100 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=B2=D0=B5=D1=81=D1=82=D0=B8=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B3=D1=83=D0=BB=D1=8F=D1=80=D0=BD=D1=83=D1=8E=20=D0=BF?= =?UTF-8?q?=D1=83=D0=B1=D0=BB=D0=B8=D0=BA=D0=B0=D1=86=D0=B8=D1=8E=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BB=D0=B0=D0=B4=D0=BE=D1=87=D0=BD=D0=BE=D0=B9=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=81=D0=B8=D0=B8=20(#6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cbr.get | 2 +- nginx/cfg | 2 +- publish.dbg | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ publish.prod | 15 +++++++++++++++ publish.setup | 4 ++++ 5 files changed, 71 insertions(+), 2 deletions(-) create mode 100755 publish.dbg create mode 100755 publish.prod create mode 100755 publish.setup diff --git a/cbr.get b/cbr.get index 66c2ee8..80833a4 100755 --- a/cbr.get +++ b/cbr.get @@ -1,4 +1,4 @@ #!/bin/bash URL=https://www.cbr.ru/scripts/XML_daily.asp -OUT=/var/www/html/cbr.xml +OUT=/var/www/html/cbr/cur.xml wget $URL -O $OUT diff --git a/nginx/cfg b/nginx/cfg index 834b7c1..c065037 100644 --- a/nginx/cfg +++ b/nginx/cfg @@ -26,7 +26,6 @@ server { root /var/www/html; - # Add index.php to the list if you are using PHP index index.html; server_name _; @@ -36,6 +35,7 @@ server { # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; add_header "Access-Control-Allow-Origin" "*"; + add_header "Cache-Control" "max-age=43200"; # Remove CORS. if ($request_method = "OPTIONS") { add_header "Access-Control-Allow-Origin" "*"; diff --git a/publish.dbg b/publish.dbg new file mode 100755 index 0000000..4a3d5ae --- /dev/null +++ b/publish.dbg @@ -0,0 +1,50 @@ +#!/bin/bash + +DST_DIR=/var/www/dbg +KMP_FILE=kornerr-ver-browser +KMP_FILE_EXT=js +MAIN_BRANCH=main +REPO_DIR=/home/kornerr/repo-ru +REPO_URL=https://github.com/kornerr/ru + +# Clone if the directory does not exist +if [ ! -d "$REPO_DIR" ]; then + git clone $REPO_URL $REPO_DIR +fi + +# Get the latest changes +cd $REPO_DIR +git checkout -f $MAIN_BRANCH +git fetch --all + +# Find out the latest commit in the whole repo +#git branch -av --sort=-committerdate +#git branch -av --sort=-committerdate | tr -s ' ' | head -n1 +cmt=`git branch -av --sort=-committerdate | tr -s ' ' | head -n1 | cut -d' ' -f3` +echo "Latest commit: $cmt" + +# Switch to the latest commit +git checkout -f $cmt + +# Copy dist +mkdir -p $DST_DIR +rm -fR $DST_DIR/* +cp -R dist/* $DST_DIR + +# Rename kornerr-ver-browser.js to work around caching +kmpWas=$KMP_FILE.$KMP_FILE_EXT +kmpNow=${KMP_FILE}_`uuidgen`.$KMP_FILE_EXT +mv $DST_DIR/$kmpWas $DST_DIR/$kmpNow + +# Replace text in a file +function replace { + file=$1 + was=$2 + now=$3 + cmd="sed -i 's|$was|$now|g' $file" + eval "$cmd" +} + +# Rename references +replace $DST_DIR/bank.html "$kmpWas" "$kmpNow" +replace $DST_DIR/quiz.html "$kmpWas" "$kmpNow" diff --git a/publish.prod b/publish.prod new file mode 100755 index 0000000..ec07515 --- /dev/null +++ b/publish.prod @@ -0,0 +1,15 @@ +#!/bin/bash + +DBG_DIR=/var/www/dbg +DST_DIR=/var/www/html + +# Remove current prod +rm -fR $DST_DIR + +# Copy dbg to prod +rsync -aivc --delete $DBG_DIR/ $DST_DIR + +# Symlink +cd $DST_DIR +ln -s ../cbr +ln -s ../dbg diff --git a/publish.setup b/publish.setup new file mode 100755 index 0000000..d863c58 --- /dev/null +++ b/publish.setup @@ -0,0 +1,4 @@ +#!/bin/bash +CMD="0 20 * * * kornerr /home/kornerr/vps/publish.dbg" +CRON_FILE=/etc/cron.d/dbg +echo "$CMD" > $CRON_FILE