-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaketestdata.sh
84 lines (66 loc) · 1.79 KB
/
maketestdata.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
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
HOME=/Users/gary
BASE=test
BASE=test
DIRDEPTH=5
NUMFILES=64
FILESIZE=$((1024))
###############################################################################
function random_data {
num_bytes=$(($1 / 2))
cat /dev/urandom \
| od -N "$num_bytes" -t x1 \
| sed 's/^[0-9a-f]*//g;' \
| tr -d ' \n'
}
###############################################################################
function md5_file {
md5 -r $1 | awk '{print $1}'
}
###############################################################################
function random_path {
depth=$(($RANDOM % $1 + 1))
path=""
for i in `eval echo {1..$depth}`; do
digit=$(($RANDOM % 10))
if [ -z "$path" ]; then
path="$digit"
else
path="$path/$digit"
fi
done
echo $path
}
###############################################################################
function make_data {
tmp="$BASE/tmp"
for i in `eval echo {1..$NUMFILES}`; do
path=`random_path $DIRDEPTH`
while [ -f "$path" ]; do
path=`random_path $DIRDEPTH`
done
random_data $FILESIZE > "$tmp"
name=`md5_file $tmp`
mkdir -p "$BASE/$path"
mv "$tmp" "$BASE/$path/$name"
done
}
###############################################################################
function main {
cd $HOME
rm -rf "$BASE"
mkdir "$BASE"
ssh diskstation rm -rf "$BASE"
ssh maxi rm -rf "$BASE"
make_data
rsync -a --delete "$BASE" diskstation:.
sh sync/sync.sh init
rsync -aH "$BASE" maxi:.
ssh diskstation ln -s "../versions/0" "$BASE/.sync/clients/Maxi"
}
###############################################################################
#main
cd $HOME
rm -rf "$BASE"
mkdir "$BASE"
make_data