slitaz-forge annotate dvd/mkpkgiso @ rev 612

tank, pangolin: add console link
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Feb 03 18:29:16 2016 +0100 (2016-02-03)
parents d658c9cd743b
children 061a079077a3
rev   line source
al@602 1 #!/bin/sh
al@602 2 # mkpkgiso, build packages ISO image.
al@602 3 # (C) 2007-TODAY SliTaz - GNU General Public License v3.
al@602 4 #
al@602 5 # Authors : Eric Joseph-Alexandre <erjo@slitaz.org>
al@602 6 # Pascal Bellard <pascal.bellard@slitaz.org>
al@602 7
al@602 8 VERSION=0.9
al@602 9
al@602 10 PKG_VER=$1
al@602 11 ROOT=/home/slitaz/iso
al@602 12 REPOS=/var/www/slitaz/mirror/packages/$PKG_VER
al@602 13 SOURCES=/var/www/slitaz/mirror/sources/packages
al@602 14 IFMEM_C32=/var/www/slitaz/mirror/pxe/ifmem.c32
al@602 15 ISO_DIR=/var/www/slitaz/mirror/iso/$PKG_VER
al@602 16
al@602 17 [ -s /etc/slitaz/mkpkgiso.conf ] && . /etc/slitaz/mkpkgiso.conf
al@602 18 [ -s ./mkpkgiso.conf ] && . ./mkpkgiso.conf
al@602 19
al@602 20 SORT_DIR=${ROOT}/_iso.$$
al@602 21 TEMP_DIR=${ROOT}/_iso.$$
al@602 22 SORT_FILE=${ROOT}/_sort.$$
al@602 23 shift
al@602 24 OPTIONS=$@
al@602 25 PKG_DIR=$TEMP_DIR/packages/$PKG_VER
al@602 26 SRC_DIR=$TEMP_DIR/src
al@602 27 LOG=$PWD/$(basename $0).log
al@602 28
al@602 29 #
al@602 30 VOLUME_ID="packages-${PKG_VER}"
al@602 31 PUBLISHER="SliTaz http://www.slitaz.org/"
al@602 32 IMAGE="packages-${PKG_VER}.iso"
al@602 33 case " $@ " in
al@602 34 *\ --sources\ *)
al@602 35 IMAGE="sources-${PKG_VER}.iso" ;;
al@602 36 esac
al@602 37 OUTPUT="$ROOT/$IMAGE"
al@602 38
al@602 39 # Check command line option.
al@602 40 if [ -z $PKG_VER ]; then
al@602 41 cat <<EOT
al@602 42 Usage: $(basename $0) <Version>
al@602 43 [--boot [--auto-install] [--loram-detect]]|--webboot] [--filter]
al@602 44 [--wok] [--wok-stable] [--website] [--sources] [--dry-run]
al@602 45 $(basename $0) update-hg <dir>
al@602 46 Example:
al@602 47 $(basename $0) cooking --boot --auto-install --loram-detect --filter --wok --website --sources
al@602 48 EOT
al@602 49 exit 1
al@602 50 fi
al@602 51
al@602 52 # Update hg repos
al@602 53 if [ "$PKG_VER" == "update-hg" ]; then
al@602 54 for i in $1/* ; do
al@602 55 grep -qs '\[paths]' $i/.hg/hgrc || continue
al@602 56 cd $i
al@602 57 hg pull
al@602 58 hg update
al@602 59 cd - > /dev/null
al@602 60 done
al@602 61 exit 1
al@602 62 fi
al@602 63
al@602 64 # Check if we provide a valide version
al@602 65 if [ ! -d $REPOS ]; then
al@602 66 echo "Boooh! $PKG_VER is not a valid version."
al@602 67 exit 1
al@602 68 fi
al@602 69
al@602 70 # Status function.
al@602 71 status()
al@602 72 {
al@602 73 local CHECK=$?
al@602 74 echo -en "\\033[70G[ "
al@602 75 if [ $CHECK = 0 ]; then
al@602 76 echo -en "\\033[1;33mOK"
al@602 77 else
al@602 78 echo -en "\\033[1;31mFailed"
al@602 79 fi
al@602 80 echo -e "\\033[0;39m ]"
al@602 81 }
al@602 82
al@602 83 need()
al@602 84 {
al@602 85 found=1
al@602 86 for i in $@ ; do
al@602 87 [ -s $i ] && continue
al@602 88 echo "Missing: $i "
al@602 89 found=0
al@602 90 done
al@602 91 [ $found -ne 0 ] && return
al@602 92 status
al@602 93 rm -rf $TEMP_DIR $SORT_FILE
al@602 94 exit 1
al@602 95 }
al@602 96
al@602 97 # Create temp directory
al@602 98 mkdir -p $TEMP_DIR/packages/$PKG_VER
al@602 99 which genisoimage > /dev/null || need /usr/bin/genisoimage
al@602 100
al@602 101 # Prepare evrything for ISO
al@602 102
al@602 103 echo ""
al@602 104 echo "Building ISO for packages $PKG_VER"
al@602 105 echo "==============================================================================="
al@602 106 echo -n "Creating working dir $(basename $TEMP_DIR)"
al@602 107 status
al@602 108 echo -n "Creating symlink"
al@602 109 status
al@602 110
al@602 111 # Link every packages to temp dir
al@602 112 cd $PKG_DIR
al@602 113 for i in $REPOS/*
al@602 114 do
al@602 115 ln -s $i >> $LOG 2>&1
al@602 116 done
al@602 117
al@602 118 echo -n "Creating install script"
al@602 119 # Create install script as suggested by Pascal.
al@602 120 cat >$TEMP_DIR/install.sh<<EOF
al@602 121 #!/bin/sh
al@602 122 #
al@602 123
al@602 124 DIR=\$(cd \$(busybox dirname \$0); pwd)
al@602 125
al@602 126 # Handle --auto-install case
al@602 127 if [ "\$DIR" == "/etc/init.d" ]; then
al@602 128 DIR=/cdrom
al@602 129 if [ ! -f /cdrom/install.sh ]; then
al@602 130 mkdir /cdrom 2> /dev/null
al@602 131 mount --bind /mnt /cdrom
al@602 132 fi
al@602 133 # Handle loram on hybrid hard disk / usb key case
al@602 134 if [ ! -d /usr/bin ]; then
al@602 135 echo ""
al@602 136 if [ -d /.usr.rw ]; then
al@602 137 echo -n "Mounting /usr read-write... "
al@602 138 usr=.usr.ro
al@602 139 else
al@602 140 echo -n "Mounting /usr read-only... "
al@602 141 usr=usr
al@602 142 fi
al@602 143 FS=\$DIR/usr.cromfs
al@602 144 if [ -f \$FS ]; then
al@602 145 /bin/cromfs-driver \$FS /\$usr -o ro,dev,suid,allow_other
al@602 146 elif [ -f \$DIR/usr.sqfs ]; then
al@602 147 FS=\$DIR/usr.sqfs
al@602 148 mount -o loop,ro -t squashfs \$FS /\$usr
al@602 149 elif [ -L /\$usr ]; then
al@602 150 FS=\$DIR/usr
al@602 151 fi
al@602 152 status
al@602 153 if [ -d /.usr.rw ]; then
al@602 154 if [ -x /bin/funionfs ]; then
al@602 155 /bin/funionfs -o dirs=/.usr.ro=RO:/.usr.rw -o allow_other -o suid,dev NONE /usr
al@602 156 else
al@602 157 /bin/mount -t aufs -o br:/.usr.rw:/.usr.ro none /usr
al@602 158 fi
al@602 159 fi
al@602 160 fi
al@602 161 fi
al@602 162
al@602 163 [ -d /var/cache/tazpkg ] || mkdir -p /var/cache/tazpkg
al@602 164 ls -d \$DIR/packages/* > /var/lib/tazpkg/mirror
al@602 165 ln -fs \$DIR/packages/*/*.tazpkg /var/cache/tazpkg/
al@602 166 ln -fs \$DIR/packages/*/packages.* /var/lib/tazpkg
al@602 167 echo ""
al@602 168 echo "=> all $PKG_VER packages are available for tazpkg/tazpkgbox"
al@602 169 EOF
al@602 170 [ -e files.list.lzma ] && cat >>$TEMP_DIR/install.sh<<EOF
al@602 171 ln -fs \$DIR/packages/*/files.list.lzma /var/lib/tazpkg
al@602 172 EOF
al@602 173
al@602 174 status
al@602 175 cat > $SORT_FILE <<EOT
al@602 176 $SORT_DIR/install.sh -4000
al@602 177 $SORT_DIR/README -4000
al@602 178 $SORT_DIR/index.html -4000
al@602 179 $SORT_DIR/md5sum -4000
al@602 180 $SORT_DIR/style.css -4000
al@602 181 $SORT_DIR/images/header.png -4000
al@602 182 $SORT_DIR/boot/bzImage 2
al@602 183 $SORT_DIR/boot/rootfs.gz 1
al@602 184 $SORT_DIR/packages -9000
al@602 185 EOT
al@602 186 ( cd $ROOT; ls $SORT_DIR/packages/*/packages* $SORT_DIR/packages/*/files.list.lzma ) | \
al@602 187 awk '{ printf "%s -7000\n",$0 }' >> $SORT_FILE
al@602 188 chmod 755 $TEMP_DIR/install.sh
al@602 189
al@602 190 case " $OPTIONS " in
al@602 191 *\ --filter\ *)
al@602 192 SIZE=0
al@602 193 for i in *.tazpkg; do
al@602 194 while read f; do
al@602 195 case "$i" in
al@602 196 $f*) continue 2;;
al@602 197 esac
al@602 198 done < packages.list
al@602 199 echo -n "Filtering out $i ($(du -hs $(readlink $i) | awk '{ print $1 }'))..."
al@602 200 SIZE=$(( $SIZE + $(stat -c %s $(readlink $i)) ))
al@602 201 rm $i
al@602 202 status
al@602 203 done
al@602 204 UNIT=" bytes"
al@602 205 if [ $SIZE -gt 10240 ]; then
al@602 206 SIZE=$(( $SIZE / 1024 ))
al@602 207 UNIT="K"
al@602 208 fi
al@602 209 if [ $SIZE -gt 10240 ]; then
al@602 210 SIZE=$(( $SIZE / 1024 ))
al@602 211 UNIT="M"
al@602 212 fi
al@602 213 echo "$SIZE$UNIT removed.";;
al@602 214 esac
al@602 215
al@602 216 # Copy hg subtree
al@602 217 get_from_hg()
al@602 218 {
al@602 219 echo -n "Adding $2"
al@602 220 if [ -s /home/slitaz/$1/.hg/hgrc ]; then
al@602 221 cp -a /home/slitaz/$1 $TEMP_DIR
al@602 222 else
al@602 223 wget -q -O - http://hg.slitaz.org/$1/archive/tip.tar.bz2 | tar xjf - -C $TEMP_DIR
al@602 224 mv $TEMP_DIR/$1-* $TEMP_DIR/$1
al@602 225 fi
al@602 226 status
al@602 227 echo "$(du -hs $TEMP_DIR/$1 | awk '{ print $1 }') used by $2."
al@602 228 }
al@602 229
al@602 230 for i in $OPTIONS ; do
al@602 231 case "$i" in
al@602 232 --wok)
al@602 233 cat >>$TEMP_DIR/install.sh<<EOF
al@602 234 mkdir -p /home/slitaz
al@602 235 ln -s \$DIR/wok /home/slitaz
al@602 236 echo "=> Wok (cooking) is in /home/slitaz/wok"
al@602 237 EOF
al@602 238 if get_from_hg wok "wok (cooking)"; then
al@602 239 echo "$SORT_DIR/wok -8000" >> $SORT_FILE
al@602 240 fi;;
al@602 241 --wok-stable)
al@602 242 cat >>$TEMP_DIR/install.sh<<EOF
al@602 243 mkdir -p /home/slitaz
al@602 244 ln -s \$DIR/wok /home/slitaz
al@602 245 echo "=> Wok (stable) is in /home/slitaz/wok"
al@602 246 EOF
al@602 247 if get_from_hg wok-stable "wok (stable)"; then
al@602 248 mv $TEMP_DIR/wok-stable $TEMP_DIR/wok
al@602 249 echo "$SORT_DIR/wok -8000" >> $SORT_FILE
al@602 250 fi;;
al@602 251 --website)
al@602 252 if get_from_hg website "web site"; then
al@602 253 echo "$SORT_DIR/website -6000" >> $SORT_FILE
al@602 254 cat >>$TEMP_DIR/install.sh<<EOF
al@602 255 echo "=> slitaz web site installed in file://\$DIR/website/index.html"
al@602 256 EOF
al@602 257 fi;;
al@602 258 --sources)
al@602 259 echo -n "Removing previous ISO..."
al@602 260 rm -f $OUTPUT
al@602 261 status
al@602 262 cat >>$TEMP_DIR/install.sh<<EOF
al@602 263 mkdir -p /home/slitaz
al@602 264 ln -s \$DIR/src /home/slitaz
al@602 265 echo "=> sources are in /home/slitaz/src"
al@602 266 EOF
al@602 267 mkdir -p $SRC_DIR
al@602 268 cd $SRC_DIR
al@602 269 for i in $SOURCES/*/*
al@602 270 do
al@602 271 case "$i" in
al@602 272 */md5sum) continue;;
al@602 273 esac
al@602 274 ln -s $i >> $LOG 2>&1
al@602 275 done
al@602 276 find * -not -type d | grep -v md5sum | xargs md5sum > md5sum
al@602 277 echo "$(du -hs $SOURCES | awk '{ print $1 }') used by sources." ;;
al@602 278 esac
al@602 279 done
al@602 280
al@602 281 # Extract boot package function
al@602 282 extract_boot()
al@602 283 {
al@602 284 f=$(ls $REPOS/$1-[0-9]*.tazpkg 2> /dev/null)
al@602 285 [ -f "$f" ] || return 1
al@602 286 [ -d $TEMP_DIR/boot ] || mkdir $TEMP_DIR/boot
al@602 287 ( cd $TEMP_DIR/boot ; cpio -i fs.cpio.gz < $f 2> /dev/null )
al@602 288 ( cd $TEMP_DIR/boot ; zcat fs.cpio.gz | cpio -id 2> /dev/null )
al@602 289 mv $TEMP_DIR/boot/fs/boot/* $TEMP_DIR/boot
al@602 290 rm -rf $TEMP_DIR/boot/fs.cpio.gz $TEMP_DIR/boot/fs
al@602 291 return 0
al@602 292 }
al@602 293
pascal@608 294 # Build hybdrid shell/mbr boot
pascal@608 295 shhybrid()
pascal@608 296 {
pascal@608 297 blkuuid="$(blkid $1 | sed 's/.* UUID="\([^"]*\).*/\1/')"
pascal@608 298 echo -e "#\xE4\x73\x1C\nexec sed 1,/^#@/d/^\$/q \$0" | dd of=$1 conv=notrunc 2>/dev/null
pascal@608 299 dd bs=512 seek=1 conv=notrunc of=$1 2>/dev/null <<EOT
pascal@608 300
pascal@608 301 #@
pascal@608 302 #!/bin/sh
pascal@608 303
pascal@609 304 dev=\$({ blkid $1; blkid; } | sed '/$blkuuid/!d;s/:.*//;q')
pascal@608 305
pascal@608 306 if [ -n "\$dev" ]; then
pascal@608 307 mkdir -p /mnt/packages
pascal@608 308 mount -t iso9660 -o loop,ro \$dev /mnt/packages
pascal@608 309 /mnt/packages/install.sh
pascal@608 310 fi
pascal@608 311
pascal@608 312 EOT
pascal@608 313 }
pascal@608 314
al@602 315 # Gen boot part
al@602 316 BOOT_OPT=""
al@602 317 iso=$ISO_DIR/slitaz-$PKG_VER.iso
al@602 318 for i in slitaz-loram-cdrom-sqfs slitaz-$PKG_VER-loram-cdrom ; do
al@602 319 isoloram=$ISO_DIR/flavors/$i.iso
al@602 320 [ -s $isoloram ] && break
al@602 321 done
al@602 322 case " $OPTIONS " in
al@602 323 *\ --boot\ *)
al@602 324 echo -n "Creating boot tree"
al@602 325 need $iso
al@602 326 which isoinfo > /dev/null || need /usr/bin/isoinfo
al@602 327 isoinfo -R -l -i $iso | awk '/^Directory/ { path=$4 } /^-/ { print path$12 }' | while read file; do
al@602 328 [ "$(basename $file)" == ".." ] && continue
al@602 329 [ "$file" = "/boot/isolinux/boot.cat" ] && continue
al@602 330 [ -d "$(dirname $TEMP_DIR/$file)" ] ||
al@602 331 mkdir -p "$(dirname $TEMP_DIR/$file)"
al@602 332 isoinfo -R -x "$file" -i $iso > "$TEMP_DIR/$file"
al@602 333 done
al@602 334 if [ -f "$(echo $TEMP_DIR/boot/vmlinuz*)" ]; then
al@602 335 rm -f $TEMP_DIR/boot/bzImage
al@602 336 ln $TEMP_DIR/boot/vmlinuz* $TEMP_DIR/boot/bzImage
al@602 337 fi
al@602 338 status
al@602 339 BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \
al@602 340 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
al@602 341 case " $OPTIONS " in
al@602 342 *\ --auto-install\ *)
al@602 343 echo -n "Enabling auto install"
al@602 344 sed -i "s/rw root/rw config=LABEL=packages-$PKG_VER,install.sh root/" \
al@602 345 $TEMP_DIR/boot/isolinux/*.cfg
al@602 346 status
al@602 347 ;;
al@602 348 esac
al@602 349 case " $OPTIONS " in
al@602 350 *\ --loram-detect\ *)
al@602 351 echo -n "Enabling loram autodetection"
al@602 352 need $IFMEM_C32 $isoloram
al@602 353 which isoinfo > /dev/null || need /usr/bin/isoinfo
al@602 354 cp $IFMEM_C32 "$TEMP_DIR/boot/isolinux"
al@602 355 isoinfo -R -x "/usr.sqfs" -i $isoloram \
al@602 356 > "$TEMP_DIR/usr.sqfs" 2> /dev/null
al@602 357 if [ -s "$TEMP_DIR/usr.sqfs" ]; then
al@602 358 echo "$SORT_DIR/usr.sqfs -5000" >> $SORT_FILE
al@602 359 else
al@602 360 rm -f "$TEMP_DIR/usr.sqfs"
al@602 361 isoinfo -R -x "/rootfs.gz" -i $isoloram \
al@602 362 > "$TEMP_DIR/rootfs.gz" 2> /dev/null
al@602 363 echo "$SORT_DIR/rootfs.gz -5000" >> $SORT_FILE
al@602 364 fi
al@602 365 isoinfo -R -x "/boot/rootfs.gz" -i $isoloram > \
al@602 366 "$TEMP_DIR/boot/loram.gz"
al@602 367 cat >> $TEMP_DIR/boot/isolinux/common.cfg <<EOT
al@602 368 label noram
al@602 369 config noram.cfg
al@602 370 EOT
al@602 371 cat >> $TEMP_DIR/boot/isolinux/noram.cfg <<EOT
al@602 372 display isolinux.msg
al@602 373 say Not enough RAM to boot slitaz.
al@602 374 default reboot
al@602 375 label reboot
al@602 376 com32 reboot.c32
al@602 377
al@602 378 implicit 0
al@602 379 prompt 1
al@602 380 timeout 80
al@602 381 F1 help.txt
al@602 382 F2 options.txt
al@602 383 F3 isolinux.msg
al@602 384 F4 display.txt
al@602 385 F5 enhelp.txt
al@602 386 F6 enopts.txt
al@602 387 EOT
al@602 388 sed -i -e 's|kernel /boot/bzImage|kernel /boot/isolinux/ifmem.c32\n\tappend 160768 core 29696 loram noram\n|' \
al@602 389 -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,|" \
al@602 390 $TEMP_DIR/boot/isolinux/*.cfg
al@602 391 status
al@602 392 ;;
al@602 393 esac
al@602 394 echo "$SORT_DIR/boot 0" >> $SORT_FILE
al@602 395 ;;
al@602 396 *\ --webboot\ *)
al@602 397 if extract_boot gpxe; then
al@602 398 echo -n "Creating web boot tree"
al@602 399 which isoinfo > /dev/null || need /usr/bin/isoinfo
al@602 400 mkdir $TEMP_DIR/boot/isolinux/
al@602 401 isoinfo -R -x "/boot/isolinux/isolinux.bin" -i $iso > \
al@602 402 $TEMP_DIR/boot/isolinux/isolinux.bin
al@602 403 mv $TEMP_DIR/boot/gpxe $TEMP_DIR/boot/isolinux
al@602 404 echo "$SORT_DIR/boot 0" >> $SORT_FILE
al@602 405 cat > $TEMP_DIR/boot/isolinux/isolinux.cfg <<EOT
al@602 406 default gpxe
al@602 407 append http://mirror.slitaz.org/pxe/pxelinux.0
al@602 408 EOT
al@602 409 status
al@602 410 BOOT_OPT="-sort $SORT_FILE -b boot/isolinux/isolinux.bin \
al@602 411 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
al@602 412 fi
al@602 413 ;;
al@602 414 esac
al@602 415
al@602 416 if [ -n "$BOOT_OPT" ]; then
al@602 417 echo "$(du -chs $TEMP_DIR/boot $TEMP_DIR/usr.sqfs 2> /dev/null | \
al@602 418 awk 'END { print $1 }') used by boot."
al@602 419 fi
al@602 420
al@602 421 case " $OPTIONS " in
al@602 422 *\ --dry-run\ *)
al@602 423 echo "Please check and remove $TEMP_DIR and $SORT_FILE"
al@602 424 exit
al@602 425 ;;
al@602 426 esac
al@602 427 # Gen ISO
al@602 428 echo -n "Generating iso image"
al@602 429 genisoimage -R -J -f -V $VOLUME_ID \
al@602 430 -P "$PUBLISHER" -md5-list $REPOS/packages.md5 \
al@602 431 -quiet -o $OUTPUT $BOOT_OPT $TEMP_DIR
al@602 432 status
al@602 433
al@602 434 echo "$(du -hs $OUTPUT | awk '{ print $1 }') used by iso image."
al@602 435
al@602 436 cd ${ROOT}
al@602 437 echo -n "Creating hybrid DVD/CDROM"
al@602 438 which isohybrid > /dev/null && isohybrid $IMAGE 2> /dev/null
al@602 439 status
al@602 440
pascal@608 441 echo -n "Creating hybrid shell/mbr"
pascal@608 442 shhybrid $IMAGE
pascal@608 443 status
pascal@608 444
al@602 445 echo -n "Calculating md5sum"
al@602 446 md5sum $IMAGE > $(basename $IMAGE .iso).md5
al@602 447 status
al@602 448
al@602 449 echo -n "Moving file to mirror"
al@602 450 mv $IMAGE $ISO_DIR
al@602 451 mv $(basename $IMAGE .iso).md5 $ISO_DIR
al@602 452 status
al@602 453
al@602 454 # Cleaning temp files
al@602 455 rm -rf $TEMP_DIR $SORT_FILE
al@602 456