#!/bin/bash
# File Name: BashGet.sh
# Author: Mark Sullivan
# Edited by beowu1f: 1) Support for getopts is included [getopt(1) is now
# deprecated]
# 2) This script also works in CYGWIN since CYGWIN does
# not include getopt(1) at all!
# 3) GNU Wget 1.10.2 has a new --no-check-certificate option
# that must be passed in order to gain access to rapidshare.com 
# and download the premiumzone.cgi page 
# 4) Have Fun!
while getopts u:p:l: choice 
do 
case "$choice" in 
u) user="$OPTARG";; 
p) pass="$OPTARG";; 
l) url="$OPTARG";; 
[?]) echo; echo "Usage: $0 -u <username> -p <password> -l <URL> --> terminating..."; \ 
echo >&2; exit 1;; 
esac 
done 

UserData=$(echo "-u " $user "-p " $pass "-u " $url) 

#colour definitions 
RED='\e[1;31m';CYAN='\e[1;36m';NC='\e[0m';BL='\e[1;34m';GR='\e[0;32m';YEL='\e[1;33m';DG='\e[1;30m' 

echo 
echo -e ${RED} 
echo "****************************************************************************" >&2 

echo "***Remember to turn on 'Direct Downloads' in rapidshare.com online setup!***" >&2 
echo -e "****************************************************************************" >&2 
echo -e ${NC} 
echo 
echo "<>-- your user data entered --<>" 
echo $UserData 
echo 

echo -e ${CYAN}real URL:${NC}$url 
fileName=`basename $url` 
echo -e ${CYAN}Filename:${NC}$fileName 
cookie=cookie 

## LOGIN and save cookie ## 
wget --save-cookies=$cookie -q --post-data="login=$user&password=$pass" https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi --no-check-certificate 

echo 

rm premiumzone.cgi 

echo -e "${CYAN}downloading: ${BL}$fileName${NC} ..." 
wget --load-cookies=$cookie -q $url -O ./downloads/$fileName --no-check-certificate 

if [ $? == 0 ] 
then 
echo -e ${DG} "downloading complete! ${BL} [${GR} OK ${BL}]" >&2 
else 
echo -e ${RED} "wget did not complete. downloading failed!" ${NC} >&2; exit 1 
fi 
############################################################################## 
