Uninstall and update works
This commit is contained in:
213
scripts/obico.sh
213
scripts/obico.sh
@@ -22,7 +22,7 @@ function moonraker_obico_systemd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function moonraker_obico_setup_dialog() {
|
function moonraker_obico_setup_dialog() {
|
||||||
status_msg "Initializing moonraker-obico installation ..."
|
status_msg "Initializing Moonraker-obico installation ..."
|
||||||
|
|
||||||
### return early if python version check fails
|
### return early if python version check fails
|
||||||
if [[ $(python3_check) == "false" ]]; then
|
if [[ $(python3_check) == "false" ]]; then
|
||||||
@@ -35,9 +35,9 @@ function moonraker_obico_setup_dialog() {
|
|||||||
local moonraker_obico_services
|
local moonraker_obico_services
|
||||||
moonraker_obico_services=$(moonraker_obico_systemd)
|
moonraker_obico_services=$(moonraker_obico_systemd)
|
||||||
if [[ -n ${moonraker_obico_services} ]]; then
|
if [[ -n ${moonraker_obico_services} ]]; then
|
||||||
local error="At least one moonraker-obico service is already installed:"
|
local error="At least one Moonraker-obico service is already installed:"
|
||||||
for s in ${moonraker_obico_services}; do
|
for s in ${moonraker_obico_services}; do
|
||||||
log_info "Found moonraker-obico service: ${s}"
|
log_info "Found Moonraker-obico service: ${s}"
|
||||||
error="${error}\n ➔ ${s}"
|
error="${error}\n ➔ ${s}"
|
||||||
done
|
done
|
||||||
print_error "${error}" && return
|
print_error "${error}" && return
|
||||||
@@ -70,24 +70,24 @@ function moonraker_obico_setup_dialog() {
|
|||||||
done
|
done
|
||||||
blank_line
|
blank_line
|
||||||
echo -e "| The setup will apply the same names to |"
|
echo -e "| The setup will apply the same names to |"
|
||||||
echo -e "| moonraker-obico! |"
|
echo -e "| Moonraker-obico! |"
|
||||||
blank_line
|
blank_line
|
||||||
echo -e "| Please select the number of moonraker-obico instances |"
|
echo -e "| Please select the number of Moonraker-obico instances |"
|
||||||
echo -e "| to install. Usually one moonraker-obico instance per |"
|
echo -e "| to install. Usually one Moonraker-obico instance per |"
|
||||||
echo -e "| Moonraker instance is required, but you may not |"
|
echo -e "| Moonraker instance is required, but you may not |"
|
||||||
echo -e "| install more moonraker-obico instances than available |"
|
echo -e "| install more Moonraker-obico instances than available |"
|
||||||
echo -e "| Moonraker instances. |"
|
echo -e "| Moonraker instances. |"
|
||||||
bottom_border
|
bottom_border
|
||||||
|
|
||||||
### ask for amount of instances
|
### ask for amount of instances
|
||||||
local re="^[1-9][0-9]*$"
|
local re="^[1-9][0-9]*$"
|
||||||
while [[ ! ${moonraker_obico_count} =~ ${re} || ${moonraker_obico_count} -gt ${moonraker_count} ]]; do
|
while [[ ! ${moonraker_obico_count} =~ ${re} || ${moonraker_obico_count} -gt ${moonraker_count} ]]; do
|
||||||
read -p "${cyan}###### Number of moonraker-obico instances to set up:${white} " -i "${moonraker_count}" -e moonraker_obico_count
|
read -p "${cyan}###### Number of Moonraker-obico instances to set up:${white} " -i "${moonraker_count}" -e moonraker_obico_count
|
||||||
### break if input is valid
|
### break if input is valid
|
||||||
[[ ${moonraker_obico_count} =~ ${re} && ${moonraker_obico_count} -le ${moonraker_count} ]] && break
|
[[ ${moonraker_obico_count} =~ ${re} && ${moonraker_obico_count} -le ${moonraker_count} ]] && break
|
||||||
### conditional error messages
|
### conditional error messages
|
||||||
[[ ! ${moonraker_obico_count} =~ ${re} ]] && error_msg "Input not a number"
|
[[ ! ${moonraker_obico_count} =~ ${re} ]] && error_msg "Input not a number"
|
||||||
(( moonraker_obico_count > moonraker_count )) && error_msg "Number of moonraker-obico instances larger than installed Moonraker instances"
|
(( moonraker_obico_count > moonraker_count )) && error_msg "Number of Moonraker-obico instances larger than installed Moonraker instances"
|
||||||
done && select_msg "${moonraker_obico_count}"
|
done && select_msg "${moonraker_obico_count}"
|
||||||
else
|
else
|
||||||
log_error "Internal error. moonraker_count of '${moonraker_count}' not equal or grather than one!"
|
log_error "Internal error. moonraker_count of '${moonraker_count}' not equal or grather than one!"
|
||||||
@@ -99,8 +99,8 @@ function moonraker_obico_setup_dialog() {
|
|||||||
### confirm instance amount
|
### confirm instance amount
|
||||||
local yn
|
local yn
|
||||||
while true; do
|
while true; do
|
||||||
(( moonraker_obico_count == 1 )) && local question="Install moonraker-obico?"
|
(( moonraker_obico_count == 1 )) && local question="Install Moonraker-obico?"
|
||||||
(( moonraker_obico_count > 1 )) && local question="Install ${moonraker_obico_count} moonraker-obico instances?"
|
(( moonraker_obico_count > 1 )) && local question="Install ${moonraker_obico_count} Moonraker-obico instances?"
|
||||||
read -p "${cyan}###### ${question} (Y/n):${white} " yn
|
read -p "${cyan}###### ${question} (Y/n):${white} " yn
|
||||||
case "${yn}" in
|
case "${yn}" in
|
||||||
Y|y|Yes|yes|"")
|
Y|y|Yes|yes|"")
|
||||||
@@ -108,7 +108,7 @@ function moonraker_obico_setup_dialog() {
|
|||||||
break;;
|
break;;
|
||||||
N|n|No|no)
|
N|n|No|no)
|
||||||
select_msg "No"
|
select_msg "No"
|
||||||
abort_msg "Exiting moonraker-obico setup ...\n"
|
abort_msg "Exiting Moonraker-obico setup ...\n"
|
||||||
return;;
|
return;;
|
||||||
*)
|
*)
|
||||||
error_msg "Invalid Input!";;
|
error_msg "Invalid Input!";;
|
||||||
@@ -122,8 +122,8 @@ function moonraker_obico_setup_dialog() {
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
(( moonraker_obico_count > 1 )) && status_msg "Installing ${moonraker_count} moonraker-obico instances ..."
|
(( moonraker_obico_count > 1 )) && status_msg "Installing ${moonraker_count} Moonraker-obico instances ..."
|
||||||
(( moonraker_obico_count == 1 )) && status_msg "Installing moonraker-obico ..."
|
(( moonraker_obico_count == 1 )) && status_msg "Installing Moonraker-obico ..."
|
||||||
moonraker_obico_setup "${user_input[@]}"
|
moonraker_obico_setup "${user_input[@]}"
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -179,88 +179,104 @@ function moonraker_obico_setup() {
|
|||||||
function clone_moonraker_obico() {
|
function clone_moonraker_obico() {
|
||||||
local repo=${1}
|
local repo=${1}
|
||||||
|
|
||||||
status_msg "Cloning moonraker-obico from ${repo} ..."
|
status_msg "Cloning Moonraker-obico from ${repo} ..."
|
||||||
|
|
||||||
### force remove existing moonraker-obico dir and clone into fresh moonraker-obico dir
|
### force remove existing moonraker-obico dir and clone into fresh moonraker-obico dir
|
||||||
[[ -d ${MOONRAKER_OBICO_DIR} ]] && rm -rf "${MOONRAKER_OBICO_DIR}"
|
[[ -d ${MOONRAKER_OBICO_DIR} ]] && rm -rf "${MOONRAKER_OBICO_DIR}"
|
||||||
|
|
||||||
cd "${HOME}" || exit 1
|
cd "${HOME}" || exit 1
|
||||||
if ! git clone "${MOONRAKER_OBICO_REPO}" "${MOONRAKER_OBICO_DIR}"; then
|
if ! git clone "${MOONRAKER_OBICO_REPO}" "${MOONRAKER_OBICO_DIR}"; then
|
||||||
print_error "Cloning moonraker-obico from\n ${repo}\n failed!"
|
print_error "Cloning Moonraker-obico from\n ${repo}\n failed!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function moonraker_obico_install() {
|
function moonraker_obico_install() {
|
||||||
echo "${MOONRAKER_OBICO_DIR}/install.sh" $*
|
"${MOONRAKER_OBICO_DIR}/install.sh" $@
|
||||||
}
|
}
|
||||||
|
|
||||||
#===================================================#
|
#===================================================#
|
||||||
#============= REMOVE MOONRAKER-OBICO ==============#
|
#============= REMOVE MOONRAKER-OBICO ==============#
|
||||||
#===================================================#
|
#===================================================#
|
||||||
|
|
||||||
function remove_klipperscreen() {
|
function remove_moonraker_obico_systemd() {
|
||||||
### remove KlipperScreen dir
|
[[ -z $(moonraker_obico_systemd) ]] && return
|
||||||
if [[ -d ${KLIPPERSCREEN_DIR} ]]; then
|
status_msg "Removing Moonraker-obico Systemd Services ..."
|
||||||
status_msg "Removing KlipperScreen directory ..."
|
|
||||||
rm -rf "${KLIPPERSCREEN_DIR}" && ok_msg "Directory removed!"
|
for service in $(moonraker_obico_systemd | cut -d"/" -f5); do
|
||||||
|
status_msg "Removing ${service} ..."
|
||||||
|
sudo systemctl stop "${service}"
|
||||||
|
sudo systemctl disable "${service}"
|
||||||
|
sudo rm -f "${SYSTEMD}/${service}"
|
||||||
|
ok_msg "Done!"
|
||||||
|
done
|
||||||
|
|
||||||
|
### reloading units
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl reset-failed
|
||||||
|
ok_msg "Moonraker-obico Services removed!"
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove_moonraker_obico_logs() {
|
||||||
|
local files regex="moonraker-obico(-[0-9a-zA-Z]+)?\.log(.*)?"
|
||||||
|
files=$(find "${KLIPPER_LOGS}" -maxdepth 1 -regextype posix-extended -regex "${KLIPPER_LOGS}/${regex}" 2> /dev/null | sort)
|
||||||
|
|
||||||
|
if [[ -n ${files} ]]; then
|
||||||
|
for file in ${files}; do
|
||||||
|
status_msg "Removing ${file} ..."
|
||||||
|
rm -f "${file}"
|
||||||
|
ok_msg "${file} removed!"
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
### remove KlipperScreen VENV dir
|
function remove_moonraker_obico_dir() {
|
||||||
if [[ -d ${KLIPPERSCREEN_ENV} ]]; then
|
[[ ! -d ${MOONRAKER_OBICO_DIR} ]] && return
|
||||||
status_msg "Removing KlipperScreen VENV directory ..."
|
|
||||||
rm -rf "${KLIPPERSCREEN_ENV}" && ok_msg "Directory removed!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
### remove KlipperScreen service
|
status_msg "Removing Moonraker-obico directory ..."
|
||||||
if [[ -e "${SYSTEMD}/KlipperScreen.service" ]]; then
|
rm -rf "${MOONRAKER_OBICO_DIR}"
|
||||||
status_msg "Removing KlipperScreen service ..."
|
ok_msg "Directory removed!"
|
||||||
do_action_service "stop" "KlipperScreen"
|
}
|
||||||
do_action_service "disable" "KlipperScreen"
|
|
||||||
sudo rm -f "${SYSTEMD}/KlipperScreen.service"
|
|
||||||
|
|
||||||
###reloading units
|
function remove_moonraker_obico_env() {
|
||||||
sudo systemctl daemon-reload
|
[[ ! -d "${HOME}/moonraker-env" ]] && return
|
||||||
sudo systemctl reset-failed
|
|
||||||
ok_msg "KlipperScreen Service removed!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
### remove KlipperScreen log
|
status_msg "Removing moonraker-env directory ..."
|
||||||
if [[ -e "/tmp/KlipperScreen.log" ]]; then
|
rm -rf "${HOME}/moonraker-env"
|
||||||
status_msg "Removing KlipperScreen log file ..."
|
ok_msg "Directory removed!"
|
||||||
rm -f "/tmp/KlipperScreen.log" && ok_msg "File removed!"
|
}
|
||||||
fi
|
|
||||||
|
|
||||||
### remove KlipperScreen log symlink in config dir
|
function remove_moonraker_obico() {
|
||||||
if [[ -e "${KLIPPER_CONFIG}/KlipperScreen.log" ]]; then
|
remove_moonraker_obico_systemd
|
||||||
status_msg "Removing KlipperScreen log symlink ..."
|
remove_moonraker_obico_logs
|
||||||
rm -f "${KLIPPER_CONFIG}/KlipperScreen.log" && ok_msg "File removed!"
|
remove_moonraker_obico_dir
|
||||||
fi
|
remove_moonraker_obico_env
|
||||||
|
|
||||||
print_confirm "KlipperScreen successfully removed!"
|
print_confirm "Moonraker-obico was successfully removed!"
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
#===================================================#
|
#===================================================#
|
||||||
#============= UPDATE MOONRAKER-OBICO ==============#
|
#============= UPDATE MOONRAKER-OBICO ==============#
|
||||||
#===================================================#
|
#===================================================#
|
||||||
|
|
||||||
function update_klipperscreen() {
|
function update_moonraker() {
|
||||||
local old_md5
|
for service in $(moonraker_obico_systemd | cut -d"/" -f5); do
|
||||||
old_md5=$(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1)
|
do_action_service "stop" "${service}"
|
||||||
|
done
|
||||||
|
|
||||||
do_action_service "stop" "KlipperScreen"
|
if [[ ! -d ${MOONRAKER_OBICO_DIR} ]]; then
|
||||||
cd "${KLIPPERSCREEN_DIR}"
|
clone_moonraker_obico "${MOONRAKER_OBICO_REPO}"
|
||||||
git pull origin master -q && ok_msg "Fetch successfull!"
|
else
|
||||||
git checkout -f master && ok_msg "Checkout successfull"
|
status_msg "Updating Moonraker-obico ..."
|
||||||
|
cd "${MOONRAKER_OBICO_DIR}" && git pull
|
||||||
if [[ $(md5sum "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
|
"${MOONRAKER_OBICO_DIR}/install.sh" -u
|
||||||
status_msg "New dependecies detected..."
|
|
||||||
"${KLIPPERSCREEN_ENV}"/bin/pip install -r "${KLIPPERSCREEN_DIR}/scripts/KlipperScreen-requirements.txt"
|
|
||||||
ok_msg "Dependencies have been installed!"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ok_msg "Update complete!"
|
ok_msg "Update complete!"
|
||||||
do_action_service "start" "KlipperScreen"
|
for service in $(moonraker_obico_systemd | cut -d"/" -f5); do
|
||||||
|
do_action_service "restart" "${service}"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
#===================================================#
|
#===================================================#
|
||||||
@@ -290,76 +306,3 @@ function get_obico_status() {
|
|||||||
fi
|
fi
|
||||||
echo "${status}"
|
echo "${status}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_local_klipperscreen_commit() {
|
|
||||||
[[ ! -d ${KLIPPERSCREEN_DIR} || ! -d "${KLIPPERSCREEN_DIR}/.git" ]] && return
|
|
||||||
|
|
||||||
local commit
|
|
||||||
cd "${KLIPPERSCREEN_DIR}"
|
|
||||||
commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
|
|
||||||
echo "${commit}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_remote_klipperscreen_commit() {
|
|
||||||
[[ ! -d ${KLIPPERSCREEN_DIR} || ! -d "${KLIPPERSCREEN_DIR}/.git" ]] && return
|
|
||||||
|
|
||||||
local commit
|
|
||||||
cd "${KLIPPERSCREEN_DIR}" && git fetch origin -q
|
|
||||||
commit=$(git describe origin/master --always --tags | cut -d "-" -f 1,2)
|
|
||||||
echo "${commit}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function compare_klipperscreen_versions() {
|
|
||||||
local versions local_ver remote_ver
|
|
||||||
local_ver="$(get_local_klipperscreen_commit)"
|
|
||||||
remote_ver="$(get_remote_klipperscreen_commit)"
|
|
||||||
|
|
||||||
if [[ ${local_ver} != "${remote_ver}" ]]; then
|
|
||||||
versions="${yellow}$(printf " %-14s" "${local_ver}")${white}"
|
|
||||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
|
||||||
# add moonraker to application_updates_available in kiauh.ini
|
|
||||||
add_to_application_updates "klipperscreen"
|
|
||||||
else
|
|
||||||
versions="${green}$(printf " %-14s" "${local_ver}")${white}"
|
|
||||||
versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "${versions}"
|
|
||||||
}
|
|
||||||
|
|
||||||
#================================================#
|
|
||||||
#=================== HELPERS ====================#
|
|
||||||
#================================================#
|
|
||||||
|
|
||||||
function patch_klipperscreen_update_manager() {
|
|
||||||
local patched="false"
|
|
||||||
local moonraker_configs
|
|
||||||
moonraker_configs=$(find "${KLIPPER_CONFIG}" -type f -name "moonraker.conf" | sort)
|
|
||||||
|
|
||||||
for conf in ${moonraker_configs}; do
|
|
||||||
if ! grep -Eq "^\[update_manager KlipperScreen\]$" "${conf}"; then
|
|
||||||
### add new line to conf if it doesn't end with one
|
|
||||||
[[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
|
|
||||||
|
|
||||||
### add KlipperScreens update manager section to moonraker.conf
|
|
||||||
status_msg "Adding KlipperScreen to update manager in file:\n ${conf}"
|
|
||||||
/bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
|
|
||||||
|
|
||||||
[update_manager KlipperScreen]
|
|
||||||
type: git_repo
|
|
||||||
path: ${HOME}/KlipperScreen
|
|
||||||
origin: https://github.com/jordanruthe/KlipperScreen.git
|
|
||||||
env: ${HOME}/.KlipperScreen-env/bin/python
|
|
||||||
requirements: scripts/KlipperScreen-requirements.txt
|
|
||||||
install_script: scripts/KlipperScreen-install.sh
|
|
||||||
MOONRAKER_CONF
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
patched="true"
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ ${patched} == "true" ]]; then
|
|
||||||
do_action_service "restart" "moonraker"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user