feat: custom klipper repos

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus
2022-04-17 17:45:10 +02:00
parent 5f78228eb0
commit af0f03008c
6 changed files with 214 additions and 45 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.idea
.shellcheckrc
.shellcheckrc
klipper_repos.txt

12
klipper_repos.txt Normal file
View File

@@ -0,0 +1,12 @@
##############################################################
## DO NOT REMOVE OR EDIT THIS COMMENT BLOCK! ##
## ##
## Always add the URL and branch in this form: ##
## <URL>,<branch> ##
## Example: ##
## https://github.com/Klipper3d/klipper,master ##
## ##
## A wrong format will cause issues! You have been warned! ##
##############################################################
##~~~~~ Add the custom repositories below this line ~~~~~~~~##
https://github.com/Klipper3d/klipper,master

View File

@@ -1,36 +0,0 @@
#!/bin/bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
switch_to_master(){
cd $KLIPPER_DIR
status_msg "Switching...Please wait ..."; echo
git fetch origin -q && git checkout master; echo
}
switch_to_scurve_shaping(){
cd $KLIPPER_DIR
status_msg "Switching...Please wait ..."; echo
if ! git remote | grep dmbutyugin -q; then
git remote add dmbutyugin $DMBUTYUGIN_REPO
fi
git fetch dmbutyugin -q && git checkout scurve-shaping; echo
}
switch_to_scurve_smoothing(){
cd $KLIPPER_DIR
status_msg "Switching...Please wait ..."; echo
if ! git remote | grep dmbutyugin -q; then
git remote add dmbutyugin $DMBUTYUGIN_REPO
fi
git fetch dmbutyugin -q && git checkout scurve-smoothing; echo
}

View File

@@ -0,0 +1,131 @@
#!/bin/bash
#=======================================================================#
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
# #
# This file is part of KIAUH - Klipper Installation And Update Helper #
# https://github.com/th33xitus/kiauh #
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
#=======================================================================#
set -e
function change_klipper_repo_menu(){
local repo_file="${SRCDIR}/kiauh/klipper_repos.txt"
local url branch i=0
top_border
echo -e "| ~~~~~~~~ [ Set custom Klipper repo ] ~~~~~~~~ | "
hr
blank_line
### dynamically generate the repolist from the klipper_repos.txt textfile
get_klipper_repo_list "${repo_file}"
blank_line
back_help_footer
while IFS="," read -r col1 col2; do
url+=("${col1}")
branch+=("${col2}")
i=$((i+1))
done < <(grep "" "${repo_file}" | tail -n "+12")
while true; do
read -p "${cyan}Select Klipper repo:${white} " option
if [ "${option}" = "b" ] || [ "${option}" = "B" ]; then
clear && print_header
settings_menu
break
elif [ "${option}" = "h" ] || [ "${option}" = "H" ]; then
clear && print_header
show_custom_klipper_repo_help
elif [ "${option}" -le ${#url[@]} ]; then
if [ -d "${KLIPPER_DIR}" ]; then
top_border
echo -e "| ${red}!!! ATTENTION !!!${white} |"
echo -e "| Existing Klipper folder found! Proceeding will remove | "
echo -e "| the existing Klipper folder and replace it with a | "
echo -e "| clean copy of the previously selected source repo! | "
bottom_border
while true; do
read -p "${cyan}###### Proceed? (Y/n):${white} " yn
case "${yn}" in
Y|y|Yes|yes|"")
select_msg "Yes"
switch_klipper_repo "${url[${option}]}" "${branch[${option}]}"
set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}"
break;;
N|n|No|no)
select_msg "No"
break;;
*)
error_msg "Invalid command!";;
esac
done
else
status_msg "Set custom Klipper repository to:\n ● Repository URL: ${url[${option}]}\n ● Branch: ${branch[${option}]}"
set_custom_klipper_repo "${url[${option}]}" "${branch[${option}]}"
ok_msg "This repo will now be used for new Klipper installations!\n"
fi
break
else
clear && print_header
print_error "Invalid command!"
change_klipper_repo_menu
fi
done
}
#================================================#
#=================== HELPERS ====================#
#================================================#
function get_klipper_repo_list(){
local repo_file=${1} i=0
while IFS="," read -r col1 col2; do
col1=$(echo "${col1}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//" )
col1=${yellow}${col1}${white}
printf "| ${i}) %s → %-31s|\n" "${col1}" "${col2}"
i=$((i+1))
done < <(grep "" "${repo_file}" | tail -n "+12")
}
function switch_klipper_repo(){
local url branch
url=${1} branch=${2}
status_msg "Switching Klipper repository..."
do_action_service "stop" "klipper"
cd ~ && rm -rf "${KLIPPER_DIR}"
git clone "${url}" && cd "${KLIPPER_DIR}"
git checkout "${branch}" && cd ~
do_action_service "start" "klipper"
}
function show_custom_klipper_repo_help(){
top_border
echo -e "| ~~~~ < ? > Help: Custom Klipper repo < ? > ~~~~ |"
hr
echo -e "| With this setting, it is possible to install Klipper | "
echo -e "| from a custom repository. It will also switch an | "
echo -e "| existing Klipper installation to the newly selected | "
echo -e "| source repository. | "
echo -e "| A list of selectable repositories is automatically | "
echo -e "| generated by a 'klipper_repos.txt' textfile in KIAUHs | "
echo -e "| root folder. You can add as many additional repos as | "
echo -e "| you wish. Make sure to always add URL ${red}and${white} branch! | "
blank_line
echo -e "| Default: ${red}none${white} |"
blank_line
back_footer
while true; do
read -p "${cyan}###### Please select:${white} " choice
case "${choice}" in
B|b)
clear && print_header
change_klipper_repo_menu
break;;
*)
deny_action "show_settings_help";;
esac
done
}

View File

@@ -14,14 +14,31 @@ set -e
function settings_ui() {
read_kiauh_ini
local custom_cfg_loc="${custom_klipper_cfg_loc}"
local custom_repo="${custom_klipper_repo}"
local custom_branch="${custom_klipper_repo_branch}"
local ms_pre_rls="${mainsail_install_unstable}"
local fl_pre_rls="${fluidd_install_unstable}"
### config location
if [ -z "${custom_cfg_loc}" ]; then
custom_cfg_loc="${cyan}${KLIPPER_CONFIG}${white}"
else
custom_cfg_loc="${cyan}${custom_cfg_loc}${white}"
fi
### custom repository
custom_repo=$(echo "${custom_repo}" | sed "s/https:\/\/github\.com\///" | sed "s/\.git$//" )
if [ -z "${custom_repo}" ]; then
custom_repo="${cyan}Klipper3D/klipper${white}"
else
custom_repo="${cyan}${custom_repo}${white}"
fi
### custom repository branch
if [ -z "${custom_branch}" ]; then
custom_branch="${cyan}master${white}"
else
custom_branch="${cyan}${custom_branch}${white}"
fi
### webinterface stable toggle
if [ "${ms_pre_rls}" == "false" ]; then
ms_pre_rls="${red}${ms_pre_rls}${white}"
else
@@ -37,15 +54,27 @@ function settings_ui() {
echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") |"
hr
echo -e "| Klipper: |"
printf "| Config folder: %-49s|\n" "${custom_cfg_loc}"
blank_line
echo -e "| ● Config folder: |"
printf "| %-60s|\n" "${custom_cfg_loc}"
echo -e "| ● Repository: |"
printf "| %-70s|\n" "${custom_repo} (${custom_branch})"
hr
echo -e "| Install unstable releases: |"
printf "| Mainsail: %-56s|\n" "${ms_pre_rls}"
printf "| Fluidd: %-56s|\n" "${fl_pre_rls}"
printf "| Mainsail: %-55s|\n" "${ms_pre_rls}"
printf "| Fluidd: %-55s|\n" "${fl_pre_rls}"
hr
echo -e "| 1) Change Klipper config folder location |"
echo -e "| 2) Allow / Disallow unstable Mainsail releases |"
echo -e "| 3) Allow / Disallow unstable Fluidd releases |"
echo -e "| 2) Set custom Klipper repository |"
if [ "${mainsail_install_unstable}" == "false" ]; then
echo -e "| 3) ${green}Allow${white} unstable Mainsail releases |"
else
echo -e "| 3) ${red}Disallow${white} unstable Mainsail releases |"
fi
if [ "${fluidd_install_unstable}" == "false" ]; then
echo -e "| 4) ${green}Allow${white} unstable Fluidd releases |"
else
echo -e "| 4) ${red}Disallow${white} unstable Fluidd releases |"
fi
back_help_footer
}
@@ -89,6 +118,7 @@ function show_settings_help(){
}
settings_menu(){
clear && print_header
settings_ui
while true; do
read -p "${cyan}Perform action:${white} " action; echo
@@ -96,9 +126,13 @@ settings_menu(){
1)
change_klipper_cfg_folder && settings_ui;;
2)
switch_mainsail_releasetype && settings_ui;;
clear && print_header
change_klipper_repo_menu
settings_ui;;
3)
switch_fluidd_releasetype && settings_ui;;
switch_mainsail_releasetype && settings_menu;;
4)
switch_fluidd_releasetype && settings_menu;;
B|b)
clear
main_menu

View File

@@ -134,6 +134,12 @@ function init_ini(){
if ! grep -Eq "^custom_klipper_cfg_loc=" "${INI_FILE}"; then
echo -e "\ncustom_klipper_cfg_loc=\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^custom_klipper_repo=" "${INI_FILE}"; then
echo -e "\ncustom_klipper_repo=\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^custom_klipper_repo_branch=" "${INI_FILE}"; then
echo -e "\ncustom_klipper_repo_branch=\c" >> "${INI_FILE}"
fi
if ! grep -Eq "^mainsail_install_unstable=" "${INI_FILE}"; then
echo -e "\nmainsail_install_unstable=false\c" >> "${INI_FILE}"
fi
@@ -304,6 +310,27 @@ function switch_fluidd_releasetype() {
fi
}
function switch_fluidd_releasetype() {
read_kiauh_ini
local state="${fluidd_install_unstable}"
if [ "${state}" == "false" ]; then
sed -i '/fluidd_install_unstable=/s/false/true/' "${INI_FILE}"
log_info "fluidd_install_unstable changed (false -> true) "
else
sed -i '/fluidd_install_unstable=/s/true/false/' "${INI_FILE}"
log_info "fluidd_install_unstable changed (true -> false) "
fi
}
function set_custom_klipper_repo() {
read_kiauh_ini
local repo_url=${1} branch=${2}
sed -i "/^custom_klipper_repo=/d" "${INI_FILE}"
sed -i '$a'"custom_klipper_repo=${repo_url}" "${INI_FILE}"
sed -i "/^custom_klipper_repo_branch=/d" "${INI_FILE}"
sed -i '$a'"custom_klipper_repo_branch=${branch}" "${INI_FILE}"
}
#================================================#
#=============== HANDLE SERVICES ================#
#================================================#