generalize addsubdomain to work with different locations

This commit is contained in:
fram3d 2024-01-22 17:02:28 +01:00
parent f1c39a5cf0
commit 3ee717e7d1
Signed by: fram3d
GPG Key ID: 938920E709EEA32A
6 changed files with 44 additions and 40 deletions

View File

@ -18,8 +18,8 @@ fi
ssh-add -t 200 $DMZKEYFILE
torsocks scp ./remotecmd $NGINXHOST:/root/remotecmd.sh
torsocks scp ./subdomain.krov.dmz.rs $NGINXHOST:/etc/nginx/sites-available/
torsocks scp ./subdomain.krov.dmz.rs.https $NGINXHOST:/etc/nginx/sites-available/
torsocks scp ./subdomain.dmz.rs.http $NGINXHOST:/etc/nginx/sites-available/
torsocks scp ./subdomain.dmz.rs.https $NGINXHOST:/etc/nginx/sites-available/
torsocks ssh $NGINXHOST "chmod +x /root/remotecmd.sh; /root/remotecmd.sh $SUBDOMAIN"

View File

@ -1,22 +1,26 @@
#!/bin/bash
SUBDOMAIN=$1
SUBNODOT=$(echo -n $1 | cut -d"." -f1- --output-delimiter="" )
if [[ -z "$SUBDOMAIN" ]]; then
echo "Set subdomain"
exit 1
fi
sed -i 's/subdomain/'$SUBDOMAIN'/g' /etc/nginx/sites-available/subdomain.krov.dmz.rs
sed -i 's/subdomain/'$SUBDOMAIN'/g' /etc/nginx/sites-available/subdomain.krov.dmz.rs.https
mkdir /var/www/"$SUBDOMAIN"krovdmzrs/
mv /etc/nginx/sites-available/subdomain.krov.dmz.rs /etc/nginx/sites-available/"$SUBDOMAIN".krov.dmz.rs
mv /etc/nginx/sites-available/subdomain.krov.dmz.rs.https /etc/nginx/sites-available/"$SUBDOMAIN".krov.dmz.rs.https
ln -s /etc/nginx/sites-available/"$SUBDOMAIN".krov.dmz.rs /etc/nginx/sites-enabled/"$SUBDOMAIN".krov.dmz.rs
sed -i 's/subdomain/'$SUBDOMAIN'/g' /etc/nginx/sites-available/subdomain.dmz.rs.http
sed -i 's/subdomain/'$SUBDOMAIN'/g' /etc/nginx/sites-available/subdomain.dmz.rs.https
sed -i 's/subnodot/'$SUBNODOT'/g' /etc/nginx/sites-available/subdomain.dmz.rs.http
sed -i 's/subnodot/'$SUBNODOT'/g' /etc/nginx/sites-available/subdomain.dmz.rs.https
mkdir /var/www/"$SUBNODOT"dmzrs/
mv /etc/nginx/sites-available/subdomain.dmz.rs.http /etc/nginx/sites-available/"$SUBDOMAIN".dmz.rs.http
mv /etc/nginx/sites-available/subdomain.dmz.rs.https /etc/nginx/sites-available/"$SUBDOMAIN".dmz.rs.https
ln -s /etc/nginx/sites-available/"$SUBDOMAIN".dmz.rs.http /etc/nginx/sites-enabled/"$SUBDOMAIN".dmz.rs.http
service nginx reload
certbot certonly -d "$SUBDOMAIN".krov.dmz.rs,"$SUBDOMAIN".krov.decentrala.org --webroot -w /var/www/"$SUBDOMAIN"krovdmzrs
cat /etc/nginx/sites-available/"$SUBDOMAIN".krov.dmz.rs /etc/nginx/sites-available/"$SUBDOMAIN".krov.dmz.rs.https > /etc/nginx/sites-available/"$SUBDOMAIN".krov.dmz.rs.all
mv /etc/nginx/sites-available/"$SUBDOMAIN".krov.dmz.rs.all /etc/nginx/sites-available/"$SUBDOMAIN".krov.dmz.rs
rm /etc/nginx/sites-available/"$SUBDOMAIN".krov.dmz.rs.https
certbot certonly -d "$SUBDOMAIN".dmz.rs,"$SUBDOMAIN".decentrala.org --webroot -w /var/www/"$SUBNODOT"dmzrs
cat /etc/nginx/sites-available/"$SUBDOMAIN".dmz.rs.http /etc/nginx/sites-available/"$SUBDOMAIN".dmz.rs.https > /etc/nginx/sites-available/"$SUBDOMAIN".dmz.rs.all
mv /etc/nginx/sites-available/"$SUBDOMAIN".dmz.rs.all /etc/nginx/sites-available/"$SUBDOMAIN".dmz.rs
rm /etc/nginx/sites-available/"$SUBDOMAIN".dmz.rs.https
rm /etc/nginx/sites-available/"$SUBDOMAIN".dmz.rs.http
service nginx reload
rm /root/remotecmd.sh

View File

@ -0,0 +1,10 @@
server {
listen 80;
listen [::]:80;
index index.html index.htm index.nginx-debian.html;
server_name subdomain.dmz.rs subdomain.decentrala.org;
root /var/www/subnodotdmzrs;
}

View File

@ -0,0 +1,18 @@
server {
listen 443 ssl ;
listen [::]:443 ssl ;
index index.html index.htm index.nginx-debian.html;
server_name subdomain.dmz.rs subdomain.decentrala.org;
ssl_certificate /etc/letsencrypt/live/subdomain.dmz.rs/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/subdomain.dmz.rs/privkey.pem;
ssl_dhparam /etc/ssl/dhparam.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root /var/www/subnodotdmzrs;
resolver 9.9.9.9;
}

View File

@ -1,10 +0,0 @@
server {
listen 80;
listen [::]:80;
index index.html index.htm index.nginx-debian.html;
server_name subdomain.krov.dmz.rs subdomain.krov.decentrala.org;
root /var/www/subdomainkrovdmzrs;
}

View File

@ -1,18 +0,0 @@
server {
listen 443 ssl ;
listen [::]:443 ssl ;
index index.html index.htm index.nginx-debian.html;
server_name subdomain.krov.dmz.rs subdomain.krov.decentrala.org;
ssl_certificate /etc/letsencrypt/live/subdomain.krov.dmz.rs/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/subdomain.krov.dmz.rs/privkey.pem;
ssl_dhparam /etc/ssl/dhparam.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root /var/www/subdomainkrovdmzrs;
resolver 9.9.9.9;
}