This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 26th, 2010  |  syntax: Bash  |  size: 2.41 KB  |  views: 336  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env bash
  2.  
  3. # function
  4. zsync-one-iso () {
  5. if [ "$1" == "ubuntu" ]; then
  6.       WEBDIR=""
  7.       ISONAME="maverick-desktop-i386"
  8.    elif [ "$1" == "kubuntu" ]; then
  9.       WEBDIR="kubuntu/"
  10.       ISONAME="maverick-desktop-i386"
  11.    elif [ "$1" == "xubuntu" ]; then
  12.       WEBDIR="xubuntu/"
  13.       ISONAME="maverick-desktop-i386"
  14.    elif [ "$1" == "ubuntu-netbook" ]; then
  15.       WEBDIR="ubuntu-netbook/"
  16.       ISONAME="maverick-netbook-i386"
  17.    else
  18.       echo "$0 [ubuntu|kubuntu|xubuntu|ubuntu-netbook]"
  19.       exit 1
  20.    fi
  21.  
  22.    WEBDIR=$WEBDIR"daily-live/current"
  23.  
  24.    if [ ! -d ~/Downloads/$1 ]; then
  25.       mkdir -p ~/Downloads/$1
  26.    fi
  27.    cd ~/Downloads/$1
  28.  
  29.    # phase 1
  30.    if [ "$2" == 1 ]; then
  31.       # Get MD5SUMS, keeping the previous version
  32.       if [ -e MD5SUMS ]; then
  33.          if [ -e MD5SUMS.prv ]; then
  34.             rm MD5SUMS.prv
  35.          fi
  36.          mv MD5SUMS MD5SUMS.prv
  37.       fi
  38.       wget http://cdimage.ubuntu.com/$WEBDIR/MD5SUMS 2>/dev/null
  39.       if [ ! -e MD5SUMS ]; then
  40.          echo "WGET did not get MD5SUMS"
  41.          if [ -e MD5SUMS.prv ]; then
  42.             mv MD5SUMS.prv MD5SUMS
  43.             exit 1
  44.          fi
  45.       fi
  46.  
  47.       # This check also succeeds if MD5SUMS.prv doesn't exist
  48.       if [ MD5SUMS -nt MD5SUMS.prv ]; then
  49.          echo "Getting $1 ISO..."
  50.          # Get the manifest and ISO
  51.          if [ -e $ISONAME.manifest ]; then
  52.             rm $ISONAME.manifest
  53.          fi
  54.          wget -N http://cdimage.ubuntu.com/$WEBDIR/$ISONAME.manifest 2>/dev/null
  55.          if [ -e $ISONAME.iso ]; then
  56.             zsync http://cdimage.ubuntu.com/$WEBDIR/$ISONAME.iso.zsync
  57.          else
  58.             wget http://cdimage.ubuntu.com/$WEBDIR/$ISONAME.iso 2>/dev/null
  59.          fi
  60.       else
  61.          echo "No new build for $1"
  62.       fi
  63.    # phase 2
  64.    else
  65.       echo "Checking $1 ISO..."
  66.       # nice trick to skip other files in MD5SUMS besides $ISONAME
  67.       cat MD5SUMS | grep $ISONAME | md5sum -c
  68.    fi
  69. }
  70.  
  71. # main
  72.  
  73. # call the function for phase 1 (get ISO)
  74. if [ -z "$1" ]; then
  75.    zsync-one-iso "ubuntu" 1
  76.    zsync-one-iso "ubuntu-netbook" 1
  77.    # zsync-one-iso "kubuntu" 1
  78.    # zsync-one-iso "xubuntu" 1
  79. else
  80.    zsync-one-iso $1 1
  81. fi
  82.  
  83. # call the function for phase 2 (check ISO)
  84. if [ -z "$1" ]; then
  85.    zsync-one-iso "ubuntu" 2
  86.    zsync-one-iso "ubuntu-netbook" 2
  87.    # zsync-one-iso "kubuntu" 2
  88.    # zsync-one-iso "xubuntu" 2
  89. else
  90.    zsync-one-iso $1 2
  91. fi
clone this paste RAW Paste Data