]> git.ipfire.org Git - thirdparty/dehydrated.git/commitdiff
fixed fetching of account information (fixes #652, fixes #647, fixes #650, closes...
authorLukas Schauer <lukas@schauer.so>
Tue, 25 Jun 2019 10:19:20 +0000 (12:19 +0200)
committerLukas Schauer <lukas@schauer.so>
Tue, 25 Jun 2019 10:19:20 +0000 (12:19 +0200)
dehydrated

index 8f916baeaed4f2a2c46d9c0ed60378a348f6636a..5aed00c1cc898789a87fe3b6cb4875a37011d228 100755 (executable)
@@ -401,7 +401,16 @@ init_system() {
 
   # Read account information or request from CA if missing
   if [[ -e "${ACCOUNT_KEY_JSON}" ]]; then
+    if [[ -z "$(cat "${ACCOUNT_KEY_JSON}" | get_json_int_value id)" ]]; then
+      echo "+ Fetching account information..."
+      ACCOUNT_URL="$(signed_request "${CA_NEW_ACCOUNT}" '{"onlyReturnExisting": true}' 4>&1 | grep -i ^Location: | awk '{print $2}' | tr -d '\r\n')"
+      ACCOUNT_INFO="$(signed_request "${ACCOUNT_URL}" '{}')"
+      echo "${ACCOUNT_INFO}" > "${ACCOUNT_KEY_JSON}"
+    fi
     ACCOUNT_ID="$(cat "${ACCOUNT_KEY_JSON}" | get_json_int_value id)"
+    if [[ -z "${ACCOUNT_ID}" ]]; then
+      _exiterr "Unknown error on fetching account information"
+    fi
     if [[ ${API} -eq 1 ]]; then
       ACCOUNT_URL="${CA_REG}/${ACCOUNT_ID}"
     else