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

Contents of /trunk/bin/fai-mirror

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5433 - (show annotations) (download)
Sun Jul 19 10:08:17 2009 UTC (3 years, 10 months ago) by lange
File size: 10518 byte(s)
line (closes: #497548), remove outdated information about
/files/packages
* fai-mirror: remove use of $addpackages (closes: #537544)
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-2009, 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.10, 19-july-2009"
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 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73 umount_dirs() {
74
75 [ "$FAI_DEBMIRROR" ] && umount $MNTPOINT 2>/dev/null 1>&2 || true
76 }
77 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78 cleandirs() {
79
80 return # currently nothing to do
81 # rm $statefile
82 # rm -rf $mirrordir/.apt-move $statefile
83 # [ $debug -eq 1 ] || rm -rf $aptcache $archivedir
84 # rm -rf $aptcache $archivedir
85 }
86 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87 initialize() {
88
89 # TODO: root is only needed when FAI_DEBMIRROR is defined. Then we
90 # must mount a directory
91
92 debdist=$(echo "$FAI_DEBOOTSTRAP" | awk '{print $1}')
93 # store all packages temporary in the mirror partition so we need only a move,
94 # not a copy later during apt-move
95 aptcache=$mirrordir/aptcache # holds the package cache data
96 archivedir=$aptcache/var/cache/apt/archives
97 aptmovefile=$aptcache/etc/apt-move.conf # stores apt-move.conf
98 statefile=$aptcache/statefile
99
100 # also used in install_packages.conf
101 export aptoptions=" \
102 -o Aptitude::Log=/dev/null \
103 -o Aptitude::CmdLine::Ignore-Trust-Violations=yes\
104 -o APT::Get::AllowUnauthenticated=true \
105 -o DPkg::force-conflicts::=yes \
106 -o Dir::State::status=$statefile \
107 -o APT::Get::Force-Yes=true \
108 -o Dir::Cache=$aptcache/var/cache/apt \
109 -o Dir::State=$aptcache/var/cache/apt \
110 -o Dir::Cache::Archives=$archivedir \
111 -o Dir::Etc=$aptcache/etc/apt/ \
112 -o Dir::State::Lists=$aptcache/var/lib/apt/lists/"
113
114 # not needed
115 # -o APT::Get::ReInstall
116 # ."-o APT::Get::Download-Only=true -o Aptitude::Cmd-Line::Download-Only=true "
117
118 # we only need some empty dirs
119 set -e
120 mkdir -p $archivedir/partial $aptcache/etc/apt $aptcache/var/lib/apt/lists/partial
121 > $statefile
122 set +e
123 }
124 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
125 delete_base_packages() {
126
127 # now delete all packages that are already included in base.tgz
128 local p
129
130 if [ ! -f $NFSROOT/var/tmp/base-pkgs.lis ]; then
131 echo "$NFSROOT/var/tmp/base-pkgs.lis not available."
132 echo "Can't remove wasteful packages that are already in base.tgz."
133 return
134 fi
135 echo "Removing packages that are already included in base.tgz"
136 for p in $(cat $NFSROOT/var/tmp/base-pkgs.lis); do
137 if [ -f $archivedir/${p}_*.deb ]; then
138 [ $verbose -eq 1 ] && echo "deleting package $p"
139 rm $archivedir/${p}_*.deb
140 # else commands only for debugging
141 # else
142 # echo "package $p not found"
143 # ls $archivedir/${p}_*.deb
144 fi
145 done
146 }
147 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
148 add_base_packages() {
149
150 local plist
151 # add packages from base.tgz and additional packages in nfsroot
152
153 # arch dependent packages defined in make-fai-nfsroot
154 echo "Adding packages of $cfdir/NFSROOT."
155 if [ -f $NFSROOT/var/tmp/packages.nfsroot ]; then
156 plist=$(< $NFSROOT/var/tmp/packages.nfsroot)
157 apt-get $qflag -d $aptoptions -y --force-yes --fix-missing install $plist
158 else
159 echo "WARNING: $NFSROOT/var/tmp/packages.nfsroot does not exists."
160 echo "Can't add those packages. Maybe the nfsroot is not yet created."
161 fi
162
163 # now use sources.list for debootstrap packages
164 echo "$FAI_DEBOOTSTRAP" | awk '{printf "deb %s %s main\n",$2,$1}' | perl -p -e 's/file:/copy:/' > $aptcache/etc/apt/sources.list
165 echo "Adding packages from $NFSROOT/var/tmp/base-pkgs.lis"
166 if [ -f $NFSROOT/var/tmp/base-pkgs.lis ]; then
167 plist=$(< $NFSROOT/var/tmp/base-pkgs.lis)
168 apt-get $qflag $aptoptions update >/dev/null
169 apt-get $qflag -d $aptoptions -y --force-yes --fix-missing install $plist
170 else
171 echo "WARNING: $NFSROOT/var/tmp/base-pkgs.lis does not exists."
172 echo "Can't add those packages. Maybe the nfsroot is not yet created."
173 fi
174 }
175 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
176 set-classes() {
177
178 # if -c is given, ignore -x
179 if [ -n "$cclasses" ]; then
180 export classes=${cclasses//,/ }
181 return
182 fi
183
184 set +e
185 # all available file names are classes
186 classes=$(cd $FAI_CONFIGDIR/package_config; ls -1 | egrep -i "^[a-zA-Z0-9_-]+$")
187 addclasses=$(grep -h PACKAGES $FAI_CONFIGDIR/package_config/* | sed -e 's/#.*//' | awk '{printf $3"\n"$4"\n"$5"\n"$6"\n"}')
188 export classes=$(echo -e "$classes\n$addclasses\n" | sort | uniq)
189 [ -n "$exclasses" ] && excludeclass $exclasses
190 set -e
191 }
192 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
193
194 [ -x "$(which apt-move)" ] || die 5 "apt-move not found. Please install package."
195
196 preserve=0
197 verbose=0
198 add=1
199 qflag=-qq
200 while getopts "Bvhx:pc:C:" opt ; do
201 case "$opt" in
202 B) add=0 ;;
203 C) cfdir=$OPTARG ;;
204 h) usage ;;
205 x) exclasses="$OPTARG";;
206 c) cclasses="$OPTARG";;
207 p) preserve=1;;
208 v) verbose=1; vflag=-v; qflag='';;
209 ?) die 1 "Unknown option";;
210 esac
211 done
212 shift $(($OPTIND - 1))
213
214 # use FAI_ETC_DIR from environment variable
215 if [ -n "$FAI_ETC_DIR" -a -z "$cfdir" ]; then
216 echo "Using environment variable \$FAI_ETC_DIR."
217 fi
218 # use -C option if present otherwise use $FAI_ETC_DIR or default to /etc/fai
219 if [ -z "$cfdir" ]; then
220 cfdir=${FAI_ETC_DIR:=/etc/fai}
221 fi
222 cfdir=$(readlink -f $cfdir) # canonicalize path
223 if [ ! -d "$cfdir" ]; then
224 echo "$cfdir is not a directory"
225 exit 6
226 fi
227 [ "$verbose" -eq 1 ] && echo "Using configuration files from $cfdir"
228 . $cfdir/fai.conf
229 . $cfdir/make-fai-nfsroot.conf
230 export NFSROOT="$NFSROOT/live/filesystem.dir"
231
232 [ -n "$packages" ] && die "WARNING: The use of \$packages in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
233 [ -n "$NFSROOT_PACKAGES" ] && die "WARNING: The use of \$packages in make-fai-nfsroot.conf is now deprecated. Please include this information into $cfdir/NFSROOT."
234
235 [ -n "$exclasses" -a -n "$cclasses" ] && die 3 "Options -x and -c not allowed at the same time."
236
237 mirrordir=$1
238 if [ -z "$mirrordir" ]; then
239 die 2 "Please give the absolute path to the mirror."
240 fi
241 { echo $mirrordir | egrep -q '^/'; } || die 4 "Mirrordir must start with a slash /."
242 if [ -d $mirrordir/pool -o -d $mirrordir/dists ]; then
243 die 3 "Please first remove $mirrordir/pool and $mirrordir/dists"
244 fi
245
246 [ -d $FAI_CONFIGDIR/package_config ] || die 6 "Can't find package config files in $FAI_CONFIGDIR."
247
248 # set default if undefined
249 [ -z "$MAXPACKAGES" ] && export MAXPACKAGES=1
250
251 initialize
252
253 # if we are using nfs mounts for Debian mirror, this may fail here, since inside a chroot environment different dir are used
254
255 # if sources.list includes file AND FAI_DEBMIRROR is defined we have to mount
256 # otherwise mounting is not needed. call task_mirror
257
258 if [ "$FAI_DEBMIRROR" ]; then
259 mkdir -p $MNTPOINT
260 mount -r $FAI_DEBMIRROR $MNTPOINT || exit 9
261 fi
262
263 # TODO: use -p to preserve sources.list
264 perl -p -e 's/file:/copy:/' $cfdir/apt/sources.list > $aptcache/etc/apt/sources.list
265
266 echo "Getting package information"
267 apt-get $qflag $aptoptions update >/dev/null
268
269 set-classes
270 echo "Downloading packages for classes:" $classes
271 FAI=$FAI_CONFIGDIR install_packages -d $vflag
272 [ $add -eq 1 ] && add_base_packages
273 umount_dirs
274 trap "" EXIT ERR
275 [ $add -eq 0 ] && delete_base_packages
276
277 # create mirror directory structure
278 echo "Calling apt-move"
279 cat > $aptmovefile <<EOF # generate apt-move.conf
280 APTSITES=*
281 LOCALDIR=$mirrordir
282 DIST=$debdist
283 FILECACHE=$archivedir
284 LISTSTATE=$aptcache/var/lib/apt/lists
285 DELETE=no
286 CONTENTS=no
287 PKGCOMP='none gzip'
288 EOF
289 apt-move $qflag -c $aptmovefile update
290 # since Packages.gz from apt-move does not include packages from my
291 # repository, let's use apt-ftparchive for generiating correct index
292 # files
293 pfilegz=$(find $mirrordir/dists -name Packages.gz)
294 pfile=$(find $mirrordir/dists -name Packages)
295 pdist=$(cd $mirrordir/dists ; ls)
296 cd $mirrordir
297 # md5sums of apt-move are not valid, when we recreate Packages.gz using
298 # apt-ftparchive, but we can use the header of the Release file
299 grep -B99 MD5Sum: $mirrordir/dists/$pdist/Release | grep -v MD5Sum: > $mirrordir/tmpfile
300 rm $mirrordir/dists/$pdist/Release
301 apt-ftparchive packages pool > $pfile
302 gzip -c $pfile > $pfilegz
303 apt-ftparchive release dists/$pdist >> tmpfile
304 mv tmpfile dists/$pdist/Release
305
306 echo "$0 finished."
307 echo -n "Mirror size and location: ";du -sh $mirrordir
308 cleandirs

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5