From 301a99833f3d522aa145e6fe3a7e384bd4a63141 Mon Sep 17 00:00:00 2001 From: Ze'ev Schurmann Date: Fri, 3 Nov 2023 20:40:38 +0200 Subject: [PATCH] Created makevhost.sh and updated dirsize.sh --- dirsize/dirsize.sh | 25 ++++++++++++- makevhost/makevhost.sh | 81 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 makevhost/makevhost.sh diff --git a/dirsize/dirsize.sh b/dirsize/dirsize.sh index 579d00c..8472a2c 100644 --- a/dirsize/dirsize.sh +++ b/dirsize/dirsize.sh @@ -1,4 +1,27 @@ #!/bin/bash + +## MakeVHost Script +## Author: Ze'ev Schurmann +## Reddit: u/thisiszeev +## License: GPL-3.0 or later + +## Copy this file to /usr/bin as dirsize (not dirsize.sh) + +## From any folder that you want to assess the size of each folder within the current folder, +## simply type dirsize + +## Please consider making me small donation. Even though my scripts are open source and free to use, I still need to eat. And the +## occasional bottle of wine also goes down well. +## $5 buys me a cup of coffee +## $10 buys me a nice burger +## $20 buys me a bottle of wine +## Anything above that will be awesome as well. +## You can send me a donation via Paypal https://www.paypal.com/paypalme/thisiszeev +## Drop me a message on Reddit if you do make a donation. +## Support is only offered freely to those who donate $20 or more. +## Your donation contributes to further development. +## If you need a custom script, contact me on Reddit for pricing. + if [[ -f "/tmp/dir.list" ]]; then rm "/tmp/dir.list" fi @@ -20,4 +43,4 @@ while read -r foldername; do du -h $foldername | tail -1 fi done < "/tmp/dir.list" -rm "/tmp/dir.list +rm "/tmp/dir.list" diff --git a/makevhost/makevhost.sh b/makevhost/makevhost.sh new file mode 100644 index 0000000..22e9194 --- /dev/null +++ b/makevhost/makevhost.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +## MakeVHost Script +## Author: Ze'ev Schurmann +## Reddit: u/thisiszeev +## License: GPL-3.0 or later + +## This script creates a vhost on a debian based server running Apache2. It assumes that +## the www path is /var/www/ and that the Apache2 logs are stored at /var/log/apache2/ + +## To use it, either use ./makevhost.sh {domainname} or simple use ./makevhost.sh and it +## will ask you for the domain name. + +## Requires certbot from Let's Encrypt + +## Please consider making me small donation. Even though my scripts are open source and free to use, I still need to eat. And the +## occasional bottle of wine also goes down well. +## $5 buys me a cup of coffee +## $10 buys me a nice burger +## $20 buys me a bottle of wine +## Anything above that will be awesome as well. +## You can send me a donation via Paypal https://www.paypal.com/paypalme/thisiszeev +## Drop me a message on Reddit if you do make a donation. +## Support is only offered freely to those who donate $20 or more. +## Your donation contributes to further development. +## If you need a custom script, contact me on Reddit for pricing. + +if [[ -z $1 ]]; then + echo -n "Enter domain to add to Apache2 server as vhost: " + read domain +else + domain=$1 +fi + +echo "Creating web folder at /var/www/$domain/" +mkdir "/var/www/$domain" +touch "/var/www/$domain/index.html" +echo "$domain

$domain is working!

" >> "/var/www/$domain/index.html" +chown -R www-data:www-data "/var/www/$domain" + +echo "Creating log folder at /var/log/apache2/$domain/" +mkdir "/var/log/apache2/$domain" +chown -R root:adm "/var/log/apache2/$domain" + +echo "Configuring Apache2" +touch "/etc/apache2/sites-available/$domain.conf" +echo "" >> "/etc/apache2/sites-available/$domain.conf" +echo " # Created using MakeVHost Script" >> "/etc/apache2/sites-available/$domain.conf" +echo " # https://git.zaks.web.za/thisiszeev/linux-server-tools" >> "/etc/apache2/sites-available/$domain.conf" +echo " ServerName $domain" >> "/etc/apache2/sites-available/$domain.conf" +echo " ServerAdmin webmaster@localhost" >> "/etc/apache2/sites-available/$domain.conf" +echo " DocumentRoot /var/www/$domain" >> "/etc/apache2/sites-available/$domain.conf" +echo " ErrorLog /var/log/apache2/$domain/error.log" >> "/etc/apache2/sites-available/$domain.conf" +echo " CustomLog /var/log/apache2/$domain/access.log combined" >> "/etc/apache2/sites-available/$domain.conf" +echo "" >> "/etc/apache2/sites-available/$domain.conf" +systemctl reload apache2 + +echo "Enabling VHost for $domain" +a2ensite $domain.conf +systemctl reload apache2 + +echo "Checking if DNS is working..." +test=$( nslookup $domain | grep "** server can" ) +if [[ -z $test ]]; then + echo "Looks good!" +else + echo "Please configure the DNS zone for the domain to point to this server and set the TTL to 180 or less." + echo "Will keep checking every 300 seconds..." + echo "To exit, press CTRL+C" + while [[ ! -z $test ]]; do + sleep 300s + test=$( nslookup $domain | grep "** server can" ) + done + echo "Looks good!" +fi + +echo "Setting up Let's Encrypt Certificate" +certbot --apache -d "$domain" + +echo "DONE!!!" +