-
Notifications
You must be signed in to change notification settings - Fork 2
/
sync-albums
executable file
·61 lines (52 loc) · 1.15 KB
/
sync-albums
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
#!/bin/sh
usage()
{
cat >&2 <<__EOF__
Usage: $(basename $0) [ -m mount-dir ] [ album-dir ]
Options:
-m mount-dir -- iPod mount point. Defaults to ${HOME}/mnt/ipod.
album-dir -- Name of the album directory. Defaults to
${HOME}/media/music/classical.
__EOF__
exit ${1-1}
}
log()
{
echo "$(basename $0): $1" >&2
}
while [ $# -gt 0 ]; do
case $1 in
-h|--help)
usage 0
;;
-m)
shift; mntdir=$1
;;
*)
albumsdir=$1
shift
[ $# -gt 0 ] && usage
;;
esac
shift
done
: ${mntdir=${HOME}/mnt/ipod}
: ${albumsdir=${HOME}/media/music/classical}
if [ ! -d "$mntdir" ]; then
log "$mntdir is not a directory"
exit 1
elif ! expr "$mntdir" : / >/dev/null 2>&1; then
mntdir=$(realpath "$mntdir")
fi
cd "$albumsdir"
IFS='
'
for audfile in $(find . -name '*.mp3' -o -name '*.ogg'); do
dir=$(dirname "$audfile")
file=$(basename "$audfile")
mkdir -p "$mntdir/$dir"
if [ ! -f "$mntdir/$audfile" ] || ! cmp -s "$mntdir/$audfile" "$audfile"; then
log "copying $audfile to iPod"
cp "$audfile" "$mntdir/$dir"
fi
done