-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabel-gen
More file actions
executable file
·71 lines (58 loc) · 1.98 KB
/
Copy pathlabel-gen
File metadata and controls
executable file
·71 lines (58 loc) · 1.98 KB
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
#!/bin/bash
# Check if Inkscape and barcode are installed
if ! command -v inkscape &> /dev/null || ! command -v barcode &> /dev/null
then
echo "inkscape and/or barcode are not installed. Please install them and try again."
exit 1
fi
# Check if correct number of arguments are provided
if [ "$#" -lt 3 ]; then
echo "Usage: $0 <serial_number> <model_number> <quantity> [-s]"
exit 1
fi
SERIAL_NUMBER=$1
MODEL_NUMBER=$2
QUANTITY=$3
SKIP_PRINT=$4
# Validate quantity to prevent printing too many from a typo
if ((QUANTITY < 0 || > 9)) then
echo "Please only print between 1 and 9 labels at a time."
exit 1
fi
if ((QUANTITY == 0)) then
echo "Please use -s flag to skip printing."
exit 1
fi
# Generate barcode
barcode -b "${MODEL_NUMBER},${SERIAL_NUMBER}" -o barcode.svg -g 282.5x37.5+0+0 -S -n
# Create the main SVG file with the required content
cat << EOF > temp_label.svg
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" width="450" height="150">
<rect width="100%" height="100%" fill="white"/>
<g transform="translate(20, 0)">
$(cat barcode.svg | grep -v '<?xml' | grep -v '<svg' | grep -v '</svg>')
</g>
<text x="0" y="65" font-family="sans-serif" font-size="25" fill="black">
<tspan x="15" dy="1.3em">Model: ${MODEL_NUMBER}</tspan>
<tspan x="15" dy="1.1em">S/N: ${SERIAL_NUMBER}</tspan>
</text>
<text x="0" y="80" font-family="sans-serif" font-size="30" fill="black">
<tspan x="230" dy="1.3em">Made in USA</tspan>
</svg>
EOF
# Convert the SVG to PDF
inkscape temp_label.svg --export-pdf=label_${SERIAL_NUMBER}.pdf
# Clean up files
rm barcode.svg temp_label.svg
# Print the label
if [ "${SKIP_PRINT}" == "-s" ]; then
echo "Skipping print/delete"
exit 0
fi
for i in $(seq 1 $QUANTITY);
do
lp label_${SERIAL_NUMBER}.pdf -d Zebra_Technologies_ZTC_ZD411-300dpi_ZPL -o fit-to-page
done
rm label_${SERIAL_NUMBER}.pdf
echo "Printed ${QUANTITY} label(s) for ${MODEL_NUMBER} with serial number: ${SERIAL_NUMBER}"