Skip to content

Instantly share code, notes, and snippets.

@juanje
Last active October 9, 2020 20:07
Show Gist options
  • Save juanje/0b49125c848708e0087d2433ab820907 to your computer and use it in GitHub Desktop.
Save juanje/0b49125c848708e0087d2433ab820907 to your computer and use it in GitHub Desktop.

Revisions

  1. juanje revised this gist Oct 9, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions try_until.sh
    Original file line number Diff line number Diff line change
    @@ -19,9 +19,9 @@ function get_file() {
    # the max number of retries gets reached.
    until wget -q "${filename}" ; do
    sleep $wait_time
    (( count += 1 ))
    count+= 1

    if (( "$count" == "$max_retries" )); then
    if [ "$count" -eq "$max_retries" ]; then
    # Max number of retries exceeded
    echo "It was impossible to download ${filename}."
    return 1
  2. juanje revised this gist Aug 11, 2020. 2 changed files with 33 additions and 23 deletions.
    33 changes: 33 additions & 0 deletions try_until.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/bin/bash

    URL="http://ipv4.download.thinkbroadband.com/50MB.zip"

    function get_file() {
    # Declare these local variables as integer
    local -i count
    local -i max_retries
    local -i wait_time
    local filename

    filename="$1"

    max_retries=5
    wait_time=15

    count=0
    # Loop until the file gets downloaded or
    # the max number of retries gets reached.
    until wget -q "${filename}" ; do
    sleep $wait_time
    (( count += 1 ))

    if (( "$count" == "$max_retries" )); then
    # Max number of retries exceeded
    echo "It was impossible to download ${filename}."
    return 1
    fi
    done
    }

    # Call the function
    get_file "${URL}"
    23 changes: 0 additions & 23 deletions wait.sh
    Original file line number Diff line number Diff line change
    @@ -1,23 +0,0 @@
    function pull_image() {
    local version
    local image
    local -i count
    local -i max_retries
    local -i wait_time
    version="$1"
    image="${REGISTRY_URL}/f${version}/fedora-toolbox:${version}"
    count=0
    max_retries=5
    wait_time=15

    until ${PODMAN} pull "${image}" >/dev/null ; do
    sleep $wait_time
    (( count += 1 ))

    if (( "$count" == "$max_retries" )); then
    # Max number of retries exceeded
    echo "Podman couldn't pull the image ${image}."
    return 1
    fi
    done
    }
  3. juanje created this gist Aug 10, 2020.
    23 changes: 23 additions & 0 deletions wait.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    function pull_image() {
    local version
    local image
    local -i count
    local -i max_retries
    local -i wait_time
    version="$1"
    image="${REGISTRY_URL}/f${version}/fedora-toolbox:${version}"
    count=0
    max_retries=5
    wait_time=15

    until ${PODMAN} pull "${image}" >/dev/null ; do
    sleep $wait_time
    (( count += 1 ))

    if (( "$count" == "$max_retries" )); then
    # Max number of retries exceeded
    echo "Podman couldn't pull the image ${image}."
    return 1
    fi
    done
    }