-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathautotier-init-dirs
82 lines (72 loc) · 2.11 KB
/
autotier-init-dirs
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
#!/usr/bin/env bash
# Copyright (C) 2019-2021 Joshua Boudreau <jboudreau@45drives.com>
#
# This file is part of autotier.
#
# autotier is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# autotier is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with autotier. If not, see <https://www.gnu.org/licenses/>.
function usage {
echo "autotier-init-dirs Copyright (C) 2019-2021 Josh Boudreau <jboudreau@45drives.com>"
echo "This program is released under the GNU General Public License v3."
echo "See <https://www.gnu.org/licenses/> for more details."
echo
echo "Use this script to copy the directory structures across each tier before mounting."
echo "This is only needed for setting up autotier where data already exists in the tiers."
echo
echo "usage:"
echo " autotier-init-dirs /path/to/tier1 /path/to/tier2 [ /path/to/tier3 ... ]"
}
function join_by { local IFS="$1"; shift; echo "$*"; }
command -v rsync > /dev/null 2>&1 || { echo "rsync must be installed to run this script. Install it and try again."; exit 1; }
while getopts "h" opt; do
case $opt in
h)
usage
exit 0
;;
*)
echo "Unknown option."
echo
usage
exit 1
;;
esac
done
if [[ "$#" < "2" ]]; then
echo Must provide at least two tier paths.
usage
exit 1
fi
# check that each argument is a valid path
for tier in $@; do
if [ ! -d "$tier" ]; then
echo "$tier is not a directory!"
echo
usage
exit 1
fi
done
read -p "Clone directories across {$(join_by , $@)}? [y/N]" response
case $response in
y|yes|Y|YES)
;;
*)
exit 0
;;
esac
for src in $@; do
for dst in $@; do
[[ "$src" != "$dst" ]] && rsync -a --include='*/' --exclude='*' $src/* $dst
done
done
exit 0