From e6920b69bd5523c00a695cad958fdc7ca28a4b32 Mon Sep 17 00:00:00 2001 From: Johan Date: Tue, 7 Mar 2023 12:51:23 +0100 Subject: [PATCH] Add helper script apache-add-site.sh --- BashScripts/install-apache/apache-add-site.sh | 111 ++++++++++++++++++ Git cheat sheet.md | 4 + 2 files changed, 115 insertions(+) create mode 100644 BashScripts/install-apache/apache-add-site.sh diff --git a/BashScripts/install-apache/apache-add-site.sh b/BashScripts/install-apache/apache-add-site.sh new file mode 100644 index 0000000..e77fcca --- /dev/null +++ b/BashScripts/install-apache/apache-add-site.sh @@ -0,0 +1,111 @@ +#!/bin/bash +# Make sure script is ran as root +if [[ $EUID -ne 0 ]]; then + exec sudo /bin/bash "$0" "$@" +fi +if [[ $1 = "" ]]; then + echo "Usage: add-site.sh [domain.com]" + exit 0 +fi +domain=$(perl -e "(\$d)=\"$1\"=~/(\\w+\\.\\w+)\$/;print \$d") +red='\033[0;31m' +green='\033[0;32m' +nocolor='\033[0m' +if [[ ! -d "/var/www/$1/www" ]]; then + # echo "Directory '/var/www/$1/www' does not exist" + # exit 1 + mkdir "/var/www/$1" + mkdir "/var/www/$1/www" +fi +if [[ ! -d "/var/www/$1/logs" ]]; then + mkdir "/var/www/$1/logs" +fi +if [[ -f "/etc/apache2/sites-enabled/$1.conf" ]]; then + echo "Config file $1.conf does already exist" + exit 1 +fi +chmod -R 777 "/var/www/$1" + +declare -a CertDirectories=("/var/www/$domain/certs" "/var/www/SSL-Cerfificates") +unset CertDirectory +for TestDirectory in "${CertDirectories[@]}" +do + if [[ -f "$TestDirectory/$domain-crt.pem" ]] && [[ -f "$TestDirectory/$domain-key.pem" ]] && [[ -f "$TestDirectory/$domain-chain.pem" ]]; then + CertDirectory=$TestDirectory; + fi +done + +echo Adding site +cat <> "/etc/apache2/sites-enabled/$1.conf" + + + ServerName $1 + ServerAlias www.$1 + ServerAdmin webmaster@$1 + DocumentRoot /var/www/$1/www + + HostnameLookups Off + ErrorLog /var/www/$1/logs/error.log + CustomLog /var/www/$1/logs/access.log combined + + + Options Indexes FollowSymLinks MultiViews + DirectoryIndex index.html index.pl + AllowOverride All + Require all granted + + + AddHandler cgi-script .pl + Options +ExecCGI + + + +EOT1 + +if [[ ! $CertDirectory = "" ]]; then + echo Adding SSL settings + cat <> "/etc/apache2/sites-enabled/$1.conf" + + + + ServerName $1 + ServerAlias www.$1 + ServerAdmin webmaster@$1 + DocumentRoot /var/www/$1/www + + HostnameLookups Off + LogFormat "%h %l %u %{%Y-%m-%d %H:%M:%S}t \"%r\" %>s %b" mylogformat + ErrorLog /var/www/$1/logs/error-ssl.log + CustomLog /var/www/$1/logs/access-ssl.log mylogformat + + + Options Indexes FollowSymLinks MultiViews + DirectoryIndex index.html index.pl + AllowOverride All + Require all granted + + + AddHandler cgi-script .pl + Options +ExecCGI + + + SSLEngine on + SSLCertificateFile "$CertDirectory/$domain-crt.pem" + SSLCertificateKeyFile "$CertDirectory/$domain-key.pem" + SSLCertificateChainFile "$CertDirectory/$domain-chain.pem" + BrowserMatch "MSIE [2-5]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0 + + + +EOT2 +fi + +apacheresult=$(apachectl configtest 2>&1) +if [[ ! $apacheresult =~ "Syntax OK" ]]; then + rm "/etc/apache2/sites-enabled/$1.conf" + echo "Errors detected:" + echo "$apacheresult" +else + echo "Site added!" + systemctl restart apache2 +fi diff --git a/Git cheat sheet.md b/Git cheat sheet.md index 404acaa..a09bae2 100644 --- a/Git cheat sheet.md +++ b/Git cheat sheet.md @@ -71,6 +71,10 @@ Eller för en hel katalog (rekursivt) Alternativt lägg till -C "<user@domain.com>" +#### Aktivera credential store + +
git config --global credential.helper store
+ #### Aktivera Windows Credentials manager
git config --global credential.helper manager