From 3a224f2111c6024f29e4c77c10a778c7382ca3a3 Mon Sep 17 00:00:00 2001 From: inexcode Date: Wed, 6 Apr 2022 15:50:45 +0300 Subject: [PATCH 1/3] Decode password from base64 --- nixos-infect | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/nixos-infect b/nixos-infect index b820f41..c759267 100755 --- a/nixos-infect +++ b/nixos-infect @@ -5,9 +5,14 @@ set -e -o pipefail makeConf() { - export HASHED_PASSWORD=$( mkpasswd -m sha-512 "$PASSWORD" ) # Skip everything if main config already present [[ -e /etc/nixos/configuration.nix ]] && return 0 + if [[ $PASSWORD == null ]]; then + export PASSWORD=$(printf $ENCODED_PASSWORD | base64 --decode) + + export ESCAPED_PASSWORD=$(printf $ENCODED_PASSWORD | base64 --decode | jq -Rs .) + export HASHED_PASSWORD=$( mkpasswd -m sha-512 "$PASSWORD" ) + # NB <<"EOF" quotes / $ ` in heredocs, < Date: Wed, 6 Apr 2022 19:49:24 +0300 Subject: [PATCH 2/3] Fix if condition --- nixos-infect | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos-infect b/nixos-infect index c759267..0e9b214 100755 --- a/nixos-infect +++ b/nixos-infect @@ -9,6 +9,7 @@ makeConf() { [[ -e /etc/nixos/configuration.nix ]] && return 0 if [[ $PASSWORD == null ]]; then export PASSWORD=$(printf $ENCODED_PASSWORD | base64 --decode) + fi export ESCAPED_PASSWORD=$(printf $ENCODED_PASSWORD | base64 --decode | jq -Rs .) export HASHED_PASSWORD=$( mkpasswd -m sha-512 "$PASSWORD" ) -- 2.42.0 From ecdac11cbe3cd3ba155cc3c7a4b24ef57ba45c80 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Wed, 6 Apr 2022 19:55:19 +0300 Subject: [PATCH 3/3] Fix password escaping in JSON --- nixos-infect | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nixos-infect b/nixos-infect index 0e9b214..12fab21 100755 --- a/nixos-infect +++ b/nixos-infect @@ -50,8 +50,8 @@ makeConf() { "hostname": "$HOSTNAME", "nextcloud": { "enable": true, - "adminPassword": "$ESCAPED_PASSWORD", - "databasePassword": "$ESCAPED_PASSWORD" + "adminPassword": $ESCAPED_PASSWORD, + "databasePassword": $ESCAPED_PASSWORD }, "gitea": { "enable": true @@ -66,7 +66,7 @@ makeConf() { "enable": true }, "timezone": "Europe/Uzhgorod", - "resticPassword": "$ESCAPED_PASSWORD", + "resticPassword": $ESCAPED_PASSWORD, "username": "$LUSER" } EOF -- 2.42.0