From b55bd06bb598d65aa32dfc1994fced9fa8037cfb Mon Sep 17 00:00:00 2001 From: JaviPege Date: Wed, 22 Oct 2025 22:43:59 +0200 Subject: [PATCH] refactor: convert healthcheck creation and cleanup prompt to atomic functions - Use create_file_from_content() for healthcheck test file - Use create_folder() for healthcheck directory - Convert cleanup prompt to ask_user_input() - No new functions created, only reused existing validated functions --- setup.sh | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/setup.sh b/setup.sh index ddd9208..bacacb2 100755 --- a/setup.sh +++ b/setup.sh @@ -1408,11 +1408,13 @@ if [ "$INSTALL_HEALTHCHECK_FILES" = true ]; then # Create test file if [ -d "${ROOT_DIR}/data/realdebrid-zurg/torrents" ]; then - echo "HEALTHCHECK TEST FILE - DO NOT DELETE" | sudo tee ${ROOT_DIR}/data/realdebrid-zurg/torrents/.healthcheck_test.txt > /dev/null - sudo chown rclone:mediacenter ${ROOT_DIR}/data/realdebrid-zurg/torrents/.healthcheck_test.txt + create_file_from_content \ + "${ROOT_DIR}/data/realdebrid-zurg/torrents/.healthcheck_test.txt" \ + "HEALTHCHECK TEST FILE - DO NOT DELETE" \ + "rclone:mediacenter" # Create symlink in media directory - sudo mkdir -p ${ROOT_DIR}/data/media/.healthcheck + create_folder "${ROOT_DIR}/data/media/.healthcheck" sudo ln -sf ${ROOT_DIR}/data/realdebrid-zurg/torrents/.healthcheck_test.txt ${ROOT_DIR}/data/media/.healthcheck/test_symlink.txt echo "✓ Healthcheck test file created" @@ -1515,20 +1517,19 @@ log_info "Installation completed successfully" log_to_file "COMPLETE" "Installation finished at $(date)" # Ask if user wants to remove the installer repository -echo "" -echo "=========================================" -echo "Cleanup" -echo "=========================================" -echo "" -echo "The installer repository is no longer needed. All configuration" -echo "files have been copied to ${ROOT_DIR}." -echo "" -echo "Installation directory: $(pwd)" -echo "" -read -p "Do you want to remove the installer repository? [y/N]: " -n 1 -r -echo "" +REMOVE_INSTALLER="" +ask_user_input \ + "Cleanup" \ + "The installer repository is no longer needed. All configuration +files have been copied to ${ROOT_DIR}. -if [[ $REPLY =~ ^[Yy]$ ]]; then +Installation directory: $(pwd)" \ + "Do you want to remove the installer repository? [y/N]: " \ + "n" \ + false \ + REMOVE_INSTALLER + +if [[ "$REMOVE_INSTALLER" =~ ^[Yy]$ ]]; then # Use SCRIPT_DIR that was calculated at the start of the script # This is more reliable than recalculating from BASH_SOURCE log_info "Removing installer repository: ${SCRIPT_DIR}"