Skip to content

Instantly share code, notes, and snippets.

@Razuuu
Last active August 28, 2023 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Razuuu/4c53f14a7bb33dc800d45b7292c115ac to your computer and use it in GitHub Desktop.
Save Razuuu/4c53f14a7bb33dc800d45b7292c115ac to your computer and use it in GitHub Desktop.
Nginx sites enabler / linker - Domain needs a custom folder: /etc/nginx/<domain>/<file>
#!/bin/bash
# ------------------------------------------------------
# Functions - Common
# ------------------------------------------------------
domain=$1
domainpath0="/etc/nginx/sites-available/${domain,,}"
domainpath1="/etc/nginx/sites-enabled/${domain,,}"
logpath="/var/log/nginx/${domain,,}"
# Prints Domain
function print_domain() {
echo "Domain: $domain"
echo
}
# Creates folder if not exist
function create_folder() {
for FOLDER in ${domainpath1} ${logpath}; do
if [ ! -d ${FOLDER} ]; then
echo "Folder ${FOLDER} created!"
mkdir -p ${FOLDER}
fi
done
}
# Creates file if not exist
function create_file() {
if [ "$(ls ${domainpath0})" == "$(ls ${domainpath1})" ]; then
echo "Nothing to do..."
fi
for FILE in $(ls ${domainpath0}); do
if [ ! -f ${domainpath1}/${FILE} ]; then
ln -s ${domainpath0}/${FILE} ${domainpath1}/
echo "File ${FILE} successfully linked!"
fi
done
}
# Checks if $domain is empty
function check_var_empty() {
if [ -z $domain ]; then
echo "bash `basename $0` <Domain>"
exit 0
fi
}
# ------------------------------------------------------
# Script - Start
# ------------------------------------------------------
check_var_empty
print_domain
create_folder
create_file
# ------------------------------------------------------
# Script - End
# ------------------------------------------------------
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment