[1] | 1 | #!/bin/sh
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 | MOUNTPT=/tmp/mojo-jojo-iso
|
---|
| 5 |
|
---|
| 6 | Die() {
|
---|
| 7 | echo "$1" >> /dev/stderr
|
---|
| 8 | exit 1
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | mount_iso_for_me() {
|
---|
| 13 | [ -e "$1/$2.iso" ] || Die "ISO #$2 not found at $1. Terminating."
|
---|
| 14 | mount $1/$2.iso -o loop,ro $MOUNTPT || Die "Cannot mount ISO $isoloc/$isono"
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | trap_me_here() {
|
---|
| 20 | i=1
|
---|
| 21 | while [ "$i" -le "50" ] ; do
|
---|
| 22 | umount $isoloc/$i.iso 2> /dev/null
|
---|
| 23 | i=$(($i+1))
|
---|
| 24 | done
|
---|
| 25 | echo "Terminating in reponse to a signal caught by the OS"
|
---|
| 26 | exit 1
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | process_this_cd() {
|
---|
| 32 | local restorepath res
|
---|
| 33 | isono=$1
|
---|
| 34 | restorepath=$2
|
---|
| 35 |
|
---|
| 36 | find $MOUNTPT/archives | grep "slice-" > /dev/null || Die "No bigfiles at $MOUNTPT"
|
---|
| 37 | mkdir -p $restorepath
|
---|
| 38 | cd $restorepath
|
---|
| 39 | for slicename in `find $MOUNTPT/archives | grep "slice-" | sort` ; do
|
---|
| 40 | echo -en "."
|
---|
| 41 | if echo "$slicename" | grep "slice-[0-9]*.00000\.dat" 2> /dev/null; then
|
---|
[273] | 42 | CHECKSUM=`head -n1 $slicename | cut -f1`
|
---|
| 43 | OUTFNAME=`head -n1 $slicename | cut -f2`
|
---|
[1] | 44 | OUTFNAME=`echo "$restorepath/$OUTFNAME" | tr -s '/' '/'`
|
---|
| 45 | echo "Now restoring $OUTFNAME"
|
---|
| 46 | [ "$OUTFNAME" ] || Die "No filename?! WTF?"
|
---|
| 47 | rm -f "$OUTFNAME" 2> /dev/null
|
---|
| 48 | mkdir -p "$OUTFNAME" 2> /dev/null
|
---|
| 49 | rmdir "$OUTFNAME" 2> /dev/null
|
---|
| 50 | > "$OUTFNAME" || Die "Cannot write to $OUTFNAME"
|
---|
| 51 | elif [ ! -s "$slicename" ] ; then
|
---|
| 52 | echo "Finished restoring $OUTFNAME"
|
---|
| 53 | res=`md5sum "$OUTFNAME" | cut -d' ' -f1`
|
---|
| 54 | # echo "Orig=$CHECKSUM. Disk=$res"
|
---|
| 55 | if [ "$CHECKSUM" != "$res" ] ; then
|
---|
| 56 | echo "Warning - checksums do not match"
|
---|
| 57 | fi
|
---|
| 58 | CHECKSUM=""
|
---|
| 59 | OUTFNAME=""
|
---|
| 60 | else
|
---|
| 61 | [ "$OUTFNAME" = "" ] && Die "No filename to write to! Are you sure you inserted the _first_ ISO to begin with?"
|
---|
| 62 | if echo "$slicename" | grep "bz2" > /dev/null ; then
|
---|
| 63 | bzip2 -dc $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
|
---|
[998] | 64 | elif echo "$slicename" | grep "gz" > /dev/null ; then
|
---|
| 65 | gzip -dc $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
|
---|
[1] | 66 | elif echo "$slicename" | grep "lzo" > /dev/null ; then
|
---|
| 67 | lzop -dc $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
|
---|
| 68 | else
|
---|
| 69 | cat $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
|
---|
| 70 | fi
|
---|
| 71 | fi
|
---|
| 72 | done
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | # ------------------- main -------------------
|
---|
| 79 |
|
---|
| 80 | trap trap_me_here SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
|
---|
| 81 | [ "$#" -eq "1" ] || Die "restore-bigfiles-from-iso <location of ISOs> --- e.g. /storage/ISOs"
|
---|
| 82 | isoloc=$1
|
---|
| 83 | mkdir -p $MOUNTPT
|
---|
| 84 | isono=1
|
---|
| 85 | OUTFNAME=""
|
---|
| 86 | CHECKSUM=""
|
---|
| 87 |
|
---|
| 88 | def="/RESTORED"
|
---|
| 89 | echo -en "Restore path (default is '$def') --> "
|
---|
| 90 | read restorepath
|
---|
| 91 | [ "$restorepath" ] || restorepath=$def
|
---|
| 92 | while [ ! -e "$isoloc/$isono.iso" ] ; do
|
---|
| 93 | echo "Skipping CD #$isono (does not exist)"
|
---|
| 94 | isono=$(($isono+1))
|
---|
| 95 | [ "$isono" -gt "50" ] && Die "Ran out of ISOs to try"
|
---|
| 96 | done
|
---|
| 97 | while [ -e "$isoloc/$isono.iso" ] ; do
|
---|
| 98 | echo "Processing CD #$isono"
|
---|
| 99 | mount_iso_for_me $isoloc $isono
|
---|
| 100 | process_this_cd $isono $restorepath
|
---|
| 101 | umount $isoloc/$isono.iso || Die "Unable to unmount ISO $isono"
|
---|
| 102 | isono=$(($isono+1))
|
---|
| 103 | done
|
---|
| 104 | echo "OK, done."
|
---|
| 105 | exit 0
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 |
|
---|