File tree Expand file tree Collapse file tree 3 files changed +30
-16
lines changed
Expand file tree Collapse file tree 3 files changed +30
-16
lines changed Original file line number Diff line number Diff line change @@ -175,20 +175,7 @@ backup_contacts: $backup_contacts
175175 # -bb3: verbose logging
176176 # The undefined variable (archive_password) is set by the user if they're using unattended mode
177177 if [ -z " $archive_password " ]; then
178- while true ; do
179- cecho " Enter a password to encrypt the backup archive (input will be hidden):"
180- IFS= read -s archive_password
181- echo
182- cecho " Re-enter the password to confirm:"
183- IFS= read -s archive_password_confirm
184- echo
185- if [ " $archive_password " = " $archive_password_confirm " ]; then
186- unset archive_password_confirm
187- break
188- else
189- cecho " Passwords do not match. Please try again."
190- fi
191- done
178+ get_password_input " Enter a password to encrypt the backup archive (input will be hidden):" archive_password
192179 fi
193180 declare backup_archive=" $archive_path /open-android-backup-$( date +%m-%d-%Y-%H-%M-%S) .7z"
194181 retry 5 7z a -p -mhe=on -mx=$compression_level -bb3 " $backup_archive " backup-tmp/* < <( echo " $archive_password " )
Original file line number Diff line number Diff line change @@ -231,4 +231,26 @@ function directory_ok() {
231231 fi
232232 return 0
233233}
234- # ---
234+
235+ # Prompts the user to enter and confirm a password
236+ # Usage: get_password_input <prompt_message> <result_variable>
237+ function get_password_input() {
238+ local prompt_message=" $1 "
239+ local -n password_ref=" $2 " # Use nameref for indirect assignment
240+
241+ while true ; do
242+ cecho " $prompt_message "
243+ IFS= read -s password_input
244+ echo
245+ cecho " Re-enter the password to confirm:"
246+ IFS= read -s password_confirm
247+ echo
248+ if [ " $password_input " = " $password_confirm " ]; then
249+ password_ref=" $password_input "
250+ unset password_confirm
251+ break
252+ else
253+ cecho " Passwords do not match. Please try again."
254+ fi
255+ done
256+ }
Original file line number Diff line number Diff line change @@ -44,7 +44,12 @@ function restore_func() {
4444 fi
4545
4646 cecho " Extracting archive."
47- 7z x " $archive_path " # -obackup-tmp isn't needed
47+ # Archive is encrypted, ask for password
48+ get_password_input " Enter the password to decrypt the backup archive (input will be hidden):" archive_password
49+ # Extract with password
50+ 7z x " $archive_path " < <( echo " $archive_password " )
51+ # Clear sensitive data
52+ unset archive_password
4853
4954 # Check if directories are empty
5055 apps_empty=$( find ./backup-tmp/Apps -mindepth 1 | read -r && echo " no" || echo " yes" )
You can’t perform that action at this time.
0 commit comments