|
8 | 8 | #### This File is distributed under GPLv3
|
9 | 9 | ####
|
10 | 10 |
|
11 |
| -# # shellcheck enable=require-variable-braces |
| 11 | +# shellcheck enable=require-variable-braces |
12 | 12 |
|
13 |
| -# Error handling |
14 |
| -set -ex |
| 13 | +## Source error handling, leave this in place |
| 14 | +set -Eex |
15 | 15 |
|
| 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 |
16 | 26 | source /common.sh
|
17 | 27 | install_cleanup_trap
|
18 | 28 |
|
| 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 | + |
19 | 45 | 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 |
22 | 50 | 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 |
27 | 58 | 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 |
31 | 62 | 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}" |
41 | 67 | fi
|
| 68 | + ## Copy default config |
42 | 69 | echo_green "Copying default config file ..."
|
43 | 70 | 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" |
50 | 73 |
|
| 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 |
51 | 81 | popd &> /dev/null || exit 1
|
| 82 | + |
| 83 | +## Done message |
| 84 | +echo_green "Installing sonar and enable sonar Service ... done!" |
0 commit comments