mirror of
https://github.com/dehydrated-io/dehydrated.git
synced 2026-07-11 15:42:44 +02:00
use different sed version for different system types (mostly for compatibility with ancient linux distros nobody should be using anyway ¯\_(ツ)_/¯)
This commit is contained in:
+18
-7
@@ -12,7 +12,7 @@ BASEDIR="${SCRIPTDIR}"
|
|||||||
check_dependencies() {
|
check_dependencies() {
|
||||||
curl -V > /dev/null 2>&1 || _exiterr "This script requires curl."
|
curl -V > /dev/null 2>&1 || _exiterr "This script requires curl."
|
||||||
openssl version > /dev/null 2>&1 || _exiterr "This script requires an openssl binary."
|
openssl version > /dev/null 2>&1 || _exiterr "This script requires an openssl binary."
|
||||||
sed -E "" < /dev/null > /dev/null 2>&1 || _exiterr "This script requires sed with support for extended (modern) regular expressions."
|
_sed "" < /dev/null > /dev/null 2>&1 || _exiterr "This script requires sed with support for extended (modern) regular expressions."
|
||||||
grep -V > /dev/null 2>&1 || _exiterr "This script requires grep."
|
grep -V > /dev/null 2>&1 || _exiterr "This script requires grep."
|
||||||
mktemp -u -t XXXXXX > /dev/null 2>&1 || _exiterr "This script requires mktemp."
|
mktemp -u -t XXXXXX > /dev/null 2>&1 || _exiterr "This script requires mktemp."
|
||||||
}
|
}
|
||||||
@@ -134,6 +134,15 @@ init_system() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Different sed version for different os types...
|
||||||
|
_sed() {
|
||||||
|
if [ "${OSTYPE}" = "Linux" ]; then
|
||||||
|
sed -r "${@}"
|
||||||
|
else
|
||||||
|
sed -E "${@}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Print error message and exit with error
|
# Print error message and exit with error
|
||||||
_exiterr() {
|
_exiterr() {
|
||||||
echo "ERROR: ${1}" >&2
|
echo "ERROR: ${1}" >&2
|
||||||
@@ -143,13 +152,13 @@ _exiterr() {
|
|||||||
# Encode data as url-safe formatted base64
|
# Encode data as url-safe formatted base64
|
||||||
urlbase64() {
|
urlbase64() {
|
||||||
# urlbase64: base64 encoded string with '+' replaced with '-' and '/' replaced with '_'
|
# urlbase64: base64 encoded string with '+' replaced with '-' and '/' replaced with '_'
|
||||||
openssl base64 -e | tr -d '\n\r' | sed -e 's:=*$::g' -e 'y:+/:-_:'
|
openssl base64 -e | tr -d '\n\r' | _sed -e 's:=*$::g' -e 'y:+/:-_:'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Convert hex string to binary data
|
# Convert hex string to binary data
|
||||||
hex2bin() {
|
hex2bin() {
|
||||||
# Remove spaces, add leading zero, escape as hex string and parse with printf
|
# Remove spaces, add leading zero, escape as hex string and parse with printf
|
||||||
printf -- "$(cat | sed -E -e 's/[[:space:]]//g' -e 's/^(.(.{2})*)$/0\1/' -e 's/(.{2})/\\x\1/g')"
|
printf -- "$(cat | _sed -e 's/[[:space:]]//g' -e 's/^(.(.{2})*)$/0\1/' -e 's/(.{2})/\\x\1/g')"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get string value from json dictionary
|
# Get string value from json dictionary
|
||||||
@@ -280,7 +289,7 @@ sign_domain() {
|
|||||||
challenges="$(printf '%s\n' "${response}" | grep -Eo '"challenges":[^\[]*\[[^]]*]')"
|
challenges="$(printf '%s\n' "${response}" | grep -Eo '"challenges":[^\[]*\[[^]]*]')"
|
||||||
repl=$'\n''{' # fix syntax highlighting in Vim
|
repl=$'\n''{' # fix syntax highlighting in Vim
|
||||||
challenge="$(printf "%s" "${challenges//\{/${repl}}" | grep \""${CHALLENGETYPE}"\")"
|
challenge="$(printf "%s" "${challenges//\{/${repl}}" | grep \""${CHALLENGETYPE}"\")"
|
||||||
challenge_token="$(printf '%s' "${challenge}" | get_json_string_value token | sed 's/[^A-Za-z0-9_\-]/_/g')"
|
challenge_token="$(printf '%s' "${challenge}" | get_json_string_value token | _sed 's/[^A-Za-z0-9_\-]/_/g')"
|
||||||
challenge_uri="$(printf '%s' "${challenge}" | get_json_string_value uri)"
|
challenge_uri="$(printf '%s' "${challenge}" | get_json_string_value uri)"
|
||||||
|
|
||||||
if [[ -z "${challenge_token}" ]] || [[ -z "${challenge_uri}" ]]; then
|
if [[ -z "${challenge_token}" ]] || [[ -z "${challenge_uri}" ]]; then
|
||||||
@@ -381,7 +390,7 @@ command_sign_domains() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Generate certificates for all domains found in domains.txt. Check if existing certificate are about to expire
|
# Generate certificates for all domains found in domains.txt. Check if existing certificate are about to expire
|
||||||
<"${DOMAINS_TXT}" sed -E -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' -e 's/[[:space:]]+/ /g' | (grep -vE '^(#|$)' || true) | while read -r line; do
|
<"${DOMAINS_TXT}" _sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' -e 's/[[:space:]]+/ /g' | (grep -vE '^(#|$)' || true) | while read -r line; do
|
||||||
domain="$(printf '%s\n' "${line}" | cut -d' ' -f1)"
|
domain="$(printf '%s\n' "${line}" | cut -d' ' -f1)"
|
||||||
morenames="$(printf '%s\n' "${line}" | cut -s -d' ' -f2-)"
|
morenames="$(printf '%s\n' "${line}" | cut -s -d' ' -f2-)"
|
||||||
cert="${BASEDIR}/certs/${domain}/cert.pem"
|
cert="${BASEDIR}/certs/${domain}/cert.pem"
|
||||||
@@ -397,8 +406,8 @@ command_sign_domains() {
|
|||||||
if [[ -e "${cert}" ]]; then
|
if [[ -e "${cert}" ]]; then
|
||||||
printf " + Checking domain name(s) of existing cert..."
|
printf " + Checking domain name(s) of existing cert..."
|
||||||
|
|
||||||
certnames="$(openssl x509 -in "${cert}" -text -noout | grep DNS: | sed 's/DNS://g' | tr -d ' ' | tr ',' '\n' | sort -u | tr '\n' ' ' | sed 's/ $//')"
|
certnames="$(openssl x509 -in "${cert}" -text -noout | grep DNS: | _sed 's/DNS://g' | tr -d ' ' | tr ',' '\n' | sort -u | tr '\n' ' ' | _sed 's/ $//')"
|
||||||
givennames="$(echo "${domain}" "${morenames}"| tr ' ' '\n' | sort -u | tr '\n' ' ' | sed 's/ $//' | sed 's/^ //')"
|
givennames="$(echo "${domain}" "${morenames}"| tr ' ' '\n' | sort -u | tr '\n' ' ' | _sed 's/ $//' | _sed 's/^ //')"
|
||||||
|
|
||||||
if [[ "${certnames}" = "${givennames}" ]]; then
|
if [[ "${certnames}" = "${givennames}" ]]; then
|
||||||
echo " unchanged."
|
echo " unchanged."
|
||||||
@@ -502,6 +511,8 @@ command_env() {
|
|||||||
|
|
||||||
# Main method (parses script arguments and calls command_* methods)
|
# Main method (parses script arguments and calls command_* methods)
|
||||||
main() {
|
main() {
|
||||||
|
OSTYPE="$(uname)"
|
||||||
|
|
||||||
COMMAND=""
|
COMMAND=""
|
||||||
set_command() {
|
set_command() {
|
||||||
[[ -z "${COMMAND}" ]] || _exiterr "Only one command can be executed at a time. See help (-h) for more information."
|
[[ -z "${COMMAND}" ]] || _exiterr "Only one command can be executed at a time. See help (-h) for more information."
|
||||||
|
|||||||
Reference in New Issue
Block a user