d2ray/image/run.sh

64 lines
1.3 KiB
Bash
Raw Normal View History

2021-04-10 08:21:07 +00:00
#!/bin/sh
2021-04-22 09:07:11 +00:00
set -e
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-23 06:51:06 +00:00
echo "===== Fetching Configuration ====="
2021-04-22 09:18:57 +00:00
decrypt $URL $KEY
2021-04-22 09:01:45 +00:00
URL=$crypt_ret
echo "Fetching from $URL..."
2021-04-22 09:18:57 +00:00
hash_sha256 $FQDN $KEY
2021-04-22 09:01:45 +00:00
URL=$URL/$crypt_ret
wget $URL -O /opt/$FQDN
echo "Decrypting..."
2021-04-23 07:14:37 +00:00
decrypt_file /opt/$FQDN $KEY /opt/config.json
2021-04-22 09:01:45 +00:00
2021-04-23 07:14:37 +00:00
decrypt_file /opt/htpasswd $KEY /opt/nginx/.htpasswd
2021-04-23 06:51:06 +00:00
2021-04-22 09:01:45 +00:00
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