forked from boredazfcuk/docker-icloudpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
healthcheck.sh
45 lines (44 loc) · 2.02 KB
/
healthcheck.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
#!/bin/ash
if [ -f "/tmp/icloudpd/icloud_check_exit_code" ] || [ -f "/tmp/icloudpd/icloud_download_exit_code}" ]; then
if [ -f "/tmp/icloudpd/icloud_download_exit_code}" ]; then
download_exit_code="$(cat /tmp/icloudpd/icloud_download_exit_code)"
if [ "${download_exit_code}" -ne 0 ]; then
echo "File download error: ${download_exit_code}"
exit 1
fi
fi
if [ -f "/tmp/icloudpd/icloud_check_exit_code" ]; then
check_exit_code="$(cat /tmp/icloudpd/icloud_check_exit_code)"
if [ "${check_exit_code}" -ne 0 ]; then
echo "File check error: ${check_exit_code}"
exit 1
fi
fi
fi
cookie="$(echo -n "${apple_id//[^a-zA-Z0-9_]}" | tr '[:upper:]' '[:lower:]')"
if [ ! -f "${config_dir}/${cookie}" ]; then
echo "Error: Cookie does not exist. Please generate new cookie"
exit 1
fi
if [ "${authentication_type:=2FA}" = "2FA" ]; then
twofa_expire_date="$(grep "X-APPLE-WEBAUTH-HSA-TRUST" "${config_dir}/${cookie}" | sed -e 's#.*expires="\(.*\)Z"; HttpOnly.*#\1#')"
twofa_expire_seconds="$(date -d "${twofa_expire_date}" '+%s')"
days_remaining="$(($((twofa_expire_seconds - $(date '+%s'))) / 86400))"
if [ -z "${notification_days}" ]; then notification_days=7; fi
if [ "${days_remaining}" -lt "${notification_days}" ]; then
echo "Warning: Two-factor authentication cookie is due for renewal in ${notification_days} days"
exit 1
elif [ "${days_remaining}" -lt 1 ]; then
echo "Error: Two-factor authentication cookie has expired"
exit 1
fi
elif [ "${authentication_type}" = "Web" ]; then
web_cookie_expire_date="$(grep "X_APPLE_WEB_KB" "${config_dir}/${cookie}" | sed -e 's#.*expires="\(.*\)Z"; HttpOnly.*#\1#')"
web_cookie_expire_seconds="$(date -d "${web_cookie_expire_date}" '+%s')"
days_remaining="$(($((web_cookie_expire_seconds - $(date '+%s'))) / 86400))"
else
echo "Error: Authentication type not recognised"
exit 1
fi
echo "iCloud Photos Downloader successful and ${authentication_type} cookie valid for ${days_remaining} day(s)"
exit 0