Pyrit and Quilt in Debian Packaging

This script takes two arguments URL to download and destination directory where the file will be saved. If no arguments are provided, it displays an error message and exits with status code 1.

#!/bin/bash

# Check if both arguments have been passed or not
if [ $# -lt 2 ]; then 
    echo "Usage: ./download_file.sh <URL> <destination directory>"
    exit 1 # Exit with status code 1 if arguments are not provided
fi

url=$1 # Assign first argument to variable "url"
dest_dir=$2 # Assign second argument to variable "dest_dir"

# Check if either one is empty
if [ -z "$url" ] || [ -z "$dest_dir" ]; then 
    echo "Error: URL or destination directory cannot be blank."
    exit 1 # Exit with status code 1 if either argument is empty
fi

# Use wget utility to download the file from URL using -q option for quiet mode and saves it in destination directory specified by user.
wget --quiet $url -P $dest_dir 

# Check if there is any error during downloading process
if [ $? -ne 0 ]; then 
    echo "Error: Failed to download file."
    exit 1 # Exit with status code 1 if there is an error during downloading
fi

echo "File has been successfully downloaded." # Display a success message to the console.

In this script, we first check if both arguments have been passed or not using `if [ $# -lt 2 ]`. If either one is empty, it displays an error message and exits with status code 1. We then set the URL variable to the value of the first argument provided by user and similarly, we set the destination directory variable to the second argument provided by user.

Next, we check if both variables have been set or not using `if [ -z “$url” ] || [ -z “$dest_dir” ]`. If either one is empty, it displays an error message and exits with status code 1. We then use wget utility to download the file from URL using `wget –quiet $url -P $dest_dir` option for quiet mode and saves it in destination directory specified by user.

Finally, we check if there is any error during downloading process using `if [ $? -ne 0 ]`. If there is any error, it displays an error message and exits with status code 1. Otherwise, it displays a success message to the console.

SICORPS