25K4 #7
@@ -1 +1 @@
|
||||
Some scripts to automate VPS setup
|
||||
Scripts to automate VPS setup and maintenance
|
||||
|
||||
7
cert/clientRenew
Исполняемый файл
7
cert/clientRenew
Исполняемый файл
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash -e
|
||||
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
||||
T=$SDIR/../step
|
||||
|
||||
STEP=0
|
||||
source $T/ensureRootUser
|
||||
source $T/renewCertbot
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
#!/bin/bash -e
|
||||
# https://habr.com/ru/articles/735712/
|
||||
brew install certbot
|
||||
23
cert/vpsRenew
Исполняемый файл
23
cert/vpsRenew
Исполняемый файл
@@ -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
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
apt install nginx
|
||||
cp nginx/cfg /etc/nginx/sites-enabled/default
|
||||
systemctl restart nginx
|
||||
10
nginx/acme.cfg
Обычный файл
10
nginx/acme.cfg
Обычный файл
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ server {
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
# Serve through HTTPS only
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name kornerr.ru;
|
||||
9
nginx/setup
Исполняемый файл
9
nginx/setup
Исполняемый файл
@@ -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
|
||||
@@ -15,7 +15,9 @@ 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
|
||||
@@ -47,4 +49,5 @@ function replace {
|
||||
|
||||
# Rename references
|
||||
replace $DST_DIR/bank.html "$kmpWas" "$kmpNow"
|
||||
replace $DST_DIR/budget.html "$kmpWas" "$kmpNow"
|
||||
replace $DST_DIR/quiz.html "$kmpWas" "$kmpNow"
|
||||
|
||||
@@ -13,3 +13,4 @@ rsync -aivc --delete $DBG_DIR/ $DST_DIR
|
||||
cd $DST_DIR
|
||||
ln -s ../cbr
|
||||
ln -s ../dbg
|
||||
ln -s ../vid
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
CMD="0 20 * * * kornerr /home/kornerr/vps/publish.dbg"
|
||||
CMD="0 20 * * * root /home/kornerr/vps/publish.dbg"
|
||||
CRON_FILE=/etc/cron.d/dbg
|
||||
echo "$CMD" > $CRON_FILE
|
||||
|
||||
5
step/copyNginxACMEConfig
Обычный файл
5
step/copyNginxACMEConfig
Обычный файл
@@ -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
Обычный файл
5
step/copyNginxProdConfig
Обычный файл
@@ -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
Обычный файл
6
step/createACMEChallenge
Обычный файл
@@ -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
Обычный файл
6
step/deleteACMEChallenge
Обычный файл
@@ -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
Обычный файл
9
step/ensureRootUser
Обычный файл
@@ -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
Обычный файл
5
step/installNginx
Обычный файл
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
STEP=$((STEP+1))
|
||||
echo -e "\n> > > > Шаг №$STEP. Устанавливаем Nginx"
|
||||
apt install nginx
|
||||
5
cert.renew → step/renewCertbot
Исполняемый файл → Обычный файл
5
cert.renew → step/renewCertbot
Исполняемый файл → Обычный файл
@@ -1,3 +1,6 @@
|
||||
#!/bin/bash
|
||||
#!/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
Обычный файл
5
step/restartNginx
Обычный файл
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
STEP=$((STEP+1))
|
||||
echo -e "\n> > > > Шаг №$STEP. Перезапускаем Nginx"
|
||||
systemctl restart nginx
|
||||
5
step/waitForReturnKey
Обычный файл
5
step/waitForReturnKey
Обычный файл
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
STEP=$((STEP+1))
|
||||
echo -e "\n> > > > Шаг №$STEP. Ожидаем нажатия клавиши Return"
|
||||
read -p "Нажмите Return..."
|
||||
Ссылка в новой задаче
Block a user