chiark / gitweb /
ubuntu-paste: convert to python3/argparse/requests
[bin.git] / ubuntu-daily
1 #! /bin/sh
2
3 PROJECT=
4 CURRENT_DIST=oneiric
5 DIST="$CURRENT_DIST"
6 BASE=cdimage.ubuntu.com::cdimage
7 RSYNC=false
8 HTTP=false
9
10 usage () {
11         cat <<EOF
12 Usage: $0 [options] image_type architecture
13
14 Options:
15   -f|--flavour FLAVOUR          Flavour (default: ubuntu).
16   -d|--dist DIST                Distribution (default: oneiric).
17   -a|--authenticated            Use privileged access.
18   -r|--rsync                    Force rsync.
19   -h|--http                     Force HTTP only (no reuse).
20 EOF
21 }
22
23 eval set -- "$(getopt -o f:d:arh -l help,flavour:,dist:,authenticated,rsync,http -- "$@")" || { usage >&2; exit 2; }
24 while :; do
25         case $1 in
26                 --help)
27                         usage
28                         exit 0
29                         ;;
30                 -f|--flavour)
31                         PROJECT="$2"
32                         if [ "$PROJECT" = ubuntu ]; then
33                                 PROJECT=
34                         fi
35                         shift 2
36                         ;;
37                 -d|--dist)
38                         DIST="$2"
39                         shift 2
40                         ;;
41                 -a|--authenticated)
42                         BASE=antimony:cdimage/www/full
43                         shift
44                         ;;
45                 -r|--rsync)
46                         RSYNC=:
47                         shift
48                         ;;
49                 -h|--http)
50                         HTTP=:
51                         shift
52                         ;;
53                 --)     shift; break ;;
54                 *)      usage >&2; exit 2;
55         esac
56 done
57
58 if $HTTP; then
59         BASE="http://cdimage.ubuntu.com"
60 fi
61
62 PREFIX=
63 if [ "$DIST" != "$CURRENT_DIST" ]; then
64         PREFIX="$DIST/$PREFIX"
65 fi
66 case $1 in
67         server)
68                 PREFIX="ubuntu-server/$PREFIX"
69                 ;;
70         jeos)
71                 PREFIX="jeos/$PREFIX"
72                 ;;
73         mid)
74                 PREFIX="ubuntu-mid/$PREFIX"
75                 ;;
76 esac
77 case $1 in
78         live|desktop|mid)
79                 IMAGE_TYPE=${IMAGE_TYPE:-${PREFIX}daily-live}
80                 ;;
81         dvd)
82                 IMAGE_TYPE=${IMAGE_TYPE:-${PREFIX}dvd}
83                 ;;
84         *)
85                 IMAGE_TYPE=${IMAGE_TYPE:-${PREFIX}daily}
86                 ;;
87 esac
88 case $1 in
89         mid)
90                 EXTENSION=img
91                 ;;
92         *)
93                 EXTENSION=iso
94                 ;;
95 esac
96
97 case $1 in
98         install|alternate|server|addon|serveraddon)     ;;
99         *)
100                 $HTTP || RSYNC=:
101                 ;;
102 esac
103
104 LOCAL="./${PROJECT:+$PROJECT-}$DIST-$1-$2"
105 REMOTE="$BASE/${PROJECT:+$PROJECT/}$IMAGE_TYPE/current/$DIST-$1-$2"
106
107 if $RSYNC; then
108         ionice -c2 -n7 rsync -avP "$REMOTE.$EXTENSION" "$LOCAL.$EXTENSION"
109 elif $HTTP; then
110         wget -O "$LOCAL.$EXTENSION" "$REMOTE.$EXTENSION"
111 else
112         rsync -avP "$REMOTE.jigdo" "$LOCAL.jigdo"
113         if [ "$PROJECT" ]; then
114                 sed -i "s/=$DIST-$1-$2/=$PROJECT-$DIST-$1-$2/g" "$LOCAL.jigdo"
115         fi
116         rsync -avP "$REMOTE.template" "$LOCAL.template"
117
118         mkdir -p old
119
120         EXISTING=false
121         MOUNTS=
122
123         do_mount () {
124                 mkdir -p "old/$1"
125                 MOUNTS="${MOUNTS:+$MOUNTS }$1"
126                 sudo mount -o loop,ro "$1" "old/$1"
127         }
128
129         cleanup () {
130                 trap - EXIT HUP INT QUIT TERM
131
132                 local mount
133
134                 for mount in $MOUNTS; do
135                         sudo umount "old/$mount"
136                         rmdir -p --ignore-fail-on-non-empty "old/$mount"
137                 done
138
139                 if $EXISTING; then
140                         rm -f "$LOCAL.iso.old"
141                 fi
142         }
143         trap cleanup EXIT HUP INT QUIT TERM
144
145         if [ -e "$LOCAL.iso" ]; then
146                 EXISTING=:
147                 mv "$LOCAL.iso" "$LOCAL.iso.old"
148                 do_mount "$LOCAL.iso.old"
149         fi
150
151         for iso in *"$DIST"-*.iso; do
152                 case $iso in
153                         *-install-*|*-alternate-*|*-server-*|*-addon-*|*-serveraddon-*) ;;
154                         *)
155                                 continue
156                                 ;;
157                 esac
158                 do_mount "$iso"
159         done
160
161         ionice -c2 -n7 jigdo-lite --scan "$PWD/old" "$LOCAL.jigdo"
162 fi