slitaz-modular view mkiso.sh @ rev 21
Changed HG_DIR folder path to /home/slitaz/hg. Added PROFILE name to iso name now. (Ex. slitaz-core-DATE.iso)
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Sun Dec 26 23:31:03 2010 +0000 (2010-12-26) |
parents | 50388b0d5b22 |
children | 8f8af6b88207 |
line source
1 #!/bin/sh
3 if [ -f "./tazwok.conf" ]; then
4 . ./tazwok.conf
5 elif [ -f "/etc/tazwok.conf" ]; then
6 . /etc/tazwok.conf
7 else
8 echo -e "\nUnable to find tazwok configuration file : /etc/tazwok.conf"
9 exit 1
10 fi
12 QUIET="y"
13 FORCE="y"
14 export LABEL="slitaz_$(date +%Y%m)"
15 PUBLISHER="Slitaz"
16 APPLICATION="Slitaz"
17 CREATE_DEFAULT="n"
18 BASEDIR="$(pwd)"
19 PROFILE="$BASEDIR/$1"
20 ver=""
21 CDNAME="slitaz"
22 RMSTUFF=n
23 MVSTUFF=n
24 UNGZIP=n
25 EXT="xz"
26 COMPRESSION="xz -Xbcj x86"
27 MKOPTION="-b 256k"
28 MODULES=""
29 WORKING="$PROFILE/working"
30 INITRAMFS="$WORKING/initramfs"
31 UNION="$WORKING/union"
32 LOG="$WORKING/log"
33 ISODIR="$WORKING/iso"
34 IMGNAME="$PROFILE/$CDNAME-$1-$(date +%F).iso"
35 IMGMD5NAME="$IMGNAME.md5"
36 LASTBR="$INITRAMFS"
37 SGNFILE="$ISODIR/$CDNAME/livecd.sgn"
38 MODULES_DIR="$WORKING/modules"
39 HG_DIR="/home/slitaz/hg"
40 COPY_HG="no"
41 UPDATE_HG="no"
42 BACKUP_SOURCES="no"
43 BACKUP_PACKAGES="no"
44 CLEAN_MODULES_DIR="no"
45 CLEAN_INITRAMFS="no"
46 HG_LIST="flavors flavors-stable slitaz-base-files slitaz-boot-scripts slitaz-configs slitaz-doc slitaz-pizza slitaz-tools tank tazlito tazpkg tazusb tazwok website wok"
48 error () { echo -e "\033[1;31;40m!!! \033[1;37;40m$@\033[1;0m"; }
49 warn () { echo -e "\033[1;33;40m*** \033[1;37;40m$@\033[1;0m"; }
50 info () { echo -e "\033[1;32;40m>>> \033[1;37;40m$@\033[1;0m"; }
52 # do UID checking here so someone can at least get usage instructions
53 #if [ "$EUID" != "0" ]; then
54 # error "error: This script must be run as root."
55 # exit 1
56 #fi
57 if [ ! -d $PROFILE -o "$1" = "" ]; then
58 echo "$0 profile-name"
59 echo "ex $0 core"
60 exit 1
61 fi
63 ROOT_MOD="$(ls -1 ${PROFILE}/list | head -1)"
64 INST_ROOT="${MODULES_DIR}/$(basename ${ROOT_MOD} .list)"
66 if [ -f ${PROFILE}/config ]; then
67 source ${PROFILE}/config
68 fi
70 _overlay()
71 {
72 if [ -d ${MODULES_DIR}/overlay ]; then
73 rm -rf ${MODULES_DIR}/overlay
74 cp -rf ${PROFILE}/overlay ${MODULES_DIR}
75 else
76 cp -rf ${PROFILE}/overlay ${MODULES_DIR}
77 fi
79 if [ "${QUIET}" = "y" ]; then
80 mksquashfs "${MODULES_DIR}/overlay" "${ISODIR}/${CDNAME}/modules/zzz.overlay.${EXT}" -comp ${COMPRESSION} -noappend ${MKOPTION} >/dev/null
81 else
82 mksquashfs "${MODULES_DIR}/overlay" "${ISODIR}/${CDNAME}/modules/zzz.overlay.${EXT}" -comp ${COMPRESSION} -noappend ${MKOPTION}
83 fi
84 }
86 lzma_switches()
87 {
88 echo "-d$(echo 24) -mt$(grep ^processor < /proc/cpuinfo | wc -l)"
89 }
91 # Pack rootfs
92 pack_rootfs()
93 {
94 ( cd $1 ; find . -print | cpio -o -H newc ) | \
95 if [ -x /usr/bin/lzma ]; then
96 info "Generating lzma'ed initramfs... "
97 lzma e -si -so $(lzma_switches $1) > $2
98 else
99 info "Generating gziped initramfs... "
100 gzip -9 > $2
101 fi
102 echo 1 > /tmp/rootfs
103 }
105 initramfs () {
107 if [ ! -e "$BASEDIR/initramfs/initramfs.list" ]; then
108 error "error: $BASEDIR/initramfs/initramfs.list doesn't exist, aborting."
109 exit 1
110 fi
112 if [ "$CLEAN_INITRAMFS" = "yes" ]; then
113 if [ -d ${INITRAMFS} ]; then
114 rm -Rf ${INITRAMFS}
115 fi
116 fi
118 if [ ! -d ${INITRAMFS} ]; then
119 mkdir -p $INITRAMFS
120 fi
122 info "Making bootable image"
123 cat "$BASEDIR/initramfs/initramfs.list" | grep -v "^#" | while read pkgname; do
124 if [ ! -f ${INITRAMFS}/var/lib/tazpkg/installed/${pkgname}/files.list ]; then
125 tazpkg get-install $pkgname --root=$INITRAMFS | tee -a $LOG/initramfs.log
126 sleep 1
127 else
128 info "${pkgname} installed"
129 fi
130 done
132 if [ ! -d $ISODIR/boot ]; then
133 mkdir -p $ISODIR/boot
134 fi
136 #if [ ! -f $ISODIR/boot/bzImage ]; then
137 cp -f $INITRAMFS/boot/vmlinuz* $ISODIR/boot/bzImage
138 rm -f $INITRAMFS/boot/vmlinuz*
139 #fi
141 if [ -d $BASEDIR/initramfs ]; then
142 cp -af $BASEDIR/initramfs/* $INITRAMFS
143 fi
144 }
146 copy_hg() {
147 if [ ! -d ${HG_DIR}/${1}/home/slitaz/hg/$1 ]; then
148 info "Cloning $1 repo ..."
149 hg clone http://hg.slitaz.org/$1 ${HG_DIR}/${1}/home/slitaz/hg/$1
150 elif [ -d ${HG_DIR}/${1}/home/slitaz/hg/$1 -a ${UPDATE_HG} = "yes" ]; then
151 info "Updating $1 repo ..."
152 cd ${HG_DIR}/${1}/home/slitaz/hg/$1 &&
153 hg pull -u
154 cd $PROFILE
155 fi
156 }
158 squashfs_hg() {
159 if [ ! -d "$ISODIR/$CDNAME/modules/hg" ]; then
160 mkdir -p "$ISODIR/$CDNAME/modules/hg"
161 fi
162 if [ -d ${HG_DIR}/${1}/home/slitaz/hg/$1 ]; then
163 _mksquash ${HG_DIR}/${1} "$ISODIR/$CDNAME/modules/hg" /home/slitaz/hg/$1
164 fi
165 }
167 slitaz_union () {
169 if [ -d ${MODULES_DIR}/${mod}/var/lib/tazpkg/installed ]; then
170 echo "${mod} module exist. Moving on."
171 elif [ ! -d ${MODULES_DIR}/${mod}/var/lib/tazpkg/installed ]; then
172 if [ -f "$PROFILE/list/${mod}.list" ]; then
173 cat "$PROFILE/list/${mod}.list" | grep -v "^#" | while read pkgname; do
174 if [ ! -f ${UNION}/var/lib/tazpkg/installed/${pkgname}/files.list ]; then
175 tazpkg get-install $pkgname --root=${UNION} | tee -a ${LOG}/${mod}-current.log
176 sleep 1
177 else
178 info "${pkgname} installed"
179 fi
180 done
181 fi
183 if [ -f $PROFILE/list/${mod}.removelist ]; then
184 cat "$PROFILE/list/${mod}.removelist" | grep -v "^#" | while read pkgname; do
185 if [ -f ${UNION}/var/lib/tazpkg/installed/${pkgname}/files.list ]; then
186 echo "y" | tazpkg remove ${pkgname} --root=${UNION} | tee -a ${LOG}/${mod}-current.log
187 sleep 1
188 else
189 info "${pkgname} removed"
190 fi
191 done
192 fi
193 fi
194 }
196 union () {
197 mkdir -p $WORKING
198 mkdir -p $UNION
199 mkdir -p $LOG
200 mkdir -p $ISODIR/${CDNAME}/base
201 mkdir -p $ISODIR/${CDNAME}/modules
202 mkdir -p $ISODIR/${CDNAME}/optional
203 mkdir -p $ISODIR/${CDNAME}/rootcopy
204 mkdir -p $ISODIR/${CDNAME}/tmp
205 mkdir -p $LASTBR
206 touch $SGNFILE
208 modprobe aufs
209 if [ $? -ne 0 ]; then
210 error "Error loading Union filesystem module. (aufs)"
211 exit 1
212 fi
214 # $INITRAMFS is now $LASTBR
215 # This will be copyed to /mnt/memory/changes on boot
216 initramfs
218 mount -t aufs -o br:${LASTBR}=rw aufs ${UNION}
219 if [ $? -ne 0 ]; then
220 error "Error mounting $union."
221 exit 1
222 fi
224 info "====> Installing packages to '$UNION'"
225 for mod in $MODULES; do
227 if [ "$CLEAN_MODULES_DIR" = "yes" ]; then
228 if [ -d $MODULES_DIR/$mod ]; then
229 rm -Rf $MODULES_DIR/$mod
230 fi
231 fi
233 if [ ! -d $MODULES_DIR/$mod ]; then
234 mkdir -p $MODULES_DIR/$mod
235 fi
236 info "Adding $MODULES_DIR/$mod as top branch of union."
237 mount -t aufs -o remount,add:0:${MODULES_DIR}/${mod}=rw aufs $UNION
238 info "Adding $LASTBR as lower branch of union."
239 mount -t aufs -o remount,mod:${LASTBR}=rr+wh aufs $UNION
240 LASTBR="$MODULES_DIR/${mod}"
242 slitaz_union
243 done
245 info "Unmounting union"
246 umount -l "${UNION}"
248 info "Removing unionfs .wh. files."
249 find ${MODULES_DIR} -type f -name ".wh.*" -exec rm {} \;
250 find ${MODULES_DIR} -type d -name ".wh.*" -exec rm -rf {} \;
251 }
254 # _mksquash dirname
255 _mksquash () {
256 if [ ! -d "$1" ]; then
257 error "Error: '$1' is not a directory"
258 return 1
259 fi
261 if [ ! -d "$2" ]; then
262 error "Error: '$2' is not a directory"
263 return 1
264 fi
266 if [ ! -d "${1}${3}" ]; then
267 error "Error: '${1}${3}' is not a directory"
268 return 1
269 fi
271 time_dir="${3}"
272 sqimg="${2}/$(basename ${1}).${EXT}"
273 info "====> Generating SquashFS image for '${1}'"
274 if [ -e "${sqimg}" ]; then
275 dirhaschanged=$(find ${1}${time_dir} -newer ${sqimg})
276 if [ "${dirhaschanged}" != "" ]; then
277 info "SquashFS image '${sqimg}' is not up to date, rebuilding..."
278 rm "${sqimg}"
279 else
280 info "SquashFS image '${sqimg}' is up to date, skipping."
281 return
282 fi
283 fi
285 info "Creating SquashFS image. This may take some time..."
286 start=$(date +%s)
287 if [ "${QUIET}" = "y" ]; then
288 mksquashfs "${1}" "${sqimg}" -noappend ${MKOPTION} -comp ${COMPRESSION} >/dev/null
289 else
290 mksquashfs "${1}" "${sqimg}" -noappend ${MKOPTION} -comp ${COMPRESSION}
291 fi
292 minutes=$(echo $start $(date +%s) | awk '{ printf "%0.2f",($2-$1)/60 }')
293 info "Image creation done in $minutes minutes."
294 }
296 imgcommon () {
297 if [ "${MODULES}" != "" ]; then
298 for MOD in ${MODULES}; do
299 if [ -d "${MODULES_DIR}/${MOD}" ]; then
300 _mksquash "${MODULES_DIR}/${MOD}" "$ISODIR/$CDNAME/base" /var/lib/tazpkg/installed
301 fi
302 done
303 fi
305 if [ "$HG_LIST" != "" ]; then
306 if [ "$COPY_HG" = "yes" ]; then
307 for hg in $HG_LIST; do
308 copy_hg $hg
309 squashfs_hg $hg
310 done
311 fi
312 fi
314 if [ "${HG_LIST}" != "" ]; then
315 for hg in ${HG_LIST}; do
316 if [ -d "${MODULES_DIR}/${hg}" ]; then
317 squashfs_hg $hg
318 fi
319 done
320 fi
322 info "====> Making bootable image"
324 # Sanity checks
325 if [ ! -d "${ISODIR}" ]; then
326 error "Error: '${ISODIR}' doesn't exist. What did you do?!"
327 exit 1
328 fi
330 if [ ! -f "${SGNFILE}" ]; then
331 error "Error: the ${SGNFILE} file doesn't exist. This image won't do anything"
332 error " Protecting you from yourself and erroring out here..."
333 exit 1
334 fi
337 if [ -e "${IMGNAME}" ]; then
338 if [ "${FORCE}" = "y" ]; then
339 info "Removing existing bootable image..."
340 rm -rf "${IMGNAME}"
341 else
342 error "Error: Image '${IMGNAME}' already exists, aborting."
343 exit 1
344 fi
345 fi
347 }
349 make_iso () {
350 imgcommon
352 info "Creating rootfs.gz"
353 pack_rootfs $INITRAMFS $ISODIR/boot/rootfs.gz
355 if [ -d $PROFILE/rootcd ]; then
356 cp -af $PROFILE/rootcd/* $ISODIR/
357 fi
359 info "Copying isolinux files..."
360 if [ -d $INITRAMFS/boot/isolinux ]; then
361 cp -a $INITRAMFS/boot/isolinux $ISODIR/boot
362 fi
364 if [ -d ${PROFILE}/overlay ]; then
365 _overlay
366 fi
368 info "Creating ISO image..."
369 genisoimage -R -o $IMGNAME -b boot/isolinux/isolinux.bin \
370 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
371 -V "SliTaz" -input-charset iso8859-1 -boot-info-table $ISODIR
372 if [ -x /usr/bin/isohybrid ]; then
373 info "Creating hybrid ISO..."
374 isohybrid "${IMGNAME}"
375 fi
376 md5sum "${IMGNAME}" > $IMGMD5NAME
377 }
379 if [ "$MODULES" != "" ]; then
380 union
381 else
382 error "MODULES was empty. exiting."
383 exit 1
384 fi
386 make_iso