#!/bin/sh

# Wget script to retrieve Patches from SunSolve.sun.com via https and 
# supply username and password.
#

# ----Begin of user defined values -----

# Patch to wget
WGETPATH="/opt/csw/bin"

# Patch list file
PATCHLIST="patch-list.txt"

#Sun Login info.  Modify with your account Sun account info.
UserID="yourusername"
UserPWD="yourpassword"

# Patch output directory
# DOWNLOADIR="/tmp/patches"
DOWNLOADIR="download directory"

# Proxy info
WEBPROXY=""

# Signed or unsigned patch setting
# Valid values are "signed" or "unsigned".  
# "unsigned" patches are in zip format.
# "signed" patches are in jar format.
PATCHTYPE="unsigned"

# ----End of user defined values -----

LOGFILE=patchlog-`date +%m-%d-%y-%H:%M`

# Verify value for PATCHTYPE is correct.
if [ ${PATCHTYPE} = "signed" ] || [ ${PATCHTYPE} = "unsigned" ];then
    echo""
else
      echo "PATCHVALUE not valid. Please correct."
      exit

fi

# Verify patch download directory exists.
if [ ! -d $DOWNLOADIR ];then
     echo ""
     echo "$DOWNLOADIR patch download directory does not exist."
     echo "Please create directory $DOWNLOADIR."
     exit
fi

if [ "$PATCHTYPE" = "unsigned" ];then
   for line in `cat ${PATCHLIST}`;do
        echo ""
        echo "Downloading unsigned patch ${line}."
        echo ""
        ${WGETPATH}/wget --http-user=${UserID} --http-passwd=${UserPWD} --no-check-certificate -nv "https://sunsolve.sun.com/private-cgi/pdownload.pl?target=${line}&method=h" -O ${DOWNLOADIR}/${line}.zip >> ${LOGFILE} 2>&1
   done
elif [ "$PATCHTYPE" = "signed" ];then
   for line in `cat ${PATCHLIST}`;do
        echo ""
        echo "Downloading signed patch ${line}."
        echo ""
        ${WGETPATH}/wget --http-user=${UserID} --http-passwd=${UserPWD} --no-check-certificate -nv "https://sunsolve.sun.com/private-cgi/pdownload.pl?target=${line}&method=hs" -O ${DOWNLOADIR}/${line}.jar >> ${LOGFILE} 2>&1
   done
fi



