added autostart script

master
Jan Umbach 2023-07-31 20:44:45 +02:00
parent 97197b6cbe
commit cc254d58c6
7 changed files with 59 additions and 5 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
label.png
.venv/
tmp/

View File

@ -1,6 +1,8 @@
# Install
sh install.sh
**Warning: there are dependency problems. And if it is fixed in some time, it may not install properly!**
# Install, run and put into autostart
sh setup_autostart.sh
# run
sh start.sh
If started it will watch the `~/Downloads` folder and prints automaticly all `label.pdf` and `label_rot90.pdf`.

View File

@ -4,9 +4,11 @@ BASEDIR=$(dirname "$0")
echo "installing LabelPrinting in $BASEDIR"
cd $BASEDIR
mkdir tmp
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
pip install --force-reinstall -v "Pillow==9.5.0"
echo "Done"
echo "Done"

View File

@ -0,0 +1,13 @@
[Unit]
Description=Label Printing Service
After=network.target
[Service]
Type=simple
User={user}
WorkingDirectory={dir}
ExecStart=/bin/bash {dir}/start.sh
Restart=always
[Install]
WantedBy=multi-user.target

View File

@ -36,7 +36,7 @@ def printPDF(path):
for page in pages:
try:
page.save('label.png', 'PNG')
page.save('tmp/label.png', 'PNG')
pngHeight = page.height
if (path == labelPathRot90):
@ -57,11 +57,11 @@ def printPDF(path):
# box=(left, upper, right, lower)
page.crop((0, spacing, page.width, h-spacing)
).save('label.png', 'PNG')
).save('tmp/label.png', 'PNG')
if (labelHeight != 0):
os.system('brother_ql -m QL-1060N -p ' +
printer_identifier + ' print -d -l ' + str(labelHeight) + ' label.png -r 90')
printer_identifier + ' print -d -l ' + str(labelHeight) + ' tmp/label.png -r 90')
else:
print("UNKNOWN LABEL PICTURE HEIGHT!")
except:

22
setup_autostart.sh Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env bash
BASEDIR=$(dirname "$(readlink -f "$0")")
escaped_script_dir=$(echo "$BASEDIR" | sed 's/[\/&]/\\&/g')
echo "installing LabelPrinting autostart!"
sudo systemctl stop labelprinting
cp install/labelprinting.service tmp/
sed -i "s|{dir}|$escaped_script_dir|g; s|{user}|$USER|g;" tmp/labelprinting.service
sudo cp tmp/labelprinting.service /etc/systemd/system/labelprinting.service
rm tmp/labelprinting.service
sudo systemctl daemon-reload
sudo systemctl enable labelprinting
sudo systemctl start labelprinting
sudo systemctl status labelprinting
echo "Done"

15
uninstall.sh Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
BASEDIR=$(dirname "$(readlink -f "$0")")
escaped_script_dir=$(echo "$BASEDIR" | sed 's/[\/&]/\\&/g')
echo "uninstalling LabelPrinting autostart!"
sudo systemctl stop labelprinting
sudo systemctl disable labelprinting
sudo rm /etc/systemd/system/labelprinting.service
sudo systemctl daemon-reload
echo "Done"