Skip to content

Instantly share code, notes, and snippets.

@TheComputerGuy96
Created March 1, 2022 07:46
Show Gist options
  • Save TheComputerGuy96/7b1806197eb182b33dc75f34be9f11fc to your computer and use it in GitHub Desktop.
Save TheComputerGuy96/7b1806197eb182b33dc75f34be9f11fc to your computer and use it in GitHub Desktop.
Programa kuri pateikia informaciją apie galimybių paso QR kodą
#!/bin/bash
LC_TIME=lt_LT.UTF-8
LANG=lt_LT.UTF-8
TZ=Europe/Vilnius
done=false
tmpfile=`mktemp /tmp/covid.XXXXX`
progmissing=false
for programs in zbarcam zbarimg base45 awk identify sed jq mktemp grep file; do
if ! command -v "${programs}" > /dev/null; then
"${done}" || echo "Reikalingos programos nesurastos"
echo "Įrašykite šitas: ${programs}"
done=true
progmissing=true
fi
done
"${progmissing}" && exit 1
if [ -z "$1" ]; then
echo "Parodykite QR kodą..."
if [ -z "${DISPLAY}" ] || [ ! -z "${DISPLAY}" ] && [ ! -z "${WAYLAND_DISPLAY}" ]; then
input=`zbarcam -1 --raw --nodisplay 2>/dev/null`
else
input=`zbarcam -1 --raw 2>/dev/null`
fi
elif [ "$1" == "--pagalba" ]; then
echo "Naudojimas:"; echo
echo " $0 <paso QR kodo nuotraukos failas/QR kodo informacija>"; echo
echo " Jei nuotrauka/QR kodo informacija/jos failas nenurodyta(-s), tai paso QR kodas bus"
echo " skaitomas iš kompiuterio kameros."
exit 1
elif identify "$1" > /dev/null 2>/dev/null; then
input=`zbarimg -1 --raw "$1" 2>/dev/null`
elif file "$1" > /dev/null && grep -FqI '' "$1" 2>/dev/null; then
input=`cat "$1"`
elif echo "$1" > "${tmpfile}"; grep -FqI '' "${tmpfile}"; then
input="$1"
rm "${tmpfile}"
fi
base45=$(echo "${input}" | sed 's/^[0-9]*\$//' | head -c `awk '{print int($1)}' <(echo "${input}")`)
json=$(echo "${base45}" | base45 --decode)
fn=`echo ${json} | jq -r .fn | awk '{$i=substr($1,1,1)tolower(substr($i,2))}1'`
ln=`echo ${json} | jq -r .ln | awk '{$i=substr($1,1,1)tolower(substr($i,2))}1'`
by=`echo ${json} | jq .by`
iss=`echo ${json} | jq .iss`
vt=`echo ${json} | jq .vt`
t=`echo ${json} | jq -r .t`
[ -z "$1" ] && echo
echo "Paso informacija:"; echo
echo " Vardas: ${fn}"
echo " Pavardė: ${ln}"
echo " Gimimo metai: ${by}"
echo " Išdavimo data: `date -d @$((${iss} / 1000))`"
echo " Galiojimo pabaigos data: `date -d @$((${vt} / 1000))`"
echo " Nežinoma informacija: ${t}"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment