/
pisync
executable file
·161 lines (142 loc) · 3.02 KB
/
pisync
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
#!/bin/sh
#
# Script zum synchronisieren von Serien auf den Pi
#
# Einzelne Serien Staffeln
# sowie
# aktuelle Folgen von woechentlich ausgetrahlten Serien
#
# 0.1 Initial release - 2014/09/23
# 0.2 Added case - 2014/09/23
#
#
#
# Variablendeklaration
target="/mnt/rpiseries"
source="/media/d3c21c66-af4b-41d4-b098-462e83fa641d/Serien"
age="-14"
ageSeason="$4"
files="/tmp/rsyncfiles"
searchVar1="$2"
searchVar2="$3"
host="nuc"
sedIgnore=/etc/default/pisyncsedignore
# Check ob das Mountverzeichnis exisitert
if [ ! -d "$target" ]; then
mkdir "$target"
fi
# Funktion zum mounten des Verzeichnisses in das lokale Dateisystem via NFS
mountRPi () {
echo "Checking if Directory is already mounted..."
if [ `stat -fc%t:%T "$target"` != `stat -fc%t:%T "$target/.."` ]; then
echo "$target is already mounted!"
else
echo "$target is not mounted."
echo "Mounting Directory now..."
mount 192.168.178.66:/export/Serien/Serien "$target"
echo "Directory mounted successfully!"
fi
}
# Funktion zum unmounten des Verzeichnisses
umountRPi () {
echo "Unmounting Directory now..."
umount "$target"
echo "Directory unmounted successfully!"
}
# Funktion zum auflisten der Dateien nicht aelter als X Tage
collectFiles () {
echo "Changing directory..."
cd "$source"
echo "Directory changed. Searching for files that where modified within the last 14 days..."
find . -type f -mtime "$age" | sed -f "$sedIgnore" > "$files"
echo "Files collected."
}
# Funktion zum synchronisieren der woechentlichen Serien
syncFiles () {
echo "Syncing files now..."
rsync -Ravh --files-from="$files" . "$target"
echo "Files synced successfully!"
}
collectSeason () {
echo "Writing Season with correct path to $files"
#example: find . -name "Scrubs*""*S04*"
cd "$source"
find . -type f -name "$searchVar1""$searchVar2" -mtime "$ageSeason" > "$files"
cat "$files"
}
syncSeason () {
echo "Syncing Season now..."
rsync -Ravh --files-from="$files" . "$target"
echo "Seasons synced successfully!"
}
updateXBMCLib () {
echo "Updating XBMC Library..."
xbmc-send --action="UpdateLibrary(video)" --host="$host"
echo "Updated XBMC Library!"
}
updateXBMCLibClean () {
echo "Updated and cleaning XBMC Library..."
xbmc-send --action="UpdateLibrary(video)" --host="$host"
sleep 10
xbmc-send --action="CleanLibrary(video)" --host="$host"
echo "Updated and cleaned XBMC Library!"
}
readme () {
echo "Usage
pisync [option] [arguments]
options:
sync
no arguments
drysync
no arguments
season
\"title\" \"season\" \"modification time\"
\"Arrow\" \"*S01*\" \"-30\"
mount
no arguments
umount
no arguments
updateLib
no arguments
cleanLib
no arguments"
}
case $1 in
season)
mountRPi
collectSeason
syncSeason
umountRPi
updateXBMCLib
;;
sync)
mountRPi
collectFiles
syncFiles
umountRPi
updateXBMCLib
;;
drysync)
mountRPi
collectFiles
umountRPi
;;
mount)
mountRPi
;;
umount)
umountRPi
;;
updateLib)
updateXBMCLib
;;
cleanLib)
updateXBMCLibClean
;;
*)
echo "pisync called with unkown argument"
readme
exit 1
;;
esac
exit 0