d2ray/run.sh

54 lines
1.3 KiB
Bash
Raw Normal View History

2021-04-10 08:21:07 +00:00
#!/bin/sh
set +e
2021-04-10 09:29:44 +00:00
BUCKET_HASH=3bd6b2ce5101e791b665d709aa8518ce
2021-04-10 08:21:07 +00:00
echo "===== Checking Environment Variables ====="
if [ -z "$FQDN" ]; then
echo "FQDN must be set"
exit 1
else
echo "FQDN = $FQDN"
fi
if [ -z "$SALT" ]; then
echo "SALT must be set"
exit 1
else
echo "SALT = $SALT"
fi
if [ -z "$KEY" ]; then
echo "KEY must be set"
exit 1
else
echo "KEY = $KEY"
fi
echo "===== Setting Up Environment ======"
2021-04-10 09:29:44 +00:00
rm -rf /etc/letsencrypt
2021-04-10 08:21:07 +00:00
ln -s /opt/config/certs /etc/letsencrypt
echo "===== Checking Certificates ===="
if [ ! -d "/etc/letsencrypt/live/$FQDN" ]; then
echo "Generating new certificates..."
certbot certonly -n --standalone -m dummy@dummy.com --agree-tos --no-eff-email -d "$FQDN"
else
echo "Certificate exists. Checking renewal..."
certbot renew
fi
echo "===== Downloading configuration file ====="
2021-04-10 09:29:44 +00:00
hash=$(echo -n "$FQDN.$SALT" | openssl dgst -md5 | sed -E 's/\(stdin\)= (.*)/\1/')
2021-04-10 08:21:07 +00:00
echo "Host hash is $hash"
wget http://$BUCKET_HASH.s3-website-us-west-1.amazonaws.com/config/$hash.conf -P /opt/
openssl aes-256-cbc -d -md sha512 -pbkdf2 -in /opt/$hash.conf -out /opt/$FQDN.conf -k $KEY
echo "===== Starting services ====="
crond -L /opt/config/logs/crond/log.txt
nginx -c /opt/nginx.conf
echo "===== Starting xray ====="
/opt/xray/xray -c /opt/$FQDN.conf