-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make write_tags work when called from other dirs
Also make the service be restarted if the program is stopped with ctrl-c
- Loading branch information
Showing
1 changed file
with
21 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |