This repository has been archived by the owner on Mar 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsettings.run
executable file
·385 lines (354 loc) · 20 KB
/
settings.run
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#!/bin/bash
source config.ini
if [ -z "$SQL_password" ]
then
query(){
mysql -NB -h$DB_IP -P$DB_PORT -u$SQL_user "S1" -e "$2;"
}
else
query(){
mysql -NB -h$DB_IP -P$DB_PORT -u$SQL_user -p$SQL_password "$1" -e "$2;"
}
fi
# Logging
mkdir -p $PATH_TO_STATS/logs
touch $PATH_TO_STATS/logs/log_$(date '+%Y%m').log
echo "[`date '+%Y%m%d %H:%M:%S'`] Setting.run executed" >> $PATH_TO_STATS/logs/log_$(date '+%Y%m').log
# Check mariadb version
echo ""
DBversion=$(query "$MAD_DB" "SELECT left(version(),4)")
if ((${DBversion/./} > 101)) ;
then
echo "MariaDB version check passed"
echo ""
else
echo "Mariadb version should be 10.2 or higher !!!"
echo ""
exit
fi
# grrrrrrrrrrr had to implement db version long time ago
# check first install, does stats_worker even exist
first_install=$(query "$MAD_DB" "SELECT count(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '$STATS_DB' AND TABLE_NAME = 'stats_worker';")
# Check collation on stats_worker
V1_check1=$(query "$STATS_DB" "SELECT count(*) FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = '$STATS_DB' and table_name = 'stats_worker' and table_collation = 'utf8mb4_unicode_ci';")
# Check if column Area exists in stats_worker
V1_check2=$(query "$STATS_DB" "SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS where table_schema = '$STATS_DB' and table_name = 'stats_worker' and column_name = 'Area';")
if [ $first_install != "1" ]
then
echo "First install of Stats, proceeding"
statsDBversion=1
echo ""
else
# Check current stats db version
echo ""
statsDBversion=$(query "$STATS_DB" "select version from version where version.key = 'stats';")
echo "Not first install, checking old V1 table updates"
if [[ $V1_check1 != "1" || $V1_check2 != "1" ]]
then
echo "FFS you should have updated long time ago, running old table updates"
echo "This might take a while"
echo ""
cp $PATH_TO_STATS/default_files/table_changes_V1.sql.default $PATH_TO_STATS/table_changes_V1.sql
sed -i "s/pogodb/$STATS_DB/g" $PATH_TO_STATS/table_changes_V1.sql
if [ -z "$SQL_password" ]
then
mysql -h$DB_IP -P$DB_PORT -u$SQL_user $STATS_DB < $PATH_TO_STATS/table_changes_V1.sql
rm -f $PATH_TO_STATS/table_changes_V1.sql
else
mysql -h$DB_IP -P$DB_PORT -u$SQL_user -p$SQL_password $STATS_DB < $PATH_TO_STATS/table_changes_V1.sql
rm -f $PATH_TO_STATS/table_changes_V1.sql
fi
else
echo "All good, proceeding"
echo ""
fi
fi
#Check MAD collation, else 15_worker will fail
table_check=$(query "$MAD_DB" "SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_COLLATION FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '$MAD_DB' and ((TABLE_NAME = 'trs_stats_detect' or TABLE_NAME = 'trs_stats_location' or TABLE_NAME = 'trs_stats_location_raw'or TABLE_NAME = 'trs_status' or TABLE_NAME = 'trs_stats_detect_mon_raw') and TABLE_COLLATION <>'utf8mb4_unicode_ci');")
column_check=$(query "$MAD_DB" "SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$MAD_DB' and ((TABLE_NAME = 'trs_stats_detect' or TABLE_NAME = 'trs_stats_location' or TABLE_NAME = 'trs_stats_location_raw'or TABLE_NAME = 'trs_status' or TABLE_NAME = 'trs_stats_detect_mon_raw') and COLLATION_NAME <> 'utf8mb4_unicode_ci');")
if [[ -z $table_check || -z $column_check ]];
then
echo 'MAD collation check passed'
echo ""
else
echo "ERROR: (some) MAD table/column collation set incorrect !!!"
echo "Check https://github.com/Map-A-Droid/MAD/tree/master/scripts/SQL and adapt accordingly"
query "$MAD_DB" "SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_COLLATION FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '$MAD_DB' and ((TABLE_NAME = 'trs_stats_detect' or TABLE_NAME = 'trs_stats_location' or TABLE_NAME = 'trs_stats_location_raw'or TABLE_NAME = 'trs_status' or TABLE_NAME = 'trs_stats_detect_mon_raw') and TABLE_COLLATION <>'utf8mb4_unicode_ci');"
query "$MAD_DB" "SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$MAD_DB' and ((TABLE_NAME = 'trs_stats_detect' or TABLE_NAME = 'trs_stats_location' or TABLE_NAME = 'trs_stats_location_raw'or TABLE_NAME = 'trs_status' or TABLE_NAME = 'trs_stats_detect_mon_raw') and COLLATION_NAME <> 'utf8mb4_unicode_ci');"
echo ""
echo ""
echo "SQL commands below will most likely fix this, but verify before running and execute settings.run afterwards to verify"
echo "ALTER TABLE $MAD_DB.trs_stats_detect CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
echo "ALTER TABLE $MAD_DB.trs_stats_location CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
echo "ALTER TABLE $MAD_DB.trs_stats_location_raw CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
exit
fi
echo "Create sql table, trigger and procedure files"
echo ""
cp $PATH_TO_STATS/default_files/tables.sql.default $PATH_TO_STATS/tables.sql
cp $PATH_TO_STATS/default_files/triggers.sql.default $PATH_TO_STATS/triggers.sql
cp $PATH_TO_STATS/default_files/procedures.sql.default $PATH_TO_STATS/procedures.sql
cd $PATH_TO_STATS && sed -i "s/pogodb/$STATS_DB/g" *.sql
cd $PATH_TO_STATS && sed -i "s/rmdb/$MAD_DB/g" *.sql
echo "Create tables"
echo ""
if [ -z "$SQL_password" ]
then
mysql -h$DB_IP -P$DB_PORT -u$SQL_user $STATS_DB < $PATH_TO_STATS/tables.sql
else
mysql -h$DB_IP -P$DB_PORT -u$SQL_user -p$SQL_password $STATS_DB < $PATH_TO_STATS/tables.sql
fi
# no more triggers, remove if exist
if [ -z "$SQL_password" ]
then
mysql -h$DB_IP -P$DB_PORT -u$SQL_user $MAD_DB < $PATH_TO_STATS/triggers.sql
else
mysql -h$DB_IP -P$DB_PORT -u$SQL_user -p$SQL_password $MAD_DB < $PATH_TO_STATS/triggers.sql
fi
echo "Create procedure"
echo ""
if [ -z "$SQL_password" ]
then
mysql -h$DB_IP -P$DB_PORT -u$SQL_user $MAD_DB < $PATH_TO_STATS/procedures.sql
else
mysql -h$DB_IP -P$DB_PORT -u$SQL_user -p$SQL_password $MAD_DB < $PATH_TO_STATS/procedures.sql
fi
echo "Create crontab"
echo ""
cd $PATH_TO_STATS && rm -f *.default
cd $PATH_TO_STATS && rm -f -R sql_cron/
cp $PATH_TO_STATS/default_files/crontab.txt.default $PATH_TO_STATS/crontab.txt
cd $PATH_TO_STATS/cron_files && rm -f *.default
# MAD fence update
echo "Enabling MAD fence updates to Stats"
echo ""
if [[ "$MAD_FENCE_UPDATE_INTERVAL" == "day" ]]
then
sed -i "$ a \#\# Update MAD fences and devices" $PATH_TO_STATS/crontab.txt
sed -i "$ a 55 0 * * * cd pathToStatscron_files && ./MAD_fence_update.sh 2>>pathToStatslogs/log_\$(date '+\\\%Y\\\%m').log" $PATH_TO_STATS/crontab.txt
else
sed -i "$ a \#\# Update MAD fences and devices" $PATH_TO_STATS/crontab.txt
sed -i "$ a 55 * * * * cd pathToStatscron_files && ./MAD_fence_update.sh 2>>pathToStatslogs/log_\$(date '+\\\%Y\\\%m').log" $PATH_TO_STATS/crontab.txt
fi
# Recalc quest routes
if "$recalc_quest_routes"
then
rm -f $PATH_TO_STATS/quest_recalc.sh
echo "Set recalculation of quest routes"
echo ""
sed -i "$ a \#\# Recalculate quest routes" $PATH_TO_STATS/crontab.txt
sed -i "$ a 20 0 * * 1 cd pathToStatscron_files && ./quest_recalc.sh 2>>pathToStatslogs/log_\$(date '+\\\%Y\\\%m').log" $PATH_TO_STATS/crontab.txt
fi
if "$QUEST_SPAWN_CLEANUP"
then
echo "Enabling cleanup spawnponits discovered during questing hours in cron"
echo ""
sed -i "$ a \#\# Cleanup spawnpoints discovered during quest scan hours" $PATH_TO_STATS/crontab.txt
sed -i "$ a $QUEST_SPAWN_CLEAN_MIN $QUEST_SPAWN_CLEAN_HR * * * cd pathToStatscron_files/ && mysql userpass < quest_spawn_cleanup.sql 2>>pathToStatslogs/log_\$(date '+\\\%Y\\\%m').log" $PATH_TO_STATS/crontab.txt
fi
if "$SPAWN_ALL_CLEANUP"
then
echo "Enabling clean of all spawnpoints unseen or no endtime leaned for X days"
echo ""
sed -i "$ a \#\# Cleanup spawnpoints not seen or no entime learned for X days" $PATH_TO_STATS/crontab.txt
sed -i "$ a 20 23 * * * cd pathToStatscron_files/ && mysql userpass < all_spawn_cleanup.sql 2>>pathToStatslogs/log_\$(date '+\\\%Y\\\%m').log" $PATH_TO_STATS/crontab.txt
fi
if "$SPAWN_UNFENCED_CLEANUP"
then
echo "Enabling unfenced spawnpoint cleanup in cron"
echo ""
sed -i "$ a \#\# Cleaup unfenced spawnpoints" $PATH_TO_STATS/crontab.txt
sed -i "$ a 50 23 * * * cd pathToStatscron_files/ && ./unfenced_spawn_cleanup.sh 2>>pathToStatslogs/log_\$(date '+\\\%Y\\\%m').log" $PATH_TO_STATS/crontab.txt
fi
# get ATV details
if "$atvdetails"
then
echo "Set processing of ATVdetails"
echo ""
sed -i "$ a \#\# ATV details" $PATH_TO_STATS/crontab.txt
sed -i "$ a 20 */$atvdetails_hours * * * cd pathToStatscron_files && ./atvdetails.sh 2>>pathToStatslogs/log_\$(date '+\\\%Y\\\%m').log" $PATH_TO_STATS/crontab.txt
fi
# add device outage reporting
if "$outage_report"
then
echo "Adding device outage reporting"
echo ""
sed -i "$ a \#\# Device outage report" $PATH_TO_STATS/crontab.txt
sed -i "$ a */$outage_interval * * * * cd pathToStatsdefault_files && ./discord.sh --username \"Device status\" --color \"16711680\" --avatar \"https://www.iconsdb.com/icons/preview/red/exclamation-xxl.png\" --webhook-url \"outage_webhook\" --description \"$\(mysql userpass MAD_DB -N -e \"select rpad\(concat\('**',c.name,'** >'),18,'>'), concat\('**',if\(a.lastProtoDateTime='','Unknown',time_format\(a.lastProtoDateTime,'\\\%H:\\\%i')),'** <<< '), concat\('IP: ','**',e.ip,'**') from MAD_DB.trs_status a left join MAD_DB.settings_device c on a.device_id = c.device_id left join STATS_DB.ATVgeneral e on c.name = e.origin where \(a.lastProtoDateTime < now\() - interval device_outage minute or a.lastProtoDateTime = '') and date\(e.datetime) = curdate\() order by c.name;\" | jq -Rs . | cut -c 2- | rev | cut -c 2- | rev)\" 2>>pathToStatslogs/log_\$\(date '+\\\%Y\\\%m').log" $PATH_TO_STATS/crontab.txt
fi
PATH_TO_STATS2=$(sed 's@/@\\/@g' <<< $PATH_TO_STATS)
cd $PATH_TO_STATS && sed -i "s/pathToStats/$PATH_TO_STATS2/g" *.txt
cd $PATH_TO_STATS && sed -i "s/STATS_DB/$STATS_DB/g" *.txt
cd $PATH_TO_STATS && sed -i "s/MAD_DB/$MAD_DB/g" *.txt
cd $PATH_TO_STATS && sed -i "s/device_outage/$device_outage/g" *.txt
cd $PATH_TO_STATS && sed -i "s[outage_webhook[$outage_webhook[g" *.txt
if [ -z "$SQL_password" ]
then
sed -i "s/userpass/-h$DB_IP -P$DB_PORT -u$SQL_user/g" $PATH_TO_STATS/crontab.txt
else
sed -i "s/userpass/-h$DB_IP -P$DB_PORT -u$SQL_user -p$SQL_password/g" $PATH_TO_STATS/crontab.txt
fi
# add mad fences and devices to db
cd $PATH_TO_STATS/cron_files && ./MAD_fence_update.sh
# cleanup old area queries
rm -f $PATH_TO_STATS/cron_files/*_area.sql
rm -f $PATH_TO_STATS/cron_files/*_area_quest.sql
echo ""
echo "Create remaining cron files"
echo ""
cp $PATH_TO_STATS/default_files/15_worker.sql.default $PATH_TO_STATS/cron_files/15_worker.sql
cp $PATH_TO_STATS/default_files/quest_spawn_cleanup.sql.default $PATH_TO_STATS/cron_files/quest_spawn_cleanup.sql
cp $PATH_TO_STATS/default_files/all_spawn_cleanup.sql.default $PATH_TO_STATS/cron_files/all_spawn_cleanup.sql
cp $PATH_TO_STATS/default_files/madlog1440.sql.default $PATH_TO_STATS/cron_files/madlog1440.sql
cp $PATH_TO_STATS/default_files/madlog10080.sql.default $PATH_TO_STATS/cron_files/madlog10080.sql
cp $PATH_TO_STATS/default_files/madlog_worker1440.sql.default $PATH_TO_STATS/cron_files/madlog_worker1440.sql
cp $PATH_TO_STATS/default_files/madlog_worker10080.sql.default $PATH_TO_STATS/cron_files/madlog_worker10080.sql
cp $PATH_TO_STATS/default_files/15_vmlog.sql.default $PATH_TO_STATS/cron_files/15_vmlog.sql
cp $PATH_TO_STATS/default_files/60_vmlog.sql.default $PATH_TO_STATS/cron_files/60_vmlog.sql
cp $PATH_TO_STATS/default_files/1440_vmlog.sql.default $PATH_TO_STATS/cron_files/1440_vmlog.sql
cp $PATH_TO_STATS/default_files/10080_vmlog.sql.default $PATH_TO_STATS/cron_files/10080_vmlog.sql
cp $PATH_TO_STATS/default_files/1440_atvstats.sql.default $PATH_TO_STATS/cron_files/1440_atvstats.sql
sed -i "s/pogodb/$STATS_DB/g" $PATH_TO_STATS/cron_files/*.sql
sed -i "s/rmdb/$MAD_DB/g" $PATH_TO_STATS/cron_files/*.sql
sed -i "s/RPL15/$RPL15/g" $PATH_TO_STATS/cron_files/*.sql
sed -i "s/RPL60/$RPL60/g" $PATH_TO_STATS/cron_files/*.sql
sed -i "s/RPL1440/$RPL1440/g" $PATH_TO_STATS/cron_files/*.sql
sed -i "s/RPL10080/$RPL10080/g" $PATH_TO_STATS/cron_files/*.sql
sed -i "s/QUEST_START/$QUEST_START/g" $PATH_TO_STATS/cron_files/*.sql
sed -i "s/QUEST_END/$QUEST_END/g" $PATH_TO_STATS/cron_files/*.sql
sed -i "s/SPAWN_UNSEEN_DAYS/$SPAWN_UNSEEN_DAYS/g" $PATH_TO_STATS/cron_files/*.sql
sed -i "s/SPAWN_NO_ENDTIME_DAYS/$SPAWN_NO_ENDTIME_DAYS/g" $PATH_TO_STATS/cron_files/*.sql
sed -i "s/SPAWNDEF15_HOURS/$SPAWNDEF15_HOURS/g" $PATH_TO_STATS/cron_files/*.sql
echo "Creating grafana files"
echo ""
# Create grafana templates
echo "Creating grafana templates in $folder/grafana"
mkdir -p $PATH_TO_STATS/grafana
rm -f $PATH_TO_STATS/grafana/*
cp $PATH_TO_STATS/default_files/*.json.default $PATH_TO_STATS/grafana
for i in "$PATH_TO_STATS"/grafana/*.json.default ;do
mv $i ${i%%.default}
done
DS_STATS="${DataSource_stats^^}"
DS_MAD="${DataSource_MAD^^}"
cd $PATH_TO_STATS/grafana/ && sed -i "s/pogodb/$DataSource_stats/g" *.json
cd $PATH_TO_STATS/grafana/ && sed -i "s/rmdb/$DataSource_MAD/g" *.json
cd $PATH_TO_STATS/grafana/ && sed -i "s/POGODB/$DS_STATS/g" *.json
cd $PATH_TO_STATS/grafana/ && sed -i "s/RMDB/$DS_MAD/g" *.json
#MAD log process check
if [ -z "$SQL_password" ]
then
firstInstall=$(mysql -h$DB_IP -P$DB_PORT -u$SQL_user $STATS_DB -N -se "SELECT count(*) FROM error;")
else
firstInstall=$(mysql -h$DB_IP -P$DB_PORT -u$SQL_user -p$SQL_password $STATS_DB -N -se "SELECT count(*) FROM error;")
fi
#firstInstall=0
if "$madlog"
then
if [ $firstInstall = 0 ]
then
echo ""
echo "No MAD logs processed yet, do you wish to process last 6 days?"
read -p "Continue (y/n)?" choice
if [ $choice = "y" ] || [ $choice = "yes" ] || [ $choice = "Y" ] || [ $choice = "Yes" ]
then
hoursback=144
while test $hoursback != 0
do
echo ""
echo ""
echo "Hourly data: processing now - $hoursback hours"
echo ""
cp $PATH_TO_STATS/cron_files/60_madlog.sh $PATH_TO_STATS/cron_files/madlog.sh.tmp
sed -i "s/1 hour ago/$hoursback hour ago/g" $PATH_TO_STATS/cron_files/madlog.sh.tmp
cd $PATH_TO_STATS/cron_files && ./madlog.sh.tmp
rm $PATH_TO_STATS/cron_files/madlog.sh.tmp
hoursback="$(( hoursback - 1 ))"
done
fi
if [ $choice = "y" ] || [ $choice = "yes" ] || [ $choice = "Y" ] || [ $choice = "Yes" ]
then
hoursback=8640
while test $hoursback != 0
do
echo ""
echo ""
echo "Daily data: processing now - $hoursback minutes"
echo ""
cp $PATH_TO_STATS/default_files/madlog1440.sql.default $PATH_TO_STATS/default_files/madlog1440.sql.tmp
sed -i "s/interval 1440 minute/interval $hoursback minute/g" $PATH_TO_STATS/default_files/madlog1440.sql.tmp
sed -i "s/pogodb/$STATS_DB/g" $PATH_TO_STATS/default_files/madlog1440.sql.tmp
if [ -z "$SQL_password" ]
then
mysql -h$DB_IP -P$DB_PORT -u$SQL_user $STATS_DB < $PATH_TO_STATS/default_files/madlog1440.sql.tmp
else
mysql -h$DB_IP -P$DB_PORT -u$SQL_user -p$SQL_password $STATS_DB < $PATH_TO_STATS/default_files/madlog1440.sql.tmp
fi
rm $PATH_TO_STATS/default_files/madlog1440.sql.tmp
hoursback="$(( hoursback - 1440 ))"
done
fi
fi
fi
# Migrate ATVdetails to seperate tables
if [ $first_install != "1" ]
then
echo "First install of Stats nothing to migrate, proceeding"
echo ""
else
if (( $statsDBversion < 13 ))
then
echo ""
echo "Migrating ATVdetails to seperate tables"
echo ""
query "$STATS_DB" "INSERT IGNORE INTO ATVgeneral (datetime,origin,arch,rom,vm_script,mitm,pogo,rgc,pogodroid,vmapper,pogo_update,pd_update,vm_update,rgc_update,pingreboot,temperature,magisk,magisk_modules,MACw,MACe,ip,gmail) select datetime,origin,arch,rom,VM_script,mitm,pogo,rgc,pogodroid,vmapper,pogo_update,pd_update,VM_Autoupdate,rgc_update,pingreboot,temperature,magisk,magisk_modules,MACw,MACe,ip,gmail from ATVdetails;"
query "$STATS_DB" "INSERT IGNORE INTO ATVpd (datetime,origin,auth_username,auth_password,user_login,auth_id,auth_token,post_destination,boot_delay,injection_delay,switch_disable_last_sent,intentional_stop,switch_send_protos,last_time_injected,switch_disable_external_communication,last_pid_injected,switch_enable_oomadj,switch_enable_auth_header,switch_send_raw_protos,switch_popup_last_sent,full_daemon,switch_enable_mock_location_patch,last_system_patch_timestamp,last_sys_inj,default_mappging_mode,switch_setenforce,post_destination_raw,session_id,libfilename,latest_version_known,disable_pogo_freeze_detection) SELECT datetime,origin,PD_auth_username,PD_auth_password,PD_user_login,PD_auth_id,PD_auth_token,PD_post_destination,PD_boot_delay,PD_injection_delay,PD_switch_disable_last_sent,PD_intentional_stop,PD_switch_send_protos,PD_last_time_injected,PD_switch_disable_external_communication,PD_last_pid_injected,PD_switch_enable_oomadj,PD_switch_enable_auth_header,PD_switch_send_raw_protos,PD_switch_popup_last_sent,PD_full_daemon,PD_switch_enable_mock_location_patch, PD_last_system_patch_timestamp,PD_last_sys_inj,PD_default_mappging_mode,PD_switch_setenforce,PD_post_destination_raw,PD_session_id,PD_libfilename,PD_latest_version_known,PD_disable_pogo_freeze_detection FROM ATVdetails;"
query "$STATS_DB" "INSERT IGNORE INTO ATVrgc (datetime,origin,auth_username,auth_password,websocket_uri,boot_delay,mediaprojection_previously_started,suspended_mocking,reset_agps_once,overwrite_fused,switch_enable_auth_header,reset_agps_continuously,reset_google_play_services,last_location_longitude,last_location_altitude,last_location_latitude,boot_startup,use_mock_location,oom_adj_override,location_reporter_service_running,stop_location_provider_service,autostart_services) SELECT datetime,origin,RGC_auth_username,RGC_auth_password,RGC_websocket_uri,RGC_boot_delay,RGC_mediaprojection_previously_started,RGC_suspended_mocking,RGC_reset_agps_once,RGC_overwrite_fused,RGC_switch_enable_auth_header,RGC_reset_agps_continuously,RGC_reset_google_play_services,RGC_last_location_longitude,RGC_last_location_altitude,RGC_last_location_latitude,RGC_boot_startup,RGC_use_mock_location,RGC_oom_adj_override,RGC_location_reporter_service_running,RGC_stop_location_provider_service,RGC_autostart_services FROM ATVdetails;"
query "$STATS_DB" "INSERT IGNORE INTO ATVvm (datetime,origin,bootdelay,gzip,betamode,patchedpid,selinux,daemon,authpassword,authuser,injector,authid,postdest,fridastarted,fridaver,openlucky) SELECT datetime,origin,VM_bootdelay,VM_gzip,VM_betamode,VM_patchedpid,VM_selinux,VM_daemon,VM_authpassword,VM_authuser,VM_injector,VM_authid,VM_postdest,VM_fridastarted,VM_fridaver,VM_openlucky FROM ATVdetails;"
fi
fi
# Migrate spawnpoint data to seperate table
if [ $first_install != "1" ]
then
echo "First install of Stats nothing to migrate, proceeding"
echo ""
else
if (( $statsDBversion < 39 ))
then
echo ""
echo "Migrating spawnpoint data to seperate table"
echo ""
query "$STATS_DB" "INSERT IGNORE INTO stats_area_spawnpoint (datetime,rpl,area,fence,spawnpoints,eventSpawns,verified,def15,not15,seen,1d,3d,7d) SELECT Datetime,RPL,Area,Fence,DBspawns,DBspawns_event-DBspawns,DBspawns-Spawn_NULL,Spawndef15,SpawndefNot15,Last_scanned_today_acc,Last_scanned_1d,Last_scanned_3d,Last_scanned_7dp FROM stats_area;"
fi
fi
# fix double job_wait in config.ini
if [[ $(grep -w job_wait $PATH_TO_STATS/config.ini | wc -l) == 2 ]]
then
echo "some idiot put 2x job_wait in config.ini, changing the one from ATVdeails to job_wait_atv"
echo ""
sed -i '0,/job_wait/s//job_wait_atv/' $PATH_TO_STATS/config.ini
else
if [[ $(grep -w job_wait $PATH_TO_STATS/config.ini | wc -l) == 1 ]] && [[ $(grep -w job_wait_atv $PATH_TO_STATS/config.ini | wc -l) == 0 ]]
then
sed -i '0,/job_wait/s//job_wait_atv/' $PATH_TO_STATS/config.ini
fi
fi
## Checks
# Make sure QUEST_END is set when using spawndef reset
if "$SPAWNDEF15_CLEANUP"
then
if [[ $QUEST_END = "06:00:00" ]]
then
echo "Warning: QUEST_END is set to default, make sure it matches your setup"
fi
fi
# Make sure not to delete pokemon_history when mon_backup is enabled
if "$monthly_mon_table"
then
if "$mon_cleanup"
then
echo "ERROR: make sure to disable mon_cleanup as your monthly backup will be incomplete otherwise"
fi
fi
echo ''
echo "All done"