-
-
Notifications
You must be signed in to change notification settings - Fork 290
/
Copy pathstart_chroot_script
85 lines (67 loc) · 2.48 KB
/
start_chroot_script
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
#!/usr/bin/env bash
#### Klipper Install Module
####
#### Based on work done by Raymond Himle and Stefan Dej
####
#### Written by Stephan Wendel aka KwadFan <me@stephanwe.de>
#### Copyright 2022
#### https://github.com/mainsail-crew/MainsailOS
####
#### This File is distributed under GPLv3
####
# shellcheck enable=require-variable-braces
### For easier maintainability look to klipper/config.
## Source error handling, leave this in place
set -Eex
## Set LC_ALL to prevent errors
export LC_ALL=C
# Set DEBIAN_FRONTEND to noninteractive
if [[ "${DEBIAN_FRONTEND}" != "noninteractive" ]]; then
export DEBIAN_FRONTEND=noninteractive
fi
## Source CustomPIOS common.sh
# shellcheck disable=SC1091
source /common.sh
install_cleanup_trap
unpack /filesystem/root /
echo_green "Installing Klipper and enable klippy Service ..."
## Install all deps at once for time consumption reasons.
## APT: Update Repo Database and install Dependencies
# Force apt update
apt update
echo_green "Installing Klipper Dependencies ..."
## Disabling shellcheck SC2086, because we want "wordsplitting"
# shellcheck disable=SC2086
check_install_pkgs ${KLIPPER_DEPS}
## Make sure user pi has access to serial ports
## NOTE: BASE_USER is defined by CustomPIOS Variable
## there for if you plan to set something else than "pi"
## Currently CustomPIOS uses "pi"
usermod -a -G "${KLIPPER_USER_GROUPS}" "${BASE_USER}"
## Clone klipper repo
pushd "/home/${BASE_USER}" &> /dev/null || exit 1
gitclone KLIPPER_REPO klipper
## Create needed dirs
for dir in ${KLIPPER_USER_DIRS}; do
if [[ -d "/home/${BASE_USER}/${dir}" ]]; then
echo_green "${dir} already exists!"
else
echo_green "Creating ${dir}"
sudo -u "${BASE_USER}" mkdir -p "${dir}"
fi
done
popd &> /dev/null || exit 1
# Copy printer_data for klipper/klippy
echo_green "Copy files to 'printer_data' ..."
unpack /filesystem/home/"${BASE_USER}" /home/"${BASE_USER}" "${BASE_USER}"
## create python virtualenv and install klipper requirements
pushd "/home/${BASE_USER}" &> /dev/null || exit 1
echo_green "Creating Virtualenv for Klipper (klippy-env) ..."
sudo -u "${BASE_USER}" virtualenv -p python3 "${KLIPPER_PYTHON_DIR}"
echo_green "Installing klippy Python Dependencies ..."
sudo -u "${BASE_USER}" "${KLIPPER_PYTHON_DIR}"/bin/pip install -r "${KLIPPER_SRC_DIR}"/"${KLIPPER_PYENV_REQ}"
popd &> /dev/null || exit 1
## Enable systemd service
systemctl_if_exists enable klipper.service
## Done message
echo_green "Installing Klipper and enable klippy Service ..."