Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhanced handling of errors #479

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions docker/scripts/file-downloader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,36 @@
if [ $# -lt 2 ]; then
echo "Usage: $0 file_url destination_folder"
echo "Example: $0 https://example.com/somefile.txt /path/to/destination/"
exit
exit 1
fi

check_and_download_file() {
local file_url="$1"
local directory="$2"
local filename="${file_url##*/}" # Extracts the filename from the URL

# Check if the file exists in the directory
# Create the directory if it doesn't exist
if [[ ! -d "$directory" ]]; then
echo "Directory $directory does not exist. Creating it..."
mkdir -p "$directory" || {
echo "Failed to create directory $directory."
exit 1
}
fi

# Check if the file already exists
if [[ ! -f "$directory/$filename" ]]; then
# File does not exist, download it
echo "Downloading $file_url ..."
wget "$file_url" -P "$directory"
echo "Download complete!"
echo "Downloading $file_url to $directory..."
if wget -q "$file_url" -P "$directory"; then
echo "Download of $filename completed successfully!"
else
echo "Failed to download $file_url."
exit 1
fi
else
echo "File $filename already exists in $directory."
echo "File $filename already exists in $directory. Skipping download"
fi
}
echo "$0 $1 $2"

# Execute the function
check_and_download_file "$1" "$2"