-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathlauncher.sh
709 lines (657 loc) · 23.9 KB
/
launcher.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
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
#!/bin/ash
log_info()
{
echo "$(date '+%Y-%m-%d %H:%M:%S') INFO ${1}"
}
log_info_n()
{
echo -n "$(date '+%Y-%m-%d %H:%M:%S') INFO ${1}"
}
log_warning()
{
echo "$(date '+%Y-%m-%d %H:%M:%S') WARNING ${1}"
}
log_error()
{
echo "$(date '+%Y-%m-%d %H:%M:%S') ERROR ${1}"
}
log_debug()
{
if [ "${debug_logging}" = true ]
then
echo "$(date '+%Y-%m-%d %H:%M:%S') DEBUG ${1}"
fi
}
create_group()
{
if [ "$(grep -c "^${group}:x:${group_id}:" "/etc/group")" -eq 0 ]
then
log_debug " | Creating minimal /etc/group file"
{
echo 'root:x:0:root'
echo 'tty:x:5:'
echo 'shadow:x:42:'
} >/etc/group
if [ "$(grep -c "^${group}:" "/etc/group")" -eq 1 ]
then
log_error " | Group name, ${group}, already in use. Cannot continue. Halting"
sleep infinity
fi
log_debug " | Creating group ${group}:${group_id}"
groupadd --gid "${group_id}" "${group}"
fi
}
create_user()
{
if [ "$(grep -c "^${user}:x:${user_id}:${group_id}" "/etc/passwd")" -eq 0 ]
then
log_debug " | Creating minimal /etc/passwd file"
echo "root:x:0:0:root:/root:/bin/ash" >/etc/passwd
log_debug " | Creating user ${user}:x:${user_id}:${group_id}::/home/${user}:/bin/ash"
useradd "${user}" --uid "${user_id}" --gid "${group_id}" --home-dir "/home/${user}" --shell /bin/ash --badname
fi
}
set_user_mask()
{
case "${file_permissions}" in
600) user_mask=077;;
640) user_mask=027;;
644) user_mask=022;;
660) user_mask=007;;
664) user_mask=002;;
666) user_mask=000;;
*) user_mask=077;;
esac
log_info " - Setting file mode creation mask from configured file permissions (${file_permissions}): ${user_mask}"
sed -i "s/^umask.*/umask ${user_mask}/" /etc/profile
umask "${user_mask}"
}
set_owner_and_permissions_downloads()
{
log_info " - Setting owner, group and permissions on: ${download_path}"
log_debug " | Set owner"
find "${download_path}" ! -type l ! -user "${user_id}" ! -path "${ignore_path}" -exec chown "${user_id}" {} +
log_debug " | Set group"
find "${download_path}" ! -type l ! -group "${group_id}" ! -path "${ignore_path}" -exec chgrp "${group_id}" {} +
log_debug " | Set ${directory_permissions} permissions on directories"
find "${download_path}" -type d ! -perm "${directory_permissions}" ! -path "${ignore_path}" -exec chmod "${directory_permissions}" '{}' +
log_debug " | Set ${file_permissions} permissions on files"
find "${download_path}" -type f ! -perm "${file_permissions}" ! -path "${ignore_path}" -exec chmod "${file_permissions}" '{}' +
}
set_owner_and_permissions_jpegs()
{
log_info " - Setting owner, group and permissions on: ${jpeg_path}"
log_debug " | Set owner"
find "${jpeg_path}" ! -type l ! -user "${user_id}" ! -path "${ignore_path}" -exec chown "${user_id}" {} +
log_debug " | Set group"
find "${jpeg_path}" ! -type l ! -group "${group_id}" ! -path "${ignore_path}" -exec chgrp "${group_id}" {} +
log_debug " | Set ${directory_permissions} permissions on directories"
find "${jpeg_path}" -type d ! -perm "${directory_permissions}" ! -path "${ignore_path}" -exec chmod "${directory_permissions}" '{}' +
log_debug " | Set ${file_permissions} permissions on files"
find "${jpeg_path}" -type f ! -perm "${file_permissions}" ! -path "${ignore_path}" -exec chmod "${file_permissions}" '{}' +
}
set_owner_and_permissions_videos()
{
log_info " - Setting owner, group and permissions on: ${video_path}"
log_debug " | Set owner"
find "${video_path}" ! -type l ! -user "${user_id}" ! -path "${ignore_path}" -exec chown "${user_id}" {} +
log_debug " | Set group"
find "${video_path}" ! -type l ! -group "${group_id}" ! -path "${ignore_path}" -exec chgrp "${group_id}" {} +
log_debug " | Set ${directory_permissions} permissions on directories"
find "${video_path}" -type d ! -perm "${directory_permissions}" ! -path "${ignore_path}" -exec chmod "${directory_permissions}" '{}' +
log_debug " | Set ${file_permissions} permissions on files"
find "${video_path}" -type f ! -perm "${file_permissions}" ! -path "${ignore_path}" -exec chmod "${file_permissions}" '{}' +
}
set_owner_and_permissions_config()
{
log_info " - Set owner and group on config directory: /config"
chown -R "${user_id}:${group_id}" "/config"
log_info " - Set owner and group on icloudpd temp directory: /tmp/icloudpd"
chown -R "${user_id}:${group_id}" "/tmp/icloudpd"
}
run_as()
{
if [ "$(id -u)" = 0 ]
then
su "${user}" -s /bin/ash -c "${1}"
else
/bin/ash -c "${1}"
fi
}
disable_notifications()
{
log_warning " | $(echo "${notification_type}" | cut -c1 | tr '[:lower:]' '[:upper:]')$(echo "${notification_type}" | cut -c2-) notifications enabled, but API key/token/secret/server/id not set"
log_warning " ! Disabling nofifications"
sed 's/notification_type=.*/notification_type=/' "${config_file}"
sleep 1m
}
##### Start Script #####
log_info "Initialising container..."
# Create the temporary directory
if [ ! -d "/tmp/icloudpd" ]
then
log_info " - Creating temporary directory"
if ! mkdir --parents "/tmp/icloudpd"
then
log_error "Failed to create temporary directory"
fi
fi
# Remove pre-existing temporary files
if [ -f "/tmp/icloudpd/icloudpd_check_exit_code" ]
then
rm "/tmp/icloudpd/icloudpd_check_exit_code"
fi
if [ -f "/tmp/icloudpd/icloudpd_download_exit_code" ]
then
rm "/tmp/icloudpd/icloudpd_download_exit_code"
fi
if [ -f "/tmp/icloudpd/icloudpd_check_error" ]
then
rm "/tmp/icloudpd/icloudpd_check_error"
fi
if [ -f "/tmp/icloudpd/icloudpd_download_error" ]
then
rm "/tmp/icloudpd/icloudpd_download_error"
fi
if [ -f "/tmp/icloudpd/icloudpd_sync.log" ]
then
rm "/tmp/icloudpd/icloudpd_sync.log"
fi
if [ -f "/tmp/icloudpd/icloudpd_tracert.err" ]
then
rm "/tmp/icloudpd/icloudpd_tracert.err"
fi
# Create new temporary files
log_info " - Create temporary files"
if ! touch "/tmp/icloudpd/icloudpd_check_exit_code"
then
log_error " | Failed to create /tmp/icloudpd/icloudpd_check_exit_code"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
if ! touch "/tmp/icloudpd/icloudpd_download_exit_code"
then
log_error " | Failed to create /tmp/icloudpd/icloudpd_download_exit_code"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
if ! touch "/tmp/icloudpd/icloudpd_check_error"
then
log_error " | Failed to create /tmp/icloudpd/icloudpd_check_error"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
if ! touch "/tmp/icloudpd/icloudpd_download_error"
then
log_error " | Failed to create /tmp/icloudpd/icloudpd_download_error"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
if ! touch "/tmp/icloudpd/icloudpd_sync.log"
then
log_error " | Failed to create /tmp/icloudpd/icloudpd_sync.log"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
if ! touch "/tmp/icloudpd/icloudpd_tracert.err"
then
log_error " | Failed to create /tmp/icloudpd/icloudpd_tracert.err"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
if ! touch "/tmp/icloudpd/expect_input.txt"
then
log_error " | Failed to create /tmp/icloudpd/expect_input.txt"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
# Push icloudpd version to file so it's a smidgen quicker to load on container restarts/syncs
/opt/icloudpd/bin/icloudpd --version | awk -F, '{print $1}' | sed 's/version://' > /tmp/icloudpd/icloudpd_version
python3 --version | awk '{print $2}' > /tmp/icloudpd/python_version
# Check the config directory exists and create it if it does not
log_info " - Checking configuration file permissions"
if [ ! -d "/config" ]
then
if ! mkdir /config
then
log_error " | Failed to create configuration directory: /config"
log_error " ! Check your volume mount is not read-only. Check NFS/SMB share permissions if mounting to a shared location"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
fi
# Check the config file exists and create it if it does not
if [ ! -f "${config_file}" ]
then
if ! touch "${config_file}"
then
log_error " | Failed to create configration file: ${config_file}"
log_error " ! Check your volume mount is not read-only. Check NFS/SMB share permissions if mounting to a shared location. Check you container has root permissions."
log_error " ! Cannot continue. Halting"
sleep infinity
fi
fi
# Check the config file isn't actually a directory
if [ ! -f "${config_file}" ]
then
log_error " | Config file appears to be a directory: ${config_file}"
log_error " ! Check your volume mount"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
# Create enty config file, populate with default variables and configure it if Docker variables are also apecified
log_info " - Create/update configuration file: ${config_file}"
/usr/local/bin/init_config.sh
# Check config file was created and is writable
if [ ! -f "${config_file}" ]
then
log_error " | Failed to create configuration file: ${config_file}"
log_error " ! Cannot continue. Halting"
sleep infinity
elif [ ! -w "${config_file}" ]
then
log_error " | Cannot write to configuration file: ${config_file}"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
# Load variables from config file
log_info " - Checking ${config_file} for errors"
source "${config_file}"
# Check Apple ID set
if [ -z "${apple_id}" ]
then
log_error " | Apple ID not set"
log_error " ! Waiting for it to be added to: ${config_file}"
while [ -z "${apple_id}" ]
do
sleep 10
source "${config_file}"
done
fi
# Check synchronisation interval
case "${synchronisation_interval}" in
21600) synchronisation_interval=21600;; # 6 hours
43200) synchronisation_interval=43200;; # 12 hours
86400) synchronisation_interval=86400;; # 24 hours
129600) synchronisation_interval=129600;; # 36 hours
172800) synchronisation_interval=172800;; # 48 hours
604800) synchronisation_interval=604800;; # 7 days
*) sed 's/synchronisation_interval=.*/synchronisation_interval=86400/' "${config_file}";; # 24 hours
esac
# Lower it to 60 if set higher
if [ "${synchronisation_delay:=61}" -gt 60 ]
then
sed 's/synchronisation_delay=.*/synchronisation_delay=60/' "${config_file}"
fi
# Check user not attempting to configure the local user as root as this breaks the "runas" function
if [ "${group}" = "root" ]
then
log_warning " | The local group for synchronisation cannot be root, resetting to 'group'"
sed -i "s%^group=$%group=group%" "${config_file}"
user_warning_displayed=true
fi
if [ "${group_id}" -eq 0 ]
then
log_warning " | The local group id for synchronisation cannot be 0, resetting to '1000'"
sed -i "s%^group_id=$%group_id=1000%" "${config_file}"
user_warning_displayed=true
fi
# Check download path variable configured
if [ -z "${download_path}" ]
then
log_error " | Download path is not set properly in config"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
# Initialise download path
if [ ! -d "${download_path}" ]
then
log_info " | Download directory does not exist"
log_info " | Creating ${download_path} and configuring permssions"
if ! mkdir --parents "${download_path}"
then
log_error " | Failed to create download directory: '${download_path}'"
log_error " ! Cannot continue. Halting"
sleep infinity
else
chown "${user_id}:${group_id}" "${download_path}"
fi
fi
# Initialise jpeg_path
if [ "${jpeg_path}" ] && [ ! -d "${jpeg_path}" ]
then
log_info " | JPEG directory does not exist"
log_info " | Creating ${jpeg_path}"
if ! mkdir --parents "${jpeg_path}"
then
log_error " | Failed to create JPEG directory: '${jpeg_path}'"
log_error " ! Cannot continue. Halting"
sleep infinity
else
chown "${user_id}:${group_id}" "${jpeg_path}"
fi
fi
# Initialise videos_path
if [ "${video_path}" ] && [ ! -d "${video_path}" ]
then
log_info " | Video directory does not exist"
log_info " | Creating ${video_path}"
if ! mkdir --parents "${video_path}"
then
log_error " | Failed to create video directory: '${video_path}'"
log_error " ! Cannot continue. Halting"
sleep infinity
else
chown "${user_id}:${group_id}" "${video_path}"
fi
fi
# Warn if sync interval is too short
if [ "${synchronisation_interval}" -lt 43200 ] && [ "${warnings_acknowledged:=false}" = false ]
then
log_warning " | Setting synchronisation_interval to less than 43200 (12 hours) may cause throttling by Apple"
log_warning " ! If you run into the following error:"
log_warning " ! 'private db access disabled for this account. Please wait a few hours then try again. The remote servers might be trying to throttle requests. (ACCESS_DENIED)'"
log_warning " ! then check your synchronisation_interval is 43200 or greater and switch the container off for 6-12 hours so Apple's throttling expires"
user_warning_displayed=true
fi
# Warn if set_exif_datetime is enabled
if [ "${set_exif_datetime}" = true ]
then
log_warning " | Configuring set_exif_datetime=true changes the files that are downloaded, so they will be downloaded a second time. Enabling this setting results in a lot of duplicate photos"
user_warning_displayed=true
fi
# Halt on conflicting settings
if [ "${auto_delete}" != false ] && [ "${delete_after_download}" != false ]
then
log_error " | The variables auto_delete and delete_after_download cannot both be configured at the same time. Please choose one or the other. Halting"
sleep infinity
fi
if [ "${sideways_copy_videos_mode}" = "move" ] && [ "${delete_after_download}" = false ]
then
log_error " | The variable sideways_copy_videos_mode cannot be set to 'move' unless delete_after_download is set to 'true', otherwise all icloud videos will be downloaded every run. Please set the copy mode to 'copy' or delete_after_download to 'true'. Halting"
sleep infinity
fi
# Display warning when using keep_icloud_recent
if [ "${keep_icloud_recent_only}" = true ] && [ "${warnings_acknowledged:=false}" = false ]
then
log_warning " | The 'Keep iCloud recent' feature deletes all files from iCloud which are older than this amount of days. Setting this to 0 will delete everthing"
log_warning " Please use this with caution. I am not responsible for any data loss. Continuing in 2 minutes"
user_warning_displayed=true
fi
# Display warning when deleting accompanying files
if [ "${delete_accompanying}" = true ] && [ "${warnings_acknowledged:=false}" = false ]
then
log_info " | Delete accompanying files (.JPG/.HEIC.MOV)"
log_warning " ! This feature deletes files from your local disk. Please use with caution. I am not responsible for any data loss"
log_warning " ! This feature cannot be used if the 'folder_structure' variable is set to 'none' and also, 'set_exif_datetime' must be 'false'"
log_warning " ! These two settings will increase the chances of de-duplication happening, which could result in the wrong files being removed"
user_warning_displayed=true
fi
# Check China website and authentication sites are not mismatched
if [ "${icloud_china}" = true ]
then
if [ "${auth_china}" != true ]
then
log_warning " | You have the icloud_china variable set to true but auth_china set to false. Are you sure this is correct?"
user_warning_displayed=true
fi
fi
# Check all Nextcloud variables are present if Nextcloud uploading
if [ "${nextcloud_upload}" = true ]
then
if [ -z "${nextcloud_url}" ] && [ -Z "${nextcloud_username}" ] && [ -z "${nextcloud_password}" ]
then
log_error " | Nextcloud upload: Missing mandatory variables. Halting"
sleep infinity
fi
fi
# Skip delay when warnings are presented
if [ "${user_warning_displayed:=false}" = true ]
then
if [ "${warnings_acknowledged:=false}" = true ]
then
log_debug " | Configuration warnings acknowledged"
else
log_warning "Non-fatal configuration options detected. Continuing in 2 minutes..."
sleep 120
fi
fi
# Check notifications
if [ "${notification_type}" ]
then
log_info " - Check $(echo "${notification_type}" | cut -c1 | tr '[:lower:]' '[:upper:]')$(echo "${notification_type}" | cut -c2-) notifications configuration"
if [ "${notification_type}" = "prowl" ] && [ -z "${prowl_api_key}" ]
then
disable_notifications
fi
if [ "${notification_type}" = "pushover" ]
then
if [ -z "${pushover_user}" ] || [ -z "${pushover_token}" ]
then
disable_notifications
fi
fi
if [ "${notification_type}" = "telegram" ]
then
if [ -z "${telegram_token}" ] || [ -z "${telegram_chat_id}" ]
then
disable_notifications
fi
fi
if [ "${notification_type}" = "openhab" ]
then
if [ -z "${webhook_server}" ] || [ -z "${webhook_id}" ]
then
disable_notifications
fi
fi
if [ "${notification_type}" = "webhook" ]
then
if [ -z "${webhook_server}" ] || [ -z "${webhook_id}" ]
then
disable_notifications
fi
fi
if [ "${notification_type}" = "discord" ]
then
if [ -z "${discord_id}" ] || [ -z "${discord_token}" ]
then
disable_notifications
fi
fi
if [ "${notification_type}" = "dingtalk" ] && [ -z "${dingtalk_token}" ]
then
disable_notifications
fi
if [ "${notification_type}" = "iyuu" ] && [ -z "${iyuu_token}" ]
then
disable_notifications
fi
if [ "${notification_type}" = "wecom" ]
then
if [ -z "${wecom_id}" ] || [ -z "${wecom_secret}" ]
then
disable_notifications
fi
fi
if [ "${notification_type}" = "gotify" ]
then
if [ "${gotify_app_token}" ] || [ "${gotify_server_url}" ]
then
disable_notifications
fi
fi
if [ "${notification_type}" = "bark" ]
then
if [ -z "${bark_device_key}" ] || [ -z "${bark_server}" ]
then
disable_notifications
fi
fi
if [ "${notification_type}" = "msmtp" ]
then
if [ -z "${msmtp_host}" ] || [ -z "${msmtp_port}" ] || [ -z "${msmtp_user}" ] || [ -z "${msmtp_pass}" ]
then
disable_notifications
fi
fi
fi
# Check download directories are mounted
log_info " - Checing download locations are mounted"
if [ "${download_path}" ]
then
if [ "$(cat /proc/mounts | cut -d' ' -f2 | grep -c "${download_path%/}")" -eq 0 ]
then
log_error " | Download directory is not mounted: ${download_path%/}"
log_error " ! Cannot continue. Halting"
sleep infinity
else
log_debug " | Download directory is mounted: ${download_path%/}"
fi
fi
if [ "${jpeg_path}" ]
then
if [ "$(cat /proc/mounts | cut -d' ' -f2 | grep -c "${jpeg_path%/}")" -eq 0 ]
then
log_error " | JPEG download directory is not mounted: ${jpeg_path%/}"
log_error " ! Cannot continue. Halting"
sleep infinity
else
log_debug " | JPEG download directory is mounted: ${jpeg_path%/}"
fi
fi
if [ "${video_path}" ]
then
if [ "$(cat /proc/mounts | cut -d' ' -f2 | grep -c "${video_path%/}")" -eq 0 ]
then
log_error " | Sideways copy video directory is not mounted: ${video_path%/}"
log_error " ! Cannot continue. Halting"
sleep infinity
else
log_debug " | Sideways copy video download directory is mounted: ${video_path%/}"
fi
fi
# Create group/user
log_info " - Checking user:group account: ${user}:${group}"
create_group
create_user
set_user_mask
# Check/Set permissions
set_owner_and_permissions_config
set_owner_and_permissions_downloads
if [ "${jpeg_path}" ] && [ -d "${jpeg_path}" ]
then
set_owner_and_permissions_jpegs
fi
if [ "${video_path}" ] && [ -d "${video_path}" ]
then
set_owner_and_permissions_videos
fi
# Check config directory is writable by configured user
log_info " - Checking directories are writable by user: ${user}"
if [ "$(run_as "test -w /config; echo $?")" -ne 0 ]
then
log_error " | Directory is not writable: /config"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
# Check keyring directory is writable by configured user
if [ "$(run_as "test -w /config/python_keyring; echo $?")" -ne 0 ]
then
log_error " | Directory is not writable: /config/python_keyring"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
# Check download directory is writable by configured user
if [ "$(run_as "test -w ${download_path}; echo $?")" -ne 0 ]
then
log_error " | Directory is not writable: ${download_path}"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
# Check JPEG directory is writable by configured user
if [ "${jpeg_path}" ] && [ ! -d "${jpeg_path}" ]
then
log_info " - Testing JPEG directory writable by user: ${user}"
if [ "$(run_as "test -w ${jpeg_path}; echo $?")" -ne 0 ]
then
log_error " | Directory is not writable: ${jpeg_path}"
log_error " ! Cannot continue. Halting"
sleep infinity
fi
fi
# Check route to icloud web site
if [ "${icloud_china:=false}" = true ]
then
icloud_domain="icloud.com.cn"
else
icloud_domain="icloud.com"
fi
log_info " - Checking ${icloud_domain} is accessible"
if [ "$(traceroute -q 1 -w 1 ${icloud_domain} >/dev/null 2>/tmp/icloudpd/icloudpd_tracert.err; echo $?)" = 1 ]
then
log_error " | No route to ${icloud_domain} found. Please check your container's network settings"
log_error " ! Error debug - $(cat /tmp/icloudpd/icloudpd_tracert.err)"
log_error " ! Cannot continue. Restarting in 5 minutes"
sleep 5m
exit 1
fi
# Check Telegram bot initialised
if [ "${notification_type}" = "telegram" ] && [ "${telegram_token}" ] && [ "${telegram_chat_id}" ] && [ "${telegram_polling}" = true ]
then
log_info " - Checking Telegram bot initialised"
if [ "${telegram_bot_initialised}" = false ]
then
if [ "${telegram_http}" = true ]
then
telegram_protocol="http"
else
telegram_protocol="https"
fi
if [ "${telegram_server}" ]
then
telegram_base_url="${telegram_protocol}://${telegram_server}/bot${telegram_token}"
else
telegram_base_url="${telegram_protocol}://api.telegram.org/bot${telegram_token}"
fi
telegram_update_id_offset_file="/config/telegram_update_id.num"
if [ ! -f "${telegram_update_id_offset_file}" ]
then
echo -n 0 > "${telegram_update_id_offset_file}"
fi
sleep "$((RANDOM % 15))"
bot_check="$(curl --silent -X POST "${telegram_base_url}/getUpdates" | jq -r .ok)"
if [ "${bot_check}" = true ]
then
sed -i "s%^telegram_bot_initialised=false$%telegram_bot_initialised=true%" "${config_file}"
else
log_warning " | Telegram bot does not appear to have been initialised or needs reinitialising. Please send a message to the bot from your iDevice and restart the container"
fi
fi
fi
# Check for updates
log_info_n " - Checking for updates: "
current_version="$(awk -F_ '{print $1}' /opt/build_version.txt)"
latest_version="$(curl --silent --max-time 5 https://raw.githubusercontent.com/boredazfcuk/docker-icloudpd/master/build_version.txt | awk -F_ '{print $1}')"
if [ "${current_version:=99}" -eq "99" ] || [ "${latest_version:=98}" -eq "98" ]
then
echo "Check for updates failed. Placeholder version detected. Current version: ${current_version}. Latest version: ${latest_version}"
user_warning_displayed=true
sleep 1m
elif [ "${current_version}" -lt "${latest_version}" ]
then
echo "Current version (v${current_version}) is out of date. Please upgrade to latest version (v${latest_version})."
user_warning_displayed=true
sleep 1m
elif [ "${current_version}" -gt "${latest_version}" ]
then
echo "Current version (v${current_version}) is newer than latest build (v${latest_version}). Good luck!"
elif [ "${current_version}" -eq "${latest_version}" ]
then
echo "Current version (v${current_version}) is up to date"
else
echo "Check for updates failed. Cannot continue. Halting"
sleep infinity
fi
log_info "Initialisation complete"
exec /usr/local/bin/sync-icloud.sh