slitaz-dev-tools diff mirror-tools/usr/bin/mkpkgiso @ rev 4
Starting to add mirror-tools. Add etc. home. and usr so far.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Thu Feb 24 01:03:48 2011 +0000 (2011-02-24) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mirror-tools/usr/bin/mkpkgiso Thu Feb 24 01:03:48 2011 +0000 1.3 @@ -0,0 +1,431 @@ 1.4 +#!/bin/sh 1.5 +# mkpkgiso, build packages ISO image. 1.6 +# (C) 2007-TODAY SliTaz - GNU General Public License v3. 1.7 +# 1.8 +# Authors : Eric Joseph-Alexandre <erjo@slitaz.org> 1.9 +# Pascal Bellard <pascal.bellard@slitaz.org> 1.10 + 1.11 +VERSION=0.9 1.12 + 1.13 +PKG_VER=$1 1.14 +ROOT=/home/slitaz/iso 1.15 +REPOS=/var/www/slitaz/mirror/packages/$PKG_VER 1.16 +SOURCES=/var/www/slitaz/mirror/sources/packages 1.17 +IFMEM_C32=/var/www/slitaz/mirror/pxe/ifmem.c32 1.18 +ISO_DIR=/var/www/slitaz/mirror/iso/$PKG_VER 1.19 + 1.20 +[ -s /etc/slitaz/mkpkgiso.conf ] && . /etc/slitaz/mkpkgiso.conf 1.21 +[ -s ./mkpkgiso.conf ] && . ./mkpkgiso.conf 1.22 + 1.23 +SORT_DIR=${ROOT}/_iso.$$ 1.24 +TEMP_DIR=${ROOT}/_iso.$$ 1.25 +SORT_FILE=${ROOT}/_sort.$$ 1.26 +shift 1.27 +OPTIONS=$@ 1.28 +PKG_DIR=$TEMP_DIR/packages/$PKG_VER 1.29 +SRC_DIR=$TEMP_DIR/src 1.30 +LOG=$PWD/$(basename $0).log 1.31 + 1.32 +# 1.33 +VOLUME_ID="packages-${PKG_VER}" 1.34 +PUBLISHER="SliTaz http://www.slitaz.org/" 1.35 +IMAGE="packages-${PKG_VER}.iso" 1.36 +case " $@ " in 1.37 +*\ --sources\ *) 1.38 + IMAGE="sources-${PKG_VER}.iso" ;; 1.39 +esac 1.40 +OUTPUT="$ROOT/$IMAGE" 1.41 + 1.42 +# Check command line option. 1.43 +if [ -z $PKG_VER ]; then 1.44 + cat <<EOT 1.45 +Usage: $(basename $0) <Version> 1.46 + [--boot [--auto-install] [--loram-detect]]|--webboot] [--filter] 1.47 + [--wok] [--wok-stable] [--website] [--sources] [--dry-run] 1.48 + $(basename $0) update-hg <dir> 1.49 +Example: 1.50 +$(basename $0) cooking --boot --auto-install --loram-detect --filter --wok --website --sources 1.51 +EOT 1.52 + exit 1 1.53 +fi 1.54 + 1.55 +# Update hg repos 1.56 +if [ "$PKG_VER" == "update-hg" ]; then 1.57 + for i in $1/* ; do 1.58 + grep -qs '\[paths]' $i/.hg/hgrc || continue 1.59 + cd $i 1.60 + hg pull 1.61 + hg update 1.62 + cd - > /dev/null 1.63 + done 1.64 + exit 1 1.65 +fi 1.66 + 1.67 +# Check if we provide a valide version 1.68 +if [ ! -d $REPOS ]; then 1.69 + echo "Boooh! $PKG_VER is not a valid version." 1.70 + exit 1 1.71 +fi 1.72 + 1.73 +# Status function. 1.74 +status() 1.75 +{ 1.76 + local CHECK=$? 1.77 + echo -en "\\033[70G[ " 1.78 + if [ $CHECK = 0 ]; then 1.79 + echo -en "\\033[1;33mOK" 1.80 + else 1.81 + echo -en "\\033[1;31mFailed" 1.82 + fi 1.83 + echo -e "\\033[0;39m ]" 1.84 +} 1.85 + 1.86 +need() 1.87 +{ 1.88 + found=1 1.89 + for i in $@ ; do 1.90 + [ -s $i ] && continue 1.91 + echo "Missing: $i " 1.92 + found=0 1.93 + done 1.94 + [ $found -ne 0 ] && return 1.95 + status 1.96 + rm -rf $TEMP_DIR $SORT_FILE 1.97 + exit 1 1.98 +} 1.99 + 1.100 +# Create temp directory 1.101 +mkdir -p $TEMP_DIR/packages/$PKG_VER 1.102 +which genisoimage > /dev/null || need /usr/bin/genisoimage 1.103 + 1.104 +# Prepare evrything for ISO 1.105 + 1.106 +echo "" 1.107 +echo "Building ISO for packages $PKG_VER" 1.108 +echo "===============================================================================" 1.109 +echo -n "Creating working dir $(basename $TEMP_DIR)" 1.110 +status 1.111 +echo -n "Creating symlink" 1.112 +status 1.113 + 1.114 +# Link every packages to temp dir 1.115 +cd $PKG_DIR 1.116 +for i in $REPOS/* 1.117 +do 1.118 + ln -s $i >> $LOG 2>&1 1.119 +done 1.120 + 1.121 +echo -n "Creating install script" 1.122 +# Create install script as suggested by Pascal. 1.123 +cat >$TEMP_DIR/install.sh<<EOF 1.124 +#!/bin/sh 1.125 +# 1.126 + 1.127 +DIR=\$(cd \$(busybox dirname \$0); pwd) 1.128 + 1.129 +# Handle --auto-install case 1.130 +if [ "\$DIR" == "/etc/init.d" ]; then 1.131 + DIR=/cdrom 1.132 + if [ ! -f /cdrom/install.sh ]; then 1.133 + mkdir /cdrom 2> /dev/null 1.134 + mount --bind /mnt /cdrom 1.135 + fi 1.136 + # Handle loram on hybrid hard disk / usb key case 1.137 + if [ ! -d /usr/bin ]; then 1.138 + echo "" 1.139 + if [ -d /.usr.rw ]; then 1.140 + echo -n "Mounting /usr read-write... " 1.141 + usr=.usr.ro 1.142 + else 1.143 + echo -n "Mounting /usr read-only... " 1.144 + usr=usr 1.145 + fi 1.146 + FS=\$DIR/usr.cromfs 1.147 + if [ -f \$FS ]; then 1.148 + /bin/cromfs-driver \$FS /\$usr -o ro,dev,suid,allow_other 1.149 + elif [ -f \$DIR/usr.sqfs ]; then 1.150 + FS=\$DIR/usr.sqfs 1.151 + mount -o loop,ro -t squashfs \$FS /\$usr 1.152 + elif [ -L /\$usr ]; then 1.153 + FS=\$DIR/usr 1.154 + fi 1.155 + status 1.156 + if [ -d /.usr.rw ]; then 1.157 + if [ -x /bin/funionfs ]; then 1.158 + /bin/funionfs -o dirs=/.usr.ro=RO:/.usr.rw -o allow_other -o suid,dev NONE /usr 1.159 + else 1.160 + /bin/mount -t aufs -o br:/.usr.rw:/.usr.ro none /usr 1.161 + fi 1.162 + fi 1.163 + fi 1.164 +fi 1.165 + 1.166 +[ -d /var/cache/tazpkg ] || mkdir -p /var/cache/tazpkg 1.167 +ls -d \$DIR/packages/* > /var/lib/tazpkg/mirror 1.168 +ln -fs \$DIR/packages/*/*.tazpkg /var/cache/tazpkg/ 1.169 +ln -fs \$DIR/packages/*/packages.* /var/lib/tazpkg 1.170 +echo "" 1.171 +echo "=> all $PKG_VER packages are available for tazpkg/tazpkgbox" 1.172 +EOF 1.173 +[ -e files.list.lzma ] && cat >>$TEMP_DIR/install.sh<<EOF 1.174 +ln -fs \$DIR/packages/*/files.list.lzma /var/lib/tazpkg 1.175 +EOF 1.176 + 1.177 +status 1.178 +cat > $SORT_FILE <<EOT 1.179 +$SORT_DIR/install.sh -4000 1.180 +$SORT_DIR/README -4000 1.181 +$SORT_DIR/index.html -4000 1.182 +$SORT_DIR/md5sum -4000 1.183 +$SORT_DIR/style.css -4000 1.184 +$SORT_DIR/images/header.png -4000 1.185 +$SORT_DIR/boot/bzImage 2 1.186 +$SORT_DIR/boot/rootfs.gz 1 1.187 +$SORT_DIR/packages -9000 1.188 +EOT 1.189 +( cd $ROOT; ls $SORT_DIR/packages/*/packages* $SORT_DIR/packages/*/files.list.lzma ) | \ 1.190 + awk '{ printf "%s -7000\n",$0 }' >> $SORT_FILE 1.191 +chmod 755 $TEMP_DIR/install.sh 1.192 + 1.193 +case " $OPTIONS " in 1.194 +*\ --filter\ *) 1.195 + SIZE=0 1.196 + for i in *.tazpkg; do 1.197 + while read f; do 1.198 + case "$i" in 1.199 + $f*) continue 2;; 1.200 + esac 1.201 + done < packages.list 1.202 + echo -n "Filter out $i ($(du -hs $(readlink $i) | awk '{ print $1 }'))..." 1.203 + SIZE=$(( $SIZE + $(stat -c %s $(readlink $i)) )) 1.204 + rm $i 1.205 + status 1.206 + done 1.207 + UNIT=" bytes" 1.208 + if [ $SIZE -gt 10240 ]; then 1.209 + SIZE=$(( $SIZE / 1024 )) 1.210 + UNIT="K" 1.211 + fi 1.212 + if [ $SIZE -gt 10240 ]; then 1.213 + SIZE=$(( $SIZE / 1024 )) 1.214 + UNIT="M" 1.215 + fi 1.216 + echo "$SIZE$UNIT removed.";; 1.217 +esac 1.218 + 1.219 +# Copy hg subtree 1.220 +get_from_hg() 1.221 +{ 1.222 +echo -n "Adding $2" 1.223 +if [ -s /home/slitaz/$1/.hg/hgrc ]; then 1.224 + cp -a /home/slitaz/$1 $TEMP_DIR 1.225 +else 1.226 + wget -q -O - http://hg.slitaz.org/$1/archive/tip.tar.bz2 | tar xjf - -C $TEMP_DIR 1.227 + mv $TEMP_DIR/$1-* $TEMP_DIR/$1 1.228 +fi 1.229 +status 1.230 +echo "$(du -hs $TEMP_DIR/$1 | awk '{ print $1 }') used by $2." 1.231 +} 1.232 + 1.233 +for i in $OPTIONS ; do 1.234 +case "$i" in 1.235 +--wok) 1.236 + cat >>$TEMP_DIR/install.sh<<EOF 1.237 +mkdir -p /home/slitaz 1.238 +ln -s \$DIR/wok /home/slitaz 1.239 +echo "=> Wok (cooking) is in /home/slitaz/wok" 1.240 +EOF 1.241 + if get_from_hg wok "wok (cooking)"; then 1.242 + echo "$SORT_DIR/wok -8000" >> $SORT_FILE 1.243 + fi;; 1.244 +--wok-stable) 1.245 + cat >>$TEMP_DIR/install.sh<<EOF 1.246 +mkdir -p /home/slitaz 1.247 +ln -s \$DIR/wok /home/slitaz 1.248 +echo "=> Wok (stable) is in /home/slitaz/wok" 1.249 +EOF 1.250 + if get_from_hg wok-stable "wok (stable)"; then 1.251 + mv $TEMP_DIR/wok-stable $TEMP_DIR/wok 1.252 + echo "$SORT_DIR/wok -8000" >> $SORT_FILE 1.253 + fi;; 1.254 +--website) 1.255 + if get_from_hg website "web site"; then 1.256 + echo "$SORT_DIR/website -6000" >> $SORT_FILE 1.257 + cat >>$TEMP_DIR/install.sh<<EOF 1.258 +echo "=> slitaz web site installed in file://\$DIR/website/index.html" 1.259 +EOF 1.260 + fi;; 1.261 +--sources) 1.262 + echo -n "Removing previous ISO..." 1.263 + rm -f $OUTPUT 1.264 + status 1.265 + cat >>$TEMP_DIR/install.sh<<EOF 1.266 +mkdir -p /home/slitaz 1.267 +ln -s \$DIR/src /home/slitaz 1.268 +echo "=> sources are in /home/slitaz/src" 1.269 +EOF 1.270 + mkdir -p $SRC_DIR 1.271 + cd $SRC_DIR 1.272 + for i in $SOURCES/*/* 1.273 + do 1.274 + case "$i" in 1.275 + */md5sum) continue;; 1.276 + esac 1.277 + ln -s $i >> $LOG 2>&1 1.278 + done 1.279 + find * -not -type d | grep -v md5sum | xargs md5sum > md5sum 1.280 + echo "$(du -hs $SOURCES | awk '{ print $1 }') used by sources." ;; 1.281 +esac 1.282 +done 1.283 + 1.284 +# Extract boot package function 1.285 +extract_boot() 1.286 +{ 1.287 +f=$(ls $REPOS/$1-[0-9]*.tazpkg 2> /dev/null) 1.288 +[ -f "$f" ] || return 1 1.289 +[ -d $TEMP_DIR/boot ] || mkdir $TEMP_DIR/boot 1.290 +( cd $TEMP_DIR/boot ; cpio -i fs.cpio.gz < $f 2> /dev/null ) 1.291 +( cd $TEMP_DIR/boot ; zcat fs.cpio.gz | cpio -id 2> /dev/null ) 1.292 +mv $TEMP_DIR/boot/fs/boot/* $TEMP_DIR/boot 1.293 +rm -rf $TEMP_DIR/boot/fs.cpio.gz $TEMP_DIR/boot/fs 1.294 +return 0 1.295 +} 1.296 + 1.297 +# Gen boot part 1.298 +BOOT_OPT="" 1.299 +iso=$ISO_DIR/slitaz-$PKG_VER.iso 1.300 +for i in slitaz-loram-cdrom-sqfs slitaz-$PKG_VER-loram-cdrom ; do 1.301 + isoloram=$ISO_DIR/flavors/$i.iso 1.302 + [ -s $isoloram ] && break 1.303 +done 1.304 +case " $OPTIONS " in 1.305 +*\ --boot\ *) 1.306 + echo -n "Creating boot tree" 1.307 + need $iso 1.308 + which isoinfo > /dev/null || need /usr/bin/isoinfo 1.309 + isoinfo -R -l -i $iso | awk '/^Directory/ { path=$4 } /^-/ { print path$12 }' | while read file; do 1.310 + [ "$(basename $file)" == ".." ] && continue 1.311 + [ "$file" = "/boot/isolinux/boot.cat" ] && continue 1.312 + [ -d "$(dirname $TEMP_DIR/$file)" ] || 1.313 + mkdir -p "$(dirname $TEMP_DIR/$file)" 1.314 + isoinfo -R -x "$file" -i $iso > "$TEMP_DIR/$file" 1.315 + done 1.316 + if [ -f "$(echo $TEMP_DIR/boot/vmlinuz*)" ]; then 1.317 + rm -f $TEMP_DIR/boot/bzImage 1.318 + ln $TEMP_DIR/boot/vmlinuz* $TEMP_DIR/boot/bzImage 1.319 + fi 1.320 + status 1.321 + BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \ 1.322 +-c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table" 1.323 + case " $OPTIONS " in 1.324 + *\ --auto-install\ *) 1.325 + echo -n "Enable auto install" 1.326 + sed -i "s/rw root/rw config=LABEL=packages-$PKG_VER,install.sh root/" \ 1.327 + $TEMP_DIR/boot/isolinux/*.cfg 1.328 + status 1.329 + ;; 1.330 + esac 1.331 + case " $OPTIONS " in 1.332 + *\ --loram-detect\ *) 1.333 + echo -n "Enable loram autodetection" 1.334 + need $IFMEM_C32 $isoloram 1.335 + which isoinfo > /dev/null || need /usr/bin/isoinfo 1.336 + cp $IFMEM_C32 "$TEMP_DIR/boot/isolinux" 1.337 + isoinfo -R -x "/usr.sqfs" -i $isoloram \ 1.338 + > "$TEMP_DIR/usr.sqfs" 2> /dev/null 1.339 + if [ -s "$TEMP_DIR/usr.sqfs" ]; then 1.340 + echo "$SORT_DIR/usr.sqfs -5000" >> $SORT_FILE 1.341 + else 1.342 + rm -f "$TEMP_DIR/usr.sqfs" 1.343 + isoinfo -R -x "/rootfs.gz" -i $isoloram \ 1.344 + > "$TEMP_DIR/rootfs.gz" 2> /dev/null 1.345 + echo "$SORT_DIR/rootfs.gz -5000" >> $SORT_FILE 1.346 + fi 1.347 + isoinfo -R -x "/boot/rootfs.gz" -i $isoloram > \ 1.348 + "$TEMP_DIR/boot/loram.gz" 1.349 + cat >> $TEMP_DIR/boot/isolinux/common.cfg <<EOT 1.350 +label noram 1.351 + config noram.cfg 1.352 +EOT 1.353 + cat >> $TEMP_DIR/boot/isolinux/noram.cfg <<EOT 1.354 +display isolinux.msg 1.355 +say Not enough RAM to boot slitaz. 1.356 +default reboot 1.357 +label reboot 1.358 + com32 reboot.c32 1.359 + 1.360 +implicit 0 1.361 +prompt 1 1.362 +timeout 80 1.363 +F1 help.txt 1.364 +F2 options.txt 1.365 +F3 isolinux.msg 1.366 +F4 display.txt 1.367 +F5 enhelp.txt 1.368 +F6 enopts.txt 1.369 +EOT 1.370 + sed -i -e 's|kernel /boot/bzImage|kernel /boot/isolinux/ifmem.c32\n\tappend 160768 core 29696 loram noram\n|' \ 1.371 + -e "s|\\(.*/\\)rootfs\\(.gz .*\\)\$|label core\\n\\tkernel /boot/bzImage\\n\\1rootfs\\2\\n\\nlabel loram\\n\\tkernel /boot/bzImage\\n\\1loram\\2 loram=LABEL=packages-$PKG_VER,|" \ 1.372 + $TEMP_DIR/boot/isolinux/*.cfg 1.373 + status 1.374 + ;; 1.375 + esac 1.376 + echo "$SORT_DIR/boot 0" >> $SORT_FILE 1.377 + ;; 1.378 +*\ --webboot\ *) 1.379 + if extract_boot gpxe; then 1.380 + echo -n "Creating web boot tree" 1.381 + which isoinfo > /dev/null || need /usr/bin/isoinfo 1.382 + mkdir $TEMP_DIR/boot/isolinux/ 1.383 + isoinfo -R -x "/boot/isolinux/isolinux.bin" -i $iso > \ 1.384 + $TEMP_DIR/boot/isolinux/isolinux.bin 1.385 + mv $TEMP_DIR/boot/gpxe $TEMP_DIR/boot/isolinux 1.386 + echo "$SORT_DIR/boot 0" >> $SORT_FILE 1.387 + cat > $TEMP_DIR/boot/isolinux/isolinux.cfg <<EOT 1.388 +default gpxe 1.389 +append http://mirror.slitaz.org/pxe/pxelinux.0 1.390 +EOT 1.391 + status 1.392 + BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \ 1.393 +-c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table" 1.394 + fi 1.395 + ;; 1.396 +esac 1.397 + 1.398 +if [ -n "$BOOT_OPT" ]; then 1.399 + echo "$(du -chs $TEMP_DIR/boot $TEMP_DIR/usr.sqfs 2> /dev/null | \ 1.400 + awk 'END { print $1 }') used by boot." 1.401 +fi 1.402 + 1.403 +case " $OPTIONS " in 1.404 +*\ --dry-run\ *) 1.405 + echo "Please check and remove $TEMP_DIR and $SORT_FILE" 1.406 + exit 1.407 + ;; 1.408 +esac 1.409 +# Gen ISO 1.410 +echo -n "Generating iso image" 1.411 +genisoimage -R -J -f -V $VOLUME_ID \ 1.412 + -P "$PUBLISHER" -md5-list $REPOS/packages.md5 \ 1.413 + -quiet -o $OUTPUT $BOOT_OPT $TEMP_DIR 1.414 +status 1.415 + 1.416 +echo "$(du -hs $OUTPUT | awk '{ print $1 }') used by iso image." 1.417 + 1.418 +cd ${ROOT} 1.419 +echo -n "Create hybrid DVD/CDROM" 1.420 +which isohybrid > /dev/null && isohybrid $IMAGE 2> /dev/null 1.421 +status 1.422 + 1.423 +echo -n "Calculate md5sum" 1.424 +md5sum $IMAGE > $(basename $IMAGE .iso).md5 1.425 +status 1.426 + 1.427 +echo -n "Moving file to mirror" 1.428 +mv $IMAGE $ISO_DIR 1.429 +mv $(basename $IMAGE .iso).md5 $ISO_DIR 1.430 +status 1.431 + 1.432 +# Cleaning temp files 1.433 +rm -rf $TEMP_DIR $SORT_FILE 1.434 +