fix: 1.loop stop flag, 2.request user to perform first run by themself

This commit is contained in:
DarkCat09 2025-02-19 15:50:50 +04:00
parent e47a81fc84
commit 264c992e49
Signed by: DarkCat09
GPG key ID: BD3CE9B65916CD82

59
run.sh
View file

@ -1,38 +1,12 @@
#!/bin/ash
if [ ! -e /etc/letsencrypt/live ]
then
echo "[!!] Certbot directory is not initialized"
echo "[!!] Either it's the first run or you forgot to add a volume"
# check if stdin (fd 0) is assigned to a tty
[ ! -t 0 ] && echo "Not a TTY! Exiting" && exit 1
echo "Choose installation method:"
echo " 1. get certs for hosts specified in nginx.conf"
echo " and automatically edit the config (default)"
echo " 2. get certs for hosts, do not edit the config"
echo " 3. just launch shell, i'll do it myself"
read -p '>> ' n
if [ "$n" = 3 ]
then
/bin/ash -i
elif [ "$n" = 2 ]
then
/venv/bin/certbot certonly --nginx
else
/venv/bin/certbot --nginx
fi
exit $?
fi
/usr/sbin/nginx -c /etc/nginx/nginx.conf &
ngpid=$!
waitpid=""
stopflag=0
ctrlc () {
stopflag=1
kill -QUIT "$ngpid"
[ -n "$waitpid" ] && kill -INT "$waitpid"
}
@ -40,9 +14,34 @@ ctrlc () {
trap ctrlc INT
trap ctrlc TERM
while true
if [ ! -e /etc/letsencrypt/live ]
then
echo "[!!] Certbot directory is not initialized"
echo "[!!] Either it's the first run or you forgot to add a volume"
echo
echo "1. Login to shell"
echo " > docker compose exec -it nginx ash"
echo "2. Either let certbot retrieve certs and automatically edit nginx config"
echo " # certbot --nginx"
echo " OR just get certs for hosts in your nginx config, edit manually later"
echo " # certbot certonly --nginx"
echo "3. Restart:"
echo " # exit"
echo " > docker compose down && docker compose up -d"
while [ $stopflag = 0 ]
do
sleep 5m &
waitpid=$!
wait
done
fi
while [ $stopflag = 0 ]
do
/venv/bin/certbot renew --post-hook "kill -HUP $ngpid"
/venv/bin/certbot renew --post-hook "kill -HUP $ngpid" &
sleep 12h &
waitpid=$!
wait