dotfiles/bin/rwget

56 lines
1.2 KiB
Plaintext
Raw Normal View History

2017-03-31 13:54:00 +02:00
#!/bin/bash
# Base wget command
BASE_CMD="wget -r -c --no-host-directories --no-parent --reject='index.html*'"
# Let's get the URL first
if [ "$1" == "" ]; then
echo "No url given!" >&2
2017-04-04 22:13:10 +02:00
echo "Usage: $0 URL RATELIMIT [USER PASSWORD]" >&2
2017-03-31 13:54:00 +02:00
exit 1
else
PARAM_URL="'$1'"
shift
fi
# Collect non-essential parameters and build the final command to run
FINAL_CMD="$BASE_CMD"
# Collect rate limit
if [ "$1" != "" ]; then
PARAM_LIMIT="--limit-rate='$1'"
FINAL_CMD="$FINAL_CMD $PARAM_LIMIT"
fi
shift
# Collect user + pass, error out if one is missing
if [ "$1" != "" ]; then
PARAM_USER="--user='$1'"
shift
# Collect password, too
if [ "$1" == "" ] ; then
echo "User given, but password missing?!" >&2
exit 1
else
PARAM_PASS="--password='$1'"
fi
FINAL_CMD="$FINAL_CMD $PARAM_USER $PARAM_PASS"
fi
shift
# Append URL and that's it.
FINAL_CMD="$FINAL_CMD $PARAM_URL"
# Debug output
echo "-------------------------------------"
echo "PARAM_LIMIT: $PARAM_LIMIT"
echo "PARAM_USER: $PARAM_USER"
echo "PARAM_PASS: $PARAM_PASS"
echo "PARAM_URL: $PARAM_URL"
echo "-------------------------------------"
echo "Running command: $FINAL_CMD"
echo "-------------------------------------"
echo ""
eval $FINAL_CMD