@@ -111,14 +111,54 @@ then
111
111
exit 0
112
112
fi
113
113
114
+ unmount_or_abort ()
115
+ {
116
+ echo -n " Do you want to unmount $1 ? (yes/no): "
117
+ read resp
118
+ if [ " $resp " = " y" ] || [ " $resp " = " yes" ]
119
+ then
120
+ if ! umount $1
121
+ then
122
+ echo " Sorry, $PGM could not unmount $1 ."
123
+ echo -e " Aborting!\n"
124
+ exit 0
125
+ fi
126
+ else
127
+ echo -e " Aborting!\n"
128
+ exit 0
129
+ fi
130
+ }
131
+
132
+ DST_ROOT_PARTITION=/dev/${DST_DISK} 2
133
+ DST_BOOT_PARTITION=/dev/${DST_DISK} 1
134
+
135
+ # Check that none of the destination partitions are busy (mounted).
136
+ #
137
+ DST_ROOT_CURMOUNT=` fgrep " $DST_ROOT_PARTITION " /etc/mtab | cut -f 2 -d ' ' `
138
+ DST_BOOT_CURMOUNT=` fgrep " $DST_BOOT_PARTITION " /etc/mtab | cut -f 2 -d ' ' `
139
+
140
+ if [ " $DST_ROOT_CURMOUNT " != " " ] || [ " $DST_BOOT_CURMOUNT " != " " ]
141
+ then
142
+ echo " A destination partition is busy (mounted). Mount status:"
143
+ echo " $DST_ROOT_PARTITION : $DST_ROOT_CURMOUNT "
144
+ echo " $DST_BOOT_PARTITION : $DST_BOOT_CURMOUNT "
145
+ if [ " $DST_BOOT_CURMOUNT " != " " ]
146
+ then
147
+ unmount_or_abort $DST_BOOT_CURMOUNT
148
+ fi
149
+ if [ " $DST_ROOT_CURMOUNT " != " " ]
150
+ then
151
+ unmount_or_abort $DST_ROOT_CURMOUNT
152
+ fi
153
+ fi
154
+
114
155
115
156
TEST_MOUNTED=` fgrep " $CLONE " /etc/mtab | cut -f 1 -d ' ' `
116
157
if [ " $TEST_MOUNTED " != " " ]
117
158
then
118
159
echo " This script uses $CLONE for mounting filesystems, but"
119
160
echo " $CLONE is already mounted with $TEST_MOUNTED ."
120
- echo -e " Unmount $CLONE before running this script.\n"
121
- exit 0
161
+ unmount_or_abort $CLONE
122
162
fi
123
163
124
164
if [ ! -d $CLONE ]
129
169
mkdir $CLONE
130
170
else
131
171
echo " $MNT_MOUNT is currently mounted on /mnt."
132
- echo -e " Unmount /mnt before running $PGM .\n "
133
- exit 0
172
+ unmount_or_abort /mnt
173
+ mkdir $CLONE
134
174
fi
135
175
fi
136
176
161
201
162
202
# =========== Disk Setup and Checks ===========
163
203
#
164
- DST_ROOT_PARTITION=/dev/${DST_DISK} 2
165
- DST_BOOT_PARTITION=/dev/${DST_DISK} 1
166
-
167
- # Check that none of the destination partitions are busy (mounted).
168
- #
169
- DST_ROOT_CURMOUNT=` fgrep " $DST_ROOT_PARTITION " /etc/mtab | cut -f 2 -d ' ' `
170
- DST_BOOT_CURMOUNT=` fgrep " $DST_BOOT_PARTITION " /etc/mtab | cut -f 2 -d ' ' `
171
-
172
- if [ " $DST_ROOT_CURMOUNT " != " " ] || [ " $DST_BOOT_CURMOUNT " != " " ]
173
- then
174
- echo " A destination partition is busy (mounted). Mount status:"
175
- echo " $DST_ROOT_PARTITION : $DST_ROOT_CURMOUNT "
176
- echo " $DST_BOOT_PARTITION : $DST_BOOT_CURMOUNT "
177
- echo -e " Aborting!\n"
178
- exit 0
179
- fi
180
-
181
204
# Check that destination partitions are the right type.
182
205
#
183
206
DST_BOOT_PARTITION_TYPE=` parted /dev/$DST_DISK -ms p \
0 commit comments