refactor: refactor clone_and_update function into two separate ones

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
th33xitus
2022-08-13 14:03:47 +02:00
parent 53e03254e7
commit cb53982cac

View File

@@ -181,7 +181,7 @@ function moonraker_obico_setup_dialog() {
dependency_check "${dep[@]}" dependency_check "${dep[@]}"
### Step 5: Clone the moonraker-obico repo ### Step 5: Clone the moonraker-obico repo
clone_or_update_moonraker_obico "${MOONRAKER_OBICO_REPO}" clone_moonraker_obico "${MOONRAKER_OBICO_REPO}"
### step 6: call moonrake-obico/install.sh with the correct params ### step 6: call moonrake-obico/install.sh with the correct params
local port=7125 moonraker_cfg local port=7125 moonraker_cfg
@@ -263,19 +263,17 @@ function moonraker_obico_setup_dialog() {
} }
function clone_or_update_moonraker_obico() { function clone_moonraker_obico() {
local repo=${1} local repo=${1}
if [[ -d ${MOONRAKER_OBICO_DIR} ]]; then status_msg "Cloning Moonraker-obico from ${repo} ..."
status_msg "Updating ${MOONRAKER_OBICO_DIR} ..." ### force remove existing Moonraker-obico dir
cd "${MOONRAKER_OBICO_DIR}" && git pull [[ -d ${repo} ]] && rm -rf "${MOONRAKER_OBICO_DIR}"
else
status_msg "Cloning Moonraker-obico from ${repo} ..." cd "${HOME}" || exit 1
cd "${HOME}" || exit 1 if ! git clone "${repo}" "${MOONRAKER_OBICO_DIR}"; then
if ! git clone "${MOONRAKER_OBICO_REPO}" "${MOONRAKER_OBICO_DIR}"; then print_error "Cloning Moonraker-obico from\n ${repo}\n failed!"
print_error "Cloning Moonraker-obico from\n ${repo}\n failed!" exit 1
exit 1
fi
fi fi
} }
@@ -351,9 +349,14 @@ function remove_moonraker_obico() {
function update_moonraker_obico() { function update_moonraker_obico() {
do_action_service "stop" "moonraker-obico" do_action_service "stop" "moonraker-obico"
clone_or_update_moonraker_obico "${MOONRAKER_OBICO_REPO}" if [[ ! -d ${MOONRAKER_OBICO_DIR} ]]; then
ok_msg "Update complete!" clone_moonraker_obico "${MOONRAKER_OBICO_REPO}"
else
status_msg "Updating Moonraker-obico ..."
cd "${MOONRAKER_OBICO_DIR}" && git pull
fi
ok_msg "Update complete!"
do_action_service "restart" "moonraker-obico" do_action_service "restart" "moonraker-obico"
} }