home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / local / bin / puppydownload < prev    next >
Encoding:
Text File  |  2004-08-06  |  3.9 KB  |  108 lines

  1. #!/bin/sh
  2.  
  3. #my own humble download accelerator frontend for axel.
  4. #(c) copyright 2004 Barry Kauler www.goosee.com/puppy
  5.  
  6. #choices: 
  7. # multiple servers or one
  8. # if one, then number connections
  9. # destination path.
  10.  
  11. COMMANDTAIL="$@"
  12.  
  13. if [ "$COMMANDTAIL" ];then
  14.  #this means that a url has been passed in on the commandline.
  15.  echo "$COMMANDTAIL" | grep -i "http://"
  16.  if [ ! $? -eq 0 ];then #=0 if found.
  17.   echo "$COMMANDTAIL" | grep -i "ftp://"
  18.   if [ ! $? -eq 0 ];then
  19.    Xdialog --wmclass "puppyaxel" --title "Puppy download accelerator" --no-buttons --icon "/usr/local/lib/X11/pixmaps/warning24.xpm" --infobox "The URL is incomplete. It needs http:// or ftp:// prefix." 0 0 20000 &
  20.   fi
  21.  fi
  22. fi
  23.  
  24. DOSETUPLOOP="true"
  25. while [ "$DOSETUPLOOP" = "true" ];do
  26.  DOSETUPLOOP="false"
  27.  
  28. RETSTR=`Xdialog --wmclass "puppyaxel" --title "Puppy Axel download accelerator" --stdout --left --separator "|" --icon "/usr/share/images/ftp64.png" --check "Bypass any proxy server" off --3inputsbox "This is a frontend for the Axel download accelerator.\nIt is capable of multiple connections to the same server,\nor download simultaneously from multiple servers.\n\nNote: you can paste from the clipboard with CTRL-V.\nDo not forget the ftp:// or http:// prefix.\nRecommend leave bypass-proxy checkbox unticked." 0 0 "First server URL:" "$COMMANDTAIL" "Second server URL (optional):" "" "Third server URL (optional):" ""`
  29.  
  30. if [ $? -eq 0 ];then
  31. URL1=`echo -n "$RETSTR" | head -n 1 | cut -f 1 -d "|"`
  32. URL2=`echo -n "$RETSTR" | head -n 1 | cut -f 2 -d "|"`
  33. URL3=`echo -n "$RETSTR" | head -n 1 | cut -f 3 -d "|"`
  34. BYPASSPROXY=`echo -n "$RETSTR" | tail -n 1`
  35. else
  36.  exit
  37. fi
  38.  
  39. MULTISERVE="$URL2$URL3"
  40. if [ ! "$MULTISERVE" ];then
  41.  MULTICONN=`Xdialog --wmclass "puppyaxel" --title "Puppy Axel download accelerator" --stdout --no-tags --radiolist "Choose one or more simultaneous connections to the server.\nMultiple connections will speed download, but a slow\ndialup connection may still be the bottleneck\n(choose 3 and above only if you have broadband).\nAlso, some servers will disconnect if download\nacceleration is attempted." 0 0 0 "1" "Single connection, no acceleration" on "2" "Two simultaneous connections" off "3" "Three simultaneous connections" off "4" "Four simultaneous connections" off`
  42. fi
  43.  
  44. if [ ! $? -eq 0 ];then
  45.  exit
  46. fi
  47.  
  48.  DESTDIR="`Xdialog --wmclass "puppyaxel" --title "Choose destination directory:" --wizard --no-cancel --help "if you leave the Selection field blank, the destination filename\nwill be the same as the source filename.\nOtherwise, type in the new name for the downloaded file." --stdout --dselect "/root/" 0 0 `"
  49.  
  50.  RETVAL=$?
  51.  #note, returns 3 if "previous" button clicked.
  52.  if [ $RETVAL -eq 3 ];then #=0 "next".
  53.   DOSETUPLOOP="true"
  54.  else
  55.   if [ ! $RETVAL -eq 0 ];then
  56.    exit
  57.   fi
  58.  fi
  59.  
  60. done
  61.  
  62. #now do the actual download...
  63.  
  64. ls "$DESTDIR" 2>&1 | grep "No such file or directory"
  65. if [ $? -eq 0 ];then
  66.  #this means that dest is not an existing file nor directory, so must
  67.  #have typed a filename into directory selection dialog.
  68.  FULLDEST="$DESTDIR"
  69. else
  70.  file $DESTDIR | grep "directory"
  71.  if [ $? -eq 0 ];then
  72.   #DESTDIR is only a path. get filename off url...
  73.   FILEDEST=`basename "$URL1"`
  74.   FULLDEST="$DESTDIR$FILEDEST"
  75.  else
  76.   #dest filename must already exist.
  77.   FULLDEST="$DESTDIR"
  78.  fi
  79. fi
  80.  
  81. if [ "$BYPASSPROXY" = "checked" ];then
  82.  BYPASSPROXY="--no-proxy"
  83. else
  84.  BYPASSPROXY=""
  85. fi
  86.  
  87. echo -e "#!/bin/sh
  88. axel $BYPASSPROXY --alternate --verbose --num-connections=\"$MULTICONN\" --output=\"$FULLDEST\" \"$URL1\" $URL2 $URL3
  89. if [ ! \$? -eq 0 ];then
  90.  echo
  91.  echo \"DOWNLOAD FAILURE!\"
  92.  if [ -f $FULLDEST ];then
  93.   echo \"The file has not been fully downloaded.\"
  94.   echo -n \"Deleting partially downloaded file...\"
  95.   echo \" done\"
  96.  else
  97.   echo \"The file has not been downloaded.\"
  98.  fi
  99.  echo
  100.  echo -n \"Press ENTER key to exit: \"
  101.  read nnn
  102. fi
  103. " > /tmp/axelrun.sh
  104.  
  105. chmod 755 /tmp/axelrun.sh
  106. rxvt -name puppyaxel -bg orange -geometry 80x10 -title "Puppy Axel download accelerator" -e /tmp/axelrun.sh
  107.  
  108.