-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.sh
executable file
·37 lines (33 loc) · 951 Bytes
/
cli.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
#!/usr/bin/env bash
HOST="$1"
if [ -z "$HOST" ];then
cat README.md | sed -n '/Cli Usage/,//p'
exit 1
fi
shift
DAYS=15
if [ "$1" = "--days" ]; then
DAYS="$2"
shift 2
fi
set -eu
scriptDir="$(test -L "$0" && dirname "$(readlink -f "$0" 2> /dev/null)" || echo './')"
leftDays="$("$scriptDir/index-cli.js" $HOST)"
# echo "HOST:$HOST"
# echo "DAYS:$DAYS"
# echo "curlOpts:$@"
msg="[$(date +"%Y-%m-%dT%H:%M:%S%z")] Checking $HOST: Expires in $leftDays days"
if [[ "$leftDays" -lt "$DAYS" ]]; then
if [[ $# -gt 0 ]]; then
curlOpts=()
for arg in "$@"; do
arg="${arg/\$CHECK_CERT_HOST/$HOST}"
arg="${arg/\$CHECK_CERT_DAYS/$leftDays}"
curlOpts+=("$arg")
done
echo -e "\n[$(date +"%Y-%m-%dT%H:%M:%S%z")] ${curlOpts[@]}" >> /tmp/check-cert-request.log
curl -sq "${curlOpts[@]}" >> /tmp/check-cert-request.log 2>&1
msg="$msg [notified]"
fi
fi
echo $msg