ubuntu-cd/sync: cleaned up error handling, variable safety, and readability

This commit is contained in:
Kees Cook 2007-06-14 12:29:05 -07:00
parent 35391d572c
commit 4f74d71a39
2 changed files with 67 additions and 65 deletions

View File

@ -1,26 +1,40 @@
#!/bin/bash
set -e
# Get the latest CD snapshot release.
Distro=$1
Distro="$1"
if [ -z "$Distro" ]; then
echo "Which distro?" >&2
exit 1
fi
Release="$2"
if [ -z "$Release" ]; then
echo "Which ISO release?" >&2
exit 1
fi
Ver=gutsy
Code=tribe
cd ~/distros/ubuntu/${Distro}/${Ver}
mkdir -p ${Code}-$2
cd ${Code}-$2
cd ~/distros/ubuntu/"${Distro}"/"${Ver}"
mkdir -p "${Code}"-"${Release}"
cd "${Code}"-"${Release}"
cp ../*.iso .
cp ../*.iso . || true
if [ "${Distro}" == "ubuntu" ]; then
rsync rsync://cdimage.ubuntu.com/cdimage/releases/${Ver}/${Code}-$2/${Ver}-alternate-i386.iso ${Ver}-alternate-i386.iso
rsync rsync://cdimage.ubuntu.com/cdimage/releases/${Ver}/${Code}-$2/${Ver}-desktop-i386.iso ${Ver}-desktop-i386.iso
#rsync rsync://cdimage.ubuntu.com/cdimage/releases/${Ver}/${Code}-$2/${Ver}-server-i386.iso ${Ver}-server-i386.iso
#rsync rsync://cdimage.ubuntu.com/cdimage/releases/${Ver}/${Code}-$2/${Ver}-alternate-amd64.iso ${Ver}-alternate-amd64.iso
#rsync rsync://cdimage.ubuntu.com/cdimage/releases/${Ver}/${Code}-$2/${Ver}-desktop-amd64.iso ${Ver}-desktop-amd64.iso
#rsync rsync://cdimage.ubuntu.com/cdimage/releases/${Ver}/${Code}-$2/${Ver}-server-amd64.iso ${Ver}-server-amd64.iso
Origin="releases"
Flavors="alternate desktop server"
Archs="i386"
#Archs="i386 amd64 powerpc"
else
rsync rsync://cdimage.ubuntu.com/cdimage/${Distro}/releases/${Ver}/${Code}-$2/${Ver}-alternate-i386.iso ${Ver}-alternate-i386.iso
rsync rsync://cdimage.ubuntu.com/cdimage/${Distro}/releases/${Ver}/${Code}-$2/${Ver}-desktop-i386.iso ${Ver}-desktop-i386.iso
#rsync rsync://cdimage.ubuntu.com/cdimage/${Distro}/releases/${Ver}/${Code}-$2/${Ver}-alternate-amd64.iso ${Ver}-alternate-amd64.iso
#rsync rsync://cdimage.ubuntu.com/cdimage/${Distro}/releases/${Ver}/${Code}-$2/${Ver}-desktop-amd64.iso ${Ver}-desktop-amd64.iso
Origin="${Distro}/releases"
Flavors="alternate desktop"
Archs="i386"
#Archs="i386 amd64"
fi
for arch in $Archs; do
for flavor in $Flavors; do
rsync "rsync://cdimage.ubuntu.com/cdimage/${Origin}/${Ver}/${Code}-${Release}/${Ver}-${flavor}-${arch}.iso" "${Ver}-${flavor}-${arch}.iso"
done
done

View File

@ -1,4 +1,5 @@
#!/bin/bash
set -e
# Syncronise new ubuntu CD images, depending on command-line flags given.
# If none are given, sync all images.
@ -8,44 +9,40 @@ if [ -e /tmp/ubuntu-sync.01532-lock ]; then
exit 1
fi
Ubuntu_Distro_Dir=$HOME/distros/ubuntu
Ubuntu_Distro_Dir="$HOME/distros/ubuntu"
Dist=gutsy
# Only sync the oldest images, and only i386 images if low bandwidth.
Low_Bandwidth=1
while [ "$1" ]; do
while [ -n "$1" ]; do
case "$1" in
-u)
Image_Sets="${Image_Sets} ubuntu"
shift 1
break
;;
-k)
Image_Sets="${Image_Sets} kubuntu"
shift 1
break
;;
-e)
Image_Sets="${Image_Sets} edubuntu"
shift 1
break
;;
-x)
Image_Sets="${Image_Sets} xubuntu"
shift 1
break
;;
-s)
Image_Sets="${Image_Sets} ubuntu-server"
shift 1
break
;;
esac
shift || true
done
if [ "${Low_Bandwidth}" == 1 ] && [ "${Image_Sets}" == "" ]; then
cd ${Ubuntu_Distro_Dir}
Image_Sets=`ls -td1 */${Dist} | tail -1 | cut -f 1 -d /`
cd "${Ubuntu_Distro_Dir}"
Image_Sets=`ls -td1 */"${Dist}" | tail -1 | cut -f 1 -d /`
elif [ "${Low_Bandwidth}" == 0 ] && [ "${Image_Sets}" == "" ]; then
Image_Sets="ubuntu xubuntu ubuntu-server edubuntu kubuntu"
fi
@ -56,48 +53,39 @@ if [ ! -e /tmp/ubuntu-sync.01532-lock ]; then
fi
for Current_Set in ${Image_Sets}
do
cd ${Ubuntu_Distro_Dir}/${Current_Set}/${Dist}
Rsync_Options="--partial-dir=${Ubuntu_Distro_Dir}/${Current_Set}/${Dist}/.partial"
mkdir -p "${Ubuntu_Distro_Dir}/${Current_Set}/${Dist}"/.partial
cd "${Ubuntu_Distro_Dir}/${Current_Set}/${Dist}"
# Figure out remote path
if [ "${Current_Set}" == "ubuntu" ]; then
if rsync ${Rsync_Options} rsync://cdimage.ubuntu.com/cdimage/daily/current/${Dist}-alternate-i386.iso ${Dist}-alternate-i386.iso ; then
date > alternate-i386-sync
fi
if rsync ${Rsync_Options} rsync://cdimage.ubuntu.com/cdimage/daily-live/current/${Dist}-desktop-i386.iso ${Dist}-desktop-i386.iso ; then
date > desktop-i386-sync
fi
if [ "${Low_Bandwidth}" == 0 ]; then
if rsync ${Rsync_Options} rsync://cdimage.ubuntu.com/cdimage/ports/daily/current/${Dist}-alternate-powerpc.iso ${Dist}-alternate-powerpc.iso ; then
date > alternate-powerpc-sync
fi
if rsync ${Rsync_Options} rsync://cdimage.ubuntu.com/cdimage/ports/daily-live/current/${Dist}-desktop-powerpc.iso ${Dist}-desktop-powerpc.iso ; then
date > desktop-powerpc-sync
fi
fi
Origin=""
else
if [ "${Current_Set}" == "edubuntu" ]; then
Install=install
Live=live
elif [ "${Current_Set}" == "ubuntu-server" ]; then
Install=server
Live=live
else
Install=alternate
Live=desktop
fi
if rsync ${Rsync_Options} rsync://cdimage.ubuntu.com/cdimage/${Current_Set}/daily/current/${Dist}-${Install}-i386.iso ${Dist}-${Install}-i386.iso ; then
date > ${Install}-i386-sync
fi
if rsync ${Rsync_Options} rsync://cdimage.ubuntu.com/cdimage/${Current_Set}/daily-live/current/${Dist}-${Live}-i386.iso ${Dist}-${Live}-i386.iso ; then
date > ${Live}-i386-sync
fi
if [ "${Low_Bandwidth}" == 0 ]; then
if rsync ${Rsync_Options} rsync://cdimage.ubuntu.com/cdimage/${Current_Set}/daily/current/${Dist}-${Install}-powerpc.iso ${Dist}-${Install}-powerpc.iso ; then
date > ${Install}-powerpc-sync
fi
if rsync ${Rsync_Options} rsync://cdimage.ubuntu.com/cdimage/${Current_Set}/daily-live/current/${Dist}-${Live}-powerpc.iso ${Dist}-${Live}-powerpc.iso ; then
date > ${Live}-powerpc-sync
fi
fi
Origin="${Current_Set}"
fi
# Which flavors to download
if [ "${Current_Set}" == "edubuntu" ]; then
Flavors="install live"
elif [ "${Current_Set}" == "ubuntu-server" ]; then
Flavors="server live"
else
Flavors="alternate desktop"
fi
# Which archs to download
if [ "${Low_Bandwidth}" == 0 ]; then
Archs="i386 powerpc"
#Archs="i386 amd64 powerpc"
else
Archs="i386"
fi
for arch in $Archs; do
for flavor in $Flavors; do
if rsync --partial-dir="${Ubuntu_Distro_Dir}/${Current_Set}/${Dist}/.partial" "rsync://cdimage.ubuntu.com/cdimage/${Origin}/daily/current/${Dist}-${flavor}-${arch}.iso" "${Dist}-${flavor}-${arch}.iso" ; then
date > "${flavor}-${arch}-sync"
fi
done
done
done
rm /tmp/ubuntu-sync.01532-lock