6 DSTDIR
="/mnt/install_dest.tmp"
8 SCRIPTDIR
="/usr/share/educastur/common-scripts/"
10 # If called with no arguments a new timer is returned.
11 # If called with arguments the first is used as a timer
12 # value and the elapsed time is returned in the form HH:MM:SS.
13 # See: http://www.linuxjournal.com/content/use-date-command-measure-elapsed-time
16 if [[ $# -eq 0 ]]; then
22 if [[ -z "$stime" ]]; then stime
=$etime; fi
26 dm
=$
(((dt
/ 60) % 60))
28 printf '%d:%02d:%02d' $dh $dm $ds
34 umount
"${DSTDIR}/dev/pts/" || umount
-l "${DSTDIR}/dev/pts/" || true
35 umount
"${DSTDIR}/dev/" || umount
-l "${DSTDIR}/dev/" || true
36 umount
"${DSTDIR}/sys" || umount
-l "${DSTDIR}/sys" || true
37 umount
"${DSTDIR}/proc" || umount
-l "${DSTDIR}/proc" || true
38 umount
"${DSTDIR}" || umount
-l "${DSTDIR}" || true
40 rmdir "${DSTDIR}" || true
42 if [ -e "${DSTDIR}" ]; then exit 1; fi
45 PART
=$
("${SCRIPTDIR}/partition-by-label" "AULA-LOCAL-WS")
46 if [ -z "$PART" ]; then echo "Destination partition not found"; exit 1; fi
48 DISK
=$
(echo "$PART" |
grep -e "^[sh]d[a-z][0-9]*$" |
sed 's/^\(...\).*$/\1/')
49 if [ -z "$DISK" ]; then echo "Disk type not supported"; exit 1; fi
53 DEST_SIZE
=$
(cat /proc
/partitions |
grep -e "${PART}$" |
awk '{print $3}')
54 if [ -z "$DEST_SIZE" ]; then "Destination partition size is not right"; exit 1; fi
55 if [ ${DEST_SIZE} -le 0 ]; then "Destination partition size is not right"; exit 1; fi
57 # Check that it is Not Mounted
59 # Ask for Confirmation
60 echo "Destination: $PART ($DEST_SIZE bytes)"
63 mkfs.ext3
-L "AULA-LOCAL-WS" "/dev/$PART"
67 if [ ! -d "${DSTDIR}" ]; then exit 1; fi
69 mount
"/dev/$PART" "${DSTDIR}"
71 rm -rf "${DSTDIR}/lost+found"
74 SRC_SIZE
=$
(cat /proc
/partitions |
grep -e "etherd/${SRC_PART}$" |
awk '{print $3}')
75 if [ -z "$SRC_SIZE" ]; then exit 1; fi
76 if [ ${DEST_SIZE} -le 10000 ]; then echo "Destination partition is too small"; exit 1; fi
78 echo "Source: rsync://server/ws"
80 rsync
-avz "rsync://server/ws/*" "${DSTDIR}"
84 mount none
-t proc
"${DSTDIR}/proc/"
85 mount none
-t sysfs
"${DSTDIR}/sys"
86 mount
--bind /dev
"${DSTDIR}/dev/"
87 mount none
-t devpts
"${DSTDIR}/dev/pts/"
89 if [ ! -z "$DISK" ]; then
90 echo "Installing GRUB in disk: $DISK";
91 chroot
"${DSTDIR}" grub-install
--force "/dev/$DISK"
94 chroot
"${DSTDIR}" update-grub
97 umount
"${DSTDIR}/dev/pts/" || umount
-l "${DSTDIR}/dev/pts/"
98 umount
"${DSTDIR}/dev/" || umount
-l "${DSTDIR}/dev/"
99 umount
"${DSTDIR}/sys" || umount
-l "${DSTDIR}/sys"
100 umount
"${DSTDIR}/proc" || umount
-l "${DSTDIR}/proc"
101 umount
"${DSTDIR}" || umount
-l "${DSTDIR}"
104 printf 'Elapsed time: %s\n' $
(timer
$t)