Skip to content

Commit 924ce38

Browse files
authored
fix(sonar): fixes missing moonraker update manager entry (#112)
This should fix missing moonraker update_manager entry Signed-off-by: Stephan Wendel <me@stephanwe.de>
1 parent f0e3ee3 commit 924ce38

File tree

2 files changed

+69
-33
lines changed

2 files changed

+69
-33
lines changed

src/modules/sonar/config

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
# shellcheck disable=all
1111

1212
# Sonar
13-
[ -n "$SONAR_SONAR_REPO_SHIP" ] || SONAR_SONAR_REPO_SHIP=https://github.com/mainsail-crew/sonar.git
14-
[ -n "$SONAR_SONAR_REPO_BRANCH" ] || SONAR_SONAR_REPO_BRANCH=main
15-
[ -n "$SONAR_SONAR_DEPS" ] || SONAR_SONAR_DEPS="git crudini iputils-ping"
16-
[ -n "$SONAR_SONAR_DEFAULT_CONF" ] || SONAR_SONAR_DEFAULT_CONF="mainsail_default.conf"
17-
# Add Sonar to moonraker.conf (update manager) bool (1:yes / 0:no)
18-
[ -n "$SONAR_SONAR_ADD_SONAR_MOONRAKER" ] || SONAR_SONAR_ADD_SONAR_MOONRAKER=1
13+
[ -n "$SONAR_REPO_SHIP" ] || SONAR_REPO_SHIP=https://github.com/mainsail-crew/sonar.git
14+
[ -n "$SONAR_REPO_BRANCH" ] || SONAR_REPO_BRANCH=main
15+
[ -n "$SONAR_DEPS" ] || SONAR_DEPS="git crudini iputils-ping"
16+
[ -n "$SONAR_DEFAULT_CONF_DIR" ] || SONAR_DEFAULT_CONF_DIR="/home/${BASE_USER}/klipper_config"
17+
[ -n "$SONAR_DEFAULT_CONF" ] || SONAR_DEFAULT_CONF="mainsail_default.conf"
18+
# Add Sonar to moonraker.conf (update_manager) bool (1:yes / 0:no)
19+
[ -n "$SONAR_ADD_SONAR_MOONRAKER" ] || SONAR_ADD_SONAR_MOONRAKER=1
20+
# Path to moonraker.conf (must be set if add to update_manager)
21+
[ -n "$SONAR_MOONRAKER_CONF" ] || SONAR_MOONRAKER_CONF="${SONAR_DEFAULT_CONF_DIR}/moonraker.conf"

src/modules/sonar/start_chroot_script

+60-27
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,77 @@
88
#### This File is distributed under GPLv3
99
####
1010

11-
# # shellcheck enable=require-variable-braces
11+
# shellcheck enable=require-variable-braces
1212

13-
# Error handling
14-
set -ex
13+
## Source error handling, leave this in place
14+
set -Eex
1515

16+
## Set LC_ALL to prevent errors
17+
export LC_ALL=C
18+
19+
# Set DEBIAN_FRONTEND to noninteractive
20+
if [ "${DEBIAN_FRONTEND}" != "noninteractive" ]; then
21+
export DEBIAN_FRONTEND=noninteractive
22+
fi
23+
24+
## Source CustomPIOS common.sh
25+
# shellcheck disable=SC1091
1626
source /common.sh
1727
install_cleanup_trap
1828

29+
# Setup template file
30+
MOONRAKER_TEMPLATE="/home/${BASE_USER}/sonar/file_templates/moonraker_update.txt"
31+
32+
## helper func moonraker update_manager
33+
function add_update_entry {
34+
if [ -f "${SONAR_MOONRAKER_CONF}" ]; then
35+
if [ -f "/tmp/moonraker.conf" ]; then
36+
rm -rf /tmp/moonraker.conf
37+
fi
38+
sudo -u "${BASE_USER}" \
39+
cat "${SONAR_MOONRAKER_CONF}" "${MOONRAKER_TEMPLATE}" | \
40+
tee /tmp/moonraker.conf > /dev/null &&
41+
cp -rf /tmp/moonraker.conf "${SONAR_MOONRAKER_CONF}"
42+
fi
43+
}
44+
1945
echo_green "Installing sonar and enable sonar Service ..."
20-
# install dependencies
21-
# force apt update
46+
47+
## Install all deps at once for time consumption reasons.
48+
## APT: Update Repo Database and install Dependencies
49+
# Force apt update
2250
apt update
23-
check_install_pkgs "${SONAR_SONAR_DEPS}"
24-
# Move to $HOME dir
25-
pushd /home/"${BASE_USER}" &> /dev/null || exit 1
26-
# clone Repo
51+
echo_green "Installing Sonar Dependencies ..."
52+
# shellcheck disable=SC2086
53+
## Disabling shellcheck SC2086, because we want "wordsplitting"
54+
check_install_pkgs ${SONAR_DEPS}
55+
## Move to $HOME dir
56+
pushd "/home/${BASE_USER}" &> /dev/null || exit 1
57+
## clone Repo
2758
echo_green "Clone sonar repository ..."
28-
gitclone SONAR_SONAR_REPO sonar
29-
# install sonar
30-
pushd /home/"${BASE_USER}"/sonar &> /dev/null || exit 1
59+
gitclone SONAR_REPO sonar
60+
## Install sonar, using builtin installer
61+
pushd "/home/${BASE_USER}/sonar" &> /dev/null || exit 1
3162
echo_green "Running sonar installer ..."
32-
if [ "${SONAR_SONAR_ADD_MOONRAKER}" == "1" ]; then
33-
sudo -u "${BASE_USER}" \
34-
make unattended
35-
else
36-
sudo -u "${BASE_USER}" \
37-
make install
38-
fi
39-
if [ ! -d "/home/${BASE_USER}/klipper_config" ]; then
40-
mkdir -p "/home/${BASE_USER}/klipper_config"
63+
sudo -u "${BASE_USER}" make unattended
64+
## Make sure config dir exits
65+
if [ ! -d "${SONAR_DEFAULT_CONF_DIR}" ]; then
66+
sudo -u "${BASE_USER}" mkdir -p "${SONAR_DEFAULT_CONF_DIR}"
4167
fi
68+
## Copy default config
4269
echo_green "Copying default config file ..."
4370
sudo -u "${BASE_USER}" \
44-
cp "${PWD}/sample_config/${SONAR_SONAR_DEFAULT_CONF}" \
45-
"/home/${BASE_USER}/klipper_config/sonar.conf"
46-
popd &> /dev/null || exit 1
47-
48-
# enable systemd service
49-
systemctl_if_exists enable sonar.service
71+
cp "${PWD}/sample_config/${SONAR_DEFAULT_CONF}" \
72+
"${SONAR_DEFAULT_CONF_DIR}/sonar.conf"
5073

74+
## Add moonraker update_manager
75+
if [ "${SONAR_ADD_SONAR_MOONRAKER}" == "1" ]; then
76+
echo -en "Adding Sonar Update Manager entry to moonraker.conf ...\r"
77+
add_update_entry
78+
echo -e "Adding Sonar Update Manager entry to moonraker.conf ... [OK]"
79+
fi
80+
popd &> /dev/null || exit 1
5181
popd &> /dev/null || exit 1
82+
83+
## Done message
84+
echo_green "Installing sonar and enable sonar Service ... done!"

0 commit comments

Comments
 (0)