/[fai]/trunk/bin/fai-mirror
ViewVC logotype

Contents of /trunk/bin/fai-mirror

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5222 - (show annotations) (download)
Tue Dec 9 12:15:53 2008 UTC (4 years, 5 months ago) by lange
File size: 11438 byte(s)
fix typos in mkdebmirror, NEWS, classes_description.txt, fai-mirror,
fai-cd.8
1 #! /bin/bash
2
3 # $Id$
4 #*********************************************************************
5 #
6 # fai-mirror -- create and manage a partial mirror for FAI
7 #
8 # This script is part of FAI (Fully Automatic Installation)
9 # (c) 2004-2007, Thomas Lange, lange@informatik.uni-koeln.de
10 #
11 #*********************************************************************
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; see the file COPYING. If not, write to the
24 # Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 # MA 02111-1307, USA.
26 #*********************************************************************
27
28 version="Version 1.9.12, 4-december-2008"
29
30 # variables: NFSROOT, FAI_CONFIGDIR, FAI_ETC_DIR
31
32 export FAI_ROOT=/ # do not execute in chroot, needed for install_packages call
33 export PATH=$PATH:/usr/sbin
34
35 trap "umount_dirs" EXIT ERR
36 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37 usage() {
38
39 echo "fai-mirror -- create and manage a partial mirror for FAI."
40 echo "$version"
41 echo "Please read the manual page fai-mirror(1)."
42 exit
43 }
44 # - - - - - - - - - - - - - - - - - - - - - - - - - -
45 die() {
46
47 local e=$1 # first parameter is the exit code
48 shift
49
50 echo "$@" # print error message
51 exit $e
52 }
53 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54 excludeclass() {
55
56 # removes/excludes all classes in $* from $classes
57 local insert eclasses newclass c e
58
59 eclasses="$*"
60 eclasses=${eclasses//,/ }
61
62 for c in $classes; do
63 insert=1
64 for e in $eclasses; do
65 [ $c = $e ] && insert=0
66 done
67 [ $insert = 1 ] && newclass="$newclass $c"
68 done
69 classes="$newclass"
70 }
71 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72 get_addpackages() {
73
74 # add packages (mostly kernels) which are defined in the variable $addpackages
75 # TODO: maybe better to create a tmp file with all these package
76 # names, then to call install_packages for the tmp file
77
78 local f p pkg pkglist
79
80 for f in $(echo $FAI_CONFIGDIR/class/*.var); do
81 pkg=$(egrep ^addpackages= $f | sed 's/addpackages=//'|sed 's/"//g'| perl -pe 's/\$[\w_-]+//g')
82
83 [ -n "$pkg" ] && pkglist="$pkglist $pkg"
84 done
85 [ -z "$pkglist" ] && return 0
86
87 echo -n "Adding packages from variable \$addpackages:"
88 # loop over the list, because maybe some packages doesn't exist in the
89 # partial mirror, but only in the local repository. These can't be
90 # downloaded via the normal method
91 for p in $pkglist; do
92 echo -n " $p"
93 # test if .deb file is available
94 if [ ! -f $FAI_CONFIG/files/packages/${p}_*.deb ]; then
95 apt-get $qflag -d $aptoptions -y --force-yes --fix-missing install $p
96 fi
97 done
98 echo ""
99 }
100 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101 umount_dirs() {
102
103 [ "$FAI_DEBMIRROR" ] && umount $MNTPOINT 2>/dev/null 1>&2 || true
104 }
105 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
106 cleandirs() {
107
108 return # currently nothing to do
109 # rm $statefile
110 # rm -rf $mirrordir/.apt-move $statefile
111 # [ $debug -eq 1 ] || rm -rf $aptcache $archivedir
112 # rm -rf $aptcache $archivedir
113 }
114 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
115 initialize() {
116
117 # TODO: root is only needed when FAI_DEBMIRROR is defined. Then we
118 # must mount a directory
119
120 debdist=$(echo "$FAI_DEBOOTSTRAP" | awk '{print $1}')
121 # store all packages temporary in the mirror partition so we need only a move,
122 # not a copy later during apt-move
123 aptcache=$mirrordir/aptcache # holds the package cache data
124 archivedir=$aptcache/var/cache/apt/archives
125 aptmovefile=$aptcache/etc/apt-move.conf # stores apt-move.conf
126 statefile=$aptcache/statefile
127
128 # also used in install_packages.conf
129 export aptoptions=" \
130 -o Aptitude::Log=/dev/null \
131 -o Aptitude::CmdLine::Ignore-Trust-Violations=yes\
132 -o APT::Get::AllowUnauthenticated=true \
133 -o DPkg::force-conflicts::=yes \
134 -o Dir::State::status=$statefile \
135 -o APT::Get::Force-Yes=true \
136 -o Dir::Cache=$aptcache/var/cache/apt \
137 -o Dir::State=$aptcache/var/cache/apt \
138 -o Dir::Cache::Archives=$archivedir \
139 -o Dir::Etc::sourcelist=$aptcache/etc/apt/sources.list \
140 -o Dir::State::Lists=$aptcache/var/lib/apt/lists/"
141
142 # not needed
143 # -o APT::Get::ReInstall
144 # ."-o APT::Get::Download-Only=true -o Aptitude::Cmd-Line::Download-Only=true "
145
146 # we only need some empty dirs
147 set -e
148 mkdir -p $archivedir/partial $aptcache/etc/apt $aptcache/var/lib/apt/lists/partial
149 > $statefile
150 set +e
151 }
152 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153 delete_base_packages() {
154
155 # now delete all packages that are already included in base.tgz
156 local p
157
158 if [ ! -f $NFSROOT/var/tmp/base-pkgs.lis ]; then
159 echo "$NFSROOT/var/tmp/base-pkgs.lis not available."
160 echo "Can't remove wasteful packages that are already in base.tgz."
161 return
162 fi
163 echo "Removing packages that are already included in base.tgz"
164 for p in $(cat $NFSROOT/var/tmp/base-pkgs.lis); do
165 if [ -f $archivedir/${p}_*.deb ]; then
166 [ $verbose -eq 1 ] && echo "deleting package $p"
167 rm $archivedir/${p}_*.deb
168 # else commands only for debugging
169 # else
170 # echo "package $p not found"
171 # ls $archivedir/${p}_*.deb
172 fi
173 done
174 }
175 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
176 add_base_packages() {
177
178 local plist
179 # add packages from base.tgz and additional packages in nfsroot
180
181 # arch dependent packages defined in make-fai-nfsroot
182 echo "Adding packages of $cfdir/NFSROOT."
183 if [ -f $NFSROOT/var/tmp/packages.nfsroot ]; then
184 plist=$(< $NFSROOT/var/tmp/packages.nfsroot)
185 apt-get $qflag -d $aptoptions -y --force-yes --fix-missing install $plist
186 else
187 echo "WARNING: $NFSROOT/var/tmp/packages.nfsroot does not exists."
188 echo "Can't add those packages. Maybe the nfsroot is not yet created."
189 fi
190
191 # now use sources.list for debootstrap packages
192 echo "$FAI_DEBOOTSTRAP" | awk '{printf "deb %s %s main\n",$2,$1}' | perl -p -e 's/file:/copy:/' > $aptcache/etc/apt/sources.list
193 echo "Adding packages from base.tgz."
194 if [ -f $NFSROOT/var/tmp/base-pkgs.lis ]; then
195 plist=$(< $NFSROOT/var/tmp/base-pkgs.lis)
196 apt-get $quiet $aptoptions update >/dev/null
197 apt-get $qflag -d $aptoptions -y --force-yes --fix-missing install $plist
198 else
199 echo "WARNING: $NFSROOT/var/tmp/base-pkgs.lis does not exists."
200 echo "Can't add those packages. Maybe the nfsroot is not yet created."
201 fi
202 }
203 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
204 set-classes() {
205
206 # if -c is given, ignore -x
207 if [ -n "$cclasses" ]; then
208 export classes=${cclasses//,/ }
209 return
210 fi
211
212 set +e
213 # all available file names are classes
214 classes=$(cd $FAI_CONFIGDIR/package_config; ls -1 | egrep -i "^[a-zA-Z0-9_-]+$")
215 addclasses=$(grep -h PACKAGES $FAI_CONFIGDIR/package_config/* | sed -e 's/#.*//' | awk '{printf $3"\n"$4"\n"$5"\n"$6"\n"}')
216 export classes=$(echo -e "$classes\n$addclasses\n" | sort | uniq)
217 [ -n "$exclasses" ] && excludeclass $exclasses
218 set -e
219 }
220 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
221
222 [ -x "$(which apt-move)" ] || die 5 "apt-move not found. Please install package."
223
224 preserve=0
225 verbose=0
226 add=1
227 qflag=-qq
228 while getopts "Bvhx:pc:C:" opt ; do
229 case "$opt" in
230 B) add=0 ;;
231 C) cfdir=$OPTARG ;;
232 h) usage ;;
233 x) exclasses="$OPTARG";;
234 c) cclasses="$OPTARG";;
235 p) preserve=1;;
236 v) verbose=1; vflag=-v; qflag='';;
237 ?) die 1 "Unknown option";;
238 esac
239 done
240 shift $(($OPTIND - 1))
241
242 # use FAI_ETC_DIR from environment variable
243 if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
244 echo "Using environment variable \$FAI_ETC_DIR."
245 fi
246 cfdir=${FAI_ETC_DIR:=/etc/fai}
247 cfdir=$(readlink -f $cfdir) # canonicalize path
248 if [ ! -d "$cfdir" ]; then
249 echo "$cfdir is not a directory"
250 exit 6
251 fi
252 [ "$verbose" ] && echo "Using configuration files from $cfdir"
253 . $cfdir/fai.conf
254 . $cfdir/make-fai-nfsroot.conf
255 export NFSROOT="$NFSROOT/live/filesystem.dir"
256
257 [ -n "$packages" ] && die "WARNING: The use of \$packages in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
258 [ -n "$NFSROOT_PACKAGES" ] && die "WARNING: The use of \$packages in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
259
260 [ -n "$exclasses" -a -n "$cclasses" ] && die 3 "Options -x and -c not allowed at the same time."
261 debug=0
262 [ $debug -eq 0 ] && quiet=-q
263
264 mirrordir=$1
265 if [ -z "$mirrordir" ]; then
266 die 2 "Please give the absolute path to the mirror."
267 fi
268 { echo $mirrordir | egrep -q '^/'; } || die 4 "Mirrordir must start with a slash /."
269 if [ -d $mirrordir/pool -o -d $mirrordir/dists ]; then
270 die 3 "Please first remove $mirrordir/pool and $mirrordir/dists"
271 fi
272
273 [ -d $FAI_CONFIGDIR/package_config ] || die 6 "Can't find package config files in $FAI_CONFIGDIR."
274
275 # set default if undefined
276 [ -z "$MAXPACKAGES" ] && export MAXPACKAGES=1
277
278 initialize
279
280 # if we are using nfs mounts for Debian mirror, this may fail here, since inside a chroot environment different dir are used
281
282 # if sources.list includes file AND FAI_DEBMIRROR is defined we have to mount
283 # otherwise mounting is not needed. call task_mirror
284
285 if [ "$FAI_DEBMIRROR" ]; then
286 mkdir -p $MNTPOINT
287 mount -r $FAI_DEBMIRROR $MNTPOINT || exit 9
288 fi
289
290 # TODO: use -p to preserve sources.list
291 perl -p -e 's/file:/copy:/' $cfdir/apt/sources.list > $aptcache/etc/apt/sources.list
292
293 echo "Getting package information"
294 apt-get $quiet $aptoptions update >/dev/null
295
296 set-classes
297 echo "Downloading packages for classes:" $classes
298 FAI=$FAI_CONFIGDIR install_packages -d $vflag
299 [ $add -eq 1 ] && add_base_packages
300 get_addpackages
301 umount_dirs
302 trap "" EXIT ERR
303 [ $add -eq 0 ] && delete_base_packages
304
305 # create mirror directory structure
306 echo "Calling apt-move"
307 cat > $aptmovefile <<EOF # generate apt-move.conf
308 APTSITES=*
309 LOCALDIR=$mirrordir
310 DIST=$debdist
311 FILECACHE=$archivedir
312 LISTSTATE=$aptcache/var/lib/apt/lists
313 DELETE=no
314 CONTENTS=no
315 PKGCOMP='none gzip'
316 EOF
317 apt-move $quiet -c $aptmovefile update
318 # since Packages.gz from apt-move does not include packages from my
319 # repository, let's use apt-ftparchive for generiating correct index
320 # files
321 pfilegz=$(find $mirrordir/dists -name Packages.gz)
322 pfile=$(find $mirrordir/dists -name Packages)
323 pdist=$(cd $mirrordir/dists ; ls)
324 cd $mirrordir
325 # md5sums of apt-move are not valid, when we recreate Packages.gz using
326 # apt-ftparchive, but we can use the header of the Release file
327 grep -B99 MD5Sum: $mirrordir/dists/$pdist/Release | grep -v MD5Sum: > $mirrordir/tmpfile
328 rm $mirrordir/dists/$pdist/Release
329 apt-ftparchive packages pool > $pfile
330 gzip -c $pfile > $pfilegz
331 apt-ftparchive release dists/$pdist >> tmpfile
332 mv tmpfile dists/$pdist/Release
333
334 echo "$0 finished."
335 echo -n "Mirror size and location: ";du -sh $mirrordir
336 cleandirs

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5