62 lines
1.7 KiB
Plaintext
62 lines
1.7 KiB
Plaintext
|
#!/bin/bash
|
||
|
if [ "$1" == "--help" ]; then
|
||
|
echo './site_add domain [<protokoll>://]<host>[:port]'
|
||
|
else
|
||
|
|
||
|
domain=$1
|
||
|
aim=$2
|
||
|
|
||
|
if [[ $aim =~ :// ]]; then
|
||
|
aim_ip=`echo ${aim//\//} | cut -d ":" -f 2`
|
||
|
aim_port=`echo ${aim//\//} | cut -d ":" -f 3`
|
||
|
else
|
||
|
aim_ip=`echo $aim | cut -d ":" -f 1`
|
||
|
aim_port=`echo $aim | cut -d ":" -f 2`
|
||
|
fi
|
||
|
|
||
|
## check domain is corect to server-ip:
|
||
|
# dig $domain | grep "A" | grep "$domain". | grep
|
||
|
#
|
||
|
# ...
|
||
|
#
|
||
|
##
|
||
|
|
||
|
## check if aim_ip can be pinged if not : msg.warning: no ping
|
||
|
#
|
||
|
# ...
|
||
|
#
|
||
|
##
|
||
|
|
||
|
echo "Start Domain=$domain AIM_IP=$aim_ip AIM_Port=$aim_port "
|
||
|
|
||
|
# if config for domain exist
|
||
|
lxc-attach -n c_proxy -- [ -f /etc/nginx/sites-enabled/"$domain"_ssl ] && {
|
||
|
|
||
|
#update certs
|
||
|
/srv/services/proxy/ssl_update
|
||
|
# del conf
|
||
|
lxc-attach -n c_proxy -- rm /etc/nginx/sites-enabled/"$domain"_ssl
|
||
|
|
||
|
}
|
||
|
|
||
|
# if config for domain NOT exist AND not cert exist
|
||
|
lxc-attach -n c_proxy -- [ -f /etc/nginx/sites-enabled/"$domain"_ssl ] || [ -f /srv/services/proxy/ssl_confs/"$domain".conf ] || {
|
||
|
/srv/services/proxy/ssl_add-domain $domain
|
||
|
}
|
||
|
|
||
|
# cp template
|
||
|
lxc-attach -n c_proxy -- cp /etc/nginx/sites-available/muster.https /etc/nginx/sites-enabled/"$domain"_ssl
|
||
|
# setup config
|
||
|
lxc-attach -n c_proxy -- sed -i "s|###DNS-Name###|${domain}|g" /etc/nginx/sites-enabled/"$domain"_ssl
|
||
|
lxc-attach -n c_proxy -- sed -i "s|###AIM###|${aim}|g" /etc/nginx/sites-enabled/"$domain"_ssl
|
||
|
|
||
|
#del all entrys in host for domain
|
||
|
#> http://ccm.net/faq/1451-delete-lines-from-a-file-using-sed
|
||
|
#add entry for domain
|
||
|
#> http://ccm.net/faq/1451-delete-lines-from-a-file-using-sed
|
||
|
#sync hosts
|
||
|
lxc-attach -n c_proxy -- cat /etc/hosts > /etc/hosts
|
||
|
|
||
|
fi
|
||
|
lxc-attach -n c_proxy -- /etc/init.d/nginx restart
|