Modified installation scripts
[aula.git] / workstation / usr / share / educastur / ws-scripts / install_rsync_local
blob031bc968f5296b7b5a9733739bfb800fa76b38fa
1 #!/bin/bash
3 set -e
4 set -x
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
14 function timer()
16 if [[ $# -eq 0 ]]; then
17 echo $(date '+%s')
18 else
19 local stime=$1
20 etime=$(date '+%s')
22 if [[ -z "$stime" ]]; then stime=$etime; fi
24 dt=$((etime - stime))
25 ds=$((dt % 60))
26 dm=$(((dt / 60) % 60))
27 dh=$((dt / 3600))
28 printf '%d:%02d:%02d' $dh $dm $ds
32 t=$(timer)
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
44 # Partition Exists
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
50 echo "Disk: $DISK";
52 # Get Size
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)"
62 # Format
63 mkfs.ext3 -L "AULA-LOCAL-WS" "/dev/$PART"
65 mkdir -p "${DSTDIR}"
67 if [ ! -d "${DSTDIR}" ]; then exit 1; fi
69 mount "/dev/$PART" "${DSTDIR}"
71 rm -rf "${DSTDIR}/lost+found"
73 # Check Size
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}"
82 sleep 1
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
96 # Umount destination
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}"
102 rmdir "${DSTDIR}"
104 printf 'Elapsed time: %s\n' $(timer $t)