refactor: rework some klipperscreen functions

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus
2022-04-17 19:50:05 +02:00
parent 3664cf0e2f
commit 26c812e1d3
2 changed files with 27 additions and 29 deletions

View File

@@ -15,6 +15,12 @@ set -e
#============== INSTALL KLIPPERSCREEN ==============# #============== INSTALL KLIPPERSCREEN ==============#
#===================================================# #===================================================#
function klipperscreen_systemd() {
local services
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/KlipperScreen.service")
echo "${services}"
}
function install_klipperscreen(){ function install_klipperscreen(){
### return early if python version check fails ### return early if python version check fails
if [ "$(python3_check)" == "false" ]; then if [ "$(python3_check)" == "false" ]; then
@@ -45,8 +51,6 @@ function klipperscreen_setup(){
#===================================================# #===================================================#
function remove_klipperscreen(){ function remove_klipperscreen(){
source_kiauh_ini
### remove KlipperScreen dir ### remove KlipperScreen dir
if [ -d "${KLIPPERSCREEN_DIR}" ]; then if [ -d "${KLIPPERSCREEN_DIR}" ]; then
status_msg "Removing KlipperScreen directory ..." status_msg "Removing KlipperScreen directory ..."
@@ -92,13 +96,14 @@ function remove_klipperscreen(){
#===================================================# #===================================================#
function update_klipperscreen(){ function update_klipperscreen(){
local old_md5
old_md5=$(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1)
do_action_service "stop" "KlipperScreen" do_action_service "stop" "KlipperScreen"
cd "${KLIPPERSCREEN_DIR}" cd "${KLIPPERSCREEN_DIR}"
KLIPPERSCREEN_OLDREQ_MD5SUM=$(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1)
git pull origin master -q && ok_msg "Fetch successfull!" git pull origin master -q && ok_msg "Fetch successfull!"
git checkout -f master && ok_msg "Checkout successfull" git checkout -f master && ok_msg "Checkout successfull"
#KLIPPERSCREEN_NEWREQ_MD5SUM=$(md5sum $KLIPPERSCREEN_DIR/scripts/KlipperScreen-requirements.txt) if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${KLIPPERSCREEN_OLDREQ_MD5SUM}" ]]; then
status_msg "New dependecies detected..." status_msg "New dependecies detected..."
PYTHONDIR="${HOME}/.KlipperScreen-env" PYTHONDIR="${HOME}/.KlipperScreen-env"
"${PYTHONDIR}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" "${PYTHONDIR}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt"
@@ -113,33 +118,27 @@ function update_klipperscreen(){
#===================================================# #===================================================#
function klipperscreen_status(){ function klipperscreen_status(){
klsccount=0 local sf_count status
klipperscreen_data=( sf_count="$(klipperscreen_systemd | wc -w)"
SERVICE
"${KLIPPERSCREEN_DIR}"
"${KLIPPERSCREEN_ENV_DIR}"
)
### count amount of klipperscreen_data service files in /etc/systemd/system ### remove the "SERVICE" entry from the data array if a moonraker service is installed
SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "KlipperScreen" | wc -l) local data_arr=(SERVICE "${KLIPPERSCREEN_DIR}" "${KLIPPERSCREEN_ENV_DIR}")
[ "${sf_count}" -gt 0 ] && unset "data_arr[0]"
### remove the "SERVICE" entry from the klipperscreen_data array if a KlipperScreen service is installed ### count+1 for each found data-item from array
[ "${SERVICE_FILE_COUNT}" -gt 0 ] && unset "klipperscreen_data[0]" local filecount=0
for data in "${data_arr[@]}"; do
#count+1 for each found data-item from array [ -e "${data}" ] && filecount=$(("${filecount}" + 1))
for klscd in "${klipperscreen_data[@]}"
do
if [ -e "${klscd}" ]; then
klsccount=$((klsccount + 1))
fi
done done
if [ "${klsccount}" == "${#klipperscreen_data[*]}" ]; then
KLIPPERSCREEN_STATUS="${green}Installed!${white} " if [ "${filecount}" == "${#data_arr[*]}" ]; then
elif [ "${klsccount}" == 0 ]; then status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")"
KLIPPERSCREEN_STATUS="${red}Not installed!${white} " elif [ "${filecount}" == 0 ]; then
status="${red}Not installed!${white} "
else else
KLIPPERSCREEN_STATUS="${yellow}Incomplete!${white} " status="${yellow}Incomplete!${white} "
fi fi
echo "${status}"
} }
function get_local_klipperscreen_commit(){ function get_local_klipperscreen_commit(){

View File

@@ -22,7 +22,7 @@ main_ui(){
echo -e "| 3) [Remove] | |" echo -e "| 3) [Remove] | |"
echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|" echo -e "| 4) [Advanced] | Mainsail: $MAINSAIL_STATUS|"
echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|" echo -e "| 5) [Backup] | Fluidd: $FLUIDD_STATUS|"
echo -e "| | KlipperScreen: $KLIPPERSCREEN_STATUS|" echo -e "| | KlipperScreen: $(klipperscreen_status)|"
echo -e "| 6) [Settings] | Telegram Bot: $(get_telegram_bot_status)|" echo -e "| 6) [Settings] | Telegram Bot: $(get_telegram_bot_status)|"
echo -e "| | |" echo -e "| | |"
echo -e "| $(get_kiauh_version)| Octoprint: $OCTOPRINT_STATUS|" echo -e "| $(get_kiauh_version)| Octoprint: $OCTOPRINT_STATUS|"
@@ -68,7 +68,6 @@ main_menu(){
fluidd_status fluidd_status
mainsail_status mainsail_status
octoprint_status octoprint_status
klipperscreen_status
main_ui main_ui
while true; do while true; do
read -p "${cyan}Perform action:${white} " action; echo read -p "${cyan}Perform action:${white} " action; echo