Browse Source

rewrite

pull/1/head
Ben Harris 2 years ago
committed by root
parent
commit
c426afbae5
  1. 65
      admin.sh
  2. 12
      byod
  3. 12
      create.sh
  4. 11
      template.conf

65
admin.sh

@ -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 ]
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
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
fi
fi
fi
else
rm -rf available.txt
fi
#!/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
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
echo "domain's dns not configured correctly"
fi
fi
done
nginx -t
systemctl reload nginx

12
byod

@ -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

12
create.sh

@ -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

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