Credentials: Create a backup file

The issue is, when the user wants to change credentials, and the
credentials they use are not valid, the credentials will reset.
Keep a backup of credentials file so it can be restored if new
credentials are invalid.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@3mdeb.com>
This commit is contained in:
Mateusz Kusiak
2026-02-09 10:08:01 +01:00
parent b643f402e7
commit 3779240997
3 changed files with 31 additions and 2 deletions
+1
View File
@@ -31,6 +31,7 @@ DPP_AVAIL_PACKAGES_LIST="$DPP_PACKAGE_MANAGER_DIR/packages-list.json"
DPP_PACKAGES_SCRIPTS_PATH="$DPP_PACKAGE_MANAGER_DIR/packages-scripts"
DPP_SUBMENU_JSON="$DPP_PACKAGES_SCRIPTS_PATH/submenu.json"
DPP_CREDENTIAL_FILE="/etc/cloud-pass"
DPP_CREDENTIAL_FILE_BCKP="$DPP_CREDENTIAL_FILE.bckp"
FW_STORE_URL="${FW_STORE_URL_DEV:-https://dl.3mdeb.com/open-source-firmware/Dasharo}"
FW_STORE_URL_DPP="dl.dasharo.com"
CLOUD_REQUEST="X-Requested-With: XMLHttpRequest"
+6 -2
View File
@@ -1216,8 +1216,12 @@ main_menu_options() {
# was not successful:
if ! login_to_dpp_server; then
print_warning "Cannot log in to DPP server, wrong email or password."
print_warning "The credentials won't be saved!"
clean_dpp_creds
if restore_dpp_creds; then
print_warning "Keeping existing credentials!"
else
print_warning "The credentials won't be saved!"
clean_dpp_creds
fi
read -p "Press Enter to continue"
return 0
fi
+24
View File
@@ -107,6 +107,27 @@ clean_dpp_creds() {
unset DPP_PASSWORD
}
# Backup dpp creds file in case new creds are bad.
backup_dpp_creds() {
cp "$DPP_CREDENTIAL_FILE" "$DPP_CREDENTIAL_FILE_BCKP" 2>/dev/null
}
# Restores credential file and settings from backup and deletes backup.
# Returns 0 if file was restored, 1 otherwise.
restore_dpp_creds() {
# No backup, nothing to do
[ ! -f "$DPP_CREDENTIAL_FILE_BCKP" ] && return 1
# Backup exists → restore credentials
cp "$DPP_CREDENTIAL_FILE_BCKP" "$DPP_CREDENTIAL_FILE" || return 1
rm -f "$DPP_CREDENTIAL_FILE_BCKP" 2>/dev/null
DPP_EMAIL=$(sed -n '1p' <"$DPP_CREDENTIAL_FILE" | tr -d '\n')
DPP_PASSWORD=$(sed -n '2p' <"$DPP_CREDENTIAL_FILE" | tr -d '\n')
return 0
}
get_dpp_creds() {
read -p "Enter DPP email: " DPP_EMAIL
if [[ -z "$DPP_EMAIL" ]]; then
@@ -128,6 +149,9 @@ get_dpp_creds() {
return 1
fi
# Make a copy of the file if credentials won't be accepted by minio
backup_dpp_creds
# Export DPP creds to a file for future use. Currently these are being used
# for both: MinIO (and its mc CLI) and cloudsend (deprecated, all DPP
# sibscribtions will be megrated to MinIO):