forked from Jandalf81/rclone_script
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rclone_script-menu.sh
212 lines (172 loc) · 4.56 KB
/
rclone_script-menu.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
#!/bin/bash
NORMAL="\Zn"
BLACK="\Z0"
RED="\Z1"
GREEN="\Z2"
YELLOW="\Z3\Zb"
BLUE="\Z4"
MAGENTA="\Z5"
CYAN="\Z6"
WHITE="\Z7"
BOLD="\Zb"
REVERSE="\Zr"
UNDERLINE="\Zu"
# include settings file
config=~/scripts/rclone_script/rclone_script.ini
source ${config}
backtitle="RCLONE_SCRIPT menu (https://github.com/Jandalf81/rclone_script)"
####################
# HELPER FUNCTIONS #
####################
function log ()
{
severity=$1
message=$2
printf "$(date +%FT%T%:z):\t${severity}:\t${message}\n" >> ${logfile}
}
function getTypeOfRemote ()
{
# list all remotes and their type
remotes=$(rclone listremotes --long)
# get line wiht RETROPIE remote
retval=$(grep -i "^retropie:" <<< ${remotes})
remoteType="${retval#*:}"
remoteType=$(echo ${remoteType} | xargs)
}
function getStatusOfParameters ()
{
if [ "${syncOnStartStop}" == "TRUE" ]
then
statusSyncOnStartStop="${GREEN}ENABLED${NORMAL}"
else
statusSyncOnStartStop="${RED}DISABLED${NORMAL}"
fi
if [ "${showNotifications}" == "TRUE" ]
then
statusShowNotifications="${GREEN}ENABLED${NORMAL}"
else
statusShowNotifications="${RED}DISABLED${NORMAL}"
fi
case ${neededConnection} in
0) statusNeededConnection="Internet access" ;;
1) statusNeededConnection="LAN / WLAN" ;;
esac
}
function saveConfig ()
{
echo "remotebasedir=${remotebasedir}" > ${config}
echo "showNotifications=${showNotifications}" >> ${config}
echo "syncOnStartStop=${syncOnStartStop}" >> ${config}
echo "logfile=~/scripts/rclone_script/rclone_script.log" >> ${config}
echo "neededConnection=${neededConnection}" >> ${config}
echo "debug=0" >> ${config}
}
##################
# MENU FUNCTIONS #
##################
# Show the main menu. Return here anytime another dialog is closed
function main_menu ()
{
local choice="1"
while true
do
getStatusOfParameters
choice=$(dialog \
--stdout \
--colors \
--backtitle "${backtitle}" \
--title "main menu" \
--default-item "${choice}" \
--menu "\nWhat do you want to do?" 25 75 20 \
1 "Full synchronization of all savefiles and statefiles" \
2 "Toggle \"Synchronize saves on start / stop\" (currently ${statusSyncOnStartStop})" \
3 "Toggle \"Show notifications on sync\" (currently ${statusShowNotifications})" \
4 "Set needed Connection (currently \"${statusNeededConnection}\")" \
"" ""\
9 "uninstall RCLONE_SCRIPT"
)
case "$choice" in
1) doFullSync ;;
2) toggleSyncOnStartStop ;;
3) toggleShowNotifications ;;
4) setNeededConnection ;;
9) ~/scripts/rclone_script/rclone_script-uninstall.sh ;;
*) break ;;
esac
done
}
# Syncs all files in both directions, only transferring newer files
function doFullSync ()
{
local tmpfile=~/scripts/rclone_script/tmp-sync.txt
getTypeOfRemote
printf "\nStarted full sync...\n\n" > ${tmpfile}
log "INFO" "Started full sync..."
# start sync process in background
{
# Download newer files from remote to local
printf "Downloading newer files from retropie:${remotebasedir} (${remoteType}) to ~/RetroPie/saves/...\n"
rclone copy retropie:${remotebasedir}/ ~/RetroPie/saves/ --update --skip-links --exclude "readme.txt" --verbose 2>&1
# Upload newer files from local to remote
printf "Uploading newer files from ~/RetroPie/saves/ to retropie:${remotebasedir} (${remoteType})...\n"
rclone copy ~/RetroPie/saves/ retropie:${remotebasedir}/ --update --skip-links --exclude "readme.txt" --verbose 2>&1
printf "Done\n"
} >> ${tmpfile} & # capture output of background process
dialog \
--backtitle "${backtitle}" \
--title "Doing full sync..." \
--colors \
--no-collapse \
--cr-wrap \
--tailbox ${tmpfile} 40 120
wait
cat ${tmpfile} >> ${logfile}
rm ${tmpfile}
log "INFO" "Finished full sync..."
}
function toggleSyncOnStartStop ()
{
if [ "${syncOnStartStop}" == "TRUE" ]
then
syncOnStartStop="FALSE"
else
syncOnStartStop="TRUE"
fi
saveConfig
}
function toggleShowNotifications ()
{
if [ "${showNotifications}" == "TRUE" ]
then
showNotifications="FALSE"
else
showNotifications="TRUE"
fi
saveConfig
}
function setNeededConnection ()
{
choice=$(dialog \
--stdout \
--colors \
--no-collapse \
--cr-wrap \
--backtitle "${backtitle}" \
--title "Needed connection" \
--default-item "${neededConnection}" \
--ok-label "Select" \
--menu "\nPlease select which type of connection will be needed for your configured remote" 20 50 5 \
0 "Internet access" \
1 "LAN / WLAN connection only"
)
case ${choice} in
0) neededConnection=0 ;;
1) neededConnection=1 ;;
*) return ;;
esac
saveConfig
}
########
# MAIN #
########
main_menu