Skip to content

Commit

Permalink
chore: update installer
Browse files Browse the repository at this point in the history
update installer to match new paths according to
Arksine/moonraker#516

Added posibility to set persistant log path at install

replaced apt with apt-get -q for installing dependencies

Signed-off-by: Stephan Wendel <[email protected]>
  • Loading branch information
KwadFan committed Oct 23, 2022
1 parent bf5f889 commit 88c85ae
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 195 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ignore config.local
tools/config.local
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ A small Keepalive daemon for MainsailOS (or any other Raspberry Pi OS based Imag
cd ~/sonar
make install

### Install Option

To use a customized path for the persistant Log file, \
you could create a file called config.local in 'tools' directory

Put a Variable in that file

SONAR_PERSISTANT_LOG_PATH="/path/to/my/persistant/log/destination"

This will be the path where you find the logfile.

By default, it will be

/home/<username>/printer_data/logs

## Uninstall

cd ~/sonar
Expand All @@ -28,20 +43,14 @@ Simply add

to your moonraker.conf

## Manual Update

cd ~/sonar
git pull
make update

## Configuration

You are able to configure it's behavior due a file in "klipper_config".\
You are able to configure it's behavior due a file in "printer_data".\
But you don't have to. Defaults are hardcoded and sonar will run without any configuration.\
Easiest way is to copy the file from "sample_config" in this repo.

cd ~/sonar
cp sample_config/sonar.conf ../klipper_config/
cp sample_config/sonar.conf ../printer_data/config/

### Options

Expand Down
3 changes: 2 additions & 1 deletion custompios/sonar/config
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
[ -n "$SONAR_REPO_SHIP" ] || SONAR_REPO_SHIP=https://github.com/mainsail-crew/sonar.git
[ -n "$SONAR_REPO_BRANCH" ] || SONAR_REPO_BRANCH=main
[ -n "$SONAR_DEPS" ] || SONAR_DEPS="git crudini iputils-ping"
[ -n "$SONAR_DEFAULT_CONF_DIR" ] || SONAR_DEFAULT_CONF_DIR="/home/${BASE_USER}/klipper_config"
[ -n "$SONAR_PERSISTANT_LOG_PATH" ] || SONAR_PERSISTANT_LOG_PATH="/home/${BASE_USER}/printer_data/logs"
[ -n "$SONAR_DEFAULT_CONF_DIR" ] || SONAR_DEFAULT_CONF_DIR="/home/${BASE_USER}/printer_data/config"
[ -n "$SONAR_DEFAULT_CONF" ] || SONAR_DEFAULT_CONF="mainsail_default.conf"
# Add Sonar to moonraker.conf (update_manager) bool (1:yes / 0:no)
[ -n "$SONAR_ADD_SONAR_MOONRAKER" ] || SONAR_ADD_SONAR_MOONRAKER=1
Expand Down
8 changes: 4 additions & 4 deletions custompios/sonar/start_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ MOONRAKER_TEMPLATE="/home/${BASE_USER}/sonar/file_templates/moonraker_update.txt

## helper func moonraker update_manager
function add_update_entry {
if [ -f "${SONAR_MOONRAKER_CONF}" ]; then
if [ -f "/tmp/moonraker.conf" ]; then
if [[ -f "${SONAR_MOONRAKER_CONF}" ]]; then
if [[ -f "/tmp/moonraker.conf" ]]; then
rm -rf /tmp/moonraker.conf
fi
sudo -u "${BASE_USER}" \
Expand Down Expand Up @@ -62,7 +62,7 @@ pushd "/home/${BASE_USER}" &> /dev/null || exit 1
echo_green "Running sonar installer ..."
sudo -u "${BASE_USER}" make unattended
## Make sure config dir exits
if [ ! -d "${SONAR_DEFAULT_CONF_DIR}" ]; then
if [[ ! -d "${SONAR_DEFAULT_CONF_DIR}" ]]; then
sudo -u "${BASE_USER}" mkdir -p "${SONAR_DEFAULT_CONF_DIR}"
fi
## Copy default config
Expand All @@ -72,7 +72,7 @@ pushd "/home/${BASE_USER}" &> /dev/null || exit 1
"${SONAR_DEFAULT_CONF_DIR}/sonar.conf"

## Add moonraker update_manager
if [ "${SONAR_ADD_SONAR_MOONRAKER}" == "1" ]; then
if [[ "${SONAR_ADD_SONAR_MOONRAKER}" == "1" ]]; then
echo -en "Adding Sonar Update Manager entry to moonraker.conf ...\r"
add_update_entry
echo -e "Adding Sonar Update Manager entry to moonraker.conf ... [OK]"
Expand Down
52 changes: 32 additions & 20 deletions tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set -Ee

# Global Vars
TITLE="Sonar - A WiFi Keepalive daemon"
SONAR_PERSISTANT_LOG_PATH=""

### Non root
if [ "${UNATTENDED}" == "false" ] && [ ${UID} == '0' ]; then
Expand Down Expand Up @@ -87,7 +88,7 @@ function install_sonar {
## Install Dependencies
echo -e "Installing 'sonar' Dependencies ..."
# shellcheck disable=2086
sudo apt install --yes --no-install-recommends crudini > /dev/null
sudo apt-get -q install --yes --no-install-recommends crudini > /dev/null
echo -e "Installing 'sonar' Dependencies ... [OK]"
## Link sonar to $PATH
echo -en "Linking sonar ...\r"
Expand All @@ -103,7 +104,7 @@ function install_sonar {
echo -e "Copying logrotate file ... [OK]\r"
## Link sonar.log to klipper_logs
echo -en "Linking sonar.log ...\r"
sudo ln -sf /var/log/sonar.log "${HOME}/klipper_logs/sonar.log" > /dev/null
sudo ln -sf /var/log/sonar.log "${SONAR_PERSISTANT_LOG_PATH}/sonar.log" > /dev/null
echo -e "Linking sonar.log ... [OK]\r"
## Update systemd, if not unattended
if [ "${UNATTENDED}" == "false" ] && [ "$(stat -c %i /)" == "2" ]; then
Expand All @@ -117,23 +118,34 @@ function install_sonar {
echo -e "Enable sonar.service on boot ... [OK]\r"
}

#### MAIN
while getopts "z" arg; do
case ${arg} in
z)
echo -e "Running in UNATTENDED Mode ..."
set -x
UNATTENDED="true"
main() {
while getopts "z" arg; do
case ${arg} in
z)
echo -e "Running in UNATTENDED Mode ..."
set -x
UNATTENDED="true"
;;
*)
UNATTENDED="false"
;;
*)
UNATTENDED="false"
;;
esac
done
install_cleanup_trap
welcome_msg
echo -e "Running apt update first ..."
sudo apt update
install_sonar
goodbye_msg
esac
done
if [[ -z "${SONAR_PERSISTANT_LOG_PATH}" ]] && [[ -f "tools/config.local" ]]; then
# shellcheck disable=SC1091
. tools/config.local
fi
if [[ -n "${SONAR_PERSISTANT_LOG_PATH}" ]] && [[ ! -f "tools/config.local" ]]; then
SONAR_PERSISTANT_LOG_PATH="${HOME}/printer_data/logs"
fi
install_cleanup_trap
welcome_msg
echo -e "Running apt update first ..."
sudo apt update
install_sonar
goodbye_msg
}

#### MAIN
main
exit 0
4 changes: 2 additions & 2 deletions tools/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ function remove_logrotate {

function remove_log_ln {
local get_path
get_path="$(find /home/ -name "klipper_logs")"
get_path="$(find "${HOME}" -name "sonar.log")"
if [ -h "${get_path}/sonar.log" ]; then
rm -f /var/log/sonar.log "${get_path}/sonar.log"
sudo rm -f /var/log/sonar.log "${get_path}"
fi
}

Expand Down
160 changes: 0 additions & 160 deletions tools/update.sh

This file was deleted.

0 comments on commit 88c85ae

Please sign in to comment.