-
Notifications
You must be signed in to change notification settings - Fork 176
/
healthcheck.sh
executable file
·80 lines (73 loc) · 2.5 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
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
#!/bin/bash
source "/config/icloudpd.conf"
if [ -f "/tmp/icloudpd/icloudpd_check_exit_code" ] || [ -f "/tmp/icloudpd/icloudpd_download_exit_code" ]
then
if [ -f "/tmp/icloudpd/icloudpd_download_exit_code" ]
then
download_exit_code="$(cat /tmp/icloudpd/icloudpd_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/icloudpd_check_exit_code" ]
then
check_exit_code="$(cat /tmp/icloudpd/icloudpd_check_exit_code)"
if [ "${check_exit_code}" -ne 0 ]
then
echo "File check error: ${check_exit_code}"
exit 1
fi
fi
else
echo "Error check files missing."
exit 1
fi
if [ -s "/tmp/icloudpd/icloudpd_check_error" ] || [ -s "/tmp/icloudpd/icloudpd_download_error" ]
then
if [ -f "/tmp/icloudpd/icloudpd_check_error" ]
then
echo "Errors reported during file check"
exit 1
fi
if [ -s "/tmp/icloudpd/icloudpd_download_error" ]
then
echo "Errors reported during file download"
exit 1
fi
fi
cookie="$(echo -n "${apple_id//[^a-zA-Z0-9_]}" | tr '[:upper:]' '[:lower:]')"
if [ ! -f "/config/${cookie}" ]
then
echo "Error: Cookie does not exist. Please generate new cookie"
exit 1
fi
if [ "${authentication_type:=MFA}" = "MFA" ]
then
mfa_expire_date="$(grep "X-APPLE-DS-WEB-SESSION-TOKEN" "/config/${cookie}" | sed -e 's#.*expires="\(.*\)Z"; HttpOnly.*#\1#')"
mfa_expire_seconds="$(date -d "${mfa_expire_date}" '+%s')"
days_remaining="$(($((mfa_expire_seconds - $(date '+%s'))) / 86400))"
if [ -z "${notification_days}" ]
then
notification_days=7
fi
if [ "${days_remaining}" -le "${notification_days}" ] && [ "${days_remaining}" -ge 1 ]
then
echo "Warning: Multi-factor authentication cookie is due for renewal in ${notification_days} days"
elif [ "${days_remaining}" -lt 1 ]
then
echo "Error: Multi-factor authentication cookie has expired"
exit 1
fi
elif [ "${authentication_type}" = "Web" ]
then
web_cookie_expire_date="$(grep "X_APPLE_WEB_KB" "/config/${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