Преглед изворни кода

Added: asking confirmation if tar file already exists

Laurent HUBERT пре 8 година
родитељ
комит
8c2bc16502
1 измењених фајлова са 37 додато и 8 уклоњено
  1. 37 8
      devel/diskimg

+ 37 - 8
devel/diskimg

@@ -207,7 +207,7 @@ prepare_partition(){
 		
 		case $part_type in
 		crypto_LUKS)
-			ask_password $the_target_device
+			ask_password $the_target_device confirm
 			create_luks_container $the_target_device
 			open_luks_container $the_target_device $backup_basename
 			#Now that the partition is opened, we will format it at next loop:
@@ -327,6 +327,26 @@ restore_disk(){
 	fi
 }
 
+check_override_file(){
+	local target_path=$1
+	answer=""
+	if [[ -f $target_path ]] ; then
+		echo "Are you sure you want to destroy all data in $target_path (all previously saved data will be losts !!!)"
+		echo "(yes/No)"
+		read answer
+		while [[ "$answer" =~ [yY]$ ]] ; do
+			echo "Please type yes or YES"
+			read answer
+		done
+		
+		if [[ "$answer" =~ yes ]] ; then
+			return 0
+		else
+			return 1
+		fi
+	fi
+}
+
 backup_mounted_volume(){
 	backup_basename=$1
 	partition_dev=$2
@@ -342,8 +362,12 @@ backup_mounted_volume(){
 	test "1" = "$VERBOSE" && echo "Backing up from $mountpoint_dir to $TARGET_DIR/$backup_filename"
 	
 	if [[ "$SKIP_TAR" != 1 ]] ; then
-		test "1" != "$DEBUG" && echo "tar --numeric-owner $COMPRESSION_ALGORITHM $VERBOSE_OPTION $EXCLUDE_STRING -pcf $TARGET_DIR/$backup_filename -C $mountpoint_dir ."
-		test "1" != "$DEBUG" && tar --numeric-owner $COMPRESSION_ALGORITHM $VERBOSE_OPTION $EXCLUDE_STRING -pcf $TARGET_DIR/$backup_filename -C $mountpoint_dir .
+		if check_override_file $TARGET_DIR/$backup_filename ; then
+			if [[ "1" != "$DEBUG" ]] ; then
+				echo "tar --numeric-owner $COMPRESSION_ALGORITHM $VERBOSE_OPTION $EXCLUDE_STRING -pcf $TARGET_DIR/$backup_filename -C $mountpoint_dir ."
+				tar --numeric-owner $COMPRESSION_ALGORITHM $VERBOSE_OPTION $EXCLUDE_STRING -pcf $TARGET_DIR/$backup_filename -C $mountpoint_dir .
+			fi
+		fi
 	fi
 	
 	umount $partition_dev
@@ -352,16 +376,21 @@ backup_mounted_volume(){
 
 ask_password(){
 	local partition_dev=$1
+	local need_confirmation=$2
 	local second_try="FAKE"
 	while [[ "$second_try" != "$_luks_password" ]] ; do
 		echo "Enter encrypted partition passphrase for $partition_dev:"
 		read -s _luks_password
 		
-		echo "Please confirm passphrase:"
-		read -s second_try
-		
-		if [[ "$second_try" != "$_luks_password" ]] ; then
-			echo "ERROR: passphrases do not match"
+		if [[ "$need_confirmation" = "confirm" ]]; then
+			echo "Please confirm passphrase:"
+			read -s second_try
+			
+			if [[ "$second_try" != "$_luks_password" ]] ; then
+				echo "ERROR: passphrases do not match ! Please try again"
+			fi
+		else
+			$second_try="$_luks_password"
 		fi
 	done
 	_luks_password=$second_try