From 58ec63c88219ec24b5e8d49dc57804c9dd162551 Mon Sep 17 00:00:00 2001 From: gyurix Date: Thu, 1 Jul 2021 18:49:49 +0000 Subject: [PATCH] Some bugfixes. --- scripts/check_certificates.sh | 15 +++++++-------- scripts/digest_registry.sh | 12 ++++++++++++ scripts/nginx_config_create.sh | 20 ++++++++------------ scripts/scheduler.sh | 3 ++- 4 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 scripts/digest_registry.sh diff --git a/scripts/check_certificates.sh b/scripts/check_certificates.sh index 8ffe6a1..7e7cef9 100755 --- a/scripts/check_certificates.sh +++ b/scripts/check_certificates.sh @@ -24,20 +24,19 @@ openssl req -x509 -newkey rsa:4096 -keyout $CERT_DIR/key.pem -out $CERT_DIR/full } -if [[ "$(ls -A $CERT_DIR)" == "" ]]; then +if [[ "$(ls $CERT_DIR)" == "" ]]; then echo "$DOMAIN not contains certificates, creates new." mkdir -p $CERT_DIR; + CURL_CHECK="curl -s -o /dev/null -w "%{http_code}" https://$LETSENCRYPT_URL"; + + if [[ "$(eval $CURL_CHECK)" != "200" ]] ; then + create_self_signed_certificate; + fi else file="$CERT_DIR/letsencrypt" { echo "{ \"DOMAIN\": \"$DOMAIN\" }" } >> "$file" -fi - -CURL_CHECK="curl -s -o /dev/null -w "%{http_code}" https://$LETSENCRYPT_URL"; - -if [[ "$(eval $CURL_CHECK)" != "200" ]] ; then - create_self_signed_certificate; -else letsencrypt_certificates; fi + diff --git a/scripts/digest_registry.sh b/scripts/digest_registry.sh new file mode 100644 index 0000000..7358481 --- /dev/null +++ b/scripts/digest_registry.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +ref="${1:-library/ubuntu:latest}" +repo="${ref%:*}" +tag="${ref##*:}" +acceptM="application/vnd.docker.distribution.manifest.v2+json" +acceptML="application/vnd.docker.distribution.manifest.list.v2+json" +token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" | jq -r '.token') +curl -H "Accept: ${acceptM}" \ + -H "Accept: ${acceptML}" \ + -H "Authorization: Bearer $token" \ + -I -s "https://registry-1.docker.io/v2/${repo}/manifests/${tag}" diff --git a/scripts/nginx_config_create.sh b/scripts/nginx_config_create.sh index de80401..ee2a9e8 100755 --- a/scripts/nginx_config_create.sh +++ b/scripts/nginx_config_create.sh @@ -7,6 +7,7 @@ DEL=$2 if [[ $DEL != "" ]]; then echo "$DOMAIN DELETED"; rm $DOMAIN.conf; + exit 0; fi DOMAIN_SOURCE=/domains/$DOMAIN @@ -31,7 +32,7 @@ echo $DOMAIN; file="/tmp/$DOMAIN.conf" -cp -a /scripts/nginx_template.conf /tmp/$DOMAIN.conf +#cp -a /scripts/nginx_template.conf /tmp/$DOMAIN.conf { @@ -44,11 +45,11 @@ rewrite_log on;" echo if [[ $REDIRECT_HTTP != "" && $HTTP_PORT != "" ]]; then - echo "return 301 http://$REDIRECT_HTTP; - }" + echo "return 301 http://$REDIRECT_HTTP;" + elif [[ $REDIRECT_HTTPS != "" && $HTTP_PORT != "" ]]; then - echo "return 301 https://$REDIRECT_HTTPS; - }" + echo "return 301 https://$REDIRECT_HTTPS;" + else if [[ $ERROR_PAGE != "" && $HTTP_PORT != "" ]]; then echo "error_page 404 /$ERROR_PAGE; @@ -75,11 +76,7 @@ location = /$ERROR_PAGE { proxy_set_header Connection "'$http_connection'"; proxy_cookie_path / /; access_log off; - }" -fi - -if [[ $HTTPS_PORT == "" ]] ; then - echo "} + } }" fi @@ -128,8 +125,7 @@ echo "proxy_redirect off; proxy_set_header Connection "'$http_connection'"; proxy_cookie_path / /; access_log off; - } -} +} }" fi diff --git a/scripts/scheduler.sh b/scripts/scheduler.sh index 4c13ec2..449615d 100755 --- a/scripts/scheduler.sh +++ b/scripts/scheduler.sh @@ -178,8 +178,9 @@ do parent="/"$(echo $dir|cut -d / -f2) - if [[ "${parent}" == "${CERT_DIR}" && "${op}" == "CREATE,CLOSE_WRITE,CLOSE" && "${file}" == "new_certificate" ]]; then + if [[ "${parent}" == "${CERT_DIR}" && "${op}" == "CREATE,CLOSE_WRITE,CLOSE" ]]; then DOMAIN=$(echo $dir|cut -d / -f3); + echo "file: "$file; echo "New cert created: '$DOMAIN'"; #check_proxy_state;