Skip to content

Commit

Permalink
Merge pull request #22 from TypQxQ/dev
Browse files Browse the repository at this point in the history
Installation updates and renaming of macros folder
  • Loading branch information
TypQxQ committed Mar 29, 2024
2 parents b164e77 + 0255d47 commit 0ccd712
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 24 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,14 @@ Thank you!
### 1\. Automatic install with Moonraker Autoupdate Support
This plugin assumes that you installed Klipper into your home directory (usually `/home/pi`).

1) Clone this repo into your home directory where Klipper is installed:
Connect to your klipper machine using SSH and run these command:
```
cd ~
git clone https://github.com/TypQxQ/KTC.git
cd ~/ && git clone https://github.com/TypQxQ/KTC.git && bash ~/KTC/install.sh
```

2) Run the `install.sh` script
```
~/KTC/install.sh
```
This will install and configure everything.

If you encouter errors after an automatic Klipper update you can safetly run the `install.sh` scipt again to repair the links to the extension.
If you encouter errors after an automatic Klipper update you can safetly run the `install.sh` scipt inside the KTC directory again to repair the links to the extension.

### 2\. Manual Install
Copy or link the python (`*.py`) files into the `\klipper\klippy\extras` directory. Assuming Then restart Klipper to pick up the extensions.
Expand Down
48 changes: 32 additions & 16 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ verify_ready()
function nextfilename {
local name="$1"
if [ -d "${name}" ]; then
printf "%s-%s ${name%%.*} $(date +%Y%m%d_%H%M%S)"
printf "%s-%s" ${name%%.*} $(date '+%Y%m%d_%H%M%S')
else
printf "%s-%s.%s-old ${name%%.*} $(date +%Y%m%d_%H%M%S) ${name#*.}"
printf "%s-%s.%s-old" ${name%%.*} $(date '+%Y%m%d_%H%M%S') ${name#*.}
fi
}

Expand Down Expand Up @@ -163,14 +163,14 @@ install_update_manager() {
already_included=$(grep -c "\[update_manager KTC\]" ${dest} || true)
if [ "${already_included}" -eq 0 ]; then
# Backup the original moonraker.conf file
next_dest="$(nextfilename "$dest")"
next_dest="$(nextfilename $dest)"
log_info "Copying original moonraker.conf file to ${next_dest}"
cp "${dest} ${next_dest}"
cp ${dest} ${next_dest}

# Add the configuration to moonraker.conf
echo "" >> "${dest}" # Add a blank line
echo "" >> "${dest}" # Add a blank line
echo -e "[update_manager KTC\]" >> "${dest}" # Add the section header
echo -e "[update_manager KTC]" >> "${dest}" # Add the section header
echo -e "type: git_repo" >> "${dest}"
echo -e "path: ${REPO_DIR}" >> "${dest}"
echo -e "origin: https://github.com/TypQxQ/KTC.git" >> "${dest}"
Expand Down Expand Up @@ -203,6 +203,7 @@ install_klipper_config() {

# Add the configuration to printer.cfg
# This example assumes that that both the server and the webcam stream are running on the same machine as Klipper
# The ktc section is not needed if a tool is configured but loaded here for the macros to work if no tool is configured
already_included=$(grep -c "\[ktc\]" ${dest} || true)
if [ "${already_included}" -eq 0 ]; then
echo "" >> "${dest}" # Add a blank line
Expand All @@ -214,24 +215,39 @@ install_klipper_config() {
else
log_error "[ktc] already exists in printer.cfg - skipping adding it there"
fi

# Add the inclusion of macros to printer.cfg if it doesn't exist
already_included=$(grep -c "\[include ktc/base/*.cfg\]" ${dest} || true)
if [ "${already_included}" -eq 0 ]; then
echo "" >> "${dest}" # Add a blank line
echo -e "[include ktc/base/*.cfg]" >> "${dest}" # Add the section header
echo -e "[include ktc/optional_rrf_compability/*.cfg]" >> "${dest}" # Add the section header
else
log_error "[include ktc/base/*.cfg] already exists in printer.cfg - skipping adding it and the optional macros there"
fi
else
log_error "File printer.cfg file not found! Cannot add KTC configuration. Do it manually."
fi

# Add the inclusion of macros.cfg to printer.cfg if it doesn't exist
already_included=$(grep -c "\[include ktc_macros.cfg\]" ${dest} || true)
if [ "${already_included}" -eq 0 ]; then
echo "" >> "${dest}" # Add a blank line
echo -e "[include ktc-macros.cfg]" >> "${dest}" # Add the section header
if [ ! -d "${KLIPPER_CONFIG_HOME}/ktc" ]; then
log_info "Creating the ${KLIPPER_CONFIG_HOME}/ktc directory"
mkdir ${KLIPPER_CONFIG_HOME}/ktc
else
log_error "[include ktc-macros.cfg] already exists in printer.cfg - skipping adding it there"
log_error "ktc directory already exists in ${KLIPPER_CONFIG_HOME} - skipping creating it"
fi

if [ ! -f "${KLIPPER_CONFIG_HOME}/ktc-macros.cfg" ]; then
log_info "Copying ktc-macros.cfg to ${KLIPPER_CONFIG_HOME}"
cp "${REPO_DIR}/ktc-macros.cfg ${KLIPPER_CONFIG_HOME}"

if [ ! -d "${KLIPPER_CONFIG_HOME}/ktc/base" ]; then
log_info "Copying base macros to ${KLIPPER_CONFIG_HOME}/ktc"
cp -r ${REPO_DIR}/macros/base ${KLIPPER_CONFIG_HOME}/ktc
else
log_error "Base macros already exists in ${KLIPPER_CONFIG_HOME}/ktc/base - skipping copying it there"
fi

if [ ! -d "${KLIPPER_CONFIG_HOME}/ktc/optional_rrf_compability" ]; then
log_info "Copying optional_rrf_compability macros to ${KLIPPER_CONFIG_HOME}/ktc"
cp -r ${REPO_DIR}/macros/optional_rrf_compability ${KLIPPER_CONFIG_HOME}/ktc
else
log_error "[include ktc-macros.cfg] already exists in printer.cfg - skipping adding it there"
log_error "Optional RRF compability macros already exists in ${KLIPPER_CONFIG_HOME}/ktc/optional_rrf_compability - skipping copying it there"
fi
# Restart Klipper
restart_klipper
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 0ccd712

Please sign in to comment.