Skip to content

Instantly share code, notes, and snippets.

@K-Yo
Last active January 3, 2025 17:18
Show Gist options
  • Select an option

  • Save K-Yo/0d0aaa9c4c6b4d0ad88867a86b4b3963 to your computer and use it in GitHub Desktop.

Select an option

Save K-Yo/0d0aaa9c4c6b4d0ad88867a86b4b3963 to your computer and use it in GitHub Desktop.
Bash script to help download the latest splunk version of your choice.
#!/bin/bash
# code used for the article https://olivontech.com/en/posts/splunk/download-splunk-without-login/
# inspired from https://gist.github.com/ThinGuy/ee76f181151047267cdb38b7e1c1f1e3
# compatible with bash 4.4+
# you need curl for the dowloads to happen
# if download is interrupted, it will resume where it left off
download-splunk() {
# Array of Splunk URLS
echo "⏳ fetching the list of splunk enterprise URLs..."
local -a SPLUNK_ENTERPRISE_URLS
mapfile -t SPLUNK_ENTERPRISE_URLS < <(curl -sSlL https://www.splunk.com/en_us/download/splunk-enterprise.html | grep -oP '(?<=data-link=")[^"]+')
echo "⏳ fetching the list of splunk universal forwarder URLs..."
local -a SPLUNK_UF_URLS
mapfile -t SPLUNK_UF_URLS < <(curl -sSlL https://www.splunk.com/en_us/download/universal-forwarder.html | grep -oP '(?<=data-link=")[^"]+')
local -a ALL_URLS
ALL_URLS=("${SPLUNK_ENTERPRISE_URLS[@]}" "${SPLUNK_UF_URLS[@]}")
# Display the array elements to the user
echo "❓Please choose a value from the following list:"
for i in "${!ALL_URLS[@]}"; do
printf "%2d. %s\n" "$((i + 1))" "${ALL_URLS[i]}"
done
# Prompt for user selection
while true; do
read -rp "Enter the number of your choice (1-${#ALL_URLS[@]}): " choice
# Validate input
if ((choice > 0)) && ((choice <= ${#ALL_URLS[@]})); then
# Adjust for zero-based indexing
local SELECTED_URL="${ALL_URLS[$((choice - 1))]}"
local FILENAME="${SELECTED_URL##*/}"
# Download the file
echo " ⤵️ Dowloading to current directory: $FILENAME"
curl -L -O -C - "$SELECTED_URL"
echo "Downloaded \"$FILENAME\""
echo "🎉Done, have a great day!"
break
else
echo "❌Invalid selection. Please enter a number between 1 and ${#ALL_URLS[@]}."
fi
done
}
download-splunk
@reveal79
Copy link

reveal79 commented Jan 3, 2025

Here is powershell code for Windows users

`function Download-Splunk {
function Get-URLsFromPage {
param (
[string]$Url,
[string]$Pattern
)
$content = (Invoke-WebRequest -Uri $Url -UseBasicParsing).Content
$matches = Select-String -InputObject $content -Pattern $Pattern -AllMatches
$urls = $matches.Matches | ForEach-Object { $_.Groups[1].Value.Trim() }
return $urls
}

Write-Host "⏳ Fetching the list of Splunk Enterprise URLs..."
$splunkEnterpriseURLs = Get-URLsFromPage -Url "https://www.splunk.com/en_us/download/splunk-enterprise.html" -Pattern 'data-link=\"([^\"]+)\"'

Write-Host "⏳ Fetching the list of Splunk Universal Forwarder URLs..."
$splunkUFURLs = Get-URLsFromPage -Url "https://www.splunk.com/en_us/download/universal-forwarder.html" -Pattern 'data-link=\"([^\"]+)\"'

$allURLs = $splunkEnterpriseURLs + $splunkUFURLs

if ($allURLs.Count -eq 0) {
    Write-Host "❌ No URLs were fetched. Please check the URLs or your internet connection." -ForegroundColor Red
    return
}

Write-Host "❓ Please choose a value from the following list:" -ForegroundColor Yellow
$allURLs | ForEach-Object {
    $index = [array]::IndexOf($allURLs, $_)
    Write-Host "$(($index + 1)). $_"
}

while ($true) {
    $choice = Read-Host "Enter the number of your choice (1-$($allURLs.Count))"

    if ($choice -as [int] -and $choice -ge 1 -and $choice -le $allURLs.Count) {
        $selectedURL = $allURLs[$choice - 1]
        $filename = [System.IO.Path]::GetFileName($selectedURL)

        # Check for existing file and its size
        if (Test-Path $filename) {
            $existingSize = (Get-Item $filename).Length
            Write-Host "⏳ Resuming download. File already exists: $filename ($existingSize bytes)" -ForegroundColor Cyan
            $headers = @{ Range = "bytes=$existingSize-" }
            Invoke-WebRequest -Uri $selectedURL -OutFile $filename -Headers $headers -UseBasicParsing
        } else {
            Write-Host "⤵️ Downloading to current directory: $filename" -ForegroundColor Cyan
            Invoke-WebRequest -Uri $selectedURL -OutFile $filename -UseBasicParsing
        }

        Write-Host "Downloaded `\"$filename`\"" -ForegroundColor Green
        Write-Host "🎉 Done, have a great day!" -ForegroundColor Green
        break
    } else {
        Write-Host "❌ Invalid selection. Please enter a number between 1 and $($allURLs.Count)." -ForegroundColor Red
    }
}

}

Download-Splunk`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment