Skip to content

Commit

Permalink
Merge pull request ArmoredTurtle#147 from ejsears/noticket-add-instal…
Browse files Browse the repository at this point in the history
…l-versioning

AFC-4 add install versioning
  • Loading branch information
MG-longshot authored Nov 29, 2024
2 parents 660bab7 + bef60a9 commit 9f7a9a1
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 151 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Minor adjustments to the use of single sensor buffers, retaining functionality for Belay

### Removed

## [2024-10-27]

### Added
Expand Down
35 changes: 35 additions & 0 deletions include/auto_update_configs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,39 @@ function auto_update() {
# merge_configs "${AFC_CONFIG_PATH}/AFC_Hardware.cfg" "${AFC_PATH}/templates/AFC_Hardware-AFC.cfg" "${AFC_CONFIG_PATH}/AFC_Hardware-temp.cfg"
# cleanup_blank_lines "${AFC_CONFIG_PATH}/AFC_Hardware-temp.cfg"
# mv "${AFC_CONFIG_PATH}/AFC_Hardware-temp.cfg" "${AFC_CONFIG_PATH}/AFC_Hardware.cfg"
}


check_old_config_version() {
# Check if 'Type: Box_Turtle' is found in the first 5 lines of the file
if head -n 15 "${AFC_CONFIG_PATH}/AFC.cfg" | grep -v '^\s*#' | grep -q 'Type: Box_Turtle'; then
FORCE_UPDATE=True
# Since we have software without an AFC_INSTALL_VERSION in it, we need a way to designate this as a version that needs to be updated.
FORCE_UPDATE_NO_VERSION=True
return
else
FORCE_UPDATE=False
FORCE_UPDATE_NO_VERSION=False
fi
}

set_install_version_if_missing() {
if ! grep -q 'AFC_INSTALL_VERSION' "${AFC_CONFIG_PATH}/.afc-version"; then
echo "AFC_INSTALL_VERSION=$CURRENT_INSTALL_VERSION" > "${AFC_CONFIG_PATH}/.afc-version"
fi
}

check_version_and_set_force_update() {
local version_file="${AFC_CONFIG_PATH}/.afc-version"
local current_version

if [[ -f $version_file ]]; then
current_version=$(grep -oP '(?<=AFC_INSTALL_VERSION=)[0-9]+\.[0-9]+\.[0-9]+' "$version_file")
fi

if [[ -z "$current_version" || "$current_version" < "$MIN_VERSION" ]]; then
FORCE_UPDATE=True
else
FORCE_UPDATE=False
fi
}
146 changes: 146 additions & 0 deletions include/buffer_configurations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/env bash
# Armored Turtle Automated Filament Changer
#
# Copyright (C) 2024 Armored Turtle
#
# This file may be distributed under the terms of the GNU GPLv3 license.

append_buffer_config() {
local buffer_system="$1"
local config_path="${AFC_CONFIG_PATH}/AFC_Hardware.cfg"
local afc_config_path="${AFC_CONFIG_PATH}/AFC.cfg"
local hardware_config_path="${AFC_CONFIG_PATH}/AFC_Hardware.cfg"
local buffer_config=""
local buffer_name=""
local tn_advance_pin=$2
local tn_trailing_pin=$3

case "$buffer_system" in
"TurtleNeck")
buffer_config=$(cat <<'EOF'
[AFC_buffer TN]
advance_pin: ${tn_advance_pin} # set advance pin
trailing_pin: ${tn_trailing_pin} # set trailing pin
multiplier_high: 1.05 # default 1.05, factor to feed more filament
multiplier_low: 0.95 # default 0.95, factor to feed less filament
velocity: 100
EOF
)
buffer_name="TN"
;;
"TurtleNeckV2")
buffer_config=$(cat <<'EOF'
[AFC_buffer TN2]
advance_pin: !turtleneck:ADVANCE
trailing_pin: !turtleneck:TRAILING
multiplier_high: 1.05 # default 1.05, factor to feed more filament
multiplier_low: 0.95 # default 0.95, factor to feed less filament
led_index: Buffer_Indicator:1
velocity: 100
[AFC_led Buffer_Indicator]
pin: turtleneck:RGB
chain_count: 1
color_order: GRBW
initial_RED: 0.0
initial_GREEN: 0.0
initial_BLUE: 0.0
initial_WHITE: 0.0
EOF
)
buffer_name="TN2"
;;
"AnnexBelay")
buffer_config=$(cat <<'EOF'
[AFC_buffer Belay]
pin: mcu:BUFFER
distance: 12
velocity: 1000
accel: 1000
EOF
)
buffer_name="Belay"
;;
*)
echo "Invalid BUFFER_SYSTEM: $buffer_system"
return 1
;;
esac

# Check if the buffer configuration already exists in the config file
print_msg INFO " Checking if buffer configuration already exists in $config_path"
if ! grep -qF "$(echo "$buffer_config" | head -n 1)" "$config_path"; then
# Append the buffer configuration to the config file
echo -e "\n$buffer_config" >> "$config_path"
else
print_msg INFO " Buffer configuration already exists in $config_path. Skipping modification."
fi

# Add [include mcu/TurtleNeckv2.cfg] to AFC_Hardware.cfg if buffer_system is TurtleNeckV2 and not already present
if [ "$buffer_system" == "TurtleNeckV2" ]; then
if ! grep -qF "[include mcu/TurtleNeckv2.cfg]" "$hardware_config_path"; then
awk '/\[include mcu\/.*\]/ {print; print "[include mcu/TurtleNeckv2.cfg]"; next}1' "$hardware_config_path" > temp && mv temp "$hardware_config_path"
print_msg INFO " Ensure you add the correct serial information to the ~/printer_data/config/AFC/mcu/TurtleNeckv2.cfg file"
fi
fi
}

add_buffer_to_extruder() {
# Function to add a buffer configuration to the [AFC_extruder extruder] section in a configuration file.
# Arguments:
# $1: file_path - The path to the configuration file.
# $2: buffer_name - The name of the buffer to be added.
local file_path="$1"
local buffer_name="$2"
local section="[AFC_extruder extruder]"
local buffer_line="buffer: $buffer_name"

awk -v section="$section" -v buffer="$buffer_line" '
BEGIN { in_section = 0 }
# Match the start of the target section
$0 == section {
in_section = 1
print $0
next
}
# Insert buffer line before the first blank line within the target section
in_section && /^$/ {
print buffer
in_section = 0
}
# End section processing if a new section starts
in_section && /^\[.+\]/ { in_section = 0 }
# Print all lines
{ print $0 }
' "$file_path" > "$file_path.tmp" && mv "$file_path.tmp" "$file_path"

print_msg WARNING " Added '$buffer_line' to the '$section' section in $file_path"
}

query_tn_pins() {
# Function to query the user for the TurtleNeck pins.
# Arguments:
# $1: buffer_name - The name of the buffer to be added.
local buffer_name="$1"
local tn_advance_pin="UNKNOWN"
local tn_trailing_pin="UNKNOWN"
local input

print_msg INFO " \n Please enter the pin numbers for the TurtleNeck buffer '$buffer_name':"
print_msg INFO " (Leave blank to use the default values)"
print_msg INFO " (Example: turtleneck:ADVANCE)"
print_msg INFO " (Example: turtleneck:TRAILING)"

read -p " Enter the advance pin (default: $tn_advance_pin): " -r input
if [ -n "$input" ]; then
tn_advance_pin="$input"
fi

read -p " Enter the trailing pin (default: $tn_trailing_pin): " -r input
if [ -n "$input" ]; then
tn_trailing_pin="$input"
fi

print_msg INFO " Set ${buffer_name} Advance pin: $tn_advance_pin"
print_msg INFO " Set ${buffer_name} Trailing pin: $tn_trailing_pin"
}
42 changes: 42 additions & 0 deletions include/check_commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,46 @@ check_for_hh() {
exit 1
fi
fi
}

check_for_afc() {
# Function to check if the AFC Klipper extension is already installed.
# It checks for the presence of the AFC extension in the Klipper extras directory.
# If the AFC extension is found, it prints an error message and exits with status 1.
# This is to prevent the user from installing AFC multiple times.

local file_path="${KLIPPER_PATH}/klippy/extras/AFC.py"

if [ ! -f "$file_path" ]; then
print_msg ERROR " AFC Klipper extension not found. Install AFC first."
exit 1
fi
}

check_for_mainsail() {
# Function to check if the Mainsail interface is already installed.

if ! grep -q "Mainsail" "${MAINSAIL_DST}/manifest.webmanifest"; then
print_msg ERROR " Mainsail interface not found. Exiting."
exit 1
fi
}

check_for_fluidd() {
# Function to check if the Fluidd interface is already installed.

if ! grep -q "fluidd" "$FLUIDD_DST"/release_info.json; then
print_msg ERROR " Fluidd interface not found. Exiting."
exit 1
fi
}

check_unzip() {
# Function to check if the unzip command is available.
# If the unzip command is not found, it prints an error message and exits with status 1.

if ! command -v unzip &> /dev/null; then
print_msg ERROR " unzip command not found. Please install unzip and try again."
exit 1
fi
}
48 changes: 48 additions & 0 deletions include/constants.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Armored Turtle Automated Filament Changer
#
# Copyright (C) 2024 Armored Turtle
#
# This file may be distributed under the terms of the GNU GPLv3 license.

# Paths
KLIPPER_PATH="${HOME}/klipper"
MOONRAKER_PATH="${HOME}/printer_data/config"
AFC_PATH="${HOME}/AFC-Klipper-Add-On"
PRINTER_CONFIG_PATH="${HOME}/printer_data/config"
AFC_CONFIG_PATH="${PRINTER_CONFIG_PATH}/AFC"

# Interface specific paths
MAINSAIL_SRC="$AFC_PATH/software/mainsail-afc.zip"
FLUIDD_SRC="$AFC_PATH/software/mainsail-afc.zip"
MAINSAIL_DST="$HOME/mainsail"
FLUIDD_DST="$HOME/fluidd"

# Variables
KLIPPER_SERVICE=klipper
GITREPO="https://github.com/ArmoredTurtle/AFC-Klipper-Add-On.git"
PRIOR_INSTALLATION=False
UPDATE_CONFIG=False
AUTO_UPDATE_CONFIG=False
UNINSTALL=False
BRANCH=main

# This FORCE_UPDATE variable is used to force an update of the AFC configuration files. This would typically be used
# when there are major changes to the AFC configuration files that require more changes than we can handle automatically.
# Anything before 1.0.0 or if it isn't defined will cause the FORCE_UPDATE to be TRUE
CURRENT_INSTALL_VERSION="1.0.0"
MIN_VERSION="1.0.0"
FORCE_UPDATE=True
BACKUP_DATE=$(date +%Y%m%d%H%M%S)


# Moonraker Config
MOONRAKER_UPDATE_CONFIG="""
[update_manager afc-software]
type: git_repo
path: ~/AFC-Klipper-Add-On
origin: $GITREPO
managed_services: klipper moonraker
primary_branch: $BRANCH
install_script: install-afc.sh
"""
Loading

0 comments on commit 9f7a9a1

Please sign in to comment.