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.

48 lines
1.7 KiB

#!/bin/bash
# Script for label printing by angestöpselt e.V.
# v0.1
######### YOUR SETTINGS HERE #########
PRINTER_IP=<PRINTER_IP>
PXESERVER_IP=<PXESERVER_IP>
######### DON'T CHANGE ANYTHING BELOW THIS LINE #########
read -n 5 -p "Bitte trage die Rechner/Asset Nummer ein. Bitte schreibe 5 Ziffern (inkl. führender Nullen): " asset_tag
API_KEY=$(curl tftp:/${PXESERVER_IP}/legacy/.api_key)
jason_var=`curl --request GET \
--url https://orga.z31.it/api/v1/hardware/bytag/$asset_tag \
--header 'authorization: Bearer '$API_KEY''`
name=$(echo $jason_var | jq -r '.name') #name for printing
asset=$(echo $jason_var | jq -r '.asset_tag') # asset_tag from api call
status=$(echo $jason_var | jq -r '.status') # if something goes wrong, the value is error
errormessage=$(echo $jason_var | jq -r '.messages') # contains error message
if [[ $asset_tag == $asset ]]; then
cat > $HOME/cFoygpkhU4HrT6A4er8sFyTV82W6ykaX.html <<EOL
<div>
<p style="float: left;"><img src="http://${PXESERVER_IP}/angestoepselt.png" height="80px" width="80px"></p>
</div>
<div>
<p style="font-size:15px">angestoepselt e.V.<br>Passwort: csw</p>
<b> <p style="font-size:23px"><b>RE${asset_tag}</p></b>
<p style="margin-left:5%; font-size:12px;">${name}</p>
</div>
EOL
## prepare for printing
wkhtmltopdf --page-height 36mm --page-width 89mm $HOME/cFoygpkhU4HrT6A4er8sFyTV82W6ykaX.html $HOME/cFoygpkhU4HrT6A4er8sFyTV82W6ykaX.pdf
## print the label
lpr -H ${PRINTER_IP}:631 -P DYMO -o landscape $HOME/cFoygpkhU4HrT6A4er8sFyTV82W6ykaX.pdf
## housekeeping
rm $HOME/cFoygpkhU4HrT6A4er8sFyTV82W6ykaX.*
else
echo "das hat nicht geklappt: ${errormessage}"
echo "führe das Script erneut aus ./label_print.sh"
fi