forked from boredazfcuk/docker-icloudpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync-icloud.sh
executable file
·2165 lines (2096 loc) · 110 KB
/
sync-icloud.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
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/ash
##### Functions #####
Initialise(){
echo
LogInfo "***** boredazfcuk/icloudpd container v1.0.$(cat /opt/build_version.txt) started *****"
LogInfo "***** For support, please go here: https://github.com/boredazfcuk/docker-icloudpd *****"
LogInfo "$(cat /etc/*-release | grep "^NAME" | sed 's/NAME=//g' | sed 's/"//g') $(cat /etc/*-release | grep "VERSION_ID" | sed 's/VERSION_ID=//g' | sed 's/"//g')"
LogInfo "Python version: $(python3 --version | awk '{print $2}')"
LogInfo "icloud-photos-downloader version: $(/opt/icloudpd/bin/icloudpd --version | awk '{print $3}')"
LogInfo "Checking for updates..."
current_version="$(cat /opt/build_version.txt | awk -F_ '{print $1}')"
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
LogError " - Check for updates failed. Continuing in 2 minutes..."
sleep 120
elif [ "${current_version}" -lt "${latest_version}" ]; then
LogInfo " - Current version (v${current_version}) is out of date. Please upgrade to latest version (v${latest_version}). Continuing in 2 minutes..."
sleep 120
elif [ "${current_version}" -gt "${latest_version}" ]; then
LogInfo " - Current version (v${current_version}) is newer than latest build (v${latest_version}). Good luck!"
elif [ "${current_version}" -eq "${latest_version}" ]; then
LogInfo " - Current version is up to date"
else
LogError " - Check for updates failed. Continuing in 2 minutes..."
sleep 120
fi
config_file="${config_dir}/icloudpd.conf"
if [ ! -f "${config_file}" ]; then
LogError "Failed to create configuration file: ${config_file} - Cannot continue, exiting"
sleep 600
exit 1
elif [ ! -w "${config_file}" ]; then
LogError "Cannot write to configuration file: ${config_file} - Cannot continue, exiting"
sleep 600
exit 1
fi
LogInfo "Loading configuration from: ${config_file}"
source "${config_file}"
save_ifs="${IFS}"
lan_ip="$(hostname -i)"
login_counter=0
apple_id="$(echo -n ${apple_id} | tr '[:upper:]' '[:lower:]')"
cookie_file="$(echo -n "${apple_id//[^a-z0-9_]/}")"
local icloud_dot_com dns_counter
if [ "${icloud_china:=false}" = true ]; then
icloud_domain="icloud.com.cn"
else
icloud_domain="icloud.com"
fi
case "${synchronisation_interval:=86400}" 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
*) synchronisation_interval=86400;; # 24 hours
esac
if [ "${synchronisation_delay:=0}" -gt 60 ]; then
synchronisation_delay=60
fi
if [ ! -d "/tmp/icloudpd" ]; then mkdir --parents "/tmp/icloudpd"; fi
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
touch "/tmp/icloudpd/icloudpd_check_exit_code"
touch "/tmp/icloudpd/icloudpd_download_exit_code"
touch "/tmp/icloudpd/icloudpd_check_error"
touch "/tmp/icloudpd/icloudpd_download_error"
touch "/tmp/icloudpd/icloudpd_sync.log"
touch "/tmp/icloudpd/icloudpd_tracert.err"
if [ -z "${apple_id}" ]; then
LogError "Apple ID not set - exiting"
sleep 120
exit 1
fi
LogDebug "Running user id: $(id --user)"
LogDebug "Running group id: $(id --group)"
if [ "${user}" = "root" ]; then
LogWarning "The local user for synchronisation cannot be root, resetting to 'user'"
unset user
sleep 120
fi
if [ "${user_id}" -eq 0 ]; then
LogWarning "The local user id for synchronisation cannot be 0, resetting to '1000'"
unset user_id
sleep 120
fi
LogDebug "Local user: ${user}:${user_id}"
if [ "${group}" = "root" ]; then
LogWarning "The local group for synchronisation cannot be root, resetting to 'group'"
unset group
sleep 120
fi
if [ "${group_id}" -eq 0 ]; then
LogWarning "The local group id for synchronisation cannot be 0, resetting to '1000'"
unset group_id force_gid
sleep 120
fi
LogDebug "Local group: ${group}:${group_id}"
LogDebug "Force GID: ${force_gid}"
LogDebug "LAN IP Address: ${lan_ip}"
LogDebug "Default gateway: $(ip route | grep default | awk '{print $3}')"
LogDebug "DNS server: $(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')"
icloud_dot_com="$(nslookup -type=a ${icloud_domain} | grep -v "127.0.0.1" | grep Address | tail -1 | awk '{print $2}')"
while [ -z "${icloud_dot_com}" ]; do
if [ "${dns_counter:=0}" = 0 ]; then
LogWarning "Cannot find ${icloud_domain} IP address - retrying"
fi
sleep 10
icloud_dot_com="$(nslookup -type=a ${icloud_domain} | grep -v "127.0.0.1" | grep Address | tail -1 | awk '{print $2}')"
dns_counter=$((dns_counter+1))
if [ "${dns_counter}" = 12 ]; then
LogError "Cannot find ${icloud_domain} IP address. Please check your DNS/Firewall settings - exiting"
sleep 120
exit 1
fi
done
LogDebug "IP address for ${icloud_domain}: ${icloud_dot_com}"
if [ "$(traceroute -q 1 -w 1 ${icloud_domain} >/dev/null 2>/tmp/icloudpd/icloudpd_tracert.err; echo $?)" = 1 ]; then
LogError "No route to ${icloud_domain} found. Please check your container's network settings - exiting"
LogError "Error debug - $(cat /tmp/icloudpd/icloudpd_tracert.err)"
sleep 120
exit 1
else
LogDebug "Route check to ${icloud_domain} successful"
fi
if [ "${debug_logging}" = true ]; then
LogDebug "Apple ID: (hidden)"
else
LogInfo "Apple ID: ${apple_id}"
fi
LogInfo "Authentication Type: ${authentication_type}"
if [ "${debug_logging}" = true ]; then
LogDebug "Cookie path: ${config_dir}/(hidden)"
else
LogInfo "Cookie path: ${config_dir}/${cookie_file}"
fi
LogInfo "Cookie expiry notification period: ${notification_days}"
LogInfo "Download destination directory: ${download_path}"
if [ ! -d "${download_path}" ]; then
LogInfo "Download directory does not exist"
LogInfo "Creating ${download_path} and configuring permissions"
mkdir --parents "${download_path}"
SetOwnerAndPermissionsDownloads
fi
LogInfo "Folder structure: ${folder_structure}"
LogDebug "Directory permissions: ${directory_permissions}"
LogDebug "File permissions: ${file_permissions}"
if [ "${syncronisation_interval}" ]; then
LogWarning "The syncronisation_interval variable contained a typo. This has now been corrected to synchronisation_interval. Please update your container. Defaulting to one sync per 24 hour period"
synchronisation_interval="86400"
fi
LogInfo "Keep Unicode: ${keep_unicode}"
LogInfo "Live Photo MOV Filename Policy: ${live_photo_mov_filename_policy}"
LogInfo "File Match Policy: ${file_match_policy}"
LogInfo "Synchronisation interval: ${synchronisation_interval}"
if [ "${synchronisation_interval}" -lt 43200 ]; then
if [ "${warnings_acknowledged:=false}" = true ]; then
LogDebug "Synchronisation interval throttle warning acknowledged"
else
LogWarning "Setting synchronisation_interval to less than 43200 (12 hours) may cause throttling by Apple"
LogWarning "If you run into the following error: "
LogWarning " - 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)"
LogWarning "Then check your synchronisation_interval is 43200 or greater and switch the container off for 6-12 hours so Apple's throttling expires. Continuing in 3 minutes"
sleep 120
fi
fi
LogInfo "Synchronisation delay (minutes): ${synchronisation_delay}"
LogInfo "Set EXIF date/time: ${set_exif_datetime}"
if [ "${set_exif_datetime}" = true ]; then
LogWarning "This setting changes the files that are downloaded, so they will be downloaded a second time. Enabling this setting results in a lot of duplicate"
fi
LogInfo "Auto delete: ${auto_delete}"
LogInfo "Delete after download: ${delete_after_download}"
if [ "${auto_delete}" != false -a "${delete_after_download}" != false ]; then
LogError "The variables auto_delete and delete_after_download cannot both be configured at the same time. Please choose one or the other - exiting"
sleep 120
exit 1
fi
LogInfo "Delete empty directories: ${delete_empty_directories}"
LogInfo "Photo size: ${photo_size}"
LogInfo "Align RAW: ${align_raw}"
LogInfo "Single pass mode: ${single_pass}"
if [ "${single_pass}" = true ]; then
LogDebug "Single pass mode enabled. Disabling download check"
skip_check=true
fi
LogInfo "Skip download check: ${skip_check}"
LogInfo "Skip live photos: ${skip_live_photos}"
if [ "${recent_only}" ]; then
LogInfo "Number of most recently added photos to download: ${recent_only}"
else
LogInfo "Number of most recently added photos to download: Download All Photos"
fi
if [ "${photo_album}" ]; then
LogInfo "Downloading photos from album(s): ${photo_album}"
elif [ "${photo_library}" ]; then
LogInfo "Downloading photos from library: ${photo_library}"
else
LogInfo "Downloading photos from: Download All Photos"
fi
if [ "${until_found}" ]; then
LogInfo "Stop downloading when prexisiting files count is: ${until_found}"
else
LogInfo "Stop downloading when prexisiting files count is: Download All Photos"
fi
if [ "${skip_live_photos}" = false ]; then
LogInfo "Live photo size: ${live_photo_size}"
fi
LogInfo "Skip videos: ${skip_videos}"
LogInfo "Convert HEIC to JPEG: ${convert_heic_to_jpeg}"
if [ "${convert_heic_to_jpeg}" = true ]; then
LogDebug "JPEG conversion quality: ${jpeg_quality}"
fi
if [ "${jpeg_path}" ]; then
LogInfo "Converted JPEGs path: ${jpeg_path}"
fi
if [ "${delete_accompanying}" = true -a -z "${warnings_acknowledged}" ]; then
LogInfo "Delete accompanying files (.JPG/.HEIC.MOV)"
LogWarning "This feature deletes files from your local disk. Please use with caution. I am not responsible for any data loss"
LogWarning "This feature cannot be used if the 'folder_structure' variable is set to 'none' and also, 'set_exif_datetime' must be 'False'"
LogWarning "These two settings will increase the chances of de-duplication happening, which could result in the wrong files being removed. Continuing in 2 minutes"
if [ "${warnings_acknowledged:=false}" = true ]; then
LogInfo "File deletion warning accepted"
else
sleep 120
fi
fi
if [ "${notification_type}" ]; then
ConfigureNotifications
fi
LogInfo "Downloading from: ${icloud_domain}"
if [ "${icloud_china}" = true ]; then
if [ "${auth_china}" = true ]; then
auth_domain="cn"
else
LogWarning "You have the icloud_china variable set, but auth_china is false. Are you sure this is correct?"
sleep 120
fi
fi
LogInfo "Authentication domain: ${auth_domain:=com}"
if [ "${nextcloud_upload}" = true ]; then
if [ "${nextcloud_url}" -a "${nextcloud_username}" -a "${nextcloud_password}" ]; then
LogInfo "Nextcloud upload: Enabled"
LogInfo "Nextcloud URL: ${nextcloud_url}"
LogInfo "Nextcloud Target Directory: ${nextcloud_target_dir}"
LogInfo "Nextcloud username: ${nextcloud_username}"
else
LogError "Nextcloud upload: Missing mandatory variables. Disabling"
unset nextlcoud_upload
fi
else
LogDebug "Nextcloud upload: Disabled"
fi
if [ "${synology_ignore_path}" = true ]; then
LogInfo "Ignore Synology extended attribute directories: Enabled"
ignore_path="*/@eaDir*"
else
LogInfo "Ignore Synology extended attribute directories: Disabled"
ignore_path=""
fi
source /opt/icloudpd/bin/activate
LogDebug "Activated Python virtual environment for icloudpd"
LogInfo "Container initialisation complete"
}
LogInfo(){
local log_message
log_message="${1}"
echo "$(date '+%Y-%m-%d %H:%M:%S') INFO ${log_message}"
}
LogInfoN(){
local log_message
log_message="${1}"
echo -n "$(date '+%Y-%m-%d %H:%M:%S') INFO ${log_message}... "
}
LogWarning(){
local log_message
log_message="${1}"
echo "$(date '+%Y-%m-%d %H:%M:%S') WARNING ${log_message}"
}
LogError(){
local log_message
log_message="${1}"
echo "$(date '+%Y-%m-%d %H:%M:%S') ERROR ${log_message}"
}
LogDebug(){
if [ "${debug_logging}" = true ]; then
local log_message
log_message="${1}"
echo "$(date '+%Y-%m-%d %H:%M:%S') DEBUG ${log_message}"
fi
}
run_as() {
local command_to_run
command_to_run="${1}"
if [ "$(id -u)" = 0 ]; then
su "${user}" -s /bin/ash -c "${command_to_run}"
else
/bin/ash -c "${command_to_run}"
fi
}
CleanNotificationTitle(){
if [ "${notification_title}" ]; then
notification_title="${notification_title//[^a-zA-Z0-9_ ]/}"
LogDebug "Cleaned notification title: ${notification_title}"
else
LogDebug "Notification title: ${notification_title:=boredazfcuk/iCloudPD}"
fi
}
ConfigureNotifications(){
if [ -z "${prowl_api_key}" -a -z "${pushover_token}" -a -z "${telegram_token}" -a -z "${webhook_id}" -a -z "${dingtalk_token}" -a -z "${discord_token}" -a -z "${iyuu_token}" -a -z "${wecom_secret}" -a -z "${gotify_app_token}" -a -z "${bark_device_key}" -a -z "${msmtp_pass}" ]; then
LogWarning "${notification_type} notifications enabled, but API key/token/secret not set - disabling notifications"
unset notification_type
else
if [ "${notification_type}" = "Prowl" -a "${prowl_api_key}" ]; then
LogInfo "${notification_type} notifications enabled"
CleanNotificationTitle
if [ "${debug_logging}" = true ]; then
LogDebug "${notification_type} api key: (hidden)"
else
LogInfo "${notification_type} api key: ${prowl_api_key}"
fi
notification_url="https://api.prowlapp.com/publicapi/add"
elif [ "${notification_type}" = "Pushover" -a "${pushover_user}" -a "${pushover_token}" ]; then
LogInfo "${notification_type} notifications enabled"
CleanNotificationTitle
if [ "${debug_logging}" = true ]; then
LogDebug "${notification_type} user: (hidden)"
LogDebug "${notification_type} token: (hidden)"
else
LogInfo "${notification_type} user: ${pushover_user}"
LogInfo "${notification_type} token: ${pushover_token}"
fi
if [ "${pushover_sound}" ]; then
case "${pushover_sound}" in
pushover|bike|bugle|cashregister|classical|cosmic|falling|gamelan|incoming|intermission|magic|mechanical|pianobar|siren|spacealarm|tugboat|alien|climb|persistent|echo|updown|vibrate|none)
LogDebug "${notification_type} sound: ${pushover_sound}"
;;
*)
LogDebug "${notification_type} sound not recognised. Using default"
unset pushover_sound
esac
fi
notification_url="https://api.pushover.net/1/messages.json"
elif [ "${notification_type}" = "Telegram" -a "${telegram_token}" -a "${telegram_chat_id}" ]; then
if [ "${telegram_server}" ] ; then
notification_url="https://${telegram_server}/bot${telegram_token}/sendMessage"
else
notification_url="https://api.telegram.org/bot${telegram_token}/sendMessage"
fi
LogInfo "${notification_type} notifications enabled"
CleanNotificationTitle
if [ "${debug_logging}" = true ]; then
LogDebug "${notification_type} token: (hidden)"
LogDebug "${notification_type} chat id: (hidden)"
LogDebug "${notification_type} polling: ${telegram_polling}"
LogDebug "${notification_type} notification URL: (hidden)"
else
LogInfo "${notification_type} token: ${telegram_token}"
LogInfo "${notification_type} chat id: ${telegram_chat_id}"
LogInfo "${notification_type} polling: ${telegram_polling}"
LogInfo "${notification_type} notification URL: ${notification_url}"
fi
if [ "${telegram_polling}" = true ]; then
telegram_update_id_offset_file="${config_dir}/telegram_update_id.num"
if [ ! -f "${telegram_update_id_offset_file}" ]; then
LogDebug "Creating Telegram Update ID offset file"
echo -n 0 > "${telegram_update_id_offset_file}"
fi
LogInfo "Check Telegram bot initialised..."
sleep "$((RANDOM % 15))"
if [ "${telegram_server}" ] ; then
LogDebug "Checking ${telegram_server} for updates"
bot_check="$(curl --silent -X POST "https://${telegram_server}/bot${telegram_token}/getUpdates" | jq -r .ok)"
else
LogDebug "Checking api.telegram.org for updates"
bot_check="$(curl --silent -X POST "https://api.telegram.org/bot${telegram_token}/getUpdates" | jq -r .ok)"
fi
LogDebug "Bot check: ${bot_check}"
if [ "${bot_check}" = true ]; then
LogInfo " - Bot has been initialised"
else
LogInfo " - Bot has not been initialised or needs reinitialising. Please send a message to the bot from your iDevice and restart the container. Disabling remote wake"
sleep 10
telegram_polling=false
fi
telegram_update_id_offset="$(head -1 ${telegram_update_id_offset_file})"
LogInfo "Latest update id: ${telegram_update_id_offset}"
fi
if [ "${telegram_silent_file_notifications}" ]; then telegram_silent_file_notifications=true; fi
LogDebug "${notification_type} silent file notifications: ${telegram_silent_file_notifications:=false}"
elif [ "${notification_type}" = "openhab" -a "${webhook_server}" -a "${webhook_id}" ]; then
if [ "${webhook_https}" = true ]; then
webhook_scheme="https"
else
webhook_scheme="http"
fi
LogInfo "${notification_type} notifications enabled"
LogDebug "${notification_type} server: ${webhook_server}"
LogDebug "${notification_type} port: ${webhook_port:=8123}"
LogDebug "${notification_type} path: ${webhook_path:=/rest/items/}"
LogDebug "${notification_type} ID: ${webhook_id}"
notification_url="${webhook_scheme}://${webhook_server}:${webhook_port}${webhook_path}${webhook_id}"
LogDebug "${notification_type} notification URL: ${notification_url}"
elif [ "${notification_type}" = "Webhook" -a "${webhook_server}" -a "${webhook_id}" ]; then
if [ "${webhook_https}" = true ]; then
webhook_scheme="https"
else
webhook_scheme="http"
fi
LogInfo "${notification_type} notifications enabled"
CleanNotificationTitle
LogDebug "${notification_type} server: ${webhook_server}"
LogDebug "${notification_type} port: ${webhook_port:=8123}"
LogDebug "${notification_type} path: ${webhook_path:=/api/webhook/}"
LogDebug "${notification_type} ID: ${webhook_id}"
notification_url="${webhook_scheme}://${webhook_server}:${webhook_port}${webhook_path}${webhook_id}"
LogDebug "${notification_type} notification URL: ${notification_url}"
LogDebug "${notification_type} body keyword: ${webhook_body:=data}"
elif [ "${notification_type}" = "Discord" -a "${discord_id}" -a "${discord_token}" ]; then
LogInfo "${notification_type} notifications enabled"
CleanNotificationTitle
if [ "${debug_logging}" = true ]; then
LogDebug "${notification_type} Discord ID: (hidden)"
LogDebug "${notification_type} Discord token: (hidden)"
notification_url="https://discord.com/api/webhooks/${discord_id}/${discord_token}"
LogDebug "${notification_type} notification URL: (hidden)"
else
LogInfo "${notification_type} Discord ID: ${discord_id}"
LogInfo "${notification_type} Discord token: ${discord_token}"
notification_url="https://discord.com/api/webhooks/${discord_id}/${discord_token}"
LogInfo "${notification_type} notification URL: ${notification_url}"
fi
elif [ "${notification_type}" = "Dingtalk" -a "${dingtalk_token}" ]; then
notification_url="https://oapi.dingtalk.com/robot/send?access_token=${dingtalk_token}"
LogInfo "${notification_type} notifications enabled"
if [ "${debug_logging}" = true ]; then
LogDebug "${notification_type} token: (hidden)"
LogDebug "${notification_type} notification URL: (hidden)"
else
LogInfo "${notification_type} token: ${dingtalk_token}"
LogInfo "${notification_type} notification URL: ${notification_url}"
fi
elif [ "${notification_type}" = "IYUU" -a "${iyuu_token}" ]; then
notification_url="http://iyuu.cn/${iyuu_token}.send?"
LogInfo "${notification_type} notifications enabled"
if [ "${debug_logging}" = true ]; then
LogDebug "${notification_type} token: (hidden)"
LogDebug "${notification_type} notification URL: (hidden)"
else
LogInfo "${notification_type} token: ${iyuu_token}"
LogInfo "${notification_type} notification URL: ${notification_url}"
fi
elif [ "${notification_type}" = "WeCom" -a "${wecom_id}" -a "${wecom_secret}" ]; then
wecom_base_url="https://qyapi.weixin.qq.com"
if [ "${wecom_proxy}" ]; then
wecom_base_url="${wecom_proxy}"
LogDebug "${notification_type} notifications proxy enabled : ${wecom_proxy}"
fi
user_agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"
if [ "${curl_user_agent}" ]; then
user_agent="${curl_user_agent}"
LogInfo "${notification_type} curl user_agnet : ${user_agent}"
fi
LogDebug "${notification_type} curl user_agnet : ${user_agent}"
wecom_token_url="${wecom_base_url}/cgi-bin/gettoken?corpid=${wecom_id}&corpsecret=${wecom_secret}"
wecom_token="$(/usr/bin/curl -s -G --user-agent "${user_agent}" "${wecom_token_url}" | awk -F\" '{print $10}')"
wecom_token_expiry="$(date --date='2 hour')"
notification_url="${wecom_base_url}/cgi-bin/message/send?access_token=${wecom_token}"
LogInfo "${notification_type} notifications enabled"
if [ "${debug_logging}" = true ]; then
LogDebug "${notification_type} token: (hidden)"
LogDebug "${notification_type} token expiry time: $(date -d "${wecom_token_expiry}")"
LogDebug "${notification_type} notification URL: (hidden)"
else
LogInfo "${notification_type} token: ${wecom_token}"
LogInfo "${notification_type} token expiry time: $(date -d "${wecom_token_expiry}")"
LogInfo "${notification_type} notification URL: ${notification_url}"
fi
elif [ "${notification_type}" = "Gotify" -a "${gotify_app_token}" -a "${gotify_server_url}" ]; then
if [ "${gotify_https}" = true ]; then
gotify_scheme="https"
else
gotify_scheme="http"
fi
LogInfo "${notification_type} notifications enabled"
CleanNotificationTitle
if [ "${debug_logging}" = true ]; then
LogDebug "${notification_type} token: (hidden)"
LogDebug "${notification_type} server URL: (hidden)"
else
LogInfo "${notification_type} token: ${gotify_app_token}"
LogInfo "${notification_type} server URL: ${gotify_scheme}://${gotify_server_url}"
fi
notification_url="${gotify_scheme}://${gotify_server_url}/message?token=${gotify_app_token}"
elif [ "${notification_type}" = "Bark" -a "${bark_device_key}" -a "${bark_server}" ]; then
LogInfo "${notification_type} notifications enabled"
CleanNotificationTitle
if [ "${debug_logging}" = true ]; then
LogDebug "${notification_type} device key: (hidden)"
LogDebug "${notification_type} server: (hidden)"
else
LogInfo "${notification_type} device key: ${bark_device_key}"
LogInfo "${notification_type} server: ${bark_server}"
fi
notification_url="http://${bark_server}/push"
elif [ "${notification_type}" = "msmtp" -a "${msmtp_host}" -a "${msmtp_port}" -a "${msmtp_user}" -a "${msmtp_pass}" ]; then
LogInfo "${notification_type} notifications enabled"
else
LogWarning "$(date '+%Y-%m-%d %H:%M:%S') WARINING ${notification_type} notifications enabled, but configured incorrectly - disabling notifications"
unset notification_type prowl_api_key pushover_user pushover_token telegram_token telegram_chat_id webhook_scheme webhook_server webhook_port webhook_id dingtalk_token discord_id discord_token iyuu_token wecom_id wecom_secret gotify_app_token gotify_scheme gotify_server_url bark_device_key bark_server
fi
if [ "${startup_notification}" = true ]; then
LogDebug "Startup notification: Enabled"
if [ "${icloud_china}" = false ]; then
Notify "startup" "iCloudPD container started" "0" "iCloudPD container now starting for Apple ID: ${apple_id}"
else
Notify "startup" "iCloudPD container started" "0" "启动成功,开始同步当前 Apple ID 中的照片" "" "" "" "开始同步 ${name} 的 iCloud 图库" "Apple ID: ${apple_id}"
fi
else
LogDebug "Startup notification: Disabled"
fi
if [ "${download_notifications}" = true ]; then
LogDebug "Download notifications: Enabled"
else
LogDebug "Download notifications: Disabled"
unset download_notifications
fi
if [ "${delete_notifications}" = true ]; then
LogDebug "Delete notifications: Enabled"
else
LogDebug "Delete notifications: Disabled"
unset delete_notifications
fi
fi
}
CreateGroup(){
if [ "$(grep -c "^${group}:x:${group_id}:" "/etc/group")" -eq 1 ]; then
LogDebug "Group, ${group}:${group_id}, already created"
else
LogDebug "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
LogError "Group name, ${group}, already in use - exiting"
sleep 120
exit 1
fi
LogDebug "Creating group ${group}:${group_id}"
groupadd --gid "${group_id}" "${group}"
fi
}
CreateUser(){
if [ "$(grep -c "^${user}:x:${user_id}:${group_id}" "/etc/passwd")" -eq 1 ]; then
LogDebug "User, ${user}:${user_id}, already created"
else
LogDebug "Creating minimal /etc/passwd file"
{
echo 'root:x:0:0:root:/root:/bin/sh'
} >/etc/passwd
LogDebug "Creating user ${user}:${user_id}"
useradd --shell /bin/ash --gid "${group_id}" --uid "${user_id}" "${user}" --home-dir "/home/${user}" --badname
fi
}
ListLibraries(){
local shared_libraries
if [ "${authentication_type}" = "MFA" ]; then
CheckMFACookie
else
CheckWebCookie
fi
IFS=$'\n'
if [ "${skip_download}" = false ]; then
shared_libraries="$(run_as "/opt/icloudpd/bin/icloudpd --username ${apple_id} --cookie-directory ${config_dir} --domain ${auth_domain} --directory /dev/null --list-libraries | sed '1d'")"
fi
LogInfo "Shared libraries:"
for library in ${shared_libraries}; do
LogInfo " - ${library}"
done
IFS="${save_ifs}"
}
ListAlbums(){
local photo_albums
if [ "${authentication_type}" = "MFA" ]; then
CheckMFACookie
else
CheckWebCookie
fi
IFS=$'\n'
if [ "${skip_download}" = false ]; then
photo_albums="$(run_as "/opt/icloudpd/bin/icloudpd --username ${apple_id} --cookie-directory ${config_dir} --domain ${auth_domain} --directory /dev/null --list-albums | sed '1d' | sed '/^Albums:$/d'")"
fi
LogInfo "Photo albums:"
for photo_album in ${photo_albums}; do
LogInfo " - ${photo_album}"
done
IFS="${save_ifs}"
}
DeletePassword(){
if [ -f "${config_dir}/python_keyring/keyring_pass.cfg" ]; then
LogWarning "Keyring file ${config_dir}/python_keyring/keyring_pass.cfg exists, but --remove-keyring command line switch has been invoked. Removing in 30 seconds"
if [ -z "${warnings_acknowledged}" ]; then
sleep 30
else
LogInfo "Warnings acknowledged, removing immediately"
fi
rm "${config_dir}/python_keyring/keyring_pass.cfg"
else
LogError "Keyring file does not exist"
fi
}
ConfigurePassword(){
LogDebug "Configure password"
if [ -f "${config_dir}/python_keyring/keyring_pass.cfg" ]; then
if [ "$(grep -c "=" "${config_dir}/python_keyring/keyring_pass.cfg")" -eq 0 ]; then
LogDebug "Keyring file ${config_dir}/python_keyring/keyring_pass.cfg exists, but does not contain any credentials. Removing"
rm "${config_dir}/python_keyring/keyring_pass.cfg"
fi
fi
if [ ! -f "${config_dir}/python_keyring/keyring_pass.cfg" ]; then
if [ "${initialise_container}" ]; then
LogDebug "Adding password to keyring file: ${config_dir}/python_keyring/keyring_pass.cfg"
run_as "/opt/icloudpd/bin/icloud --username ${apple_id} --domain ${auth_domain}"
else
LogError "Keyring file ${config_dir}/python_keyring/keyring_pass.cfg does not exist"
LogError " - Please add the your password to the system keyring using the --Initialise script command line option"
LogError " - Syntax: docker exec -it <container name> sync-icloud.sh --Initialise"
LogError " - Example: docker exec -it icloudpd sync-icloud.sh --Initialise"
LogError "Waiting for keyring file to be created..."
local counter
counter="${counter:=0}"
while [ ! -f "${config_dir}/python_keyring/keyring_pass.cfg" ]; do
sleep 5
counter=$((counter + 1))
if [ "${counter}" -eq 360 ]; then
LogError "Keyring file has not appeared within 30 minutes. Restarting container..."
exit 1
fi
done
LogDebug "Keyring file exists, continuing"
fi
else
LogDebug "Using password stored in keyring file: ${config_dir}/python_keyring/keyring_pass.cfg"
fi
if [ ! -f "${config_dir}/python_keyring/keyring_pass.cfg" ]; then
LogError "Keyring file does not exist. Please try again"
sleep 120
exit 1
fi
}
GenerateCookie(){
LogDebug "$(date '+%Y-%m-%d %H:%M:%S') INFO Correct owner on config directory, if required"
find "${config_dir}" ! -user "${user}" -exec chown "${user_id}" {} +
LogDebug "$(date '+%Y-%m-%d %H:%M:%S') INFO Correct group on config directory, if required"
find "${config_dir}" ! -group "${group}" -exec chgrp "${group_id}" {} +
if [ -f "${config_dir}/${cookie_file}" ]; then
mv "${config_dir}/${cookie_file}" "${config_dir}/${cookie_file}.bak"
fi
if [ -f "${config_dir}/${cookie_file}.session" ]; then
mv "${config_dir}/${cookie_file}.session" "${config_dir}/${cookie_file}session.bak"
fi
LogDebug "Generate ${authentication_type} cookie using password stored in keyring file"
# run_as "/opt/icloudpd/bin/icloudpd --username ${apple_id} --cookie-directory ${config_dir} --directory /dev/null --only-print-filenames --recent 0 --domain ${auth_domain}"
run_as "/opt/icloudpd/bin/icloudpd --username ${apple_id} --cookie-directory ${config_dir} --auth-only --domain ${auth_domain}"
if [ "${authentication_type}" = "MFA" ]; then
if [ "$(grep -c "X-APPLE-WEBAUTH-HSA-TRUST" "${config_dir}/${cookie_file}")" -eq 1 ]; then
LogInfo "Multifactor authentication cookie generated. Sync should now be successful"
else
LogError "Multifactor authentication information missing from cookie. Authentication has failed"
LogError " - Was the correct password entered?"
LogError " - Was the multifactor authentication code mistyped?"
LogError " - Can you log into ${icloud_domain} without receiving pop-up notifications?"
if [ "${icloud_china}" = true ]; then
LogError " - Are you based in China? You will need to set the icloud_china variable"
fi
fi
else
LogDebug "Web cookie generated. Sync should now be successful"
fi
}
CheckMount(){
LogInfo "Check download directory mounted correctly..."
if [ ! -f "${download_path}/.mounted" ]; then
LogWarning "Failsafe file ${download_path}/.mounted file is not present. Waiting for failsafe file to be created..."
local counter
counter="0"
fi
while [ ! -f "${download_path}/.mounted" ]; do
sleep 5
counter=$((counter + 1))
if [ "${counter}" -eq 360 ]; then
LogError "Failsafe file has not appeared within 30 minutes. Restarting container..."
exit 1
fi
done
LogInfo "Failsafe file ${download_path}/.mounted exists, continuing"
}
SetOwnerAndPermissionsConfig(){
LogDebug "Set owner and group on icloudpd temp directory"
chown -R "${user_id}:${group_id}" "/tmp/icloudpd"
LogDebug "Set owner and group on config directory"
chown -R "${user_id}:${group_id}" "${config_dir}"
if [ -d "${config_dir}/python_keyring/" ]; then
if [ "$(run_as "test -w ${config_dir}/python_keyring/; echo $?")" -eq 0 ]; then
LogInfo "Directory is writable: ${config_dir}/python_keyring/"
else
LogError "Directory is not writable: ${config_dir}/python_keyring/"
sleep 120
exit 1
fi
fi
}
SetOwnerAndPermissionsDownloads(){
LogDebug "Set owner on iCloud directory, if required"
find "${download_path}" ! -type l ! -user "${user_id}" ! -path "${ignore_path}" -exec chown "${user_id}" {} +
LogDebug "Set group on iCloud directory, if required"
find "${download_path}" ! -type l ! -group "${group_id}" ! -path "${ignore_path}" -exec chgrp "${group_id}" {} +
LogDebug "Set ${directory_permissions} permissions on iCloud directories, if required"
find "${download_path}" -type d ! -perm "${directory_permissions}" ! -path "${ignore_path}" -exec chmod "${directory_permissions}" '{}' +
LogDebug "Set ${file_permissions} permissions on iCloud files, if required"
find "${download_path}" -type f ! -perm "${file_permissions}" ! -path "${ignore_path}" -exec chmod "${file_permissions}" '{}' +
}
check_permissions(){
if [ "$(run_as ${user} "if ! test -w \"${download_path}\"; then echo false; fi")" = false ]; then
LogWarning "User ${user}:${user_id} cannot write to directory: ${download_path} - Attempting to set permissions"
SetOwnerAndPermissionsDownloads
if [ "$(run_as ${user} "if ! test -w \"${download_path}\"; then echo false; fi")" = false ]; then
LogError "User ${user}:${user_id} still cannot write to directory: ${download_path}"
LogError " - Fixing permissions failed - Cannot continue, exiting"
sleep 120
exit 1
fi
fi
}
CheckKeyringExists(){
if [ -f "${config_dir}/python_keyring/keyring_pass.cfg" ]; then
LogInfo "Keyring file exists, continuing"
else
LogError "Keyring does not exist"
LogError " - Please add your password to the system keyring by using the --Initialise script command line option"
LogError " - Syntax: docker exec -it <container name> sync-icloud.sh --Initialise"
LogError " - Example: docker exec -it icloudpd sync-icloud.sh --Initialise"
LogError "Waiting for keyring file to be created..."
local counter
counter="${counter:=0}"
while [ ! -f "${config_dir}/python_keyring/keyring_pass.cfg" ]; do
sleep 5
counter=$((counter + 1))
if [ "${counter}" -eq 360 ]; then
LogError "Keyring file has not appeared within 30 minutes. Restarting container..."
exit 1
fi
done
LogInfo "Keyring file exists, continuing"
fi
}
WaitForCookie(){
if [ "${1}" = "DisplayMessage" ]; then
LogError "Waiting for valid cookie file to be created..."
LogError " - Please create your cookie using the --Initialise script command line option"
LogError " - Syntax: docker exec -it <container name> sync-icloud.sh --Initialise"
LogError " - Example: docker exec -it icloudpd sync-icloud.sh --Initialise"
fi
local counter
counter="${counter:=0}"
while [ ! -f "${config_dir}/${cookie_file}" ]; do
sleep 5
counter=$((counter + 1))
if [ "${counter}" -eq 360 ]; then
LogError "Valid cookie file has not appeared within 30 minutes. Restarting container..."
exit 1
fi
done
}
WaitForAuthentication(){
local counter
counter="${counter:=0}"
while [ "$(grep -c "X-APPLE-WEBAUTH-HSA-TRUST" "${config_dir}/${cookie_file}")" -eq 0 ]; do
sleep 5
counter=$((counter + 1))
if [ "${counter}" -eq 360 ]; then
LogError "Valid cookie file has not appeared within 30 minutes. Restarting container..."
exit 1
fi
done
}
CheckWebCookie(){
if [ -f "${config_dir}/${cookie_file}" ]; then
LogDebug "Web cookie exists"
web_cookie_expire_date="$(grep "X_APPLE_WEB_KB" "${config_dir}/${cookie_file}" | sed -e 's#.*expires="\(.*\)Z"; HttpOnly.*#\1#')"
else
LogError "Web cookie does not exist"
WaitForCookie DisplayMessage
LogInfo "Cookie file exists, continuing"
fi
}
CheckMFACookie(){
if [ -f "${config_dir}/${cookie_file}" ]; then
LogDebug "Multifactor authentication cookie exists"
else
LogError "Multifactor authentication cookie does not exist"
WaitForCookie DisplayMessage
LogDebug "Multifactor authentication cookie file exists, checking validity..."
fi
if [ "$(grep -c "X-APPLE-DS-WEB-SESSION-TOKEN" "${config_dir}/${cookie_file}")" -eq 1 -a "$(grep -c "X-APPLE-WEBAUTH-HSA-TRUST" "${config_dir}/${cookie_file}")" -eq 0 ]; then
LogDebug "Multifactor authentication cookie exists, but not autenticated. Waiting for authentication to complete..."
WaitForAuthentication
LogDebug "Multifactor authentication authentication complete, checking expiry date..."
fi
if [ "$(grep -c "X-APPLE-WEBAUTH-PCS-Photos" "${config_dir}/${cookie_file}")" -eq 1 ]; then
mfa_expire_date="$(grep "X-APPLE-WEBAUTH-PCS-Photos" "${config_dir}/${cookie_file}" | sed -e 's#.*expires="\(.*\)Z"; HttpOnly.*#\1#')"
mfa_expire_seconds="$(date -d "${mfa_expire_date}" '+%s')"
days_remaining="$(($((mfa_expire_seconds - $(date '+%s'))) / 86400))"
echo "${days_remaining}" > "${config_dir}/DAYS_REMAINING"
if [ "${days_remaining}" -gt 0 ]; then
valid_mfa_cookie=true
LogDebug "Valid multifactor authentication cookie found. Days until expiration: ${days_remaining}"
else
rm -f "${config_dir}/${cookie_file}"
LogError "Cookie expired at: ${mfa_expire_date}"
LogError "Expired cookie file has been removed. Restarting container in 5 minutes"
sleep 300
exit 1
fi
else
rm -f "${config_dir}/${cookie_file}"
LogError "Cookie is not multifactor authentication capable, authentication type may have changed"
LogError "Invalid cookie file has been removed. Restarting container in 5 minutes"
sleep 300
exit 1
fi
}
DisplayMFAExpiry(){
local error_message
LogInfo "Multifactor authentication cookie expires: ${mfa_expire_date/ / @ }"
LogInfo "Days remaining until expiration: ${days_remaining}"
if [ "${days_remaining}" -le "${notification_days}" ]; then
if [ "${days_remaining}" -eq 1 ]; then
cookie_status="cookie expired"
if [ "${icloud_china}" = false ]; then
error_message="Final day before multifactor authentication cookie expires for Apple ID: ${apple_id} - Please reinitialise now. This is your last reminder"
else
error_message="今天是 ${name} 的 Apple ID 两步验证 cookie 到期前的最后一天 - 请立即重新初始化,这是最后的提醒"
fi
else
cookie_status="cookie expiration"
if [ "${icloud_china}" = false ]; then
error_message="Only ${days_remaining} days until multifactor authentication cookie expires for Apple ID: ${apple_id} - Please reinitialise"
else
error_message="${days_remaining} 天后 ${name} 的 Apple ID 两步验证将到期 - 请立即重新初始化"
fi
fi
LogWarning "${error_message}"
if [ "${synchronisation_time:=$(date +%s -d '+15 minutes')}" -gt "${next_notification_time:=$(date +%s)}" ]; then
if [ "${icloud_china}" = false ]; then
Notify "${cookie_status}" "Multifactor Authentication Cookie Expiration" "2" "${error_message}"
else
Notify "${cookie_status}" "Multifactor Authentication Cookie Expiration" "2" "${error_message}" "" "" "" "${days_remaining} 天后,${name} 的身份验证到期" "${error_message}"
fi
next_notification_time="$(date +%s -d "+24 hour")"
LogDebug "Next notification not before: $(date +%H:%M:%S -d "${next_notification_time} seconds")"
fi
fi
}
CheckFiles(){
if [ -f "/tmp/icloudpd/icloudpd_check.log" ]; then
rm "/tmp/icloudpd/icloudpd_check.log"
fi
LogInfo "Check for new files using password stored in keyring file"
LogInfo "Generating list of files in iCloud. This may take a long time if you have a large photo collection. Please be patient. Nothing is being downloaded at this time"
LogDebug "Launch command: /opt/icloudpd/bin/icloudpd --directory ${download_path} --cookie-directory ${config_dir} --username ${apple_id} --domain ${auth_domain} --folder-structure ${folder_structure} --only-print-filenames"
>/tmp/icloudpd/icloudpd_check_error
run_as "(/opt/icloudpd/bin/icloudpd --directory ${download_path} --cookie-directory ${config_dir} --username ${apple_id} --domain ${auth_domain} --folder-structure ${folder_structure} --only-print-filenames 2>/tmp/icloudpd/icloudpd_check_error; echo $? >/tmp/icloudpd/icloudpd_check_exit_code) | tee /tmp/icloudpd/icloudpd_check.log"
check_exit_code="$(cat /tmp/icloudpd/icloudpd_check_exit_code)"
if [ "${check_exit_code}" -ne 0 ] || [ -s /tmp/icloudpd/icloudpd_check_error ]; then
LogError "Failed check for new files files"
LogError " - Can you log into ${icloud_domain} without receiving pop-up notifications?"
LogError "Error debugging info:"
LogError "$(cat /tmp/icloudpd/icloudpd_check_error)"
if [ "${debug_logging}" != true ]; then
LogError "Please set debug_logging=true in your icloudpd.conf file then reproduce the error"
LogError "***** Once you have captured this log file, please post it along with a description of your problem, here: https://github.com/boredazfcuk/docker-icloudpd/issues *****"
else
LogError "***** Please post the above debug log, along with a description of your problem, here: https://github.com/boredazfcuk/docker-icloudpd/issues *****"
fi
if [ "${icloud_china}" = false ]; then
Notify "failure" "iCloudPD container failure" "0" "iCloudPD failed check for new files for Apple ID: ${apple_id}"
else
syn_end_time="$(date '+%H:%M:%S')"
syn_next_time="$(date +%H:%M:%S -d "${synchronisation_interval} seconds")"
Notify "failure" "iCloudPD container failure" "0" "检查 iCloud 图库新照片失败,将在 ${syn_next_time} 再次尝试" "" "" "" "检查 ${name} 的 iCloud 图库新照片失败" "将在 ${syn_next_time} 再次尝试"
fi
else
LogInfo "Check successful"
check_files_count="$(wc --lines /tmp/icloudpd/icloudpd_check.log | awk '{print $1}')"
if [ "${check_files_count}" -gt 0 ]; then
LogInfo "New files detected: ${check_files_count}"
else
LogInfo "No new files detected. Nothing to download"
fi
fi
login_counter=$((login_counter + 1))
}
DownloadedFilesNotification(){
local new_files_count new_files_preview new_files_text
new_files="$(grep "Downloaded /" /tmp/icloudpd/icloudpd_sync.log)"
new_files_count="$(grep -c "Downloaded /" /tmp/icloudpd/icloudpd_sync.log)"
if [ "${new_files_count:=0}" -gt 0 ]; then
LogInfo "New files downloaded: ${new_files_count}"
new_files_preview="$(echo "${new_files}" | cut -d " " -f 9- | sed -e "s%${download_path}/%%g" | head -10)"
new_files_preview_count="$(echo "${new_files_preview}" | wc -l)"
if [ "${icloud_china}" = false ]; then
new_files_text="Files downloaded for Apple ID ${apple_id}: ${new_files_count}"
Notify "downloaded files" "New files detected" "0" "${new_files_text}" "${new_files_preview_count}" "downloaded" "${new_files_preview}"
else
# 结束时间、下次同步时间
syn_end_time="$(date '+%H:%M:%S')"
syn_next_time="$(date +%H:%M:%S -d "${synchronisation_interval} seconds")"
new_files_text="iCloud 图库同步完成,新增 ${new_files_count} 张照片"
Notify "downloaded files" "New files detected" "0" "${new_files_text}" "${new_files_preview_count}" "下载" "${new_files_preview}" "新增 ${new_files_count} 张照片 - ${name}" "下次同步时间 ${syn_next_time}"
fi
fi
}
DeletedFilesNotification(){
local deleted_files deleted_files_count deleted_files_preview deleted_files_text
deleted_files="$(grep "Deleted /" /tmp/icloudpd/icloudpd_sync.log)"
deleted_files_count="$(grep -c "Deleted /" /tmp/icloudpd/icloudpd_sync.log)"
if [ "${deleted_files_count:=0}" -gt 0 ]; then
LogInfo "Number of files deleted: ${deleted_files_count}"
deleted_files_preview="$(echo "${deleted_files}" | cut -d " " -f 9- | sed -e "s%${download_path}/%%g" -e "s%!$%%g" | tail -10)"
deleted_files_preview_count="$(echo "${deleted_files_preview}" | wc -l)"
if [ "${icloud_china}" = false ]; then
deleted_files_text="Files deleted for Apple ID ${apple_id}: ${deleted_files_count}"
Notify "deleted files" "Recently deleted files detected" "0" "${deleted_files_text}" "${deleted_files_preview_count}" "deleted" "${deleted_files_preview}"
else
# 结束时间、下次同步时间
syn_end_time="$(date '+%H:%M:%S')"
syn_next_time="$(date +%H:%M:%S -d "${synchronisation_interval} seconds")"
deleted_files_text="iCloud 图库同步完成,删除 ${deleted_files_count} 张照片"
Notify "deleted files" "Recently deleted files detected" "0" "${deleted_files_text}" "${deleted_files_preview_count}" "删除" "${deleted_files_preview}" "删除 ${deleted_files_count} 张照片 - ${name}" "下次同步时间 ${syn_next_time}"
fi
fi
}
DownloadAlbums(){
local all_albums albums_to_download log_level
if [ "${photo_album}" = "all albums" ]; then
all_albums="$(run_as "/opt/icloudpd/bin/icloudpd --username ${apple_id} --cookie-directory ${config_dir} --domain ${auth_domain} --directory /dev/null --list-albums | sed '1d' | sed '/^Albums:$/d'")"
LogDebug "Buildling list of albums to download..."
IFS=$'\n'
for album in ${all_albums}; do
if [ "${skip_album}" ]; then
if [[ ! "${skip_album}" =~ "${album}" ]]; then