-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
install service script + make it work with virtualenvs cmd do not need to be part of config remove piTFT exec script (obsolete + in documentation already)
- Loading branch information
Showing
17 changed files
with
97 additions
and
90 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
current_dir=$(pwd) | ||
script="$current_dir/pizero_bikecomputer.py" | ||
|
||
i_service_file="$current_dir/scripts/install/etc/systemd/system/pizero_bikecomputer.service" | ||
o_service_file="/etc/systemd/system/pizero_bikecomputer.service" | ||
|
||
read -p "Using TFT/XWindow? [y/n] (n): " use_x | ||
|
||
# check if venv is set, in that case default to using thi venv to run the script | ||
#read -p "Use current virtualenv? [y/n] (y): " use_venv | ||
|
||
if [[ -n "$VIRTUAL_ENV" ]]; then | ||
script="$VIRTUAL_ENV/bin/python $script" | ||
else | ||
echo "No virtualenv used/activated. Default python will be used" | ||
fi | ||
|
||
if [[ "$use_x" == "y" ]]; then | ||
# add fullscreen option | ||
script="$script -f" | ||
envs="Environment=\"QT_QPA_PLATFORM=xcb\"\\nEnvironment=\"DISPLAY=:0\"\\nEnvironment=\"XAUTHORITY=/home/$USER/.Xauthority\"\\n" | ||
after="After=display-manager.service\\n" | ||
else | ||
envs="Environment=\"QT_QPA_PLATFORM=offscreen\"\\nEnvironment=\"PYUSB_DEBUG=critical\"\\n" | ||
after="" | ||
fi | ||
|
||
if [ -f "$i_service_file" ]; then | ||
content=$(<"$i_service_file") | ||
content="${content/WorkingDirectory=/WorkingDirectory=$current_dir}" | ||
content="${content/ExecStart=/ExecStart=$script}" | ||
content="${content/User=/User=$USER}" | ||
content="${content/Group=/Group=$USER}" | ||
|
||
# inject environment variables | ||
content=$(echo "$content" | sed "/\[Install\]/i $envs") | ||
|
||
if [[ -n "$after" ]]; then | ||
content=$(echo "$content" | sed "/\[Service\]/i $after") | ||
fi | ||
echo "$content" | sudo tee $o_service_file > /dev/null | ||
sudo systemctl enable pizero_bikecomputer | ||
fi |
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import subprocess | ||
|
||
from logger import app_logger | ||
|
||
|
||
def exec_cmd(cmd, cmd_print=True): | ||
if cmd_print: | ||
app_logger.info(cmd) | ||
try: | ||
subprocess.run(cmd) | ||
except Exception: # noqa | ||
app_logger.exception(f"Failed executing {cmd}") | ||
|
||
|
||
def exec_cmd_return_value(cmd, cmd_print=True): | ||
if cmd_print: | ||
app_logger.info(cmd) | ||
try: | ||
p = subprocess.run( | ||
cmd, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
) | ||
string = p.stdout.decode("utf8").strip() | ||
return string | ||
except Exception: # noqa | ||
app_logger.exception(f"Failed executing {cmd}") |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.