-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPiAssist-SaveFileManager.sh
80 lines (64 loc) · 2.4 KB
/
PiAssist-SaveFileManager.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
#!/bin/bash
#saveFileExtensions=(srm bsv sav state stat fs nv rtc)
gameSavesFileName="GameSaves.tar.gz"
esConfigLocation="~/.emulationstation/es_systems.cfg"
display_result() {
whiptail --title "$1" \
--backtitle "PiAssist - Save File Manager" \
--clear \
--msgbox "$result" 0 0
}
#########
#Synchronize save files and save states with a dropbox account
#########
synchronizeSaveFilesWithDropBox() {
rm -f "$gameSavesFileName"
#Download dropbox_uploader.bsh and make it executable
wget https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh -q -O /home/pi/dropbox_uploader.bsh
chmod +x /home/pi/dropbox_uploader.bsh
#Download latest backup
/home/pi/dropbox_uploader.bsh download /"$gameSavesFileName"
#Extract everything from the backup but only overwrite the older files
if [[ -e "$gameSavesFileName" ]]; then
tar -zxvf "$gameSavesFileName" -C / --keep-newer-files #--strip-components=2 -C /home/pi/
rm "$gameSavesFileName"
fi
#Archive all save files and upload to dropbox
if [ ! -f "$esConfigLocation" ]
then
esConfigLocation="/etc/emulationstation/es_systems.cfg"
fi
romLocations=$(grep "<path>" /etc/emulationstation/es_systems.cfg | sed "s/<path>//g" | sed "s/<\/path>//g" | sed "s/~/\/home\/pi/g")
find $romLocations \( -iname '*.srm' -o -iname '*.bsv' -o -iname '*.sav' -o -iname '*.rtc' -o -iname '*.nv' -o -iname '*.fs' -o -iname '*.stat' -o -iname '*.state' \) -print0 | tar -czvf "$gameSavesFileName" --null -T -
/home/pi/dropbox_uploader.bsh upload "$gameSavesFileName" "$gameSavesFileName"
result="The save files and save states have been synchronized."
display_result "Synchornization Complete"
rm -f "dropbox_uploader.bsh"
rm -f "$gameSavesFileName"
}
#########
#Add synchronization to shutdown
#########
addSynchronizationToShutdown() {
#test
result=""
}
#########
#Add synchronization to startup
#########
addSynchronizationToStartup() {
#test
result=""
}
wget -q --tries=10 --timeout=20 --spider http://google.com
if [[ $? -eq 0 ]]; then
synchronizeSaveFilesWithDropBox
else
wget -q --tries=10 --timeout=20 --spider http://amazon.com
if [[ $? -eq 0 ]]; then
synchronizeSaveFilesWithDropBox
else
result="Google and Amazon are unreachable so we are assuming the internet as a whole is unreachable. Please connect to either a WiFi network or local area network."
display_result "Unable to Connect to the Internet"
fi
fi