This commit is contained in:
Ben Harris 2019-08-14 15:23:14 +00:00 committed by root
parent dcf29054fa
commit c426afbae5
4 changed files with 50 additions and 50 deletions

View File

@ -1,39 +1,28 @@
for (( ; ; ))
do
rm -rf available.txt
files=$(find /home -name tilde.json -print)
echo "$files" >> available.txt
if [ -s available.txt ]
#!/bin/sh
bestip=$(dig +short a tilde.best)
for byod in /home/*/byod; do
user=$(stat -c '%U' $byod)
domain=$(cat $byod)
echo "$user is requesting $domain"
if [ -s /etc/nginx/sites-enabled/byod-$user-$domain.conf ]; then
echo "byod already configured for $user and $domain"
continue
else
domainip=$(dig +short a $domain)
if [ "$bestip" == "$domainip"]
then
tilde=$(sed '1q;d' available.txt)
domain=$(jq -r '.domain' $tilde)
username=$(echo "$tilde" | awk -F/ '{print $2}')
if [ "tilde.best" == "$domain" ]; then
sed -i '1d' ./available.txt
exit 1
sed -e "s/<user>/$user/" -e "s/<domain>/$domain/" template.conf \
> /etc/nginx/sites-available/byod-$user-$domain.conf
ln -s ../sites-available/byod-$user-$domain.conf /etc/nginx/sites-enabled/byod-$user-$domain.conf
certbot --nginx -d $domain --non-interactive --redirect
else
if [ -s /etc/nginx/sites-enabled/$domain ]
then
exit 1
else
besta=$(dig +short a tilde.best)
domaina=$(dig +short a $domain)
if [ "$besta" == "$domaina" ]
then
echo "server {" >> /etc/nginx/sites-enabled/$domain
echo " listen 80;" >> /etc/nginx/sites-enabled/$domain
echo " server_name $domain;" >> /etc/nginx/sites-enabled/$domain
echo " root /home/$username/$domain;" >> /etc/nginx/sites-enabled/$domain
echo "}" >> /etc/nginx/sites-enabled/$domain
certbot --nginx -d $domain --non-interactive --redirect --agree-tos -m root@$domain
sed -i '1d' ./available.txt
else
sed -i '1d' ./available.txt
exit 1
echo "domain's dns not configured correctly"
fi
fi
fi
else
rm -rf available.txt
fi
done
nginx -t
systemctl reload nginx

12
byod Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
echo "Please enter new domain"
read domain
if [[ $(dig +short a $domain) == $(dig +short a tilde.best) ]]; then
mkdir ~/$domain
echo $domain > ~/byod
echo "once an admin confirms the domain, the webroot will be ~/$domain"
else
echo "please set an A record for $domain for $(dig +short a tilde.best)"
fi

View File

@ -1,12 +0,0 @@
# This file needs to be added at /etc/skel
echo "Please enter new domain"
read DOMAIN
mkdir $DOMAIN
JSON_STRING=$( jq -n \
--arg d "$DOMAIN" \
'{domain: $d}' )
echo "$JSON_STRING" > tilde.json
cd $DOMAIN

11
template.conf Normal file
View File

@ -0,0 +1,11 @@
server {
listen 80;
server_name <domain>;
root /home/<user>/<domain>;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}