-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdflash.sh
executable file
·365 lines (353 loc) · 9.9 KB
/
updflash.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#!/bin/bash
#
## @file updflash.sh
## @brief Update flash drive backup storage
## @remark Archive of my movies, pictures, documents, source, etc.
## @author Ronald Joe Record (rr at ronrecord dot com)
## @copyright Copyright (c) 2014, Ronald Joe Record, all rights reserved.
## @date Written 28-Mar-2014
## @version 1.0.1
##
## Note: This script is dependent on my "upd" and "chk" scripts
#
# 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.
#
# Modify the following default locations to suit your needs.
# This script invokes the upd script. You may also wish to customize
# the default locations in the upd script.
#
########### DEFAULT LOCATIONS ######################
[ "${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}
}
# The mount point for the flash drive
TRAN_DIR=${MNTROOT}/Transcend
# A directory that we know exists there
TEST_DIR="$TRAN_DIR"
# My iTunes library
ITUNES="${ITUROOT}"
# My Photos libraries
APLIBS="${PHOROOT}/Libraries"
APLIBS_DEST="$TRAN_DIR/Pictures/Libraries"
# Where I store my photos
PIC_DIR="$PICROOT"
# Picture directories to sync
PIC_SUB_DIRS="Art Dragonflies ScreenSavers Work"
# Where I store my audio
AUD_DIR="$AUDROOT"
# Audio directories to sync
AUD_SUB_DIRS="Audacity"
# Where I store my movies
MOV_DIR="$VIDROOT"
HOM_MOV_DIR="$HOME/Videos"
# Movies directories to sync
MOV_SUB_DIRS="Artists Work"
# Directories in my Home directory that I want to backup
HOME_DIRS="Box* Dropbox Horizon Documents Movies Music Pictures bin src"
########### END DEFAULT LOCATIONS ######################
## @fn usage()
## @brief Display command line usage options
## @param none
##
## Exit the program after displaying the usage message and example invocations
usage() {
printf "Usage: $0 [-n] [-a] [-c] [-e] [-i] [-APl] [-p] [-mM] [-hH] [-u]\n"
printf "Where:\n\t-n indicates to tell me what you would do\n"
printf "\t-u indicates display this usage message and exit\n"
printf "\t-a indicates rsync the Audio directory\n"
printf "\t-c indicates check if rsync is needed before sync'ing\n"
printf "\t-e indicates ignore rsync errors\n"
printf "\t-i indicates rsync the iTunes library\n"
printf "\t-A indicates rsync the Aperture libraries\n"
printf "\t-P indicates rsync the Apple Photos libraries\n"
printf "\t-L indicates follow symbolic links\n"
printf "\t-l indicates rsync both Aperture and Photos libraries\n"
printf "\t-p indicates rsync the Pictures directory\n"
printf "\t-m indicates rsync the Movies directory\n"
printf "\t-M indicates rsync the Home Movies directory\n"
printf "\t-h indicates rsync the Home directory\n"
printf "\t-H indicates rsync the entire Home directory\n\n"
printf "When invoked with no arguments all directories will be sync'd.\n\n"
exit 1
}
# Follow symbolic links
FLW=
# Do not ignore errors
IGN=
# Default to non-dry run
DRY=
# Exclude the specified file or directory
EXCLUDE=
# Default to no check
CHK=
# If no arguments or the only argument is -n then rsync all dirs
DO_ALL=
if [ $# -eq 0 ]
then
DO_ALL=1
else
if [ $# -eq 1 ]
then
if [ "$1" = "-n" ]
then
DO_ALL=1
fi
fi
fi
if [ "$DO_ALL" ]
then
DO_APERT=1
DO_PHOTO=1
DO_ITUNES=1
DO_PIC=1
DO_MOV=1
DO_HOM_MOV=1
DO_AUD=1
DO_ALL_HOME=1
DO_HOME=
else
DO_APERT=
DO_PHOTO=
DO_ITUNES=
DO_PIC=
DO_MOV=
DO_HOM_MOV=
DO_AUD=
DO_ALL_HOME=
DO_HOME=
fi
while getopts acE:eiAPlLpmMhHnu flag; do
case $flag in
a)
DO_AUD=1
;;
c)
CHK=1
;;
E)
EXCLUDE="-E $OPTARG"
;;
e)
IGN="-e"
;;
i)
DO_ITUNES=1
;;
A)
DO_APERT=1
;;
P)
DO_PHOTO=1
;;
L)
FLW="-l"
;;
l)
DO_APERT=1
DO_PHOTO=1
;;
p)
DO_PIC=1
;;
M)
DO_HOM_MOV=1
;;
m)
DO_MOV=1
;;
H)
DO_ALL_HOME=1
;;
h)
DO_HOME=1
;;
n)
DRY="-n"
;;
u)
usage
;;
esac
done
shift $(( OPTIND - 1 ))
IGN="$IGN $EXCLUDE"
# Check if the flash drive is mounted in its proper location
[ -d "$TEST_DIR" ] || {
# Sometimes we gotta wake it up
ls "$TEST_DIR" > /dev/null 2>&1
sleep 2
[ -d "$TEST_DIR" ] || {
echo "$TRAN_DIR does not seem to be mounted. Exiting."
exit 1
}
}
[ "$DO_APERT" ] && {
# Update the backup of my Aperture libraries
if [ -d "$APLIBS" ]
then
if [ "$CHK" ]
then
chk $IGN $DRY -r -a "$APLIBS" -s ".aplibrary" -t "$APLIBS_DEST"
else
# Equivalent of "upd -L ..."
upd $IGN $DRY $FLW -a "$APLIBS" -s ".aplibrary" -t "$APLIBS_DEST"
fi
else
echo "$APLIBS does not exist or is not a directory. Skipping."
fi
}
[ "$DO_PHOTO" ] && {
# Update the backup of my Apple Photos libraries
if [ -d "$APLIBS" ]
then
if [ "$CHK" ]
then
chk $IGN $DRY -r -a "$APLIBS" -s ".photoslibrary" -t "$APLIBS_DEST"
else
# Equivalent of "upd -L ..."
upd $IGN $DRY $FLW -a "$APLIBS" -s ".photoslibrary" -t "$APLIBS_DEST"
fi
else
echo "$APLIBS does not exist or is not a directory. Skipping."
fi
}
[ "$DO_ITUNES" ] && {
# Update the backup of my iTunes library
if [ -d "$ITUNES" ]
then
if [ "$CHK" ]
then
chk $IGN $DRY -r -a "$MEDROOT" -t "$TRAN_DIR" iTunes
else
# Equivalent of "upd -I ..."
upd $IGN $DRY $FLW -a "$MEDROOT" -t "$TRAN_DIR" iTunes
fi
else
echo "$ITUNES does not exist or is not a directory. Skipping."
fi
}
[ "$DO_PIC" ] && {
# Sync the photo dirs
for i in $PIC_SUB_DIRS
do
if [ -d "$PIC_DIR/$i" ]
then
if [ "$CHK" ]
then
chk $IGN $DRY -r -a "$PIC_DIR" -t "$TRAN_DIR/Pictures" "$i"
else
# Equivalent of "upd -P ..."
upd $IGN $DRY $FLW -a "$PIC_DIR" -t "$TRAN_DIR/Pictures" "$i"
fi
else
echo "$PIC_DIR/$i does not exist or is not a directory. Skipping."
fi
done
}
[ "$DO_AUD" ] && {
# Sync the audio directories
for i in $AUD_SUB_DIRS
do
if [ -d "$AUD_DIR/$i" ]
then
if [ "$CHK" ]
then
chk $IGN $DRY -r -a "$AUD_DIR" -t "$TRAN_DIR/Audio" "$i"
else
# Equivalent of "upd -A ..."
upd $IGN $DRY $FLW -a "$AUD_DIR" -t "$TRAN_DIR/Audio" "$i"
fi
else
echo "$AUD_DIR/$i does not exist or is not a directory. Skipping."
fi
done
}
[ "$DO_MOV" ] && {
# Sync the movies directories
for i in $MOV_SUB_DIRS
do
if [ -d "$MOV_DIR/$i" ]
then
if [ "$CHK" ]
then
chk $IGN $DRY -r -a "$MOV_DIR" -t "$TRAN_DIR/Movies" "$i"
else
# Equivalent of "upd -M ..."
upd $IGN $DRY $FLW -a "$MOV_DIR" -t "$TRAN_DIR/Movies" "$i"
fi
else
echo "$MOV_DIR/$i does not exist or is not a directory. Skipping."
fi
done
}
[ "$DO_HOM_MOV" ] && {
# Sync the home movies directories
if [ -d "$HOM_MOV_DIR" ]
then
if [ "$CHK" ]
then
chk $IGN $DRY -r -a "$HOM_MOV_DIR" -t "$TRAN_DIR/Movies" .
else
# Equivalent of "upd -M ..."
upd $IGN $DRY $FLW -a "$HOM_MOV_DIR" -t "$TRAN_DIR/Movies" .
fi
else
echo "$HOM_MOV_DIR does not exist or is not a directory. Skipping."
fi
}
[ "$DO_HOME" ] && {
# Sync some of the directories in my home directory
for dir in $HOME_DIRS
do
if [ -d "$HOME/$dir" ]
then
if [ "$CHK" ]
then
chk $IGN $DRY -r -a "$HOME" -t "$TRAN_DIR/Home" "$dir"
else
# Equivalent of "upd -H ..."
upd $IGN $DRY $FLW -a "$HOME" -t "$TRAN_DIR/Home" "$dir"
fi
else
echo "$HOME/$dir does not exist or is not a directory. Skipping."
fi
done
}
[ "$DO_ALL_HOME" ] && {
# Sync my entire home directory
if [ -d "$HOME" ]
then
if [ "$CHK" ]
then
chk $IGN $DRY -r -a "${HOME}/" -t "$TRAN_DIR/Home"
else
# Equivalent of "upd -H ..."
upd $IGN $DRY $FLW -a "$HOME" -t "$TRAN_DIR/Home"
fi
else
echo "$HOME does not exist or is not a directory. Skipping."
fi
}