-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecreate.sh
executable file
·72 lines (65 loc) · 1.83 KB
/
recreate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
#Validate number of arguments
if [ $# -le 2 -o $# -gt 3 ]; then
echo "Usage : <dup file> <where to place files> <blob folder>"
exit
fi
#Assign arguments to variables for clarity
dupFile="$1"
outputFolder="$2"
blobFolder="$3"
#Confirm dupFile is present
if [ ! -f "$dupFile" ]; then
echo "$dupFile" does not exist
fi
#Check if outputFolder already exists, if it does then ask for overwrite
#permission. If it doesnt exist, create it.
if [ -d "$outputFolder" ]; then
read -p "\"$outputFolder\" already exists, want to overwrite (y/n) ? : " ans
if [ "$ans" != "y" ]; then
exit
fi
else
mkdir $outputFolder
fi
#Confirm blobFolder is present
if [ ! -d "$blobFolder" ]; then
echo "$blobFolder" does not exist
exit
fi
#Progress bar calculations
lines=$(cat $dupFile | wc -l)
chunk=$((lines/100))
inc=0
last=-1
#Loop through dupFile and parse its contents.
#Copy and rename the blobs and create the tree accordingly.
echo -n 'Progress : ['
while read line; do
if [ "$line" != "dedupe 2" ]; then
inc=$(($inc+1))
prog=$(($inc / $chunk))
type=$(echo $line | cut -d " " -f1)
item=$(echo $line | cut -d " " -f8)
hashFolder=$(echo $line | cut -d " " -f9 | cut -d "/" -f1)
hashFile=$(echo $line | cut -d " " -f9 | cut -d "/" -f2)
if [ "$type" = "f" -a ! -z "$hashFolder" -a ! -z "$hashFile" ]; then
if [ -f "$blobFolder/$hashFolder/$hashFile" ]; then
cp "$blobFolder/$hashFolder/$hashFile" "$outputFolder/$item"
else
echo "No blob for " $item " found"
fi
else
mkdir -p $outputFolder/$item
fi
if [ $last -ne $prog ]; then
if [ $(($prog % 10)) -eq 0 ]; then
echo -n $prog%
elif [ $(($prog % 4)) -eq 0 ]; then
echo -n '.'
fi
last=$prog
fi
fi
done < "$dupFile"
echo '] : Done'