d2ray/image/run.sh

63 lines
1.3 KiB
Bash
Raw Normal View History

2021-04-10 08:21:07 +00:00
#!/bin/sh
2021-04-10 10:07:21 +00:00
set +xe
2021-04-10 08:21:07 +00:00
2021-04-22 09:01:45 +00:00
source /opt/crypt.sh
2021-04-10 09:46:39 +00:00
mkdir -p /opt/config
mkdir -p /opt/config/logs
mkdir -p /opt/config/certs
mkdir -p /opt/config/logs/nginx
mkdir -p /opt/config/logs/xray
mkdir -p /opt/config/logs/crond
2021-04-22 09:01:45 +00:00
URL='U2FsdGVkX19/qz4kcbpQpJKz/iebXKih1BK3Cp1wGSoEyhLtoyAi0wewP5Tr++FbRLt/EG2f8zDF9cIEuoTLEA=='
2021-04-10 09:40:04 +00:00
echo ""
2021-04-10 08:21:07 +00:00
echo "===== Checking Environment Variables ====="
if [ -z "$FQDN" ]; then
echo "FQDN must be set"
exit 1
2021-04-22 09:01:45 +00:00
fi
if [ -z "$KEY" ]; then
echo "KEY must be set"
exit 1
2021-04-10 08:21:07 +00:00
fi
2021-04-10 09:40:04 +00:00
echo ""
2021-04-10 08:21:07 +00:00
echo "===== Checking Certificates ===="
if [ ! -d "/etc/letsencrypt/live/$FQDN" ]; then
echo "Generating new certificates..."
2021-04-10 09:42:49 +00:00
certbot certonly -n --standalone -m dummy@dummy.com --agree-tos --no-eff-email -d $FQDN
2021-04-10 08:21:07 +00:00
else
echo "Certificate exists. Checking renewal..."
certbot renew
fi
2021-04-10 09:40:04 +00:00
echo ""
2021-04-22 09:01:45 +00:00
echo "===== Fetching Configuration ===="
decrypt $URL $key
URL=$crypt_ret
echo "Fetching from $URL..."
hash_sha256 $FQDN $key
URL=$URL/$crypt_ret
wget $URL -O /opt/$FQDN
echo "Decrypting..."
decrypt $(cat /opt/$FQDN) $key
echo $crypt_ret > /opt/config.json
echo ""
echo "===== Starting cron ====="
2021-04-10 08:21:07 +00:00
crond -L /opt/config/logs/crond/log.txt
2021-04-22 09:01:45 +00:00
echo ""
echo "===== Starting Nginx ====="
nginx -c /opt/nginx/nginx.conf
2021-04-10 08:21:07 +00:00
2021-04-10 09:40:04 +00:00
echo ""
2021-04-10 08:21:07 +00:00
echo "===== Starting xray ====="
2021-04-19 07:51:22 +00:00
exec /opt/xray/xray -c /opt/config.json