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 "Slice = $slicename \r"
|
---|
41 | echo -en "."
|
---|
42 | if echo "$slicename" | grep "slice-[0-9]*.00000\.dat" 2> /dev/null; then
|
---|
43 | CHECKSUM=`head -n1 $slicename | cut -f1`
|
---|
44 | OUTFNAME=`head -n1 $slicename | cut -f2`
|
---|
45 | OUTFNAME=`echo "$restorepath/$OUTFNAME" | tr -s '/' '/'`
|
---|
46 | echo "Now restoring $OUTFNAME"
|
---|
47 | [ "$OUTFNAME" ] || Die "No filename?! WTF?"
|
---|
48 | rm -f "$OUTFNAME" 2> /dev/null
|
---|
49 | mkdir -p "$OUTFNAME" 2> /dev/null
|
---|
50 | rmdir "$OUTFNAME" 2> /dev/null
|
---|
51 | > "$OUTFNAME" || Die "Cannot write to $OUTFNAME"
|
---|
52 | elif [ ! -s "$slicename" ] ; then
|
---|
53 | echo "Finished restoring $OUTFNAME"
|
---|
54 | res=`md5sum "$OUTFNAME" | cut -d' ' -f1`
|
---|
55 | # echo "Orig=$CHECKSUM. Disk=$res"
|
---|
56 | if [ "$CHECKSUM" != "$res" ] ; then
|
---|
57 | echo "Warning - checksums do not match"
|
---|
58 | fi
|
---|
59 | CHECKSUM=""
|
---|
60 | OUTFNAME=""
|
---|
61 | else
|
---|
62 | [ "$OUTFNAME" = "" ] && Die "No filename to write to! Are you sure you inserted the _first_ ISO to begin with?"
|
---|
63 | if echo "$slicename" | grep "bz2" > /dev/null ; then
|
---|
64 | bzip2 -dc $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
|
---|
65 | elif echo "$slicename" | grep "lzo" > /dev/null ; then
|
---|
66 | lzop -dc $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
|
---|
67 | else
|
---|
68 | cat $slicename >> "$OUTFNAME" || Die "Failed to decompress slice $slicename"
|
---|
69 | fi
|
---|
70 | fi
|
---|
71 | done
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 |
|
---|
76 |
|
---|
77 | # ------------------- main -------------------
|
---|
78 |
|
---|
79 | trap trap_me_here SIGTERM SIGHUP SIGQUIT SIGKILL SIGABRT SIGINT
|
---|
80 | [ "$#" -eq "1" ] || Die "restore-bigfiles-from-iso <location of ISOs> --- e.g. /storage/ISOs"
|
---|
81 | isoloc=$1
|
---|
82 | mkdir -p $MOUNTPT
|
---|
83 | isono=1
|
---|
84 | OUTFNAME=""
|
---|
85 | CHECKSUM=""
|
---|
86 |
|
---|
87 | def="/RESTORED"
|
---|
88 | echo -en "Restore path (default is '$def') --> "
|
---|
89 | read restorepath
|
---|
90 | [ "$restorepath" ] || restorepath=$def
|
---|
91 | while [ ! -e "$isoloc/$isono.iso" ] ; do
|
---|
92 | echo "Skipping CD #$isono (does not exist)"
|
---|
93 | isono=$(($isono+1))
|
---|
94 | [ "$isono" -gt "50" ] && Die "Ran out of ISOs to try"
|
---|
95 | done
|
---|
96 | while [ -e "$isoloc/$isono.iso" ] ; do
|
---|
97 | echo "Processing CD #$isono"
|
---|
98 | mount_iso_for_me $isoloc $isono
|
---|
99 | process_this_cd $isono $restorepath
|
---|
100 | umount $isoloc/$isono.iso || Die "Unable to unmount ISO $isono"
|
---|
101 | isono=$(($isono+1))
|
---|
102 | done
|
---|
103 | echo "OK, done."
|
---|
104 | exit 0
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 |
|
---|