-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupd.sh
executable file
·277 lines (268 loc) · 8.53 KB
/
upd.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/bin/bash
#
## @file upd.sh
## @brief Sync specified directories/libraries to a USB flash drive
## @author Ronald Joe Record (rr at ronrecord dot com)
## @copyright Copyright (c) 2014, Ronald Joe Record, all rights reserved.
## @date Written 10-Feb-2014
## @version 1.0.1
##
## Note: to sync other directories use the -s, -a, and -t arguments
## when invoked as updaplibs it syncs directories in my Aperture library
## when invoked as updphotoslibs it syncs directories in my Photos library
## when invoked as upditunes it syncs directories in my iTunes library
## when invoked as updpicdir it syncs directories in my Pictures dir
## when invoked as updmovdir it syncs directories in my Movies dir
## when invoked as updauddir it syncs directories in my Audio dir
## when invoked as updhome it syncs directories in $HOME
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# The Software is provided "as is", without warranty of any kind, express or
# implied, including but not limited to the warranties of merchantability,
# fitness for a particular purpose and noninfringement. In no event shall the
# authors or copyright holders be liable for any claim, damages or other
# liability, whether in an action of contract, tort or otherwise, arising from,
# out of or in connection with the Software or the use or other dealings in
# the Software.
#
[ "${MEDROOT}" ] || MEDROOT=/u
[ "${PICROOT}" ] || PICROOT=/u/pictures
[ "${VIDROOT}" ] || VIDROOT=/u/movies
[ "${AUDROOT}" ] || AUDROOT=/Audio
[ "${PHOROOT}" ] || PHOROOT=/Photos
[ "${ITUROOT}" ] || ITUROOT=/iTunes
[ "${MNTROOT}" ] || {
USER=`id -u -n`
MNTROOT=/media/${USER}
}
SOURCEDIR=
TRANSCEND=
SUFFIX=
NAME="upd"
MYHOME=
APERT_DIR=
ITUNES_DIR=
PICDIR=
AUDDIR=
MOVDIR=
HOMEDIR=
TELL=
DRY=
EXCLUDE=
FOLLOW=
IGN="--max-size=4G"
USAGE=
VERB="q"
## @fn usage()
## @brief Display command line usage options
## @param none
##
## Exit the program after displaying the usage message and example invocations
usage() {
printf "Usage: $NAME [-d] [-h] [-n] [-u] [-a source dir] [-t dest dir]\n"
printf " [-v] [-A] [-I] [-P] [-M] [-H] [-L] [-l] [-s suffix]\n"
printf " source-subdir [subdir2 subdir3 ...]\n"
printf "Where:\n\t-d indicates a dry run sync (no changes)\n"
printf "\t-h indicates use directories from your HOME dir\n"
printf "\t-l indicates follow symbolic links\n"
printf "\t-v indicates verbose rsync output\n"
printf "\t-A indicates use the Audio directory (like updauddir)\n"
printf "\t-L indicates use the Photos libraries (like updaplibs)\n"
printf "\t-I indicates use the iTunes library (like upditunes)\n"
printf "\t-P indicates use the Pictures directory (like updpicdir)\n"
printf "\t-M indicates use the Movies directory (like updmovdir)\n"
printf "\t-H indicates use the Home directory (like updhome)\n"
printf "\t-n indicates tell me what you would do without doing it\n"
printf "\t-u displays this usage message\n"
printf "\t-a source dir sets the top-level source directory\n"
printf "\t-t dest dir sets the top-level destination directory\n"
printf "\t-s suffix sets the subdirectory suffix to look for\n"
printf "\tsource-dir is the master directory hierarchy to sync from\n"
printf "\tdest-dir is the directory hierarchy to be sync'd\n"
printf "\nWhen invoked without arguments $NAME will attempt to sync\n"
printf "all the directories in $TRANSCEND with\n"
printf "corresponding directories in the current working directory.\n\n"
exit 1
}
while getopts a:E:s:t:dehAILPMHlnuv flag; do
case $flag in
d)
DRY="n"
;;
E)
EXCLUDE="--exclude $OPTARG"
;;
e)
IGN="$IGN --ignore-errors"
;;
h)
MYHOME=1
;;
l)
FOLLOW="--copy-links"
;;
H)
HOMEDIR=1
;;
n)
TELL=1
;;
A)
AUDDIR=1
;;
I)
ITUNES_DIR=1
;;
L)
APERT_DIR=1
;;
P)
PICDIR=1
;;
M)
MOVDIR=1
;;
a)
SOURCEDIR="$OPTARG"
;;
s)
SUFFIX="$OPTARG"
;;
t)
TRANSCEND="$OPTARG"
;;
u)
USAGE=1
;;
v)
VERB=v
;;
esac
done
shift $(( OPTIND - 1 ))
EXCLUDE="--delete-excluded --exclude .DS_Store $EXCLUDE"
FOLLOW="$FOLLOW $EXCLUDE"
NAME=`basename $0`
[ "$APERT_DIR" ] || [ "$NAME" = "updphotoslibs" ] && {
[ "$SOURCEDIR" ] || SOURCEDIR="${PHOROOT}/Libraries"
[ "$TRANSCEND" ] || TRANSCEND="${MNTROOT}/Transcend/Pictures/Libraries"
SUFFIX=".photoslibrary"
}
[ "$NAME" = "updaplibs" ] && {
[ "$SOURCEDIR" ] || SOURCEDIR="${PHOROOT}/Libraries"
[ "$TRANSCEND" ] || TRANSCEND="${MNTROOT}/Transcend/Pictures/Libraries"
SUFFIX=".aplibrary"
}
[ "$ITUNES_DIR" ] || [ "$NAME" = "upditunes" ] && {
[ "$SOURCEDIR" ] || SOURCEDIR="${ITUROOT}"
[ "$TRANSCEND" ] || TRANSCEND="${MNTROOT}/Transcend/iTunes"
}
[ "$PICDIR" ] || [ "$NAME" = "updpicdir" ] && {
if [ "$MYHOME" ]
then
[ "$SOURCEDIR" ] || SOURCEDIR="$HOME/Pictures"
else
[ "$SOURCEDIR" ] || SOURCEDIR="${PICROOT}"
fi
[ "$TRANSCEND" ] || TRANSCEND="${MNTROOT}/Transcend/Pictures"
}
[ "$AUDDIR" ] || [ "$NAME" = "updauddir" ] && {
if [ "$MYHOME" ]
then
[ "$SOURCEDIR" ] || SOURCEDIR="$HOME/Audio"
else
[ "$SOURCEDIR" ] || SOURCEDIR="${AUDROOT}"
fi
[ "$TRANSCEND" ] || TRANSCEND="${MNTROOT}/Transcend/Audio"
}
[ "$MOVDIR" ] || [ "$NAME" = "updmovdir" ] && {
if [ "$MYHOME" ]
then
[ "$SOURCEDIR" ] || SOURCEDIR="$HOME/Movies"
else
[ "$SOURCEDIR" ] || SOURCEDIR="${VIDROOT}"
fi
[ "$TRANSCEND" ] || TRANSCEND="${MNTROOT}/Transcend/Movies"
}
[ "$HOMEDIR" ] || [ "$NAME" = "updhome" ] && {
[ "$SOURCEDIR" ] || SOURCEDIR="$HOME"
[ "$TRANSCEND" ] || TRANSCEND="${MNTROOT}/Transcend/Home"
}
# Where to sync from - defaults to current working directory
[ "$SOURCEDIR" ] || SOURCEDIR=`pwd`
# Where to sync to
[ "$TRANSCEND" ] || TRANSCEND="${MNTROOT}/Transcend/`basename $SOURCEDIR`"
[ "$USAGE" ] && usage
[ "$SOURCEDIR" = "/" ] && {
echo "Use of / as source directory is not supported. Exiting."
exit 1
}
[ -d "$SOURCEDIR" ] || {
echo "$SOURCEDIR does not exist or is not a directory. Exiting."
exit 1
}
cd "$SOURCEDIR"
if [ $# -eq 0 ]
then
for lib in *$SUFFIX
do
[ "$lib" = "*" ] && lib=
[ -e "$SOURCEDIR/$lib" ] || {
echo "$SOURCEDIR/$lib does not exist. Skipping."
continue
}
echo -n "Syncing $SOURCEDIR/$lib to $TRANSCEND/$lib with rsync ... "
DEL="--delete"
[ -f "$TRANSCEND/$lib/.do_not_delete" ] && DEL=""
if [ "$TELL" ]
then
echo ""
echo "rsync -${VERB}a$DRY $FOLLOW $IGN $DEL $SOURCEDIR/$lib $TRANSCEND"
else
if [ "$DRY" ]
then
rsync -van $FOLLOW $IGN $DEL "$SOURCEDIR/$lib" "$TRANSCEND"
else
rsync -Wa$VERB $FOLLOW $IGN $DEL "$SOURCEDIR/$lib" "$TRANSCEND"
touch "$TRANSCEND/.rsync_$lib"
fi
fi
echo "done."
done
else
for libnam in "$@"
do
lib="$libnam$SUFFIX"
[ "$lib" = "*" ] && lib=
[ -d "$SOURCEDIR/$lib" ] || {
echo "$SOURCEDIR/$lib does not exist or is not a directory. Skipping."
continue
}
echo -n "Syncing $SOURCEDIR/$lib to $TRANSCEND/$lib with rsync ... "
DEL="--delete"
[ -f "$TRANSCEND/$lib/.do_not_delete" ] && DEL=""
if [ "$TELL" ]
then
echo ""
echo "rsync -${VERB}a$DRY $FOLLOW $IGN $DEL $SOURCEDIR/$lib $TRANSCEND"
else
if [ "$DRY" ]
then
rsync -van $FOLLOW $IGN $DEL "$SOURCEDIR/$lib" "$TRANSCEND"
else
rsync -W${VERB}a $FOLLOW $IGN $DEL "$SOURCEDIR/$lib" "$TRANSCEND"
touch "$TRANSCEND/.rsync_$lib"
fi
fi
echo "done."
done
fi