Skip to content

Commit

Permalink
feat: add timelapse module (#130)
Browse files Browse the repository at this point in the history
* feat: add timelapse module

This adds moonraker-timelapse plugin to image.

Signed-off-by: Stephan Wendel <me@stephanwe.de>
  • Loading branch information
KwadFan authored Jul 29, 2022
1 parent 942896c commit 7b99d1f
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
export DIST_NAME=MainsailOS
export DIST_VERSION=0.6.1
export BASE_IMAGE_ENLARGEROOT=2500
export MODULES="base,pkgupgrade,mainsailos(network,piconfig,klipper,is_req_preinstall,moonraker,mainsail,crowsnest,sonar,password-for-sudo),postrename"
export MODULES="base,pkgupgrade,mainsailos(network,piconfig,klipper,is_req_preinstall,moonraker,timelapse,mainsail,crowsnest,sonar,password-for-sudo),postrename"
export BASE_RELEASE_COMPRESS=yes
export BASE_IMAGE_RESIZEROOT=600
12 changes: 12 additions & 0 deletions src/modules/postrename/filesystem/root/postrename
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ function fix_broken_links {
done
}

function fix_timelapse_links {
local config_dir src_dir target_dir
config_dir="/home/${DEFAULT_USER}/klipper_config"
src_dir="/home/${DEFAULT_USER}/moonraker-timelapse"
target_dir="/home/${DEFAULT_USER}/moonraker/moonraker/components"
sudo -u "${DEFAULT_USER}" \
ln -sf "${src_dir}/component/timelapse.py" "${target_dir}/timelapse.py"
sudo -u "${DEFAULT_USER}" \
ln -sf "${src_dir}/klipper_macro/timelapse.cfg" "${config_dir}/timelapse.cfg"
}

function main {
local cmdltxt
cmdltxt="/boot/cmdline.txt"
Expand Down Expand Up @@ -166,6 +177,7 @@ echo -e "${WHITE}Patching crowsnest logrotate ...${NOC}[${GRE}OK${NOC}]"
## fix broken links
echo -en "${WHITE}Fix broken symlinks ...${NOC}\r"
fix_broken_links
fix_timelapse_links
echo -e "${WHITE}Fix broken symlinks ...${NOC}[${GRE}OK${NOC}]"
## do a short break
sleep 2
Expand Down
16 changes: 16 additions & 0 deletions src/modules/timelapse/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# moonraker-timelapse custompios module
# https://github.com/mainsail-crew/moonraker-timelapse
# written by Stephan Wendel aka KwadFan
# <me@stephanwe.de>
# GPL V3
########
# shellcheck disable=all
[ -n "$TIMELAPSE_SRC_DIR" ] || TIMELAPSE_SRC_DIR="/home/${BASE_USER}/moonraker-timelapse"
[ -n "$TIMELAPSE_PYTHON_DIR" ] || TIMELAPSE_TARGET_DIR="/home/${BASE_USER}/moonraker/moonraker/components"
[ -n "$TIMELAPSE_CONFIG_DIR" ] || TIMELAPSE_CONFIG_DIR="/home/${BASE_USER}/klipper_config"
[ -n "$TIMELAPSE_TEMPLATE" ] || TIMELAPSE_TEMPLATE="/home/${BASE_USER}/klipper_config/timelapse_template.txt"

[ -n "$TIMELAPSE_REPO_SHIP" ] || TIMELAPSE_REPO_SHIP=https://github.com/mainsail-crew/moonraker-timelapse.git
[ -n "$TIMELAPSE_REPO_BRANCH" ] || TIMELAPSE_REPO_BRANCH=main
[ -n "$TIMELAPSE_DEPS" ] || TIMELAPSE_DEPS="ffmpeg"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

### moonraker-timelapse
### Don't forget to include timelapse.cfg to your printer.cfg
### Uncomment to enable moonraker-timelapse

#[timelapse]

#[update_manager timelapse]
#type: git_repo
#primary_branch: main
#path: ~/moonraker-timelapse
#origin: https://github.com/mainsail-crew/moonraker-timelapse.git
#managed_services: klipper moonraker
94 changes: 94 additions & 0 deletions src/modules/timelapse/start_chroot_script
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env bash
#### MainsailOS Build Chain
####
#### moonraker-timelapse install module
#### #!/bin/bash
#### https://github.com/mainsail-crew/moonraker-timelapse
####
#### Written by Stephan Wendel aka KwadFan <me@stephanwe.de>
#### Copyright 2022
#### https://github.com/mainsail-crew/MainsailOS
####
#### This File is distributed under GPLv3
####

###### THIS MODULE HAS TO BE PLACED RIGHT AFTER "moonraker" MODULE!!!

# shellcheck enable=require-variable-braces

## 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

## helper func moonraker update_manager
function add_timelapse_entry {
if [ -f "${TIMELAPSE_CONFIG_DIR}/moonraker.conf" ]; then
if [ -f "/tmp/moonraker.conf" ]; then
rm -rf /tmp/moonraker.conf
fi
sudo -u "${BASE_USER}" \
cat "${TIMELAPSE_CONFIG_DIR}/moonraker.conf" "${TIMELAPSE_TEMPLATE}" | \
tee /tmp/moonraker.conf > /dev/null &&
cp -rf /tmp/moonraker.conf "${TIMELAPSE_CONFIG_DIR}/moonraker.conf"
fi
## Cleanup template
if [ -f "${TIMELAPSE_TEMPLATE}" ]; then
rm -f "${TIMELAPSE_TEMPLATE}"
fi
}

echo_green "Installing moonraker-timelapse plugin ..."

### Install template file
unpack /filesystem/home/${BASE_USER} /home/${BASE_USER} ${BASE_USER}

## Install all deps at once for time consumption reasons.
## APT: Update Repo Database and install Dependencies
# Force apt update
apt update
echo_green "Installing moonraker-timelapse Dependencies ..."
## Disabling shellcheck SC2086, because we want "wordsplitting"
# shellcheck disable=SC2086
check_install_pkgs ${TIMELAPSE_DEPS}


## Clone klipper repo
pushd "/home/${BASE_USER}" &> /dev/null || exit 1
gitclone TIMELAPSE_REPO moonraker-timelapse

## Link component
if [ -d "${TIMELAPSE_TARGET_DIR}" ]; then
echo "Linking extension to moonraker ..."
sudo -u "${BASE_USER}" \
ln -sf "${TIMELAPSE_SRC_DIR}/component/timelapse.py" "${TIMELAPSE_TARGET_DIR}/timelapse.py"
fi

## Link timelapse.cfg
if [ -d "/home/${BASE_USER}/klipper_config" ]; then
echo "Linking macro file ..."
sudo -u "${BASE_USER}" \
ln -sf "${TIMELAPSE_SRC_DIR}/klipper_macro/timelapse.cfg" "${TIMELAPSE_CONFIG_DIR}/timelapse.cfg"
fi

## Extend moonraker.conf
echo "Modifying moonraker.conf ..."
add_timelapse_entry


popd || exit 1


## Done message
echo_green "Installing moonraker-timelapse plugin ... done!"

0 comments on commit 7b99d1f

Please sign in to comment.