now using a venv to run the scripts

This commit is contained in:
Félix Boisselier
2023-11-29 11:43:21 +01:00
parent a1e9269ba3
commit 43a205d036
9 changed files with 220 additions and 20 deletions

View File

@@ -2,7 +2,9 @@
USER_CONFIG_PATH="${HOME}/printer_data/config"
KLIPPER_PATH="${HOME}/klipper"
K_SHAKETUNE_PATH="${HOME}/klippain_shaketune"
K_SHAKETUNE_VENV_PATH="${HOME}/klippain_shaketune-env"
set -eu
export LC_ALL=C
@@ -14,19 +16,17 @@ function preflight_checks {
exit -1
fi
if ! command -v python3 &> /dev/null; then
echo "[ERROR] Python 3 is not installed. Please install Python 3 to use the Shake&Tune module!"
exit -1
fi
if [ "$(sudo systemctl list-units --full -all -t service --no-legend | grep -F 'klipper.service')" ]; then
printf "[PRE-CHECK] Klipper service found! Continuing...\n\n"
else
echo "[ERROR] Klipper service not found, please install Klipper first!"
exit -1
fi
if [ -d "${HOME}/klippain_config" ]; then
if [ -f "${USER_CONFIG_PATH}/.VERSION" ]; then
echo "[ERROR] Klippain full installation found! Nothing is needed in order to use the K-Shake&Tune module!"
exit -1
fi
fi
}
function check_download {
@@ -48,9 +48,31 @@ function check_download {
fi
}
function setup_venv {
if [ ! -d "${K_SHAKETUNE_VENV_PATH}" ]; then
echo "[SETUP] Creating Python virtual environment..."
python3 -m venv "${K_SHAKETUNE_VENV_PATH}"
else
echo "[SETUP] Virtual environment already exists. Continuing..."
fi
source "${K_SHAKETUNE_VENV_PATH}/bin/activate"
echo "[SETUP] Installing/Updating K-Shake&Tune dependencies..."
pip install --upgrade pip
pip install -r "${K_SHAKETUNE_PATH}/requirements.txt"
deactivate
printf "\n"
}
function link_extension {
echo "[INSTALL] Linking scripts to your config directory..."
ln -frsn ${K_SHAKETUNE_PATH}/K-ShakeTune ${USER_CONFIG_PATH}/K-ShakeTune
if [ -d "${HOME}/klippain_config" ] && [ -f "${USER_CONFIG_PATH}/.VERSION" ]; then
echo "[INSTALL] Klippain full installation found! Linking module to the script folder of Klippain"
ln -frsn ${K_SHAKETUNE_PATH}/K-ShakeTune ${USER_CONFIG_PATH}/scripts/K-ShakeTune
else
ln -frsn ${K_SHAKETUNE_PATH}/K-ShakeTune ${USER_CONFIG_PATH}/K-ShakeTune
fi
}
function link_gcodeshellcommandpy {
@@ -76,6 +98,7 @@ printf "=============================================\n\n"
# Run steps
preflight_checks
check_download
setup_venv
link_extension
link_gcodeshellcommandpy
restart_klipper