From cc254d58c6e715775842078fd4c5fba34ce342c0 Mon Sep 17 00:00:00 2001 From: Jan Umbach Date: Mon, 31 Jul 2023 20:44:45 +0200 Subject: [PATCH] added autostart script --- .gitignore | 2 +- README.md | 2 ++ install.sh | 4 +++- install/labelprinting.service | 13 +++++++++++++ main.py | 6 +++--- setup_autostart.sh | 22 ++++++++++++++++++++++ uninstall.sh | 15 +++++++++++++++ 7 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 install/labelprinting.service create mode 100644 setup_autostart.sh create mode 100644 uninstall.sh diff --git a/.gitignore b/.gitignore index 9728dff..b25f9c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -label.png .venv/ +tmp/ diff --git a/README.md b/README.md index 9a9a28a..c764688 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/install.sh b/install.sh index 96a3f5a..6a3c87e 100644 --- a/install.sh +++ b/install.sh @@ -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" \ No newline at end of file +echo "Done" diff --git a/install/labelprinting.service b/install/labelprinting.service new file mode 100644 index 0000000..f56bd50 --- /dev/null +++ b/install/labelprinting.service @@ -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 diff --git a/main.py b/main.py index 7f9428b..db95c82 100644 --- a/main.py +++ b/main.py @@ -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: diff --git a/setup_autostart.sh b/setup_autostart.sh new file mode 100644 index 0000000..3f04e8d --- /dev/null +++ b/setup_autostart.sh @@ -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" diff --git a/uninstall.sh b/uninstall.sh new file mode 100644 index 0000000..cd78c9e --- /dev/null +++ b/uninstall.sh @@ -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"