move-dir-mount.sh 2.24 KB
Newer Older
fsmithred's avatar
fsmithred committed
1 2 3
#!/usr/bin/env bash
# move-dir-mount.sh

4 5 6 7 8
. gettext.sh
TEXTDOMAIN=refractainstaller-base
export TEXTDOMAIN
TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAINDIR
fsmithred's avatar
fsmithred committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22

#set -x

# Send errors to the installer's error log.
error_log=$(grep error_log /etc/refractainstaller.conf | cut -d"\"" -f2)
exec 2>> "$error_log"

move_dir () {
# Select the directory you want to move to another partition
echo -n $"

 Enter the directory you want to move to another partition.
 Do not use a trailing slash.
 (examples:  /var or /usr
fsmithred's avatar
fsmithred committed
23
"
fsmithred's avatar
fsmithred committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
read source_dir

if [[ -z "$source_dir" ]] ; then
	echo $"Error: You didn't enter a directory. Nothing will be moved."
	exit 0
fi



# Make sure the user select selects source_dir from the new installation, mounted at /target


# Enter the destination partition.
echo -n $"

 Enter the destination partition for /${source_dir##*/}.
 (example: /dev/sdb3)
fsmithred's avatar
fsmithred committed
41
"
fsmithred's avatar
fsmithred committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
read destination_partition

if [[ -z "$destination_partition" ]] ; then
	echo $"Error: You didn't enter a partition. Nothing will be moved."
	exit 0
fi

if ! [[ -b "$destination_partition" ]] ; then
	echo $"Error: $destination_partition is not a valid block device. Nothing will be moved."
	exit 0
fi

if [[ ${destination_partition:8:1} != [1-9] ]]; then
	echo $"Error: $destination_partition is not a valid partition. Nothing will be moved."
	exit 0
fi

# Temporary mount point for the other partition, just to copy the files.
dirname="${source_dir##*/}"
temp_mountpoint="$(mktemp -d /tmp/$dirname.XXXXXX)"

echo "1 $source_dir  ********"
echo "2 $destination_partition  **********"
echo "3 $temp_mountpoint  ***********"

mount "$destination_partition" "$temp_mountpoint"
rsync -av --progress /target"$source_dir"/ "$temp_mountpoint"/ 

idnum=$(blkid -c /dev/null -o value -s UUID "$destination_partition")
fstype=$(blkid -c /dev/null -o value -s TYPE "$destination_partition")

echo -e "UUID=$idnum\t$source_dir\t$fstype\tdefaults,noatime\t0\t2"  >> /target/etc/fstab

rm -rf /target"$source_dir"/*
umount "$temp_mountpoint"
rmdir "$temp_mountpoint"

ask_again

}

ask_again () {
while true; do
	echo -n $"
86 87 88
 Do you want to move another directory to a separate partition?
   Press 1 for yes.
   Press ENTER for NO.
fsmithred's avatar
fsmithred committed
89 90 91
 "
	read ans
	case $ans in
92
		[1Yy]*)	move_dir; break ;;
fsmithred's avatar
fsmithred committed
93 94 95 96 97 98 99 100 101
		*)		exit 0 ;;
	esac
done
	
}

move_dir

exit 0