Skip to content

Commit

Permalink
Make write_tags work when called from other dirs
Browse files Browse the repository at this point in the history
Also make the service be restarted if the program is stopped with ctrl-c
  • Loading branch information
bofh69 committed Mar 14, 2024
1 parent d5ec9b5 commit 05c0734
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions write_tags
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
#!/bin/sh
#!/usr/bin/env bash

# SPDX-FileCopyrightText: 2024 Sebastian Andersson <[email protected]>
#
# SPDX-License-Identifier: CC0-1.0

if [[ ${BASH_SOURCE[0]} = */* ]]; then
cd -- "${BASH_SOURCE%/*}/" || exit
fi

if [ ! -d venv ]; then
echo "Creating python virtual environment"
virtualenv -p python3 venv || rm -r venv
echo "Installing python requirements"
venv/bin/pip3 install -r requirements.txt || exit
fi

restart_service() {
trap SIGINT
systemctl start nfc2klipper.service
exit
}

systemctl stop nfc2klipper.service
./venv/bin/python3 ./write_tags.py || true
systemctl start nfc2klipper.service
trap "restart_service" INT
venv/bin/python3 ./write_tags.py || true
restart_service

0 comments on commit 05c0734

Please sign in to comment.