improve 2222.sh
This commit is contained in:
parent
0a24de9380
commit
c3dc66676b
|
@ -1,5 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
# Modified First By: Mitesh Shah
|
# Modified First By: Mitesh Shah
|
||||||
# Then Modified By : VirtuBox
|
# Then Modified By : VirtuBox
|
||||||
|
@ -39,7 +38,7 @@ DAYSOLD=3
|
||||||
ALLDB=0
|
ALLDB=0
|
||||||
SINGLE_DB=1
|
SINGLE_DB=1
|
||||||
|
|
||||||
|
### Add help menu
|
||||||
_help() {
|
_help() {
|
||||||
echo "Backup MySQL databases using mysqldump"
|
echo "Backup MySQL databases using mysqldump"
|
||||||
echo "Usage: ./mysqldump.sh [mode][options] ..."
|
echo "Usage: ./mysqldump.sh [mode][options] ..."
|
||||||
|
@ -60,6 +59,8 @@ _help() {
|
||||||
### ----[ No Editing below ]------###
|
### ----[ No Editing below ]------###
|
||||||
#####################################
|
#####################################
|
||||||
|
|
||||||
|
# script arguments parsing
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
arg="$1"
|
arg="$1"
|
||||||
case $arg in
|
case $arg in
|
||||||
|
|
|
@ -1,50 +1,61 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# install acme.sh if needed
|
||||||
|
echo ""
|
||||||
|
echo "checking if acme.sh is already installed"
|
||||||
|
echo ""
|
||||||
|
if [ ! -f ~/.acme.sh/acme.sh ]; then
|
||||||
|
echo ""
|
||||||
|
echo "installing acme.sh"
|
||||||
|
echo ""
|
||||||
|
wget -O - https://get.acme.sh | sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "checking if dig is available"
|
||||||
|
echo ""
|
||||||
|
if [ ! -x /usr/bin/dig ]; then
|
||||||
|
apt-get install bind9-host -y >>/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
ee-acme-22222() {
|
NET_INTERFACES_WAN=$(ip -4 route get 8.8.8.8 | grep -oP "dev [^[:space:]]+ " | cut -d ' ' -f 2)
|
||||||
|
MY_IP=$(ip -4 address show ${NET_INTERFACES_WAN} | grep 'inet' | sed 's/.*inet \([0-9\.]\+\).*/\1/')
|
||||||
|
MY_HOSTNAME=$(/bin/hostname -f)
|
||||||
|
MY_HOSTNAME_IP=$(/usr/bin/dig +short @8.8.8.8 "$MY_HOSTNAME")
|
||||||
|
|
||||||
MY_HOSTNAME=$(hostname -f)
|
if [[ "$MY_IP" = "$MY_HOSTNAME_IP" ]]; then
|
||||||
MY_IP=$(curl -s v4.vtbox.net)
|
|
||||||
MY_HOSTNAME_IP=$(dig +short @8.8.8.8 $MY_HOSTNAME)
|
|
||||||
|
|
||||||
if [[ "$MY_IP" = "$MY_HOSTNAME_IP" ]]
|
[ ! -f /etc/systemd/system/multi-user.target.wants/nginx.service ] && {
|
||||||
then
|
|
||||||
|
|
||||||
if [ ! -f /etc/systemd/system/multi-user.target.wants/nginx.service ]
|
sudo systemctl enable nginx.service
|
||||||
then
|
}
|
||||||
sudo systemctl enable nginx.service
|
|
||||||
fi
|
|
||||||
|
|
||||||
sudo apt install socat -y
|
sudo apt install socat -y
|
||||||
|
|
||||||
if [ ! -f $HOME/.acme.sh/${MY_HOSTNAME}_ecc/fullchain.cer ]
|
[ ! -f $HOME/.acme.sh/${MY_HOSTNAME}_ecc/fullchain.cer ] && {
|
||||||
then
|
|
||||||
$HOME/.acme.sh/acme.sh --issue -d $MY_HOSTNAME --keylength ec-384 --standalone --pre-hook "service nginx stop " --post-hook "service nginx start"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -d /etc/letsencrypt/live/$MY_HOSTNAME ]
|
$HOME/.acme.sh/acme.sh --issue -d $MY_HOSTNAME --keylength ec-384 --standalone --pre-hook "service nginx stop " --post-hook "service nginx start"
|
||||||
then
|
}
|
||||||
rm -rf /etc/letsencrypt/live/$MY_HOSTNAME/*
|
|
||||||
else
|
|
||||||
mkdir -p /etc/letsencrypt/live/$MY_HOSTNAME
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
if [ -d /etc/letsencrypt/live/$MY_HOSTNAME ]; then
|
||||||
|
rm -rf /etc/letsencrypt/live/$MY_HOSTNAME/*
|
||||||
|
else
|
||||||
|
mkdir -p /etc/letsencrypt/live/$MY_HOSTNAME
|
||||||
|
fi
|
||||||
|
[ -f $HOME/.acme.sh/${MY_HOSTNAME}_ecc/fullchain.cer ] && {
|
||||||
# install the cert and reload nginx
|
# install the cert and reload nginx
|
||||||
$HOME/.acme.sh/acme.sh --install-cert -d ${MY_HOSTNAME} --ecc \
|
$HOME/.acme.sh/acme.sh --install-cert -d ${MY_HOSTNAME} --ecc \
|
||||||
--cert-file /etc/letsencrypt/live/${MY_HOSTNAME}/cert.pem \
|
--cert-file /etc/letsencrypt/live/${MY_HOSTNAME}/cert.pem \
|
||||||
--key-file /etc/letsencrypt/live/${MY_HOSTNAME}/key.pem \
|
--key-file /etc/letsencrypt/live/${MY_HOSTNAME}/key.pem \
|
||||||
--fullchain-file /etc/letsencrypt/live/${MY_HOSTNAME}/fullchain.pem \
|
--fullchain-file /etc/letsencrypt/live/${MY_HOSTNAME}/fullchain.pem \
|
||||||
--reloadcmd "systemctl reload nginx.service"
|
--reloadcmd "systemctl enable nginx.service && service nginx restart"
|
||||||
|
}
|
||||||
|
|
||||||
if [ -f /etc/letsencrypt/live/${MY_HOSTNAME}/fullchain.pem ] && [ -f /etc/letsencrypt/live/${MY_HOSTNAME}/key.pem ]
|
if [ -f /etc/letsencrypt/live/${MY_HOSTNAME}/fullchain.pem ] && [ -f /etc/letsencrypt/live/${MY_HOSTNAME}/key.pem ]; then
|
||||||
then
|
|
||||||
sed -i "s/ssl_certificate \/var\/www\/22222\/cert\/22222.crt;/ssl_certificate \/etc\/letsencrypt\/live\/${MY_HOSTNAME}\/fullchain.pem;/" /etc/nginx/sites-available/22222
|
|
||||||
sed -i "s/ssl_certificate_key \/var\/www\/22222\/cert\/22222.key;/ssl_certificate_key \/etc\/letsencrypt\/live\/${MY_HOSTNAME}\/key.pem;/" /etc/nginx/sites-available/22222
|
|
||||||
fi
|
|
||||||
service nginx reload
|
|
||||||
|
|
||||||
|
sed -i "s/ssl_certificate \/var\/www\/22222\/cert\/22222.crt;/ssl_certificate \/etc\/letsencrypt\/live\/${MY_HOSTNAME}\/fullchain.pem;/" /etc/nginx/sites-available/22222
|
||||||
|
sed -i "s/ssl_certificate_key \/var\/www\/22222\/cert\/22222.key;/ssl_certificate_key \/etc\/letsencrypt\/live\/${MY_HOSTNAME}\/key.pem;/" /etc/nginx/sites-available/22222
|
||||||
fi
|
fi
|
||||||
}
|
service nginx reload
|
||||||
|
|
||||||
ee-acme-22222
|
fi
|
||||||
|
|
Loading…
Reference in New Issue