-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·89 lines (69 loc) · 3.02 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
set -euo pipefail
# Load configuration for installation.
source ./templates/.env
source ./common_functions.sh
echo "=== Install '$SIGMADSP_EXECUTABLE'."
# Creates a new sigmadsp configuration file. This overwrites an old file with the same name.
function create_new_config_file {
echo "> Create new configuration for '$SIGMADSP_EXECUTABLE' in '$SIGMADSP_CONFIGURATION_FOLDER/$SIGMADSP_CONFIGURATION_FILE'."
sudo mkdir -p $SIGMADSP_CONFIGURATION_FOLDER
envsubst < ./templates/config.yaml.template > $SIGMADSP_TEMP_FOLDER/$SIGMADSP_CONFIGURATION_FILE
sudo mv $SIGMADSP_TEMP_FOLDER/$SIGMADSP_CONFIGURATION_FILE $SIGMADSP_CONFIGURATION_FOLDER/$SIGMADSP_CONFIGURATION_FILE
}
# Install pipx with Python, for later installing the sigmadsp package.
function install_pipx_python {
echo "=== Installing pipx."
{
sudo apt install -y pipx
pipx ensurepath
} || {
echo "! Falling back to installation via pip."
# Install the prerequisite pip3.
sudo apt-get install -y python3-pip python3-venv
# Install pipx for running sigmadsp in a virtual environment.
python3 -m pip install --user pipx
python3 -m pipx ensurepath
}
}
### Installation starts below. ###
echo "=== Install required packages."
sudo apt-get update
# Required for gpiod
sudo apt-get install python3-dev
install_pipx_python
# Use updated paths in current shell.
source ~/.bashrc
# Install the package itself, along with its executable scripts.
pipx install $SIGMADSP_EXECUTABLE
# Upgrade package, in case it was already installed.
pipx upgrade $SIGMADSP_EXECUTABLE
# Optional: stop and disable any old existing service.
stop_and_disable_sigmadsp_service || true
if [ -f "$SIGMADSP_CONFIGURATION_FOLDER/$SIGMADSP_CONFIGURATION_FILE" ]
then
echo "=== Existing configuration found for '$SIGMADSP_EXECUTABLE' in '$SIGMADSP_CONFIGURATION_FOLDER/$SIGMADSP_CONFIGURATION_FILE'."
if yes_or_no "Backup and overwrite existing configuration?"
then
sudo mv $SIGMADSP_CONFIGURATION_FOLDER/$SIGMADSP_CONFIGURATION_FILE $SIGMADSP_CONFIGURATION_FOLDER/$SIGMADSP_CONFIGURATION_FILE.bak
create_new_config_file
else
echo "> Keep existing configuration."
fi
else
create_new_config_file
fi
# Discover service.
source ~/.bashrc
echo "=== Setup '$SIGMADSP_BACKEND' service."
# Create systemd config for the service.
# This location looks for the service executable, which was previously installed with the Python package.
SIGMADSP_SERVICE_LOCATION=`which $SIGMADSP_BACKEND`
echo "> Found service executable at '$SIGMADSP_SERVICE_LOCATION'."
export SIGMADSP_SERVICE_LOCATION
envsubst < ./templates/backend.service.template > $SIGMADSP_TEMP_FOLDER/$SIGMADSP_BACKEND.service
sudo mv $SIGMADSP_TEMP_FOLDER/$SIGMADSP_BACKEND.service /usr/lib/systemd/system/$SIGMADSP_BACKEND.service
sudo systemctl daemon-reload
sudo systemctl start $SIGMADSP_BACKEND
sudo systemctl enable $SIGMADSP_BACKEND
echo "=== Finished installation of '$SIGMADSP_EXECUTABLE' and its backend service '$SIGMADSP_BACKEND'."