2022-05-29 20:11:15 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
#=======================================================================#
|
2025-10-11 16:38:08 +02:00
|
|
|
# Copyright (C) 2020 - 2025 Dominik Willner <th33xitus@gmail.com> #
|
2022-05-29 20:11:15 +02:00
|
|
|
# #
|
|
|
|
|
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
2023-08-26 18:11:00 +02:00
|
|
|
# https://github.com/dw-0/kiauh #
|
2022-05-29 20:11:15 +02:00
|
|
|
# #
|
|
|
|
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
|
|
|
|
#=======================================================================#
|
2020-05-22 18:20:17 +02:00
|
|
|
|
2022-05-29 20:11:15 +02:00
|
|
|
set -e
|
2024-10-24 12:24:05 +02:00
|
|
|
clear -x
|
2020-05-22 18:20:17 +02:00
|
|
|
|
2024-09-21 21:01:19 +02:00
|
|
|
# make sure we have the correct permissions while running the script
|
|
|
|
|
umask 022
|
|
|
|
|
|
2022-05-29 20:11:15 +02:00
|
|
|
#===================================================#
|
|
|
|
|
#=================== UPDATE KIAUH ==================#
|
|
|
|
|
#===================================================#
|
|
|
|
|
|
|
|
|
|
function update_kiauh() {
|
|
|
|
|
status_msg "Updating KIAUH ..."
|
|
|
|
|
|
|
|
|
|
cd "${KIAUH_SRCDIR}"
|
|
|
|
|
git reset --hard && git pull
|
|
|
|
|
|
|
|
|
|
ok_msg "Update complete! Please restart KIAUH."
|
|
|
|
|
exit 0
|
2020-08-23 20:48:07 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-29 20:11:15 +02:00
|
|
|
#===================================================#
|
|
|
|
|
#=================== KIAUH STATUS ==================#
|
|
|
|
|
#===================================================#
|
|
|
|
|
|
|
|
|
|
function kiauh_update_avail() {
|
|
|
|
|
[[ ! -d "${KIAUH_SRCDIR}/.git" ]] && return
|
|
|
|
|
local origin head
|
|
|
|
|
|
|
|
|
|
cd "${KIAUH_SRCDIR}"
|
|
|
|
|
|
|
|
|
|
### abort if not on master branch
|
|
|
|
|
! git branch -a | grep -q "\* master" && return
|
|
|
|
|
|
|
|
|
|
### compare commit hash
|
|
|
|
|
git fetch -q
|
|
|
|
|
origin=$(git rev-parse --short=8 origin/master)
|
|
|
|
|
head=$(git rev-parse --short=8 HEAD)
|
|
|
|
|
|
|
|
|
|
if [[ ${origin} != "${head}" ]]; then
|
|
|
|
|
echo "true"
|
2020-07-15 21:41:20 +02:00
|
|
|
fi
|
2020-05-22 18:20:17 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-29 20:11:15 +02:00
|
|
|
function kiauh_update_dialog() {
|
|
|
|
|
[[ ! $(kiauh_update_avail) == "true" ]] && return
|
2025-10-15 17:05:18 +02:00
|
|
|
echo -e "/-------------------------------------------------------\\"
|
2022-05-29 20:11:15 +02:00
|
|
|
echo -e "|${green} New KIAUH update available! ${white}|"
|
2025-10-15 17:05:18 +02:00
|
|
|
echo -e "|-------------------------------------------------------|"
|
2022-05-29 20:11:15 +02:00
|
|
|
echo -e "|${green} View Changelog: https://git.io/JnmlX ${white}|"
|
2025-10-15 17:05:18 +02:00
|
|
|
echo -e "| |"
|
2022-05-29 20:11:15 +02:00
|
|
|
echo -e "|${yellow} It is recommended to keep KIAUH up to date. Updates ${white}|"
|
|
|
|
|
echo -e "|${yellow} usually contain bugfixes, important changes or new ${white}|"
|
|
|
|
|
echo -e "|${yellow} features. Please consider updating! ${white}|"
|
2025-10-15 17:05:18 +02:00
|
|
|
echo -e "\-------------------------------------------------------/"
|
2022-05-29 20:11:15 +02:00
|
|
|
|
|
|
|
|
local yn
|
|
|
|
|
read -p "${cyan}###### Do you want to update now? (Y/n):${white} " yn
|
|
|
|
|
while true; do
|
|
|
|
|
case "${yn}" in
|
2024-08-31 19:16:52 +02:00
|
|
|
Y|y|Yes|yes|"")
|
|
|
|
|
do_action "update_kiauh"
|
|
|
|
|
break;;
|
|
|
|
|
N|n|No|no)
|
|
|
|
|
break;;
|
|
|
|
|
*)
|
|
|
|
|
deny_action "kiauh_update_dialog";;
|
2022-05-29 20:11:15 +02:00
|
|
|
esac
|
|
|
|
|
done
|
2020-05-22 18:20:17 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-11 16:38:08 +02:00
|
|
|
function check_euid() {
|
|
|
|
|
if [[ ${EUID} -eq 0 ]]; then
|
|
|
|
|
echo -e "${red}"
|
2025-10-15 17:05:18 +02:00
|
|
|
echo -e "/-------------------------------------------------------\\"
|
2025-10-11 16:38:08 +02:00
|
|
|
echo -e "| !!! THIS SCRIPT MUST NOT RUN AS ROOT !!! |"
|
|
|
|
|
echo -e "| |"
|
|
|
|
|
echo -e "| It will ask for credentials as needed. |"
|
2025-10-15 17:05:18 +02:00
|
|
|
echo -e "\-------------------------------------------------------/"
|
2025-10-11 16:38:08 +02:00
|
|
|
echo -e "${white}"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2024-08-31 19:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-11 16:38:08 +02:00
|
|
|
function check_if_ratos() {
|
|
|
|
|
if [[ -n $(which ratos) ]]; then
|
|
|
|
|
echo -e "${red}"
|
2025-10-15 17:05:18 +02:00
|
|
|
echo -e "/-------------------------------------------------------\\"
|
2025-10-11 16:38:08 +02:00
|
|
|
echo -e "| !!! RatOS 2.1 or greater detected !!! |"
|
|
|
|
|
echo -e "| |"
|
|
|
|
|
echo -e "| KIAUH does currently not support RatOS. |"
|
|
|
|
|
echo -e "| If you have any questions, please ask for help on the |"
|
|
|
|
|
echo -e "| RatRig Community Discord: https://discord.gg/ratrig |"
|
2025-10-15 17:05:18 +02:00
|
|
|
echo -e "\-------------------------------------------------------/"
|
2025-10-11 16:38:08 +02:00
|
|
|
echo -e "${white}"
|
2024-08-31 19:16:52 +02:00
|
|
|
exit 1
|
|
|
|
|
fi
|
2025-10-11 16:38:08 +02:00
|
|
|
}
|
2024-08-31 19:16:52 +02:00
|
|
|
|
2025-10-11 16:38:08 +02:00
|
|
|
function main() {
|
|
|
|
|
local entrypoint
|
2024-08-31 19:16:52 +02:00
|
|
|
|
2025-10-11 16:38:08 +02:00
|
|
|
if ! command -v python3 &>/dev/null || [[ $(python3 -V | cut -d " " -f2 | cut -d "." -f2) -lt 8 ]]; then
|
|
|
|
|
echo "Python 3.8 or higher is not installed!"
|
|
|
|
|
echo "Please install Python 3.8 or higher and try again."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2024-08-31 19:16:52 +02:00
|
|
|
|
2025-10-11 16:38:08 +02:00
|
|
|
entrypoint=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
|
2024-08-31 19:16:52 +02:00
|
|
|
|
2025-10-11 16:38:08 +02:00
|
|
|
export PYTHONPATH="${entrypoint}"
|
2024-08-31 19:16:52 +02:00
|
|
|
|
2025-10-11 16:38:08 +02:00
|
|
|
clear -x
|
|
|
|
|
python3 "${entrypoint}/kiauh/main.py"
|
2024-08-31 19:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-31 20:30:33 +02:00
|
|
|
check_if_ratos
|
2020-05-22 18:20:17 +02:00
|
|
|
check_euid
|
2022-05-29 20:11:15 +02:00
|
|
|
kiauh_update_dialog
|
2024-08-31 19:16:52 +02:00
|
|
|
main
|