15 Commits
tls ... 26k1

Author SHA1 Message Date
Михаил Капелько
b34b5da8e9 ip 2026-01-28 21:57:32 +03:00
Михаил Капелько
1d39702bf3 symlink cv 2026-01-24 07:05:07 +03:00
Михаил Капелько
4088e3cecb пусто 2026-01-24 07:03:24 +03:00
3025f3c2d8 25K4 (#7) 2026-01-24 05:01:42 +01:00
Михаил Капелько
5258bb012e Revert "highlight client scripgts"
This reverts commit 8a64ccaa3f.
2025-12-06 06:55:24 +03:00
Михаил Капелько
ec554a2aa9 Revert "rename better"
This reverts commit e2a09dcaaf.
2025-12-06 06:55:02 +03:00
Михаил Капелько
e86a5b0989 Revert "add some steps"
This reverts commit d9d691db1d.
2025-12-06 06:54:40 +03:00
Михаил Капелько
3b173d32fb Revert "rename cfg"
This reverts commit bc380a60a4.
2025-12-06 06:54:17 +03:00
Михаил Капелько
bc380a60a4 rename cfg 2025-12-06 06:51:13 +03:00
Михаил Капелько
d9d691db1d add some steps 2025-12-05 22:58:48 +03:00
Михаил Капелько
e2a09dcaaf rename better 2025-12-05 22:39:48 +03:00
Михаил Капелько
8a64ccaa3f highlight client scripgts 2025-12-05 22:38:33 +03:00
9b2731ea9c Ввести регулярную публикацию отладочной версии (#6) 2025-11-12 04:39:19 +01:00
8e8442a2e7 Заменить src IP (#5) 2025-11-08 19:35:06 +01:00
27d3d1a7e7 Configure TLS with Lets Encrypt (#4) 2025-10-09 22:19:16 +02:00
22 changed files with 197 additions and 15 deletions

View File

@@ -1 +1 @@
Some scripts to automate VPS setup
Scripts to automate VPS setup and maintenance

View File

@@ -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

7
cert/clientRenew Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash -e
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
T=$SDIR/../step
STEP=0
source $T/ensureRootUser
source $T/renewCertbot

3
cert/clientSetup Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash -e
# https://habr.com/ru/articles/735712/
brew install certbot

23
cert/vpsRenew Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash -e
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
T=$SDIR/../step
ACME_FILE=$1
ACME_VALUE=$2
if [ -z "$ACME_FILE" ] || [ -z "$ACME_VALUE" ]; then
echo "Usage: $0 ACME_FILE ACME_VALUE"
exit 1
fi
ACME_DIR="/var/www/html/.well-known/acme-challenge"
STEP=0
source $T/ensureRootUser
source $T/copyNginxACMEConfig
source $T/restartNginx
source $T/createACMEChallenge
source $T/waitForReturnKey
source $T/deleteACMEChallenge
source $T/copyNginxProdConfig
source $T/restartNginx

View File

@@ -1,5 +0,0 @@
#!/bin/bash
apt install nginx
cp nginx/cfg /etc/nginx/sites-enabled/default
systemctl restart nginx

10
nginx/acme.cfg Normal file
View File

@@ -0,0 +1,10 @@
# Serve only through HTTP while updating the certificate
server {
listen 80;
server_name kornerr.ru;
root /var/www/html;
location / {
try_files $uri $uri/ =404;
}
}

View File

@@ -1,11 +1,18 @@
# Redirect HTTP to HTTPS
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 80;
server_name kornerr.ru;
return 301 https://$server_name$request_uri;
}
# Serve through HTTPS only
server {
listen 443 ssl;
server_name kornerr.ru;
ssl_certificate /etc/encrypt/fullchain.pem;
ssl_certificate_key /etc/encrypt/privkey.pem;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
@@ -20,7 +27,6 @@ server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html;
server_name _;
@@ -30,6 +36,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" "*";

9
nginx/setup Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash -e
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
T=$SDIR/../step
STEP=0
source $T/ensureRootUser
source $T/installNginx
source $T/copyNginxProdConfig
source $T/restartNginx

53
publish.dbg Executable file
View File

@@ -0,0 +1,53 @@
#!/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 clean -fd
git fetch --all
git pull
# 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/budget.html "$kmpWas" "$kmpNow"
replace $DST_DIR/quiz.html "$kmpWas" "$kmpNow"

17
publish.prod Executable file
View File

@@ -0,0 +1,17 @@
#!/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 ../cv
ln -s ../dbg
ln -s ../vid

4
publish.setup Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
CMD="0 20 * * * root /home/kornerr/vps/publish.dbg"
CRON_FILE=/etc/cron.d/dbg
echo "$CMD" > $CRON_FILE

View File

@@ -1,4 +1,6 @@
acl tul src 83.221.16.86
acl tul src 37.113.215.50
acl tul src 83.221.24.250
http_access allow tul
http_access deny all
http_port 3128

5
step/copyNginxACMEConfig Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
STEP=$((STEP+1))
echo -e "\n> > > > Шаг №$STEP. Копируем настройки Nginx для ACME"
cp $SDIR/../nginx/acme.cfg /etc/nginx/sites-enabled/default

5
step/copyNginxProdConfig Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
STEP=$((STEP+1))
echo -e "\n> > > > Шаг №$STEP. Копируем боевые настройки Nginx"
cp $SDIR/../nginx/prod.cfg /etc/nginx/sites-enabled/default

6
step/createACMEChallenge Normal file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
STEP=$((STEP+1))
echo -e "\n> > > > Шаг №$STEP. Создаём файл проверки для ACME"
mkdir -p $ACME_DIR
echo "$ACME_VALUE" > "$ACME_DIR/$ACME_FILE"

6
step/deleteACMEChallenge Normal file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
STEP=$((STEP+1))
echo -e "\n> > > > Шаг №$STEP. Удаляем файл проверки для ACME"
rm $ACME_DIR/$ACME_FILE
rmdir $ACME_DIR

9
step/ensureRootUser Normal file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
# https://askubuntu.com/a/15856
STEP=$((STEP+1))
echo -e "\n> > > > Шаг №$STEP. Проверяем запуск из-под root"
if [[ $EUID -ne 0 ]]; then
echo "ОШИБКА: Перезапустите как root"
exit 1
fi

5
step/installNginx Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
STEP=$((STEP+1))
echo -e "\n> > > > Шаг №$STEP. Устанавливаем Nginx"
apt install nginx

6
step/renewCertbot Normal file
View File

@@ -0,0 +1,6 @@
#!/bin/bash -e
# https://habr.com/ru/articles/735712/
STEP=$((STEP+1))
echo -e "\n> > > > Шаг №$STEP. Просим certbot обновить"
certbot certonly --manual --preferred-challenges http -d "kornerr.ru"

5
step/restartNginx Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
STEP=$((STEP+1))
echo -e "\n> > > > Шаг №$STEP. Перезапускаем Nginx"
systemctl restart nginx

5
step/waitForReturnKey Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
STEP=$((STEP+1))
echo -e "\n> > > > Шаг №$STEP. Ожидаем нажатия клавиши Return"
read -p "Нажмите Return..."