Skip to content

Commit

Permalink
feat(ci): add KlipperScreen module (#284)
Browse files Browse the repository at this point in the history
* feat: add klipperscreen module

Signed-off-by: Stephan Wendel <[email protected]>

* test: build test with new module

This commit will be reverted if finished

Signed-off-by: Stephan Wendel <[email protected]>

* fix: fix typo in config

Signed-off-by: Stephan Wendel <[email protected]>

* fix: fix typo in install message

Signed-off-by: Stephan Wendel <[email protected]>

* chore: KlipperScreen to  postrename script

Signed-off-by: Stephan Wendel <[email protected]>

* fix: replace moonraker comments

Signed-off-by: Stephan Wendel <[email protected]>

* chore: change date

Signed-off-by: Stephan Wendel <[email protected]>

* chore: change date in config

Signed-off-by: Stephan Wendel <[email protected]>

---------

Signed-off-by: Stephan Wendel <[email protected]>
  • Loading branch information
KwadFan authored Feb 10, 2024
1 parent c88f2dd commit 257f28d
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflow_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ buildtest:
# Raspberry Pi OS based images
- raspberry/rpi32
- raspberry/rpi64
# rpi 64 with KS
- raspberry/rpi64-ks

# This is used to setup release build chain.
# Each entry will be used in setup matrix for releases
Expand Down
31 changes: 31 additions & 0 deletions config/raspberry/rpi64-ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Shebang for better file detection

# Declare Variables before exporting.
# See https://www.shellcheck.net/wiki/SC2155

BASE_ARCH="arm64"

# Keep for Bookworm template
# DOWNLOAD_URL_CHECKSUM="https://downloads.raspberrypi.org/raspios_lite_arm64_latest.sha256"
# DOWNLOAD_URL_IMAGE="https://downloads.raspberrypi.org/raspios_lite_arm64_latest.torrent"

# New locations after Bullseye turned into 'oldstable'
DOWNLOAD_URL_CHECKSUM="https://downloads.raspberrypi.com/raspios_oldstable_lite_arm64/images/raspios_oldstable_lite_arm64-2023-10-10/2023-05-03-raspios-bullseye-arm64-lite.img.xz.sha256"
DOWNLOAD_URL_IMAGE="https://downloads.raspberrypi.com/raspios_oldstable_lite_arm64/images/raspios_oldstable_lite_arm64-2023-10-10/2023-05-03-raspios-bullseye-arm64-lite.img.xz.torrent"


# Changed modules
# shellcheck disable=SC2034
MODULES="base,pkgupgrade,udev_fix,mainsailos(net,piconfig,klipper,is_req_preinstall,moonraker,timelapse,mainsail,klipperscreen,crowsnest,sonar,password-for-sudo),postrename"


# export variables
export BASE_ARCH
export DOWNLOAD_URL_CHECKSUM
export DOWNLOAD_URL_IMAGE

### JSON sniplet Setup
### NOTE: Please see all config files for setup variables!!!
# shellcheck disable=SC2034
JSON_SUPPORTED_SBC="pi3-64bit pi4-64bit"
13 changes: 13 additions & 0 deletions src/modules/klipperscreen/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
#Shebang for better file detection
#### KlipperScreen install module
####
#### Written by Stephan Wendel aka KwadFan <[email protected]>
#### Copyright 2024 - till today
#### https://github.com/mainsail-crew/MainsailOS
####
#### This File is distributed under GPLv3
####

[ -n "$KLIPPERSCREEN_REPO_SHIP" ] || KLIPPERSCREEN_REPO_SHIP=https://github.com/KlipperScreen/KlipperScreen.git
[ -n "$KLIPPERSCREEN_REPO_BRANCH" ] || KLIPPERSCREEN_REPO_BRANCH=master
9 changes: 9 additions & 0 deletions src/modules/klipperscreen/filesystem/tmp/ks_update_entry.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

[update_manager KlipperScreen]
type: git_repo
path: ~/KlipperScreen
origin: https://github.com/KlipperScreen/KlipperScreen.git
virtualenv: ~/.KlipperScreen-env
requirements: scripts/KlipperScreen-requirements.txt
system_dependencies: scripts/system-dependencies.json
managed_services: KlipperScreen
64 changes: 64 additions & 0 deletions src/modules/klipperscreen/start_chroot_script
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
#### KlipperScreen install module
####
#### Written by Stephan Wendel aka KwadFan <[email protected]>
#### Copyright 2024 - till today
#### https://github.com/mainsail-crew/MainsailOS
####
#### This File is distributed under GPLv3
####
# shellcheck enable=require-variable-braces

# Source error handling, leave this in place
set -Ee

# Source CustomPIOS common.sh
# shellcheck disable=SC1091
source /common.sh
install_cleanup_trap

# Module only Variables
KS_BUILD_INSTALL_SH="/home/${BASE_USER}/KlipperScreen/scripts/KlipperScreen-install.sh"
KS_MOONRAKER_CONF_PATH="/home/${BASE_USER}/printer_data/config/moonraker.conf"

echo_green "Installing KlipperScreen and enable KlipperScreen Service ..."

## Force apt update
apt-get update
## Make sure 'git' is installed!
check_install_pkgs git

## Step 1: Move to Home Dir as WorkingDirectoy
pushd "/home/${BASE_USER}" &> /dev/null || exit 1

## Step 2: clone KlipperScreen repo
gitclone KLIPPERSCREEN_REPO KlipperScreen

## Step 3: Move to KlipperScreen as working directory
pushd "/home/${BASE_USER}/KlipperScreen" &> /dev/null || exit 1

## Step 4: Run KlipperScreen install routine
echo_green "Launch KlipperScreen install routine ..."
sudo -u "${BASE_USER}" "${KS_BUILD_INSTALL_SH}"

## Step 5: Update moonraker.conf
if [[ -f "${KS_MOONRAKER_CONF_PATH}" ]]; then
echo_green "Copying temporary file ..."
unpack /filesystem/tmp /tmp root
cat /tmp/ks_update_entry.txt >> "${KS_MOONRAKER_CONF_PATH}"
else
echo_red "File moonraker.conf not found ... [SKIPPED]"
fi

## Step 6: Leave KlipperScreen
popd &> /dev/null || exit 1

## Step 7: leave home dir
popd &> /dev/null || exit 1

## Step 8: Enable service
echo_green "Enable KlipperScreen.service ..."
systemctl_if_exists enable KlipperScreen.service

## Finish
echo_green "Installing KlipperScreen and enable KlipperScreen Service ... DONE!"
20 changes: 19 additions & 1 deletion src/modules/postrename/filesystem/root/postrename
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ SERVICES=(moonraker klipper nginx sonar crowsnest)
SYSTEMD_DIR="/etc/systemd/system"
DEFAULT_USER="$(grep "1000" /etc/passwd | awk -F ':' '{print $1}')"

### KlipperScreen workaround
KS_INSTALLED="$(find /home/"${DEFAULT_USER}" -name "KlipperScreen" | wc -l)"
if [[ "${KS_INSTALLED}" = "1" ]]; then
SERVICES+=(KlipperScreen)
fi

## Helper funcs
### Mangle services
Expand Down Expand Up @@ -90,6 +95,11 @@ relocate_venv() {
local -a venvs
venvs=(klippy-env moonraker-env)

### KlipperScreen workaround
if [[ "${KS_INSTALLED}" = "1" ]]; then
venvs+=(.KlipperScreen-env)
fi

for venv in "${venvs[@]}"; do
# Move venv
# delete pycache (*.pyc files)
Expand All @@ -116,6 +126,15 @@ patch_polkit_rules() {
if [[ -f "${polkit_legacy_dir}/10-moonraker.pkla" ]]; then
sed -i 's/pi/'"${DEFAULT_USER}"'/g' "${polkit_legacy_dir}/10-moonraker.pkla"
fi
if [[ -f "${polkit_dir}/KlipperScreen.rules" ]]; then
sed -i 's/pi/'"${DEFAULT_USER}"'/g' "${polkit_dir}/KlipperScreen.rules"
fi
if [[ -f "${polkit_usr_dir}/KlipperScreen.rules" ]]; then
sed -i 's/pi/'"${DEFAULT_USER}"'/g' "${polkit_usr_dir}/KlipperScreen.rules"
fi
if [[ -f "${polkit_legacy_dir}/20-klipperscreen.pkla" ]]; then
sed -i 's/pi/'"${DEFAULT_USER}"'/g' "${polkit_legacy_dir}/20-klipperscreen.pkla"
fi
}

patch_cn_logpath() {
Expand Down Expand Up @@ -174,7 +193,6 @@ fix_kiauh_links() {
ln -sf "${src_dir}/kiauh.sh" "${target_dir}/kiauh"
}


fix_cn_links() {
local tools_dir
tools_dir="/home/${DEFAULT_USER}/crowsnest/tools"
Expand Down

0 comments on commit 257f28d

Please sign in to comment.