Skip to content

Instantly share code, notes, and snippets.

@r0mdau
Created November 24, 2023 00:27
Show Gist options
  • Save r0mdau/eb56d512022047a3df6b51a75d41f113 to your computer and use it in GitHub Desktop.
Save r0mdau/eb56d512022047a3df6b51a75d41f113 to your computer and use it in GitHub Desktop.

Revisions

  1. r0mdau created this gist Nov 24, 2023.
    43 changes: 43 additions & 0 deletions script.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    #!/bin/bash

    # Enable debug mode
    set -x

    # Log function
    log() {
    echo "[INFO] $1"
    }

    logexit() {
    echo "[ERROR] $1 Exiting..."
    exit 1
    }

    # Trap
    cleanup() {
    log "Cleaning up temporary files..."
    rm -f /tmp/website
    }

    # Trap the EXIT signal and call the cleanup function
    trap cleanup EXIT

    # Check if curl is installed
    log "Checking if curl is installed..."
    if ! command -v curl &> /dev/null; then
    logexit "curl command is not installed."
    fi

    # Download the website
    log "Downloading the website..."
    curl -s -o /tmp/website/index.html https://cv.romaindauby.fr

    # Check if the download was successful
    log "Checking if the download was successful..."
    if [ $? -ne 0 ]; then
    logexit "An error occurred while downloading the website."
    fi

    # Exit with success
    log "Script completed successfully."
    exit 0