maketars revision 1.54 1 #!/bin/sh
2 #
3 # $NetBSD: maketars,v 1.54 2004/07/23 15:11:26 erh Exp $
4 #
5 # Make release tar files for some or all lists. Usage:
6 # maketars [-b] [-x] [-i installdir] [-a arch] [-m machine] [-s setsdir]
7 # [-M metalog] [-N etcdir] [-d destdir] [-t tardir] [setname ...]
8 #
9 # The default sets are "base comp etc games man misc text"
10 # The X sets are "xbase xcomp xetc xfont xserver"
11 #
12 # If '-i installdir' is given, copy the given sets to installdir
13 # (using pax -rw ...) instead of creating tar files.
14 # In this case, remove "etc" and "xetc" from the list of default sets.
15 #
16
17 prog=${0##*/}
18
19 # set defaults
20 : ${HOST_SH=sh}
21 : ${MKTEMP=mktemp}
22 : ${MTREE=mtree}
23 : ${PAX=pax}
24
25 rundir=${0%/*}
26 . ${rundir}/sets.subr
27 lists=$nlists
28
29 tars=$RELEASEDIR
30 dest=$DESTDIR
31 metalog=
32 installdir=
33 etcdir=
34 setfilesonly=false
35
36 usage()
37 {
38 cat 1>&2 <<USAGE
39 Usage: ${prog} [-b] [-x] [-i idir] [-a arch] [-m machine] [-s setsdir] [-S]
40 [-M metalog] [-N etcdir] [-d dest] [-t targetdir] [setname ...]
41 -b Make both netbsd and x11 lists
42 -x Only make x11 lists
43 [Default: make netbsd lists]
44 -i idir Install sets to idir instead of creating tar files
45 -a arch Set arch (e.g, m68k, mipseb, mipsel, powerpc) [$MACHINE_ARCH]
46 -m machine Set machine (e.g, amiga, i386, macppc) [$MACHINE]
47 -s setsdir Directory to find sets [$setsdir]
48 -S Exit after creating set files $dest/etc/mtree/set.*
49 -M metalog metalog file
50 -N etcdir etc dir for metalog use [$dest/etc]
51 -d dest \$DESTDIR [$dest]
52 -t targetdir \$RELEASEDIR [$tars]
53 [setname ...] Sets to build [$lists]
54 USAGE
55 exit 1
56 }
57
58 # handle args
59 while getopts bxi:a:m:s:SM:N:d:t: ch; do
60 case ${ch} in
61 b)
62 lists="$nlists $xlists"
63 ;;
64 x)
65 lists="$xlists"
66 ;;
67 i)
68 installdir=${OPTARG}
69 ;;
70 a)
71 MACHINE_ARCH=${OPTARG}
72 MACHINE_CPU=$(arch_to_cpu ${OPTARG})
73 ;;
74 m)
75 MACHINE=${OPTARG}
76 ;;
77 s)
78 setsdir=${OPTARG}
79 ;;
80 S)
81 setfilesonly=true
82 ;;
83 M)
84 metalog=${OPTARG}
85 ;;
86 N)
87 etcdir=${OPTARG}
88 ;;
89 d)
90 dest=${OPTARG}
91 ;;
92 t)
93 tars=${OPTARG}
94 ;;
95 *)
96 usage
97 ;;
98 esac
99 done
100 shift $((${OPTIND} - 1))
101 if [ -n "$installdir" ]; then # if -i, remove etc & xetc from the default list
102 lists=$(echo $lists | sed -e 's/ etc / /;s/ xetc / /')
103 fi
104 if [ -n "$*" ]; then
105 lists="$*"
106 fi
107
108 if [ -z "$tars" -a -z "$installdir" ]; then
109 echo 1>&2 \$RELEASEDIR must be set, or -i must be used
110 exit 1
111 fi
112
113 if [ -z "$dest" ]; then
114 echo 1>&2 \$DESTDIR must be set
115 exit 1
116 fi
117 : ${etcdir:=${dest}/etc}
118
119 SDIR=$(${MKTEMP} -d /tmp/${prog}.XXXXXX)
120
121 setlistdir=${dest}/etc/mtree
122
123 cleanup()
124 {
125 es=$?
126 /bin/rm -rf $SDIR
127 exit $es
128 }
129 trap cleanup 0 2 3 13 # EXIT INT QUIT PIPE
130
131 #
132 # build the setfiles
133 #
134
135 if [ -n "$metalog" ]; then
136 (
137 cat ${etcdir}/mtree/NetBSD.dist
138 echo "/unset all"
139 cat $metalog 2>/dev/null
140 ) | ${MTREE} -C -k all -N ${etcdir} > $SDIR/metalog
141 rv=$?
142 if [ $rv -ne 0 ]; then
143 echo 1>&2 "${prog}: mtree parse of ${metalog} failed"
144 exit $rv
145 fi
146 fi
147 for setname in $lists; do
148 ${HOST_SH} $setsdir/makeflist -a $MACHINE_ARCH -m $MACHINE \
149 -s $setsdir $setname > $SDIR/flist.$setname
150 if [ -n "$metalog" ]; then
151 $setfilesonly && echo "Creating ${setlistdir}/set.${setname}"
152 awk -f $rundir/getdirs.awk $SDIR/flist.$setname \
153 | sort -u > $SDIR/flist.$setname.full
154 (
155 echo "/set uname=root gname=wheel"
156 awk -f $rundir/join.awk $SDIR/flist.$setname.full $SDIR/metalog
157 echo "./etc/mtree/set.${setname} type=file mode=0444"
158 ) > ${setlistdir}/set.${setname}
159 elif ! cmp -s ${SDIR}/flist.${setname} \
160 ${setlistdir}/set.${setname} >/dev/null 2>&1; then
161 rm -f ${setlistdir}/set.${setname}
162 cp ${SDIR}/flist.${setname} ${setlistdir}/set.${setname}
163 fi
164 done
165 if $setfilesonly; then # exit after creating the set lists
166 exit 0
167 fi
168
169 #
170 # now build the tarfiles
171 #
172
173 GZIP=-9 # for pax -z
174 export GZIP
175 es=0
176 for setname in $lists; do
177 out=$setname.tgz
178 if [ -n "$installdir" ]; then
179 echo "Copying set $setname"
180 ( cd $dest ; \
181 ${PAX} -O -rwpe -d -N${etcdir} ${metalog:+-M} \
182 ${installdir} < ${setlistdir}/set.${setname} )
183 else
184 if [ -n "$metalog" -a $tars/$out -nt "$metalog" ]; then
185 echo "$out is up to date"
186 continue
187 fi
188 echo "Creating $out"
189 rm -f ${tars}/$out
190 ( cd $dest ; \
191 ${PAX} -O -w -d -z -N${etcdir} ${metalog:+-M} \
192 < ${setlistdir}/set.${setname} ) > ${tars}/$out.tmp &&
193 mv ${tars}/$out.tmp ${tars}/$out
194 fi
195 es=$(($es + $?))
196 done
197 if [ $es -gt 255 ] ; then
198 es=255
199 fi
200 exit $es
201