forked from Frix-x/klippain-shaketune
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·146 lines (120 loc) · 4.62 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
USER_CONFIG_PATH="${HOME}/printer_data/config"
MOONRAKER_CONFIG="${HOME}/printer_data/config/moonraker.conf"
KLIPPER_PATH="${HOME}/klipper"
K_SHAKETUNE_PATH="${HOME}/klippain_shaketune"
K_SHAKETUNE_VENV_PATH="${HOME}/klippain_shaketune-env"
set -eu
export LC_ALL=C
function preflight_checks {
if [ "$EUID" -eq 0 ]; then
echo "[PRE-CHECK] This script must not be run as root!"
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
install_package_requirements
}
# Function to check if a package is installed
function is_package_installed {
dpkg -s "$1" &> /dev/null
return $?
}
function install_package_requirements {
packages=("python3-venv" "libopenblas-dev" "libatlas-base-dev")
packages_to_install=""
for package in "${packages[@]}"; do
if is_package_installed "$package"; then
echo "$package is already installed"
else
packages_to_install="$packages_to_install $package"
fi
done
if [ -n "$packages_to_install" ]; then
echo "Installing missing packages: $packages_to_install"
sudo apt update && sudo apt install -y $packages_to_install
fi
}
function check_download {
local shaketunedirname shaketunebasename
shaketunedirname="$(dirname ${K_SHAKETUNE_PATH})"
shaketunebasename="$(basename ${K_SHAKETUNE_PATH})"
if [ ! -d "${K_SHAKETUNE_PATH}" ]; then
echo "[DOWNLOAD] Downloading Klippain Shake&Tune module repository..."
if git -C $shaketunedirname clone https://github.com/Frix-x/klippain-shaketune.git $shaketunebasename; then
chmod +x ${K_SHAKETUNE_PATH}/install.sh
printf "[DOWNLOAD] Download complete!\n\n"
else
echo "[ERROR] Download of Klippain Shake&Tune module git repository failed!"
exit -1
fi
else
printf "[DOWNLOAD] Klippain Shake&Tune module repository already found locally. Continuing...\n\n"
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..."
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 {
if [ ! -f "${KLIPPER_PATH}/klippy/extras/gcode_shell_command.py" ]; then
echo "[INSTALL] Downloading gcode_shell_command.py Klipper extension needed for this module"
wget -P ${KLIPPER_PATH}/klippy/extras https://raw.githubusercontent.com/Frix-x/klippain/main/scripts/gcode_shell_command.py
else
printf "[INSTALL] gcode_shell_command.py Klipper extension is already installed. Continuing...\n\n"
fi
}
function add_updater {
update_section=$(grep -c '\[update_manager[a-z ]* Klippain-ShakeTune\]' $MOONRAKER_CONFIG || true)
if [ "$update_section" -eq 0 ]; then
echo -n "[INSTALL] Adding update manager to moonraker.conf..."
cat ${K_SHAKETUNE_PATH}/moonraker.conf >> $MOONRAKER_CONFIG
fi
}
function restart_klipper {
echo "[POST-INSTALL] Restarting Klipper..."
sudo systemctl restart klipper
}
function restart_moonraker {
echo "[POST-INSTALL] Restarting Moonraker..."
sudo systemctl restart moonraker
}
printf "\n=============================================\n"
echo "- Klippain Shake&Tune module install script -"
printf "=============================================\n\n"
# Run steps
preflight_checks
check_download
setup_venv
link_extension
add_updater
link_gcodeshellcommandpy
restart_klipper
restart_moonraker