From 6a1e931cd001fffac8643ad8892b86679bd3b633 Mon Sep 17 00:00:00 2001 From: ZSchoen Date: Sat, 1 Oct 2022 16:44:12 +0200 Subject: [PATCH 1/6] added password_2_hash.sh script --- password_2_hash.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 password_2_hash.sh diff --git a/password_2_hash.sh b/password_2_hash.sh new file mode 100755 index 00000000..1aab7692 --- /dev/null +++ b/password_2_hash.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -eo pipefail +shopt -s nullglob + +function hash_pw() { + openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' +} + +function test_hash() { + gen_hash=$(echo -n "$1" | hash_pw) + if [ "$gen_hash" != "$2" ]; then + exit 1 + fi +} + +test_hash 'mariadb' '*54958E764CE10E50764C2EECBB71D01F08549980' + +function ask_pw() { + stty -echo + head -n 1 | tr -d '\n' + stty echo +} + +echo -n "Password: " +ask_pw | hash_pw From 15c0698807b46b69a658e8ee641572c8bdc1e3d9 Mon Sep 17 00:00:00 2001 From: ZSchoen Date: Sat, 1 Oct 2022 16:54:46 +0200 Subject: [PATCH 2/6] added password_2_hash.sh to update.sh --- 10.10/password_2_hash.sh | 25 +++++++++++++++++++++++++ 10.3/password_2_hash.sh | 25 +++++++++++++++++++++++++ 10.4/password_2_hash.sh | 25 +++++++++++++++++++++++++ 10.5/password_2_hash.sh | 25 +++++++++++++++++++++++++ 10.6/password_2_hash.sh | 25 +++++++++++++++++++++++++ 10.7/password_2_hash.sh | 25 +++++++++++++++++++++++++ 10.8/password_2_hash.sh | 25 +++++++++++++++++++++++++ 10.9/password_2_hash.sh | 25 +++++++++++++++++++++++++ update.sh | 2 +- 9 files changed, 201 insertions(+), 1 deletion(-) create mode 100755 10.10/password_2_hash.sh create mode 100755 10.3/password_2_hash.sh create mode 100755 10.4/password_2_hash.sh create mode 100755 10.5/password_2_hash.sh create mode 100755 10.6/password_2_hash.sh create mode 100755 10.7/password_2_hash.sh create mode 100755 10.8/password_2_hash.sh create mode 100755 10.9/password_2_hash.sh diff --git a/10.10/password_2_hash.sh b/10.10/password_2_hash.sh new file mode 100755 index 00000000..1aab7692 --- /dev/null +++ b/10.10/password_2_hash.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -eo pipefail +shopt -s nullglob + +function hash_pw() { + openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' +} + +function test_hash() { + gen_hash=$(echo -n "$1" | hash_pw) + if [ "$gen_hash" != "$2" ]; then + exit 1 + fi +} + +test_hash 'mariadb' '*54958E764CE10E50764C2EECBB71D01F08549980' + +function ask_pw() { + stty -echo + head -n 1 | tr -d '\n' + stty echo +} + +echo -n "Password: " +ask_pw | hash_pw diff --git a/10.3/password_2_hash.sh b/10.3/password_2_hash.sh new file mode 100755 index 00000000..1aab7692 --- /dev/null +++ b/10.3/password_2_hash.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -eo pipefail +shopt -s nullglob + +function hash_pw() { + openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' +} + +function test_hash() { + gen_hash=$(echo -n "$1" | hash_pw) + if [ "$gen_hash" != "$2" ]; then + exit 1 + fi +} + +test_hash 'mariadb' '*54958E764CE10E50764C2EECBB71D01F08549980' + +function ask_pw() { + stty -echo + head -n 1 | tr -d '\n' + stty echo +} + +echo -n "Password: " +ask_pw | hash_pw diff --git a/10.4/password_2_hash.sh b/10.4/password_2_hash.sh new file mode 100755 index 00000000..1aab7692 --- /dev/null +++ b/10.4/password_2_hash.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -eo pipefail +shopt -s nullglob + +function hash_pw() { + openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' +} + +function test_hash() { + gen_hash=$(echo -n "$1" | hash_pw) + if [ "$gen_hash" != "$2" ]; then + exit 1 + fi +} + +test_hash 'mariadb' '*54958E764CE10E50764C2EECBB71D01F08549980' + +function ask_pw() { + stty -echo + head -n 1 | tr -d '\n' + stty echo +} + +echo -n "Password: " +ask_pw | hash_pw diff --git a/10.5/password_2_hash.sh b/10.5/password_2_hash.sh new file mode 100755 index 00000000..1aab7692 --- /dev/null +++ b/10.5/password_2_hash.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -eo pipefail +shopt -s nullglob + +function hash_pw() { + openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' +} + +function test_hash() { + gen_hash=$(echo -n "$1" | hash_pw) + if [ "$gen_hash" != "$2" ]; then + exit 1 + fi +} + +test_hash 'mariadb' '*54958E764CE10E50764C2EECBB71D01F08549980' + +function ask_pw() { + stty -echo + head -n 1 | tr -d '\n' + stty echo +} + +echo -n "Password: " +ask_pw | hash_pw diff --git a/10.6/password_2_hash.sh b/10.6/password_2_hash.sh new file mode 100755 index 00000000..1aab7692 --- /dev/null +++ b/10.6/password_2_hash.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -eo pipefail +shopt -s nullglob + +function hash_pw() { + openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' +} + +function test_hash() { + gen_hash=$(echo -n "$1" | hash_pw) + if [ "$gen_hash" != "$2" ]; then + exit 1 + fi +} + +test_hash 'mariadb' '*54958E764CE10E50764C2EECBB71D01F08549980' + +function ask_pw() { + stty -echo + head -n 1 | tr -d '\n' + stty echo +} + +echo -n "Password: " +ask_pw | hash_pw diff --git a/10.7/password_2_hash.sh b/10.7/password_2_hash.sh new file mode 100755 index 00000000..1aab7692 --- /dev/null +++ b/10.7/password_2_hash.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -eo pipefail +shopt -s nullglob + +function hash_pw() { + openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' +} + +function test_hash() { + gen_hash=$(echo -n "$1" | hash_pw) + if [ "$gen_hash" != "$2" ]; then + exit 1 + fi +} + +test_hash 'mariadb' '*54958E764CE10E50764C2EECBB71D01F08549980' + +function ask_pw() { + stty -echo + head -n 1 | tr -d '\n' + stty echo +} + +echo -n "Password: " +ask_pw | hash_pw diff --git a/10.8/password_2_hash.sh b/10.8/password_2_hash.sh new file mode 100755 index 00000000..1aab7692 --- /dev/null +++ b/10.8/password_2_hash.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -eo pipefail +shopt -s nullglob + +function hash_pw() { + openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' +} + +function test_hash() { + gen_hash=$(echo -n "$1" | hash_pw) + if [ "$gen_hash" != "$2" ]; then + exit 1 + fi +} + +test_hash 'mariadb' '*54958E764CE10E50764C2EECBB71D01F08549980' + +function ask_pw() { + stty -echo + head -n 1 | tr -d '\n' + stty echo +} + +echo -n "Password: " +ask_pw | hash_pw diff --git a/10.9/password_2_hash.sh b/10.9/password_2_hash.sh new file mode 100755 index 00000000..1aab7692 --- /dev/null +++ b/10.9/password_2_hash.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -eo pipefail +shopt -s nullglob + +function hash_pw() { + openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' +} + +function test_hash() { + gen_hash=$(echo -n "$1" | hash_pw) + if [ "$gen_hash" != "$2" ]; then + exit 1 + fi +} + +test_hash 'mariadb' '*54958E764CE10E50764C2EECBB71D01F08549980' + +function ask_pw() { + stty -echo + head -n 1 | tr -d '\n' + stty echo +} + +echo -n "Password: " +ask_pw | hash_pw diff --git a/update.sh b/update.sh index 34c63893..a750de11 100755 --- a/update.sh +++ b/update.sh @@ -43,7 +43,7 @@ update_version() cp Dockerfile.template "$version/Dockerfile" - cp docker-entrypoint.sh healthcheck.sh "$version/" + cp docker-entrypoint.sh healthcheck.sh password_2_hash.sh "$version/" chmod a+x "$version"/healthcheck.sh sed -i \ -e 's!%%MARIADB_VERSION%%!'"$fullVersion"'!g' \ From ff0613a0e26f20769bc99b3ad7624ae2beacb997 Mon Sep 17 00:00:00 2001 From: ZSchoen Date: Mon, 17 Oct 2022 09:48:13 +0200 Subject: [PATCH 3/6] added password_2_hash.sh to Dockerfile --- 10.10/Dockerfile | 1 + 10.3/Dockerfile | 1 + 10.4/Dockerfile | 1 + 10.5/Dockerfile | 1 + 10.6/Dockerfile | 1 + 10.7/Dockerfile | 1 + 10.8/Dockerfile | 1 + 10.9/Dockerfile | 1 + Dockerfile.template | 1 + 9 files changed, 9 insertions(+) diff --git a/10.10/Dockerfile b/10.10/Dockerfile index 013a9ceb..803f9aba 100644 --- a/10.10/Dockerfile +++ b/10.10/Dockerfile @@ -123,6 +123,7 @@ RUN set -ex; \ VOLUME /var/lib/mysql COPY healthcheck.sh /usr/local/bin/healthcheck.sh +COPY password_2_hash.sh /usr/local/bin/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/10.3/Dockerfile b/10.3/Dockerfile index 884f4b6b..f9d6edf0 100644 --- a/10.3/Dockerfile +++ b/10.3/Dockerfile @@ -125,6 +125,7 @@ RUN set -ex; \ VOLUME /var/lib/mysql COPY healthcheck.sh /usr/local/bin/healthcheck.sh +COPY password_2_hash.sh /usr/local/bin/ COPY docker-entrypoint.sh /usr/local/bin/ RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/10.4/Dockerfile b/10.4/Dockerfile index acf612c2..bc429619 100644 --- a/10.4/Dockerfile +++ b/10.4/Dockerfile @@ -125,6 +125,7 @@ RUN set -ex; \ VOLUME /var/lib/mysql COPY healthcheck.sh /usr/local/bin/healthcheck.sh +COPY password_2_hash.sh /usr/local/bin/ COPY docker-entrypoint.sh /usr/local/bin/ RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/10.5/Dockerfile b/10.5/Dockerfile index a4a85843..a15bcc62 100644 --- a/10.5/Dockerfile +++ b/10.5/Dockerfile @@ -125,6 +125,7 @@ RUN set -ex; \ VOLUME /var/lib/mysql COPY healthcheck.sh /usr/local/bin/healthcheck.sh +COPY password_2_hash.sh /usr/local/bin/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/10.6/Dockerfile b/10.6/Dockerfile index 9be3a41a..4ecdfbce 100644 --- a/10.6/Dockerfile +++ b/10.6/Dockerfile @@ -125,6 +125,7 @@ RUN set -ex; \ VOLUME /var/lib/mysql COPY healthcheck.sh /usr/local/bin/healthcheck.sh +COPY password_2_hash.sh /usr/local/bin/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/10.7/Dockerfile b/10.7/Dockerfile index 365b52a6..ef07153a 100644 --- a/10.7/Dockerfile +++ b/10.7/Dockerfile @@ -125,6 +125,7 @@ RUN set -ex; \ VOLUME /var/lib/mysql COPY healthcheck.sh /usr/local/bin/healthcheck.sh +COPY password_2_hash.sh /usr/local/bin/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/10.8/Dockerfile b/10.8/Dockerfile index e8e1cef4..f7d78894 100644 --- a/10.8/Dockerfile +++ b/10.8/Dockerfile @@ -125,6 +125,7 @@ RUN set -ex; \ VOLUME /var/lib/mysql COPY healthcheck.sh /usr/local/bin/healthcheck.sh +COPY password_2_hash.sh /usr/local/bin/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/10.9/Dockerfile b/10.9/Dockerfile index 579cce08..7e8ebd4d 100644 --- a/10.9/Dockerfile +++ b/10.9/Dockerfile @@ -123,6 +123,7 @@ RUN set -ex; \ VOLUME /var/lib/mysql COPY healthcheck.sh /usr/local/bin/healthcheck.sh +COPY password_2_hash.sh /usr/local/bin/ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/Dockerfile.template b/Dockerfile.template index efd55520..b7618ca7 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -125,6 +125,7 @@ RUN set -ex; \ VOLUME /var/lib/mysql COPY healthcheck.sh /usr/local/bin/healthcheck.sh +COPY password_2_hash.sh /usr/local/bin/ COPY docker-entrypoint.sh /usr/local/bin/ RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat ENTRYPOINT ["docker-entrypoint.sh"] From ad53e84857b9d7520038595254a7641196684a48 Mon Sep 17 00:00:00 2001 From: ZSchoen Date: Mon, 17 Oct 2022 14:16:15 +0200 Subject: [PATCH 4/6] added check if tools are available --- 10.10/password_2_hash.sh | 10 ++++++++++ 10.3/password_2_hash.sh | 10 ++++++++++ 10.4/password_2_hash.sh | 10 ++++++++++ 10.5/password_2_hash.sh | 10 ++++++++++ 10.6/password_2_hash.sh | 10 ++++++++++ 10.7/password_2_hash.sh | 10 ++++++++++ 10.8/password_2_hash.sh | 10 ++++++++++ 10.9/password_2_hash.sh | 10 ++++++++++ password_2_hash.sh | 10 ++++++++++ 9 files changed, 90 insertions(+) diff --git a/10.10/password_2_hash.sh b/10.10/password_2_hash.sh index 1aab7692..d29c5770 100755 --- a/10.10/password_2_hash.sh +++ b/10.10/password_2_hash.sh @@ -2,6 +2,16 @@ set -eo pipefail shopt -s nullglob +command -v openssl >/dev/null || { + echo "openssl command not found" + exit 1 +} + +command -v awk >/dev/null || { + echo "awk command not found" + exit 1 +} + function hash_pw() { openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' } diff --git a/10.3/password_2_hash.sh b/10.3/password_2_hash.sh index 1aab7692..d29c5770 100755 --- a/10.3/password_2_hash.sh +++ b/10.3/password_2_hash.sh @@ -2,6 +2,16 @@ set -eo pipefail shopt -s nullglob +command -v openssl >/dev/null || { + echo "openssl command not found" + exit 1 +} + +command -v awk >/dev/null || { + echo "awk command not found" + exit 1 +} + function hash_pw() { openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' } diff --git a/10.4/password_2_hash.sh b/10.4/password_2_hash.sh index 1aab7692..d29c5770 100755 --- a/10.4/password_2_hash.sh +++ b/10.4/password_2_hash.sh @@ -2,6 +2,16 @@ set -eo pipefail shopt -s nullglob +command -v openssl >/dev/null || { + echo "openssl command not found" + exit 1 +} + +command -v awk >/dev/null || { + echo "awk command not found" + exit 1 +} + function hash_pw() { openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' } diff --git a/10.5/password_2_hash.sh b/10.5/password_2_hash.sh index 1aab7692..d29c5770 100755 --- a/10.5/password_2_hash.sh +++ b/10.5/password_2_hash.sh @@ -2,6 +2,16 @@ set -eo pipefail shopt -s nullglob +command -v openssl >/dev/null || { + echo "openssl command not found" + exit 1 +} + +command -v awk >/dev/null || { + echo "awk command not found" + exit 1 +} + function hash_pw() { openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' } diff --git a/10.6/password_2_hash.sh b/10.6/password_2_hash.sh index 1aab7692..d29c5770 100755 --- a/10.6/password_2_hash.sh +++ b/10.6/password_2_hash.sh @@ -2,6 +2,16 @@ set -eo pipefail shopt -s nullglob +command -v openssl >/dev/null || { + echo "openssl command not found" + exit 1 +} + +command -v awk >/dev/null || { + echo "awk command not found" + exit 1 +} + function hash_pw() { openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' } diff --git a/10.7/password_2_hash.sh b/10.7/password_2_hash.sh index 1aab7692..d29c5770 100755 --- a/10.7/password_2_hash.sh +++ b/10.7/password_2_hash.sh @@ -2,6 +2,16 @@ set -eo pipefail shopt -s nullglob +command -v openssl >/dev/null || { + echo "openssl command not found" + exit 1 +} + +command -v awk >/dev/null || { + echo "awk command not found" + exit 1 +} + function hash_pw() { openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' } diff --git a/10.8/password_2_hash.sh b/10.8/password_2_hash.sh index 1aab7692..d29c5770 100755 --- a/10.8/password_2_hash.sh +++ b/10.8/password_2_hash.sh @@ -2,6 +2,16 @@ set -eo pipefail shopt -s nullglob +command -v openssl >/dev/null || { + echo "openssl command not found" + exit 1 +} + +command -v awk >/dev/null || { + echo "awk command not found" + exit 1 +} + function hash_pw() { openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' } diff --git a/10.9/password_2_hash.sh b/10.9/password_2_hash.sh index 1aab7692..d29c5770 100755 --- a/10.9/password_2_hash.sh +++ b/10.9/password_2_hash.sh @@ -2,6 +2,16 @@ set -eo pipefail shopt -s nullglob +command -v openssl >/dev/null || { + echo "openssl command not found" + exit 1 +} + +command -v awk >/dev/null || { + echo "awk command not found" + exit 1 +} + function hash_pw() { openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' } diff --git a/password_2_hash.sh b/password_2_hash.sh index 1aab7692..d29c5770 100755 --- a/password_2_hash.sh +++ b/password_2_hash.sh @@ -2,6 +2,16 @@ set -eo pipefail shopt -s nullglob +command -v openssl >/dev/null || { + echo "openssl command not found" + exit 1 +} + +command -v awk >/dev/null || { + echo "awk command not found" + exit 1 +} + function hash_pw() { openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' } From 763d57cf845ef4722b443877ca6accccd928bde6 Mon Sep 17 00:00:00 2001 From: ZSchoen Date: Tue, 18 Oct 2022 11:08:24 +0200 Subject: [PATCH 5/6] compatibility with openssl --- password_2_hash.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/password_2_hash.sh b/password_2_hash.sh index d29c5770..357b3063 100755 --- a/password_2_hash.sh +++ b/password_2_hash.sh @@ -13,7 +13,7 @@ command -v awk >/dev/null || { } function hash_pw() { - openssl sha1 -binary | openssl sha1 -hex | awk '{print "*"toupper($0)}' + openssl sha1 -binary | openssl sha1 -hex -r | awk -F ' ' '{print "*"toupper($1)}' } function test_hash() { From 39c0ed66398ba76d0b40a849a3ca4a4078ad4d0b Mon Sep 17 00:00:00 2001 From: ZSchoen Date: Tue, 18 Oct 2022 11:09:20 +0200 Subject: [PATCH 6/6] check for non-interactive shells --- password_2_hash.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/password_2_hash.sh b/password_2_hash.sh index 357b3063..51e975ea 100755 --- a/password_2_hash.sh +++ b/password_2_hash.sh @@ -26,9 +26,13 @@ function test_hash() { test_hash 'mariadb' '*54958E764CE10E50764C2EECBB71D01F08549980' function ask_pw() { - stty -echo + if tty -s; then + stty -echo + fi head -n 1 | tr -d '\n' - stty echo + if tty -s; then + stty echo + fi } echo -n "Password: "