Skip to content

Instantly share code, notes, and snippets.

@BrixSat
Created December 31, 2024 09:57

Revisions

  1. BrixSat created this gist Dec 31, 2024.
    45 changes: 45 additions & 0 deletions clone.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #!/bin/bash

    function downloadFile
    {
    url="${1}"
    # If url starts with //
    if [[ "${url}" = "//"* ]]
    then
    url="https:${url}"
    fi

    # Grab the extension the path and the filename
    extension=$(echo "${url}" | sed 's/^.*\.//')
    path_with_file=$(echo "${url}" | sed 's/https:\/\/download.mikrotik.com//g')
    file=$(basename "$path_with_file")
    path_without_file=$(echo "$path_with_file" | sed "s/$file//g")


    if [ ! -d ".${path_without_file}" ]
    then
    mkdir -p ".${path_without_file}"
    fi

    if [ -f ".${path_with_file}" ]
    then
    echo "Already exists $file"
    return
    fi

    wget "${url}"
    mv "${file}" ".${path_without_file}"
    }

    HTML=$(curl https://mikrotik.com/download)
    #HTML=$(curl http://127.0.0.1/download)
    for version in $(echo -n "$HTML" | egrep "npk|bin|zip|exe|vdi|vmdk|vhdx|vhd|ova|lzb" | sed -r 's~(href="|src=")([^"]+).*~\n\1\2~g' | awk '/^(href|src)/,//' | sed 's/href="//g')
    do
    if [[ $version =~ [rR][cC] ]]
    then
    echo "Ignoring rc version $version".
    continue
    fi
    echo "Downloading $version"
    downloadFile "$version" "routeros7"
    done