Automatic COVID SAfe check-in script for South Australia. Intended to be executed automatically upon login on a work computer.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
auto_COVID_SAfe_checkin.sh/auto_COVID_SAfe_checkin.sh

69 lines
3.6 KiB

#!/bin/bash
# Uncomment & put your mobile verification token here (unless you have it set as a global variable):
#COVID_API_TOKEN=""
# To get your COVID_API_TOKEN, fill in your number and run this command:
#curl 'https://api.sa.gov.au/covid-venue-checkin/v1/begin-mobile-verification?mobileNumber=61400000000' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://checkin.covid-19.sa.gov.au/' -H 'Origin: https://checkin.covid-19.sa.gov.au' -H 'Connection: keep-alive'
# You will receive a verification code by SMS. Fill it in here along with your mobile number and you will get your COVID_API_TOKEN:
#curl 'https://api.sa.gov.au/covid-venue-checkin/v1/complete-mobile-verification?mobileNumber=61400000000&verificationCode=000000' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://checkin.covid-19.sa.gov.au/' -H 'Origin: https://checkin.covid-19.sa.gov.au' -H 'Connection: keep-alive'
# IDK, figure this out yourself. You can find all the important data in the the venue QR code.
JSON_PAYLOAD='{"firstName":"","lastName":"","planId":"","businessName":"","businessAddress":null}'
############################### END USER CONFIGS ###############################
# File used to store the last check-in time
status_file="$HOME/.covid-safe-last-check-in"
# ANSI escape colour codes
COLOUR_ERROR='\e[97m\e[41m\e[1m\e[5m' # Flashing bold white text on a red background
COLOUR_SUCCESS='\e[97m\e[42m' # White text, green background
COLOUR_END='\033[0m' # Reset ANSI colours to default
function displaytime { # Stolen from here: https://unix.stackexchange.com/a/27014
local T=$1
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
(( $D > 0 )) && printf '%d days ' $D
(( $H > 0 )) && printf '%d hours ' $H
(( $M > 0 )) && printf '%d minutes ' $M
(( $D > 0 || $H > 0 || $M > 0 )) && printf 'and '
printf '%d seconds' $S
}
if [ -z ${COVID_API_TOKEN+x} ]; then
printf "${COLOUR_ERROR}No COVID_API_TOKEN supplied${COLOUR_END}"
exit 1
fi
if [ ! -f "$status_file" ]; then
printf "Status file doesn't exist, creating it now."
touch --date=@0 "$status_file"
fi
last_checkin=$(stat -c %Y "$status_file")
time_since_last_checkin=$(( $(date +%s) - $last_checkin ))
printf "Last checkin-in was " ; displaytime $time_since_last_checkin ; printf " ago.\n"
if [ $time_since_last_checkin -gt 18000 ]; then # 5 hours between check-ins
if [ ! -z ${SSH_CONNECTION+x} ]; then # Don't check-in if SSH session
printf "${COLOUR_ERROR}You are connected via SSH. You will not be checked-in.${COLOUR_END}\n"
exit 1
fi
curl 'https://api.sa.gov.au/covid-venue-checkin/v1/checkin' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://checkin.covid-19.sa.gov.au/' -H 'Content-Type: application/json;charset=utf-8' -H "Authorization: Bearer $COVID_API_TOKEN" -H 'Origin: https://checkin.covid-19.sa.gov.au' -H 'Connection: keep-alive' --data-raw "$JSON_PAYLOAD"
exit=$?
if [ "$exit" -eq 0 ]; then
printf "${COLOUR_SUCCESS}Successfully checked-in${COLOUR_END}\n"
touch "$status_file"
else
printf "${COLOUR_ERROR}[Error][Error][Error][Error][Error][Error]${COLOUR_END}\n"
fi
fi