refactor: octoprint status
also remove unused functions Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
@@ -15,6 +15,12 @@ set -e
|
|||||||
#=============== INSTALL OCTOPRINT ===============#
|
#=============== INSTALL OCTOPRINT ===============#
|
||||||
#=================================================#
|
#=================================================#
|
||||||
|
|
||||||
|
function octoprint_systemd() {
|
||||||
|
local services
|
||||||
|
services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/octoprint(-[^0])?[0-9]*.service")
|
||||||
|
echo "${services}"
|
||||||
|
}
|
||||||
|
|
||||||
function octoprint_setup_dialog(){
|
function octoprint_setup_dialog(){
|
||||||
status_msg "Initializing OctoPrint installation ..."
|
status_msg "Initializing OctoPrint installation ..."
|
||||||
|
|
||||||
@@ -254,20 +260,19 @@ function print_op_ip_list(){
|
|||||||
|
|
||||||
function remove_octoprint(){
|
function remove_octoprint(){
|
||||||
###remove all octoprint services
|
###remove all octoprint services
|
||||||
if ls /etc/systemd/system/octoprint*.service 2>/dev/null 1>&2; then
|
[ -z "$(octoprint_systemd)" ] && return
|
||||||
status_msg "Removing OctoPrint Services ..."
|
status_msg "Removing Moonraker Systemd Services ..."
|
||||||
for service in $(ls /etc/systemd/system/octoprint*.service | cut -d"/" -f5)
|
for service in $(octoprint_systemd | cut -d"/" -f5)
|
||||||
do
|
do
|
||||||
status_msg "Removing ${service} ..."
|
status_msg "Removing ${service} ..."
|
||||||
sudo systemctl stop "${service}"
|
sudo systemctl stop "${service}"
|
||||||
sudo systemctl disable "${service}"
|
sudo systemctl disable "${service}"
|
||||||
sudo rm -f "${SYSTEMD}/${service}"
|
sudo rm -f "${SYSTEMD}/${service}"
|
||||||
ok_msg "OctoPrint Service removed!"
|
ok_msg "Done!"
|
||||||
done
|
done
|
||||||
### reloading units
|
### reloading units
|
||||||
sudo systemctl daemon-reload
|
sudo systemctl daemon-reload
|
||||||
sudo systemctl reset-failed
|
sudo systemctl reset-failed
|
||||||
fi
|
|
||||||
|
|
||||||
### remove sudoers file
|
### remove sudoers file
|
||||||
if [ -f /etc/sudoers.d/octoprint-shutdown ]; then
|
if [ -f /etc/sudoers.d/octoprint-shutdown ]; then
|
||||||
@@ -299,63 +304,25 @@ function remove_octoprint(){
|
|||||||
#=================================================#
|
#=================================================#
|
||||||
|
|
||||||
function octoprint_status(){
|
function octoprint_status(){
|
||||||
ocount=0
|
local sf_count status
|
||||||
octoprint_data=(
|
sf_count="$(octoprint_systemd | wc -w)"
|
||||||
SERVICE
|
|
||||||
"${OCTOPRINT_DIR}"
|
|
||||||
)
|
|
||||||
### count amount of octoprint service files in /etc/systemd/system
|
|
||||||
SERVICE_FILE_COUNT=$(ls /etc/systemd/system | grep -E "^octoprint(\-[[:digit:]]+)?\.service$" | wc -l)
|
|
||||||
|
|
||||||
### remove the "SERVICE" entry from the octoprint_data array if a octoprint service is installed
|
### remove the "SERVICE" entry from the data array if a moonraker service is installed
|
||||||
[ "${SERVICE_FILE_COUNT}" -gt 0 ] && unset "octoprint_data[0]"
|
local data_arr=(SERVICE "${OCTOPRINT_DIR}")
|
||||||
|
[ "${sf_count}" -gt 0 ] && unset "data_arr[0]"
|
||||||
|
|
||||||
#count+1 for each found data-item from array
|
### count+1 for each found data-item from array
|
||||||
for op in "${octoprint_data[@]}"
|
local filecount=0
|
||||||
do
|
for data in "${data_arr[@]}"; do
|
||||||
if [ -e "${op}" ]; then
|
[ -e "${data}" ] && filecount=$(("${filecount}" + 1))
|
||||||
ocount=$((ocount+1))
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
### display status
|
if [ "${filecount}" == "${#data_arr[*]}" ]; then
|
||||||
if [ "${ocount}" == "${#octoprint_data[*]}" ]; then
|
status="$(printf "${green}Installed: %-5s${white}" "${sf_count}")"
|
||||||
OCTOPRINT_STATUS="$(printf "${green}Installed: %-5s${default}" "${SERVICE_FILE_COUNT}")"
|
elif [ "${filecount}" == 0 ]; then
|
||||||
elif [ "${ocount}" == 0 ]; then
|
status="${red}Not installed!${white} "
|
||||||
OCTOPRINT_STATUS="${red}Not installed!${white} "
|
|
||||||
else
|
else
|
||||||
OCTOPRINT_STATUS="${yellow}Incomplete!${white} "
|
status="${yellow}Incomplete!${white} "
|
||||||
fi
|
fi
|
||||||
}
|
echo "${status}"
|
||||||
|
}
|
||||||
function read_octoprint_service_status(){
|
|
||||||
unset OPRINT_SERVICE_STATUS
|
|
||||||
if [ ! -f "/etc/systemd/system/octoprint.service" ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
if systemctl list-unit-files | grep -E "octoprint*" | grep "enabled" &>/dev/null; then
|
|
||||||
OPRINT_SERVICE_STATUS="${red}[Disable]${white} OctoPrint Service "
|
|
||||||
else
|
|
||||||
OPRINT_SERVICE_STATUS="${green}[Enable]${white} OctoPrint Service "
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#================================================#
|
|
||||||
#=================== HELPERS ====================#
|
|
||||||
#================================================#
|
|
||||||
|
|
||||||
function toggle_octoprint_service(){
|
|
||||||
if systemctl list-unit-files | grep -E "octoprint.*" | grep "enabled" &>/dev/null; then
|
|
||||||
do_action_service "stop" "octoprint"
|
|
||||||
do_action_service "disable" "octoprint"
|
|
||||||
sleep 2
|
|
||||||
CONFIRM_MSG=" OctoPrint Service is now >>> DISABLED <<< !"
|
|
||||||
elif systemctl list-unit-files | grep -E "octoprint.*" | grep "disabled" &>/dev/null; then
|
|
||||||
do_action_service "enable" "octoprint"
|
|
||||||
do_action_service "start" "octoprint"
|
|
||||||
sleep 2
|
|
||||||
CONFIRM_MSG=" OctoPrint Service is now >>> ENABLED <<< !"
|
|
||||||
else
|
|
||||||
ERROR_MSG=" You cannot activate a service that does not exist!"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,7 @@ main_ui(){
|
|||||||
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)|"
|
||||||
quit_footer
|
quit_footer
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,8 +64,6 @@ main_menu(){
|
|||||||
print_header
|
print_header
|
||||||
#prompt for KIAUH update if update available
|
#prompt for KIAUH update if update available
|
||||||
kiauh_update_dialog
|
kiauh_update_dialog
|
||||||
#check install status
|
|
||||||
octoprint_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
|
||||||
|
|||||||
Reference in New Issue
Block a user