feat: custom klipper repos
Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
131
scripts/switch_klipper_repo.sh
Normal file
131
scripts/switch_klipper_repo.sh
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user