diff --git a/.gitignore b/.gitignore
index 7084f49..560b8c5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
-klipper_repos.txt
\ No newline at end of file
+.vscode
+*.code-workspace
+klipper_repos.txt
diff --git a/README.md b/README.md
index e75d00c..9a68ccb 100644
--- a/README.md
+++ b/README.md
@@ -33,7 +33,7 @@ that you have a functional Linux system on hand. `Raspberry Pi OS Lite (32bit)`
if you are using a Raspberry Pi. The [official Raspberry Pi Imager](https://www.raspberrypi.com/software/)
is the simplest way to flash an image like this to an SD card.
-* Once you downloaded, installed and launched the Raspberry Pi Imager
+* Once you have downloaded, installed and launched the Raspberry Pi Imager,
select `Choose OS -> Raspberry Pi OS (other)`: \
@@ -47,7 +47,7 @@ select `Choose OS -> Raspberry Pi OS (other)`: \
* Back in the Raspberry Pi Imager's main menu, select the corresponding SD card to which
you want to flash the image.
-* Make sure to go into the Advaced Option (the cog icon in the lower left corner of the main menu)
+* Make sure to go into the Advanced Option (the cog icon in the lower left corner of the main menu)
and enable SSH and configure Wi-Fi.
* If you need more help for using the Raspberry Pi Imager, please visit the [official documentation](https://www.raspberrypi.com/documentation/computers/getting-started.html).
@@ -68,14 +68,14 @@ sudo apt-get update && sudo apt-get install git -y
```
* **Step 2:** \
-Once git is installed, use the following command to download KIAUH into your home-directoy:
+Once git is installed, use the following command to download KIAUH into your home-directory:
```shell
cd ~ && git clone https://github.com/th33xitus/kiauh.git
```
* **Step 3:** \
-Finally start KIAUH by running the next command:
+Finally, start KIAUH by running the next command:
```shell
./kiauh/kiauh.sh
@@ -152,23 +152,24 @@ prompt and confirm by hitting ENTER.
- |
+ |
|
|
- |
+ |
 |
|
- |
+by Patrick Schmidt |
by Quinn Damerell |
|
+
diff --git a/docs/changelog.md b/docs/changelog.md
index 2381537..7a11382 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -2,6 +2,11 @@
This document covers possible important changes to KIAUH.
+### 2023-06-17
+KIAUH has now added support for installing Mobileraker's companion!
+Mobileraker is a free and Open Source Android and iOS App for Klipper, utilizing the Moonraker API, allowing you
+to control your printer. Thank you to [Clon1998](https://github.com/Clon1998) for adding this feature!
+
### 2023-02-03
The installer for MJPG-Streamer got replaced by crowsnest. It is an improved webcam service, utilizing ustreamer.
Please have a look here for additional info about crowsnest and how to configure it: https://github.com/mainsail-crew/crowsnest \
diff --git a/resources/klipper.env b/resources/klipper.env
index 1f16a6e..6ab13d6 100644
--- a/resources/klipper.env
+++ b/resources/klipper.env
@@ -1 +1 @@
-KLIPPER_ARGS="/home/%USER%/klipper/klippy/klippy.py %CFG% -I %PRINTER% -l %LOG% -a %UDS%"
\ No newline at end of file
+KLIPPER_ARGS="%KLIPPER_DIR%/klippy/klippy.py %CFG% -I %PRINTER% -l %LOG% -a %UDS%"
\ No newline at end of file
diff --git a/resources/klipper.service b/resources/klipper.service
index 8c74cd4..b41788f 100644
--- a/resources/klipper.service
+++ b/resources/klipper.service
@@ -11,7 +11,7 @@ WantedBy=multi-user.target
Type=simple
User=%USER%
RemainAfterExit=yes
-WorkingDirectory=/home/%USER%/klipper
+WorkingDirectory=%KLIPPER_DIR%
EnvironmentFile=%ENV_FILE%
ExecStart=%ENV%/bin/python $KLIPPER_ARGS
Restart=always
diff --git a/resources/moonraker-telegram-bot.env b/resources/moonraker-telegram-bot.env
index aaa7547..280f165 100644
--- a/resources/moonraker-telegram-bot.env
+++ b/resources/moonraker-telegram-bot.env
@@ -1 +1 @@
-TELEGRAM_BOT_ARGS="/home/%USER%/moonraker-telegram-bot/bot/main.py -c %CFG% -l %LOG%"
\ No newline at end of file
+TELEGRAM_BOT_ARGS="%TELEGRAM_BOT_DIR%/bot/main.py -c %CFG% -l %LOG%"
\ No newline at end of file
diff --git a/resources/moonraker-telegram-bot.service b/resources/moonraker-telegram-bot.service
index 612a6cd..567481d 100644
--- a/resources/moonraker-telegram-bot.service
+++ b/resources/moonraker-telegram-bot.service
@@ -9,7 +9,7 @@ WantedBy=multi-user.target
[Service]
Type=simple
User=%USER%
-WorkingDirectory=/home/%USER%/moonraker-telegram-bot
+WorkingDirectory=%TELEGRAM_BOT_DIR%
EnvironmentFile=%ENV_FILE%
ExecStart=%ENV%/bin/python $TELEGRAM_BOT_ARGS
Restart=always
diff --git a/resources/moonraker.env b/resources/moonraker.env
index 065ca7e..bca6af5 100644
--- a/resources/moonraker.env
+++ b/resources/moonraker.env
@@ -1 +1 @@
-MOONRAKER_ARGS="/home/%USER%/moonraker/moonraker/moonraker.py -d %PRINTER_DATA%"
\ No newline at end of file
+MOONRAKER_ARGS="%MOONRAKER_DIR%/moonraker/moonraker.py -d %PRINTER_DATA%"
\ No newline at end of file
diff --git a/resources/moonraker.service b/resources/moonraker.service
index ac8000f..7bfe8e2 100644
--- a/resources/moonraker.service
+++ b/resources/moonraker.service
@@ -12,7 +12,7 @@ Type=simple
User=%USER%
SupplementaryGroups=moonraker-admin
RemainAfterExit=yes
-WorkingDirectory=/home/%USER%/moonraker
+WorkingDirectory=%MOONRAKER_DIR%
EnvironmentFile=%ENV_FILE%
ExecStart=%ENV%/bin/python $MOONRAKER_ARGS
Restart=always
diff --git a/scripts/crowsnest.sh b/scripts/crowsnest.sh
index cda3820..fb864ab 100644
--- a/scripts/crowsnest.sh
+++ b/scripts/crowsnest.sh
@@ -197,7 +197,7 @@ function compare_crowsnest_versions() {
}
function install_crowsnest_dependencies() {
- local packages
+ local packages log_name="Crowsnest"
local install_script="${CROWSNEST_DIR}/tools/install.sh"
### read PKGLIST from official install-script
@@ -208,21 +208,11 @@ function install_crowsnest_dependencies() {
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
read -r -a packages <<< "${packages}"
- ### Update system package info
- status_msg "Updating package lists..."
- if ! sudo apt-get update --allow-releaseinfo-change; then
- log_error "failure while updating package lists"
- error_msg "Updating package lists failed!"
- exit 1
- fi
+ ### Update system package lists if stale
+ update_system_package_lists
### Install required packages
- status_msg "Installing required packages..."
- if ! sudo apt-get install --yes "${packages[@]}"; then
- log_error "failure while installing required crowsnest packages"
- error_msg "Installing required packages failed!"
- exit 1
- fi
+ install_system_packages "${log_name}" "packages[@]"
}
function update_crowsnest() {
diff --git a/scripts/globals.sh b/scripts/globals.sh
index 24f2a22..b80011b 100644
--- a/scripts/globals.sh
+++ b/scripts/globals.sh
@@ -78,4 +78,9 @@ function set_globals() {
CROWSNEST_DIR="${HOME}/crowsnest"
CROWSNEST_REPO="https://github.com/mainsail-crew/crowsnest.git"
+ #=============== Mobileraker ================#
+ MOBILERAKER_ENV="${HOME}/mobileraker-env"
+ MOBILERAKER_DIR="${HOME}/mobileraker_companion"
+ MOBILERAKER_REPO="https://github.com/Clon1998/mobileraker_companion.git"
+
}
diff --git a/scripts/klipper.sh b/scripts/klipper.sh
index 66126b4..916ff19 100644
--- a/scripts/klipper.sh
+++ b/scripts/klipper.sh
@@ -71,7 +71,7 @@ function start_klipper_setup() {
### user selection for python version
print_dialog_user_select_python_version
while true; do
- read -p "${cyan}###### Select Python version:${white} " input
+ read -p "${cyan}###### Select Python version:${white} " -i "1" -e input
case "${input}" in
1)
select_msg "Python 3.x\n"
@@ -295,7 +295,7 @@ function create_klipper_virtualenv() {
# @param {string}: python_version - klipper-env python version
#
function install_klipper_packages() {
- local packages python_version="${1}"
+ local packages log_name="Klipper" python_version="${1}"
local install_script="${KLIPPER_DIR}/scripts/install-debian.sh"
status_msg "Reading dependencies..."
@@ -321,21 +321,11 @@ function install_klipper_packages() {
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
read -r -a packages <<< "${packages}"
- ### Update system package info
- status_msg "Updating package lists..."
- if ! sudo apt-get update --allow-releaseinfo-change; then
- log_error "failure while updating package lists"
- error_msg "Updating package lists failed!"
- exit 1
- fi
+ ### Update system package lists if stale
+ update_system_package_lists
### Install required packages
- status_msg "Installing required packages..."
- if ! sudo apt-get install --yes "${packages[@]}"; then
- log_error "failure while installing required klipper packages"
- error_msg "Installing required packages failed!"
- exit 1
- fi
+ install_system_packages "${log_name}" "packages[@]"
}
function create_klipper_service() {
@@ -378,8 +368,8 @@ function create_klipper_service() {
sudo cp "${service_template}" "${service}"
sudo cp "${env_template}" "${env_file}"
- sudo sed -i "s|%USER%|${USER}|g; s|%ENV%|${KLIPPY_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}"
- sudo sed -i "s|%USER%|${USER}|; s|%LOG%|${log}|; s|%CFG%|${cfg}|; s|%PRINTER%|${klippy_serial}|; s|%UDS%|${klippy_socket}|" "${env_file}"
+ sudo sed -i "s|%USER%|${USER}|g; s|%KLIPPER_DIR%|${KLIPPER_DIR}|; s|%ENV%|${KLIPPY_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}"
+ sudo sed -i "s|%USER%|${USER}|; s|%KLIPPER_DIR%|${KLIPPER_DIR}|; s|%LOG%|${log}|; s|%CFG%|${cfg}|; s|%PRINTER%|${klippy_serial}|; s|%UDS%|${klippy_socket}|" "${env_file}"
ok_msg "Klipper service file created!"
fi
@@ -634,4 +624,4 @@ function get_klipper_python_ver() {
local version
version=$("${KLIPPY_ENV}"/bin/python --version 2>&1 | cut -d" " -f2 | cut -d"." -f1)
echo "${version}"
-}
\ No newline at end of file
+}
diff --git a/scripts/mobileraker.sh b/scripts/mobileraker.sh
new file mode 100644
index 0000000..45b8055
--- /dev/null
+++ b/scripts/mobileraker.sh
@@ -0,0 +1,247 @@
+#!/usr/bin/env bash
+
+#=======================================================================#
+# Copyright (C) 2020 - 2023 Dominik Willner #
+# #
+# 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 #
+#=======================================================================#
+
+#
+# This file is written and maintained by Patrick Schmidt author of Mobileraker
+# It is based of the kliperscreen.sh install script!
+
+
+set -e
+
+#===================================================#
+#========== INSTALL MOBILERAKER COMPANION ==========#
+#===================================================#
+
+function mobileraker_systemd() {
+ local services
+ services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/mobileraker.service")
+ echo "${services}"
+}
+
+function install_mobileraker() {
+ ### return early if python version check fails
+ if [[ $(python3_check) == "false" ]]; then
+ local error="Versioncheck failed! Python 3.7 or newer required!\n"
+ error="${error} Please upgrade Python."
+ print_error "${error}" && return
+ fi
+
+ ### first, we create a backup of the full klipper_config dir - safety first!
+ backup_klipper_config_dir
+
+ ### install Mobileraker's Companion
+ mobileraker_setup
+
+ ### add Mobileraker's Companion to the update manager in moonraker.conf
+ patch_mobileraker_update_manager
+
+ do_action_service "restart" "mobileraker"
+}
+
+function mobileraker_setup() {
+ local dep=(wget curl unzip dfu-util)
+ dependency_check "${dep[@]}"
+ status_msg "Cloning Mobileraker's companion from ${MOBILERAKER_REPO} ..."
+
+ # force remove existing Mobileraker's companion dir
+ [[ -d ${MOBILERAKER_DIR} ]] && rm -rf "${MOBILERAKER_DIR}"
+
+ # clone into fresh Mobileraker's companion dir
+ cd "${HOME}" || exit 1
+ if ! git clone "${MOBILERAKER_REPO}" "${MOBILERAKER_DIR}"; then
+ print_error "Cloning mobileraker's companion from\n ${MOBILERAKER_REPO}\n failed!"
+ exit 1
+ fi
+
+ status_msg "Installing Mobileraker's companion ..."
+ if "${MOBILERAKER_DIR}"/scripts/install-mobileraker-companion.sh; then
+ ok_msg "Mobileraker's companion successfully installed!"
+ else
+ print_error "Mobileraker's companion installation failed!"
+ exit 1
+ fi
+}
+
+#===================================================#
+#=========== REMOVE MOBILERAKER COMPANION ==========#
+#===================================================#
+
+function remove_mobileraker() {
+ ### remove Mobileraker's companion dir
+ if [[ -d ${MOBILERAKER_DIR} ]]; then
+ status_msg "Removing Mobileraker's companion directory ..."
+ rm -rf "${MOBILERAKER_DIR}" && ok_msg "Directory removed!"
+ fi
+
+ ### remove Mobileraker's companion VENV dir
+ if [[ -d ${MOBILERAKER_ENV} ]]; then
+ status_msg "Removing Mobileraker's companion VENV directory ..."
+ rm -rf "${MOBILERAKER_ENV}" && ok_msg "Directory removed!"
+ fi
+
+ ### remove Mobileraker's companion service
+ if [[ -e "${SYSTEMD}/mobileraker.service" ]]; then
+ status_msg "Removing mobileraker service ..."
+ do_action_service "stop" "mobileraker"
+ do_action_service "disable" "mobileraker"
+ sudo rm -f "${SYSTEMD}/mobileraker.service"
+
+ ###reloading units
+ sudo systemctl daemon-reload
+ sudo systemctl reset-failed
+ ok_msg "Mobileraker's companion Service removed!"
+ fi
+
+
+ remove_mobileraker_logs
+
+ print_confirm "Mobileraker's companion successfully removed!"
+}
+
+function remove_mobileraker_logs() {
+ local files regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/logs\/mobileraker\.log.*"
+ files=$(find "${HOME}" -maxdepth 3 -regextype posix-extended -regex "${regex}" | sort)
+
+ if [[ -n ${files} ]]; then
+ for file in ${files}; do
+ status_msg "Removing ${file} ..."
+ rm -f "${file}"
+ ok_msg "${file} removed!"
+ done
+ fi
+}
+
+#===================================================#
+#=========== UPDATE MOBILERAKER COMPANION ==========#
+#===================================================#
+
+function update_mobileraker() {
+ local old_md5
+ old_md5=$(md5sum "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt" | cut -d " " -f1)
+
+ do_action_service "stop" "mobileraker"
+ cd "${MOBILERAKER_DIR}"
+ git pull origin main -q && ok_msg "Fetch successfull!"
+ git checkout -f main && ok_msg "Checkout successfull"
+
+ if [[ $(md5sum "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt" | cut -d " " -f1) != "${old_md5}" ]]; then
+ status_msg "New dependecies detected..."
+ "${MOBILERAKER_ENV}"/bin/pip install -r "${MOBILERAKER_DIR}/scripts/mobileraker-requirements.txt"
+ ok_msg "Dependencies have been installed!"
+ fi
+
+ ok_msg "Update complete!"
+ do_action_service "start" "mobileraker"
+}
+
+#===================================================#
+#=========== MOBILERAKER COMPANION STATUS ==========#
+#===================================================#
+
+function get_mobileraker_status() {
+ local sf_count status
+ sf_count="$(mobileraker_systemd | wc -w)"
+
+ ### remove the "SERVICE" entry from the data array if a moonraker service is installed
+ local data_arr=(SERVICE "${MOBILERAKER_DIR}" "${MOBILERAKER_ENV}")
+ (( sf_count > 0 )) && unset "data_arr[0]"
+
+ ### count+1 for each found data-item from array
+ local filecount=0
+ for data in "${data_arr[@]}"; do
+ [[ -e ${data} ]] && filecount=$(( filecount + 1 ))
+ done
+
+ if (( filecount == ${#data_arr[*]} )); then
+ status="Installed!"
+ elif (( filecount == 0 )); then
+ status="Not installed!"
+ else
+ status="Incomplete!"
+ fi
+ echo "${status}"
+}
+
+function get_local_mobileraker_commit() {
+ [[ ! -d ${MOBILERAKER_DIR} || ! -d "${MOBILERAKER_DIR}/.git" ]] && return
+
+ local commit
+ cd "${MOBILERAKER_DIR}"
+ commit="$(git describe HEAD --always --tags | cut -d "-" -f 1,2)"
+ echo "${commit}"
+}
+
+function get_remote_mobileraker_commit() {
+ [[ ! -d ${MOBILERAKER_DIR} || ! -d "${MOBILERAKER_DIR}/.git" ]] && return
+
+ local commit
+ cd "${MOBILERAKER_DIR}" && git fetch origin -q
+ commit=$(git describe origin/main --always --tags | cut -d "-" -f 1,2)
+ echo "${commit}"
+}
+
+function compare_mobileraker_versions() {
+ local versions local_ver remote_ver
+ local_ver="$(get_local_mobileraker_commit)"
+ remote_ver="$(get_remote_mobileraker_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 "mobileraker"
+ else
+ versions="${green}$(printf " %-14s" "${local_ver}")${white}"
+ versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}"
+ fi
+
+ echo "${versions}"
+}
+
+#================================================#
+#=================== HELPERS ====================#
+#================================================#
+
+function patch_mobileraker_update_manager() {
+ local patched moonraker_configs regex
+ regex="${HOME//\//\\/}\/([A-Za-z0-9_]+)\/config\/moonraker\.conf"
+ moonraker_configs=$(find "${HOME}" -maxdepth 3 -type f -regextype posix-extended -regex "${regex}" | sort)
+
+ patched="false"
+ for conf in ${moonraker_configs}; do
+ if ! grep -Eq "^\[update_manager mobileraker\]\s*$" "${conf}"; then
+ ### add new line to conf if it doesn't end with one
+ [[ $(tail -c1 "${conf}" | wc -l) -eq 0 ]] && echo "" >> "${conf}"
+
+ ### add Mobileraker's Companion update manager section to moonraker.conf
+ status_msg "Adding Mobileraker's Companion to update manager in file:\n ${conf}"
+ /bin/sh -c "cat >> ${conf}" << MOONRAKER_CONF
+
+[update_manager mobileraker]
+type: git_repo
+path: ${HOME}/mobileraker_companion
+origin: https://github.com/Clon1998/mobileraker_companion.git
+primary_branch:main
+managed_services: mobileraker
+env: ${HOME}/mobileraker-env/bin/python
+requirements: scripts/mobileraker-requirements.txt
+install_script: scripts/install-mobileraker-companion.sh
+MOONRAKER_CONF
+
+ fi
+
+ patched="true"
+ done
+
+ if [[ ${patched} == "true" ]]; then
+ do_action_service "restart" "moonraker"
+ fi
+}
diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh
index 7aab1e9..afccef8 100644
--- a/scripts/moonraker-telegram-bot.sh
+++ b/scripts/moonraker-telegram-bot.sh
@@ -110,7 +110,7 @@ function telegram_bot_setup_dialog() {
}
function install_telegram_bot_dependencies() {
- local packages
+ local packages log_name="Telegram Bot"
local install_script="${TELEGRAM_BOT_DIR}/scripts/install.sh"
### read PKGLIST from official install-script
@@ -121,21 +121,11 @@ function install_telegram_bot_dependencies() {
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
read -r -a packages <<< "${packages}"
- ### Update system package info
- status_msg "Updating package lists..."
- if ! sudo apt-get update --allow-releaseinfo-change; then
- log_error "failure while updating package lists"
- error_msg "Updating package lists failed!"
- exit 1
- fi
+ ### Update system package lists if stale
+ update_system_package_lists
### Install required packages
- status_msg "Installing required packages..."
- if ! sudo apt-get install --yes "${packages[@]}"; then
- log_error "failure while installing required moonraker-telegram-bot packages"
- error_msg "Installing required packages failed!"
- exit 1
- fi
+ install_system_packages "${log_name}" "packages[@]"
}
function create_telegram_bot_virtualenv() {
@@ -328,11 +318,11 @@ function write_telegram_bot_service() {
else
sudo sed -i "s|%INST%|${i}|" "${service}"
fi
- sudo sed -i "s|%USER%|${USER}|g; s|%ENV%|${TELEGRAM_BOT_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}"
+ sudo sed -i "s|%USER%|${USER}|g; s|%TELEGRAM_BOT_DIR%|${TELEGRAM_BOT_DIR}|; s|%ENV%|${TELEGRAM_BOT_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}"
status_msg "Creating environment file for instance ${i} ..."
cp "${env_template}" "${env_file}"
- sed -i "s|%USER%|${USER}|; s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${env_file}"
+ sed -i "s|%USER%|${USER}|; s|%TELEGRAM_BOT_DIR%|${TELEGRAM_BOT_DIR}|; s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${env_file}"
fi
}
diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh
index 655e2d6..775b0b2 100644
--- a/scripts/moonraker.sh
+++ b/scripts/moonraker.sh
@@ -141,7 +141,7 @@ function moonraker_setup_dialog() {
}
function install_moonraker_dependencies() {
- local packages
+ local packages log_name="Moonraker"
local install_script="${MOONRAKER_DIR}/scripts/install-moonraker.sh"
### read PKGLIST from official install-script
@@ -152,21 +152,11 @@ function install_moonraker_dependencies() {
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
read -r -a packages <<< "${packages}"
- ### Update system package info
- status_msg "Updating package lists..."
- if ! sudo apt-get update --allow-releaseinfo-change; then
- log_error "failure while updating package lists"
- error_msg "Updating package lists failed!"
- exit 1
- fi
+ ### Update system package lists if stale
+ update_system_package_lists
### Install required packages
- status_msg "Installing required packages..."
- if ! sudo apt-get install --yes "${packages[@]}"; then
- log_error "failure while installing required moonraker packages"
- error_msg "Installing required packages failed!"
- exit 1
- fi
+ install_system_packages "${log_name}" "packages[@]"
}
function create_moonraker_virtualenv() {
@@ -370,8 +360,8 @@ function write_moonraker_service() {
[[ -z ${i} ]] && sudo sed -i "s| %INST%||" "${service}"
[[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}"
- sudo sed -i "s|%USER%|${USER}|g; s|%ENV%|${MOONRAKER_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}"
- sudo sed -i "s|%USER%|${USER}|; s|%PRINTER_DATA%|${printer_data}|" "${env_file}"
+ sudo sed -i "s|%USER%|${USER}|g; s|%MOONRAKER_DIR%|${MOONRAKER_DIR}|; s|%ENV%|${MOONRAKER_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}"
+ sudo sed -i "s|%USER%|${USER}|; s|%MOONRAKER_DIR%|${MOONRAKER_DIR}|; s|%PRINTER_DATA%|${printer_data}|" "${env_file}"
fi
}
diff --git a/scripts/octoeverywhere.sh b/scripts/octoeverywhere.sh
index ff953ce..635c443 100644
--- a/scripts/octoeverywhere.sh
+++ b/scripts/octoeverywhere.sh
@@ -307,7 +307,7 @@ function clone_octoeverywhere() {
}
function install_octoeverywhere_dependencies() {
- local packages
+ local packages log_name="OctoEverywhere"
local install_script="${OCTOEVERYWHERE_DIR}/install.sh"
### read PKGLIST from official install-script
@@ -318,21 +318,11 @@ function install_octoeverywhere_dependencies() {
echo "${cyan}${packages}${white}" | tr '[:space:]' '\n'
read -r -a packages <<< "${packages}"
- ### Update system package info
- status_msg "Updating package lists..."
- if ! sudo apt-get update --allow-releaseinfo-change; then
- log_error "failure while updating package lists"
- error_msg "Updating package lists failed!"
- exit 1
- fi
+ ### Update system package lists if stale
+ update_system_package_lists
### Install required packages
- status_msg "Installing required packages..."
- if ! sudo apt-get install --yes "${packages[@]}"; then
- log_error "failure while installing required octoeverywhere packages"
- error_msg "Installing required packages failed!"
- exit 1
- fi
+ install_system_packages "${log_name}" "packages[@]"
}
#===================================================#
diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh
index 2ebcc00..35cfe92 100755
--- a/scripts/ui/install_menu.sh
+++ b/scripts/ui/install_menu.sh
@@ -27,14 +27,16 @@ function install_ui() {
echo -e "| 3) [Mainsail] | 8) [Telegram Bot] |"
echo -e "| 4) [Fluidd] | 9) $(obico_install_title) |"
echo -e "| | 10) [OctoEverywhere] |"
+ echo -e "| | 11) [Mobileraker] |"
echo -e "| Touchscreen GUI: | |"
echo -e "| 5) [KlipperScreen] | Webcam Streamer: |"
- echo -e "| | 11) [Crowsnest] |"
+ echo -e "| | 12) [Crowsnest] |"
back_footer
}
function install_menu() {
- clear && print_header
+ clear -x && sudo -v && clear -x # (re)cache sudo credentials so password prompt doesn't bork ui
+ print_header
install_ui
### save all installed webinterface ports to the ini file
@@ -68,6 +70,8 @@ function install_menu() {
10)
do_action "octoeverywhere_setup_dialog" "install_ui";;
11)
+ do_action "install_mobileraker" "install_ui";;
+ 12)
do_action "install_crowsnest" "install_ui";;
B|b)
clear; main_menu; break;;
diff --git a/scripts/ui/main_menu.sh b/scripts/ui/main_menu.sh
index b04a090..f272684 100755
--- a/scripts/ui/main_menu.sh
+++ b/scripts/ui/main_menu.sh
@@ -12,10 +12,6 @@
set -e
function main_ui() {
- echo -e "${yellow}/=======================================================\\"
- echo -e "| Please read the newest changelog carefully: |"
- echo -e "| https://git.io/JnmlX |"
- echo -e "\=======================================================/${white}"
top_border
echo -e "| $(title_msg "~~~~~~~~~~~~~~~ [ Main Menu ] ~~~~~~~~~~~~~~~") |"
hr
@@ -32,8 +28,11 @@ function main_ui() {
echo -e "| | Crowsnest: $(print_status "crowsnest")|"
echo -e "| | Obico: $(print_status "moonraker_obico")|"
echo -e "| | OctoEverywhere: $(print_status "octoeverywhere")|"
+ echo -e "| | Mobileraker: $(print_status "mobileraker")|"
echo -e "| | |"
- echo -e "| $(print_kiauh_version)| Octoprint: $(print_status "octoprint")|"
+ echo -e "| | Octoprint: $(print_status "octoprint")|"
+ hr
+ echo -e "| $(print_kiauh_version)| Changelog: ${magenta}https://git.io/JnmlX${white} |"
quit_footer
}
diff --git a/scripts/ui/remove_menu.sh b/scripts/ui/remove_menu.sh
index 0749921..b6c5581 100755
--- a/scripts/ui/remove_menu.sh
+++ b/scripts/ui/remove_menu.sh
@@ -29,7 +29,8 @@ function remove_ui() {
echo -e "| | 12) [Telegram Bot] |"
echo -e "| Touchscreen GUI: | 13) [Obico for Klipper] |"
echo -e "| 7) [KlipperScreen] | 14) [OctoEverywhere] |"
- echo -e "| | 15) [NGINX] |"
+ echo -e "| | 15) [Mobileraker] |"
+ echo -e "| | 16) [NGINX] |"
back_footer
}
@@ -69,6 +70,8 @@ function remove_menu() {
14)
do_action "remove_octoeverywhere" "remove_ui";;
15)
+ do_action "remove_mobileraker" "remove_ui";;
+ 16)
do_action "remove_nginx" "remove_ui";;
B|b)
clear; main_menu; break;;
diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh
index 61e61ee..caa5e64 100755
--- a/scripts/ui/update_menu.sh
+++ b/scripts/ui/update_menu.sh
@@ -33,13 +33,15 @@ function update_ui() {
echo -e "| 7) [Telegram Bot] |$(compare_telegram_bot_versions)|"
echo -e "| 8) [Obico for Klipper]|$(compare_moonraker_obico_versions)|"
echo -e "| 9) [OctoEverywhere] |$(compare_octoeverywhere_versions)|"
- echo -e "| 10) [Crowsnest] |$(compare_crowsnest_versions)|"
+ echo -e "| 10) [Mobileraker] |$(compare_mobileraker_versions)|"
+ echo -e "| 11) [Crowsnest] |$(compare_crowsnest_versions)|"
echo -e "| |------------------------------|"
- echo -e "| 11) [System] | $(check_system_updates) |"
+ echo -e "| 12) [System] | $(check_system_updates) |"
back_footer
}
function update_menu() {
+ clear -x && sudo -v && clear -x # (re)cache sudo credentials so password prompt doesn't bork ui
do_action "" "update_ui"
local action
@@ -67,9 +69,11 @@ function update_menu() {
9)
do_action "update_octoeverywhere" "update_ui";;
10)
- do_action "update_crowsnest" "update_ui";;
+ do_action "update_mobileraker" "update_ui";;
11)
- do_action "update_system" "update_ui";;
+ do_action "update_crowsnest" "update_ui";;
+ 12)
+ do_action "upgrade_system_packages" "update_ui";;
a)
do_action "update_all" "update_ui";;
B|b)
@@ -123,6 +127,9 @@ function update_all() {
[[ "${update_arr[*]}" =~ "octoeverywhere" ]] && \
echo -e "| ${cyan}● OctoEverywhere${white} |"
+ [[ "${update_arr[*]}" =~ "mobileraker" ]] && \
+ echo -e "| ${cyan}● Mobileraker${white} |"
+
[[ "${update_arr[*]}" =~ "system" ]] && \
echo -e "| ${cyan}● System${white} |"
diff --git a/scripts/utilities.sh b/scripts/utilities.sh
index 05d0106..3d0456d 100644
--- a/scripts/utilities.sh
+++ b/scripts/utilities.sh
@@ -20,6 +20,8 @@ function check_euid() {
echo -e "${red}"
top_border
echo -e "| !!! THIS SCRIPT MUST NOT RUN AS ROOT !!! |"
+ echo -e "| |"
+ echo -e "| It will ask for credentials as needed. |"
bottom_border
echo -e "${white}"
exit 1
@@ -293,7 +295,7 @@ function python3_check() {
function dependency_check() {
local dep=( "${@}" )
- local packages
+ local packages log_name="dependencies"
status_msg "Checking for the following dependencies:"
#check if package is installed, if not write its name into array
@@ -311,12 +313,12 @@ function dependency_check() {
done
echo
- if sudo apt-get update --allow-releaseinfo-change && sudo apt-get install "${packages[@]}" -y; then
- ok_msg "Dependencies installed!"
- else
- error_msg "Installing dependencies failed!"
- return 1 # exit kiauh
- fi
+ # update system package lists if stale
+ update_system_package_lists
+
+ # install required packages
+ install_system_packages "${log_name}" "packages[@]"
+
else
ok_msg "Dependencies already met!"
return
@@ -366,27 +368,78 @@ function create_required_folders() {
done
}
-function check_system_updates() {
- local updates_avail info_msg
- updates_avail=$(apt list --upgradeable 2>/dev/null | sed "1d")
-
- if [[ -n ${updates_avail} ]]; then
- info_msg="${yellow}System upgrade available!${white}"
- # add system to application_updates_available in kiauh.ini
- add_to_application_updates "system"
+function update_system_package_lists() {
+ local cache_mtime update_age update_interval silent
+
+ if [[ $1 == '--silent' ]]; then silent="true"; fi
+
+ if [[ -e /var/lib/apt/periodic/update-success-stamp ]]; then
+ cache_mtime="$(stat -c %Y /var/lib/apt/periodic/update-success-stamp)"
+ elif [[ -e /var/lib/apt/lists ]]; then
+ cache_mtime="$(stat -c %Y /var/lib/apt/lists)"
else
- info_msg="${green}System up to date! ${white}"
+ log_warning "Failure determining package cache age, forcing update"
+ cache_mtime=0
fi
- echo "${info_msg}"
+ update_age="$(($(date +'%s') - cache_mtime))"
+ update_interval=$((48*60*60)) # 48hrs
+
+ # update if cache is greater than update_interval
+ if (( update_age > update_interval )); then
+ if [[ ! ${silent} == "true" ]]; then status_msg "Updating package lists..."; fi
+ if ! sudo apt-get update --allow-releaseinfo-change &>/dev/null; then
+ log_error "Failure while updating package lists!"
+ if [[ ! ${silent} == "true" ]]; then error_msg "Updating package lists failed!"; fi
+ return 1
+ else
+ log_info "Package lists updated successfully"
+ if [[ ! ${silent} == "true" ]]; then status_msg "Updated package lists."; fi
+ fi
+ else
+ log_info "Package lists updated recently, skipping update..."
+ fi
}
-function update_system() {
- status_msg "Updating System ..."
- if sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y; then
- print_confirm "Update complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been kept back!${green}"
+function check_system_updates() {
+ local updates_avail status
+ if ! update_system_package_lists --silent; then
+ status="${red}Update check failed! ${white}"
else
- print_error "System update failed! Please watch for any errors printed above!"
+ updates_avail="$(apt list --upgradeable 2>/dev/null | sed "1d")"
+
+ if [[ -n ${updates_avail} ]]; then
+ status="${yellow}System upgrade available!${white}"
+ # add system to application_updates_available in kiauh.ini
+ add_to_application_updates "system"
+ else
+ status="${green}System up to date! ${white}"
+ fi
+ fi
+
+ echo "${status}"
+}
+
+function upgrade_system_packages() {
+ status_msg "Upgrading System ..."
+ update_system_package_lists
+ if sudo apt-get upgrade -y; then
+ print_confirm "Upgrade complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been held back!${green}"
+ else
+ print_error "System upgrade failed! Please look for any errors printed above!"
+ fi
+}
+
+function install_system_packages() {
+ local log_name="$1"
+ local packages=("${!2}")
+ status_msg "Installing packages..."
+ if sudo apt-get install -y "${packages[@]}"; then
+ ok_msg "${log_name^} packages installed!"
+ else
+ log_error "Failure while installing ${log_name,,} packages"
+ error_msg "Installing ${log_name} packages failed!"
+ exit 1 # exit kiauh
fi
}