Difference between revisions of "Livecd-make"

From ElphelWiki
Jump to: navigation, search
(varrolcrel)
m (Reverted edit of ZelelTricb, changed back to last version by Polto)
 
Line 1: Line 1:
[http://traceejeffreys.ifrance.com/topic/birthday-card.html birthday card quotes] [http://redwoods.diglot.in/ redwoods] [http://imp-r0.isuisse.com/topic/purine-purine-base.html purine purine base] [http://radeditor.kamahi.in/ r.a.d.editor] [http://karinepiatt.iespana.es/styles/vernal-equinox.html vernal equinox] [http://accounting-clerks.mainland.in/ accounting clerks] [http://dtolstoles.isuisse.com/famu.html 100 famu march] [http://latonyawelling.ifrance.com/lib/tiffany-holliday.html tiffany holliday] [http://the-islands.mainland.in/ the islands of japan] [http://imp-r0.isuisse.com/topic/install-antivirus.html install antivirus software] [http://need-for-speed-most.explisit.in/ need for speed most watned] [http://imp-r0.isuisse.com/topic/home-design.html home design] [http://alabama-apartment.holily.in/ alabama apartment london rental] [http://erlinetor.we.bs/text/r03.html media pdp pioneer r03 reciever] [http://lucienneespinoz.ifrance.com/comments/bakery-supplies.html bakery supplies] [http://ya-uza.isuisse.com/styles/libatk-10-0dll-download.html libatk 1.0 0.dll download] [http://luannecovarrubi.iespana.es/content/police-sirens.html police light and siren] [http://brynnparkey.ifrance.com/agent-free-warbird.html agent free warbird] [http://garething.isuisse.com/new/11-basket-episode.html 11 basket episode fruit] [http://latonyawelling.ifrance.com/lib/ideal-wire-markers.html ideal wire markers] [http://reoracer.50webs.com/animal-talent-agencies.html agency animal talent] [http://ladies-in-bondage.kamahi.in/ ladies in bondage] [http://danakrogman.ifrance.com/wiki/forex-trading.html forex trading systems] [http://plant-labels.waunakee.in/ plant labels] [http://conchitawoolver.iespana.es/offre-pret.html offre pret] [http://erickacicero.ifrance.com/aids-hiv-sex-trafficking.html aids hiv sex trafficking] [http://1x-0007.ibelgique.com/resources/kimpossible.html kimpossible nude] [http://erlinetor.we.bs/text/moises-saba-stern.html moises saba stern] [http://ya-uza.isuisse.com/styles/information-kid.html information kid nutrition] [http://1x-0007.ibelgique.com/resources/dog-supply.html discount dog supply] [http://karinepiatt.iespana.es/styles/psychologists-jobs.html job psychologist saskatchewan] [http://imp-r0.isuisse.com/topic/greetings-cards.html free e greeting card] [http://j-oclama.isuisse.com/tiny-lolita-angels.html tiny lolita angels] [http://katricebliss.iespana.es/article/nes-power.html nes power] [http://danakrogman.ifrance.com/wiki/a-lesson-before.html a lesson before dying lesson plans] [http://matts-tar.ibelgique.com/lib/the-brothers-grim.html the brothers grim] [http://marlineoreilly.ifrance.com/small/sports-authority.html sports authority] [http://j-oclama.isuisse.com/inside-pool-forum.html inside pool forum] [http://j-oclama.isuisse.com/3d-ultrasound.html 3d ultrasound pregnancy] [http://marlineoreilly.ifrance.com/small/36-downdraft.html 36 electric cooktop downdraft] [http://twanagoggin.ifrance.com/web/charles-email.html charles email listing (at)aol.com info] [http://traceejeffreys.ifrance.com/topic/credit-travaux.html credit meilleur travaux] [http://marlineoreilly.ifrance.com/small/custom-guitars.html 2005 calendar custom fender guitar shop] [http://aero-lite.ibelgique.com/slam-blue-jays.html slam blue jays] [http://1983-oldsmobile.panterra.in/ 1983 oldsmobile cutlass supreme] [http://rs-mizar.diglot.in/ rs mizar] [http://conchitawoolver.iespana.es/weeping-cherry.html weeping cherry tree care] [http://yasa-shisa.isuisse.com/side-street-restaurant.html side street restaurant] [http://prin-sabun.ibelgique.com/brinkmann.html brinkmann grill] [http://predictor-of-height.lufberry.in/ predictor of height] [http://lucienneespinoz.ifrance.com/comments/lake-district.html lake district cheap holiday] [http://cookbooks.mainland.in/ cookbooks] [http://carmagaleano.ifrance.com/topic/philadelphia-subsidized.html philadelphia subsidized day care] [http://brynnparkey.ifrance.com/personal-stationery.html memo pad personal stationery] [http://marlineoreilly.ifrance.com/small/anime-muck-com.html anime muck com sakura] [http://cocktaillounge.50webs.com/data/cover-letter-example.html resume cover letter example] [http://carmagaleano.ifrance.com/topic/stopping-smoking.html stopping smoking side effects] [http://erlinetor.we.bs/text/strategic-planning.html strategic planning and forecasting] [http://karinepiatt.iespana.es/styles/home-inspection.html home inspection report software] [http://danakrogman.ifrance.com/wiki/price-chopper.html price chopper card] [http://yasa-shisa.isuisse.com/picture-of-brian.html picture of brian krause] [http://greta-pier.ibelgique.com/wiki/wrestlemania-21.html wrestlemania 21] [http://ya-uza.isuisse.com/styles/morning-glow-download.html morning glow download] [http://marlynbarrios.iespana.es/resources/southern-culture.html southern culture on the skids] [http://brynnparkey.ifrance.com/statin.html statin] [http://dtolstoles.isuisse.com/nioxin-shampoo.html nioxin shampoo] [http://latonyawelling.ifrance.com/lib/horse-fucking.html horse fucking] [http://reinaferreri.iespana.es/html/bushwacker.html bushwacker] [http://mens-tuxedo.mainland.in/ mens tuxedo pants] [http://yasa-shisa.isuisse.com/neopet-money.html free money cheat for neopets] [http://luannecovarrubi.iespana.es/content/support-groups.html grief support group] [http://reinaferreri.iespana.es/html/texas-state-track.html texas state track and field records] [http://manawebster.iespana.es/view/spermicides.html spermicides] [http://cheerfulstoic.50webs.com/comments/raulph-lauren.html raulph lauren clothing] [http://erickacicero.ifrance.com/rolly-molly.html rolly molly] [http://reoracer.50webs.com/bmwusa.html bmwusa] [http://lucienneespinoz.ifrance.com/comments/first-class-online.html first class online casinos] [http://luannecovarrubi.iespana.es/content/american-comic.html american comic] [http://erickacicero.ifrance.com/the-weekend.html nba star weekend] [http://marlineoreilly.ifrance.com/small/loft-developments.html loft developments toronto] [http://reganfeld.we.bs/girls-getting.html girls getting gunged] [http://brynnparkey.ifrance.com/marcus-allen-gay.html marcus allen gay] [http://imp-r0.isuisse.com/topic/medical-massage.html medical massage group] [http://demon-dance.ibelgique.com/web/cat-supplies.html cat supplies] [http://ya-uza.isuisse.com/styles/self-authenticating.html self authenticating] [http://erickacicero.ifrance.com/washer.html washer] [http://lucienneespinoz.ifrance.com/comments/loans-ireland.html car loan ireland] [http://solwind.50webs.com/who-settled-massachusetts.html who settled massachusetts] [http://laptop-cases.leonis.in/ laptop cases] [http://garething.isuisse.com/new/womens-health.html womens health] [http://nina-hartley-naked.diglot.in/ nina hartley naked] [http://marlynbarrios.iespana.es/resources/1007-starr.html 100.7 starr] [http://cheerfulstoic.50webs.com/comments/research-technology.html research technology management magazine] [http://marlineoreilly.ifrance.com/small/portrettist.html portrettist] [http://manawebster.iespana.es/view/international-driving.html international driving permit uk] [http://traceejeffreys.ifrance.com/topic/roller-coaster.html coaster knex roller video] [http://carmagaleano.ifrance.com/topic/patrick-swayze.html movie patrick swayze] [http://convergence.leonis.in/ convergence] [http://traceejeffreys.ifrance.com/topic/ricci.html jane ricci] [http://erlinetor.we.bs/text/hot-pictures-of.html hot leg picture sexy wife] [http://traceejeffreys.ifrance.com/topic/dancewear-solution.html dancewear solution] [http://vernors-ginger.diglot.in/ vernors ginger ale] [http://1x-0007.ibelgique.com/resources/sunroom-addition.html cost of sunroom addition] [http://erlinetor.we.bs/text/hot-sex-scenes.html bollywood hot scene sex] [http://morningmoon.we.bs/web/parkgate-community.html parkgate community centre north vancouver] [http://traceejeffreys.ifrance.com/topic/take-your-time.html hand lyric take time wounded] [http://theli.isuisse.com/blog/free-porn-videos.html free online porn video] [http://luannvicknair.iespana.es/oxford-castle.html oxford castle inn] [http://carmagaleano.ifrance.com/topic/zoolander-dvd.html zoolander dvd] [http://sania-mirza-navel.explisit.in/ sania mirza navel pics] [http://summerpica.ifrance.com/boys-load.html boys load] [http://lamb-moussaka-recipe.waunakee.in/ lamb moussaka recipe] [http://brynnparkey.ifrance.com/ttk-services.html ttk services] [http://erlinetor.we.bs/text/high-vis.html high vis] [http://email-search-hotmail.lufberry.in/ email search hotmail] [http://cheerfulstoic.50webs.com/comments/coffee-gourmet.html coffee gift gourmet] [http://cheerfulstoic.50webs.com/comments/on-line-car-auction.html on line car auction uk] [http://traceejeffreys.ifrance.com/topic/self-storage.html self storage business for sale] [http://pima-county.kamahi.in/ pima county assessor] [http://cheerfulstoic.50webs.com/comments/geforce.html 6600 geforce] [http://cocktaillounge.50webs.com/data/marge-simpsons-nude.html marge simpsons nude galleries] [http://erickacicero.ifrance.com/card-making-ideas.html birthday card idea making] [http://marlineoreilly.ifrance.com/small/mr-doubles-palisades.html mr doubles palisades] [http://cocktaillounge.50webs.com/data/san-francisco.html limousine service san francisco] [http://zench.isuisse.com/roxbury-police.html roxbury police dept] [http://dtolstoles.isuisse.com/mp3-search-engine.html mp3-search-engine] [http://marlineoreilly.ifrance.com/small/empress-high-hotel.html empress high hotel tea] [http://cocktaillounge.50webs.com/data/flirt-teen-tease.html flirt teen tease] [http://danakrogman.ifrance.com/wiki/prodigy-spitfire.html lyric prodigy spitfire] [http://luannecovarrubi.iespana.es/content/free-multiplayer-rpg.html free online multiplayer download rpg] [http://twanagoggin.ifrance.com/web/management-resume.html management resume retail sales sample] [http://summerpica.ifrance.com/guide-to-fingering.html guide to fingering a girl] [http://carmagaleano.ifrance.com/topic/movie-set-prop.html movie set prop] [http://romonacumberlan.iespana.es/comments/universities-online.html online university degree program] [http://aero-lite.ibelgique.com/ninpuchan.html ninpuchan] [http://energizer-bunny.diglot.in/ energizer bunny] [http://mulan-com.mainland.in/ mulan .com] [http://latonyawelling.ifrance.com/lib/victoria-advocate.html victoria advocate victoria texas] [http://ya-uza.isuisse.com/styles/asthma-care-child.html asthma care child self] [http://lucienneespinoz.ifrance.com/comments/naked-gay-black.html naked gay black man] [http://pretty-girls.lufberry.in/ pretty girls make graves] [http://romonacumberlan.iespana.es/comments/serous-cystadenocarcinoma.html serous cystadenocarcinoma] [http://theli.isuisse.com/blog/lottery-pa-result.html pa lottery result] [http://sound-and-spirit.leonis.in/ sound and spirit] [http://bail-bond-agents.kamahi.in/ bail bond agents] [http://marlineoreilly.ifrance.com/small/power-dvd-5-download.html power dvd 5 download] [http://birthday-massacre.holily.in/ birthday massacre] [http://korn-falling-away.waunakee.in/ korn falling away from me] [http://teen-sex-pic.panterra.in/ teen sex pic] [http://morningmoon.we.bs/web/worldwatch-institute.html worldwatch institute] [http://zench.isuisse.com/discount-power.html discount power tool] [http://live-beeez.ibelgique.com/northstar-aviation.html north star aviation] [http://reganfeld.we.bs/st-louis-metro.html st louis metro transportation] [http://traceejeffreys.ifrance.com/topic/no-woman-no-cry.html no woman no cry] [http://tangelaflora.we.bs/order-ambien.html glass candle lamp shades] [http://troy-lighting.holily.in/ troy lighting inc.] [http://yasa-shisa.isuisse.com/industrial-tools.html industrial tools] [http://live-beeez.ibelgique.com/sims-skins.html sims skin] [http://inuyashachibi.50webs.com/fabian.html patrick fabian] [http://24-5-bit-season.diglot.in/ 24 5 bit season torrent] [http://quality-manual.panterra.in/ quality manual] [http://dakot-ces.isuisse.com/acting-game.html acting exercise game game improvisation improvisation textbook theater] [http://morningmoon.we.bs/web/islamic-time.html islamic time line] [http://ebiy-one.ibelgique.com/tropical-ceiling.html tropical ceiling fan] [http://returnandremain.ibelgique.com/faith-hill-lyrics.html faith hill lyrics] [http://lucienneespinoz.ifrance.com/comments/rx8-reviews-mazda.html rx8 reviews mazda] [http://lucky-absolute.isuisse.com/sanrio.html sanrio wallpaper] [http://brynnparkey.ifrance.com/acuson.html acuson aspen] [http://marlynbarrios.iespana.es/resources/now-that-what-i.html now that what i call music 13] [http://matts-tar.ibelgique.com/lib/melt-snow-wirsbo.html melt snow wirsbo] [http://marlineoreilly.ifrance.com/small/croscill-bedding.html croscill bedding] [http://again-discovering.diglot.in/ again discovering poverty] [http://imp-r0.isuisse.com/topic/parallel-port.html parallel port address 378] [http://latonyawelling.ifrance.com/lib/with-gorgeous.html with gorgeous tits and ass] [http://lucky-absolute.isuisse.com/victorian-era.html victorian era music] [http://tuesday-weld.explisit.in/ tuesday weld] [http://brynnparkey.ifrance.com/stanley-tools.html stanley tools] [http://erickacicero.ifrance.com/andres-raya-video.html andres raya video] [http://demon-dance.ibelgique.com/web/russian-family-nudist.html russian family nudist] [http://iranian-government.holily.in/ iranian government] [http://games-flash.holily.in/ games flash] [http://marlynbarrios.iespana.es/resources/troy-bilt.html troy bilt pressure washer] [http://summerpica.ifrance.com/amazing-grace.html amazing grace lyrics] [http://dakot-ces.isuisse.com/sgt-pepper-cover.html album boxer cover pepper sgt] [http://reaccumulation.kamahi.in/ reaccumulation of fluid] [http://danakrogman.ifrance.com/wiki/dr-bizarro.html dr. bizarro] [http://ebiy-one.ibelgique.com/rikki.html rikki tikki] [http://erlinetor.we.bs/text/solid-helium.html solid helium temperature] [http://tangelaflora.we.bs/shell-reamers.html shell reamers] [http://1x-0007.ibelgique.com/resources/c700-promo.html c700 promo movie] [http://marlineoreilly.ifrance.com/small/miss-nude-mexico.html miss nude mexico] [http://metformin-diabetes.holily.in/ metformin diabetes] [http://latonyawelling.ifrance.com/lib/wire-transfer.html wire transfer us] [http://dagmar.holily.in/ dagmar] [http://marlynbarrios.iespana.es/resources/i-wanna-come-over.html i wanna come over to hell with the consequence] [http://marlineoreilly.ifrance.com/small/action-rpg-online.html action rpg online] [http://summerpica.ifrance.com/viatical-settlements.html settlement viatical] [http://ya-uza.isuisse.com/styles/furniture-parts.html furniture parts] [http://sinking-ship.waunakee.in/ sinking ship] [http://seo-michigan-ohio.diglot.in/ seo michigan ohio]
 
 
<pre>#!/bin/sh
 
<pre>#!/bin/sh
 
# Make a clone from existed knoppix live-cd or dvd
 
# Make a clone from existed knoppix live-cd or dvd

Latest revision as of 12:38, 9 January 2008

#!/bin/sh
# Make a clone from existed knoppix live-cd or dvd

NOFORK=false;
[ -z $REFRESH ] && export REFRESH=true;
[ -z $PHASE ] && export PHASE=10
[ -z "$BEST" ] && export BEST=-b
[ -z $NOSKIPDEBS ] && export NOSKIPDEBS=true;
[ -z $PAUSE ] && export PAUSE=false;
[ -z $DVD ] && export DVD=false;
while true ; do
  case $1 in
    -d) NOFORK=true ;;
    '') if $NOFORK ; then break ; fi
        on_exit() {
	  rm -f CDMAKE$$.tmp
	}
	trap on_exit 0 1 2 3 15
        mkfifo CDMAKE$$.tmp
	tee livecd-make.log <CDMAKE$$.tmp &
	if ! $0 -d 2>CDMAKE$$.tmp ; then
	  echo "WAS ERRORS! See report in livecd-make.log"
	fi
	exit 0 ;;
    unpack) PHASE=1 ;;
    remove) PHASE=2 ;;
    update) PHASE=3 ;;
    patch) PHASE=4 ;;
    quick) BEST=' ' ;;
    dvd) DVD=true ;;
    pause) PAUSE=true ;;
    no-update) NOSKIPDEBS=false ;;
    no-refresh) REFRESH=false; ;;
    *) echo "Usage: $0 [-d] [no-refresh] [no-upate] [quick] [unpack|remove|update|patch]
	unpack	- stop after unpack source distro into ''./new/''
	remove	- stop after remove packages
	update  - stop after install new packages
	patch - stop after patches and scripts
	pause - wait CR after each phase
	quick  - not use ''best'' compression
	dvd - make dvd image - not delete most packages and split root, quick is recommended
	no-update - do not remove & install packages
	no-refresh	- do not remove old ''./new/'' & unpack 
	-d	- do not redirect stderr to logfile"
       exit 1 ;;
  esac
  shift
done

read CDVER DATE < version

date >&2

query() {
    set +x
    echo -n "$1 [$2] " >&2
    read answer
    if [ -z $answer ] ; then answer=$2 ; fi
    set -x
}

set -e -x # Exit if any command fails, print command before execute

if type dialog ; then
gauge() {
    set +x
    lim=$1
    x=1
    while read j ; do 
	echo $(( x++ * 100 / lim )) ; 
    done | dialog --gauge "$2" 8 50
}
elif [ -n "$DISPLAY" ] && type Xdialog ; then
gauge() {
    set +x
    lim=$1
    x=1
    while read j ; do 
	echo $(( x++ * 100 / lim )) ; 
    done | Xdialog --gauge "$2" 8 50
}
else 
gauge() {
    set +x
    #echo $2
    lim=$1
    x=1
    [ -z $COLUMNS ] && COLUMNS=80
    while read j ; do
	echo -ne "\33[2K $(( x++ * 100 / lim ))% ${j:0:$((COLUMNS-5))}\r";
    done
    echo -ne "\33[2K"
}
fi

CSRC=SRC/KNOPPIX/KNOPPIX
UCSRC=KNOPPIX.iso
if [ -b /dev/cdrom ] ; then
  CDROM=/dev/cdrom
  CDRW="0,0,0"
elif [ -b /dev/cdroms/cdrom0 ] ; then
  CDROM=/dev/cdroms/cdrom0
  CDRW=`readlink -f $CDROM`
  CDRW=${CDRW%cd}generic
fi

not_empty() {
  test -n "$1" &&  test -L "$1" -o -e "$1"
}

# Mount knoppix CD or image

if ! [ -s $CSRC ]; then
  query "Knoppix CD or image location" "$CDROM"
  SRC="$answer"
  if ! [ -b $SRC ] ; then LOOP=",loop" ; fi
  [ -d SRC ] || mkdir SRC
  mount -o ro$LOOP $SRC SRC
else
  echo "Comressed image found"
fi
RTSRCZ=( SRC/boot/isolinux/minirt*.gz )

query "Enter default language" us
lang=$answer

if ! [ -s newcd/KNOPPIX/KNOPPIX ] || ! not_empty newcd/boot/isolinux/minirt* ; then

  if ! not_empty new/initrd*/* && not_empty bkinitrd/*/* ; then
    rm -rf new/initrd*/
    mv -f bkinitrd/* new  
  fi
  if ! grep -q "$CDVER" new/etc/knoppix-version 2> /dev/null || ! not_empty new/initrd*/*  ; then
    if [ $PHASE -gt 3 ] ; then
      # test for virtual memory size
      vmemsz=$( expr $( cat /proc/meminfo | grep '[mp]Free' | sed -e 's/.*: *//' -e 's/ k.*/ +/' ) 0 )
      if [ $vmemsz -lt 1200000 ] ; then
        echo "$vmemsz kB free virtual memory detected
	This script needs 1.2GB of memory or swap space to build the CD image.
	If you have enough free space on your hard drive you may 
	safely answer \"yes\" to the following question."
	query "Do you want to use 1.2GB of your disk space for the temporary swap file" yes
	case $answer in
	    [Yy]*)
	    dd if=/dev/zero of=swapfile bs=1M count=1200
	    mkswap swapfile
	    swapon swapfile
	esac
      else
	echo "$vmemsz kB free virtual memory - OK"
      fi
    fi
    # first try to use cloop module
    # Mount inner iso image
    for i in "" 2 3 4 5 ; do
     if ! not_empty UCSRC$i/new/* ; then
      insmod cloop >& /dev/null || true
       test -e $CSRC$i || continue
       [ -d UCSRC$i/new ] || mkdir -p UCSRC$i/new
       if ! ( [ -b /dev/cloop/0 ] &&
	losetup /dev/cloop/$((i+0)) $CSRC$i && mount /dev/cloop/$((i+0)) UCSRC$i/new ) ; then
        # Uncompress inner iso image
        if ! [ -s $UCSRC$i ] ; then
          echo Uncompress image $i...
          extract_compressed_fs $CSRC$i 2>&1 > $UCSRC$i  | 
	    gauge $(( `ls -s $CSRC$i | sed 's/[^0-9 ].*//'` / 23 )) "Uncompress inner image $i..."
        else
          echo "Uncompressed image found"
        fi
        mount -o ro,loop $UCSRC$i UCSRC$i/new
       fi
     else
      echo "Uncompressed image seems to be already mounted"
     fi
    done
    
    read verison j < UCSRC/new/etc/knoppix-version
    KVERS=( `echo UCSRC/new/lib/modules/*.*.* | sed -e 's![^ ]*/!-!g'` )
    
    if [ -d new ] ; then
      umount new/usr/src/debs new/proc || true
      umount new || true
      $REFRESH && rm -rfv new | gauge 135369 "Remove old directory for extracting files"
    fi
    
    if ! [ -d new ]; then
      for i in "" 2 3 4 5 ; do
        [ -e UCSRC$i/new ] || continue
        echo Extract files from the inner image $i
        cp -v -a -u UCSRC$i/new . 2>&1 | gauge 126000 "Extract files from the inner image $i"
      done
    fi

    #Uncompress initrd
    echo "Extract initrd image(s)"
    [ -d RT ] || mkdir RT
    umount RT || true
    for i in "${RTSRCZ[@]}" ; do
      rdimg=${i/*\//}
      rdimg=${rdimg/.gz/}
      gzip -d < $i > $rdimg.orig
      mount -o loop $rdimg.orig RT
      rddir=new/${rdimg/minirt/initrd}
      [ -e $rddir/linuxrc ] && continue
      [ -d $rddir ] && rmdir $rddir
      cp -a RT $rddir
      umount RT
    done

    [ $PHASE -lt 2 ] && exit
    $PAUSE && echo "KNOPPIX root file system unpacked to directory 'new'.
    Next phase deletes some packages and files. Press Enter to continue" && read j
    
#-------------   Modify Live CD --------------
    read j j HOSTKVERS j < /proc/version
    TMPMOD=false
remove() {
    if [ -s $2 ] ; then
	echo "$1 $2"
	eval "local -a lst=( $(cat $2) )"
	[ -z $lst ] && return 0
	chroot new sh -c "$3 ${lst[*]}" || true
    fi
}
update() {
    [ -s "$debs/${1##[^0-9]*}apt-get-list" ] && if chroot . apt-get install `cat $debs/${1##[^0-9]*}apt-get-list` ; then
	true
    else
	case $? in 100)
	    chroot . apt-get -f install
	    chroot . apt-get install `cat $debs/${1##[^0-9]*}apt-get-list`
	    ;;
	*) echo $? ; false
	esac	    
    fi
    aliens=( $debs/$1*.{rpm,tar.gz,tgz} )
    [ -z $aliens ] || chroot . alien "${aliens[@]}"
    local -a lst=( $debs/$1*.deb *.deb )
    [ -s "$lst" ] || return 0
    chroot . dpkg -i --force-overwrite ${lst[@]}
    rm *.deb || true
}
if $NOSKIPDEBS ; then
    if ! [ -d new/lib/modules/$HOSTKVERS ] ; then
        # for buggy packets
        cp -a /lib/modules/$HOSTKVERS new/lib/modules/
	TMPMOD=true
    fi
    if $DVD; then
	remove "Remove packages listed in" debs/00remove-debs-DVD "dpkg -P"
	remove "Remove files listed in" debs/00remove-files-DVD "rm -rf"
    else
	remove "Remove packages listed in" debs/00remove-debs "dpkg -P"
	remove "Remove files listed in" debs/00remove-files "rm -rf"
    fi
    $TMPMOD && rm -rf new/lib/modules/$HOSTKVERS
    
    [ $PHASE -lt 3 ] && exit
    $PAUSE && echo "Some packages and files listed in debs/00remove* are deleted.
     Next phase installs new packages and deletes listed in debs/zzremove*.
     Press Enter to continue" && read j
    
    echo Install new packages
    cd new
    mkdir -p usr/src/debs
    touch etc/fstab
    shopt -s nullglob
    debs=usr/src/debs
    mount --bind ../debs $debs
    mv etc/resolv.conf etc/resolv.conf.orig
    cp /etc/resolv.conf etc/resolv.conf
    if ! chroot . apt-get update -u ; then
	query "Continue" yes
	case $answer in
	    [Yy]*) ;;
	    *) exit 1
	esac
    fi
    
    update 00
    update 01
    update 02
    update '0[^0-2]'
    update '[^0]'
    
    chroot . apt-get -f install -u
    chroot . apt-get clean
    mv etc/resolv.conf.orig etc/resolv.conf
    
    umount usr/src/debs
    rmdir usr/src/debs

    cd ..
    
    NEWKVERS=( `echo new/lib/modules/*.*.* | sed -e 's![^ ]*/!-!g'` )

    if $DVD; then
	remove "Remove packages listed in" debs/zzremove-debs-DVD "dpkg -P"
        remove "Remove files listed in" debs/zzremove-files-DVD "rm -rf"
    else
	remove "Remove packages listed in" debs/zzremove-debs "dpkg -P"
        remove "Remove files listed in" debs/zzremove-files "rm -rf"
    fi
    COLUMNS=140 chroot new dpkg -l > packages.txt

    rm new/etc/fstab || true

fi # $NOSKIPDEBS

    [ $PHASE -lt 4 ] && exit
    $PAUSE && echo "All package add/remove operations is complete
     Next phase try and apply patches placed in 'patches' directory.
     Press Enter to continue" && read j
    
    echo Test patches
    mkdir -p patches-results
    cd new
    set +x
    st=()
    errors=false
    n=0
    for i in ../patches/* ; do
      if [ -d $i ] ; then
       st[$n]=true
      elif [ -x $i ] ; then
        if ! $i --dry-run >& ../patches-results/${i/*\//}-exec; then
	  st[$n]=true
	  errors=true
	else
	  mv ../patches-results/${i/*\//}-exec ../patches-results/${i/*\//}-exec-OK
	fi
      else case "$i" in *.tar.bz2) st[$n]="tar -xjf" ;;
      *)
        if patch -f -p0 --dry-run -i $i >& ../patches-results/${i/*\//}-p0 ; then
         st[$n]="patch -f -p0 -i"
	 mv ../patches-results/${i/*\//}-p0 ../patches-results/${i/*\//}-p0-OK
        elif patch -f -p1 --dry-run -i $i >& ../patches-results/${i/*\//}-p1 ; then
         st[$n]="patch -f -p1 -i"
	 rm ../patches-results/${i/*\//}-p0
	 mv ../patches-results/${i/*\//}-p1 ../patches-results/${i/*\//}-p1-OK
        else
         st[$n]=true
	 errors=true
        fi
      esac fi
      let ++n
    done
    n=0
    echo "Tests results" >&2
    for i in ../patches/* ; do
      echo -ne " ${i/*\//} \t " >&2
      case "${st[$n]}" in
        true) echo ERROR >&2 ;;
        tar*) echo "OK (tar)" >&2 ;;
        *-p0" "*) echo "OK (patch -p0)" >&2 ;;
        *-p1" "*) echo "OK (patch -p1)" >&2 ;;
        '') echo "OK (executable)" >&2 ;;
      esac
      let ++n
    done
    if $errors ; then
      query "Some patches are not applyable, see messages in directory 'patches-results'
Do You want to continue without failed pathes" no
      case "$answer" in [yY]*) ;; *) 
        echo "You may rerun script after corrections with next parameters:
no-update no-refresh"
        exit 1 ;
      esac
    else
      echo "All patches OK">&2
    fi

    echo Applay patches to root file system
    set -x
    n=0
    for i in ../patches/* ; do
      ${st[$n]} $i
      let ++n
    done
    echo Update menus
    #order files in directory
    mkdir etc/menu-methods.new
    mv etc/menu-methods/* etc/menu-methods.new/
    rmdir etc/menu-methods
    mv etc/menu-methods.new etc/menu-methods
    chroot . update-menus -v
    
    echo Update modules in initrd
    
    if [ -x initrd/modules/cloop.ko ] ; then
      SUF=ko
    else
      SUF=o
    fi
    (find initrd/modules -name '*.'$SUF ; cat <<-EOF ;) | while read i ; do
    initrd/modules/floppy.$SUF
    initrd/modules/scsi/usb-ehci.$SUF
    initrd/modules/scsi/usb-uhci.$SUF
    initrd/modules/scsi/usb-ohci.$SUF
    initrd/modules/scsi/usbcore.$SUF
    initrd/modules/scsi/usb_hcd.$SUF
EOF
        b=${i/*\//}
        j=( `find lib/modules/ -name "$b" -or -name "${b/.o/.ko}"` )
	if [ -s "$j" ]; then
	    # [ "$j" -nt "$i" ] && 
	    cp -avf "$j" "$i"
	else
	    b="${b/usb-/}"
	    b="${b/.o/-hcd.o}"
	    j=( `find lib/modules/ -name "$b" -or -name "${b/.o/.ko}"` )
	    if [ -s "$j" ]; then
		cp -avf "$j" "$i"
	    else
	        rm -fv $i
	    fi
	fi
    done
    
    DEFKERNEL=`readlink vmlinuz`
    ln -sf ../vmlinuz boot/vmlinuz
    ln -sf System.map-${DEFKERNEL##*-} boot/System.map
    KH=( usr/src/kernel-headers-* )
    ln -sf ${KH##*/} usr/src/kernel-headers
    echo Update dynamic library cache
    chroot . ldconfig
    echo Update molule dependencies
    for i in boot/System.map-* ; do
      [ -d lib/modules/${i##*-} ] && chroot . depmod -ae -F /$i ${i##*-}
    done
    echo Remove backups
    find . -name '*.orig'  -o -name '*~' | xargs rm -fv

    echo  "$verison-$CDVER $DATE"  > etc/knoppix-version
    cd ..
    rm -rf split?/

  else
    echo Patched Knoppix found
  fi # grep -q "$CDVER" ...
  
  umount UCSRC*/new RT || true
  for i in 0 1 2 3 4 5 ; do
    losetup -d /dev/cloop/$i || true
  done
  rmmod cloop || true

  [ $PHASE -lt 5 ] && exit
  $PAUSE && echo "All changes are complete
     Next phase make new comressed file system image.
     Press Enter to continue" && read j

  echo Make new compressed file system image...
  rm -rf new/.rr_moved $UCSRC*
  if ! not_empty new/inird*/* ; then
    rm -rf bkinitrd
    mkdir -p bkinitrd
    for i in new/initrd* ; do
      mv $i bkinitrd
      mkdir $i
    done
  fi
  umount new/proc || true
  rm -rf new/tmp/*
  
  if $DVD && ! not_empty split?/* ; then
    echo Split the file system ...
    cd new
    du -s opt/* usr/lib/* usr/share/* usr/* * | ../smartsplit.pl 4128768 > ../split-plan
    ##! Names in * must not contain space!
    for i in 0 1 2 3 4 5 6 7 ; do
	files=$( grep ^$i < ../split-plan | cut -d ' ' -f 4- )
	test -z "$files" && break;
	rm -rf ../split$i
	mkdir ../split$i
	cp -al --parents $files ../split$i
    done
    cd ..    
  fi
  mkdir -p newcd/KNOPPIX
  if $DVD; then
    for i in split? ; do
      KN=${i/split/KNOPPIX}
      KN=${KN/0/}
      mkisofs -quiet -hide-rr-moved -R $i |
      create_compressed_fs - $BEST 65536 2>&1 > newcd/KNOPPIX/$KN | gauge 60600 "Make new compressed file system image..."
    done
  else
    mkisofs -quiet -hide-rr-moved -R -U -sort iso-order -pad -x '/inird*/*' new |
    create_compressed_fs - $BEST 65536 2>&1 > newcd/KNOPPIX/KNOPPIX | gauge 30300 "Make new compressed file system image..."
  fi
  rm -rf new/initrd*
  mv bkinitrd/* new
  
else
  echo New compressed file system image found
fi # [ -s newcd/KNOPPIX/KNOPPIX ] ...

echo "Make new initrd"
mkdir -p newcd/boot/isolinux
for i in new/initrd*/ ; do
   DSIZE=`du -s $i`
   OUT=newcd/boot/isolinux/minirt${i##*initrd}
   OUT=${OUT%/}
   dd if=/dev/zero of=$OUT count=$(( ${DSIZE%%[^0-9]*} + 4000 )) bs=1k
   INODES=`ls -R $i | wc -l`
   mke2fs -Fv -N $(( INODES + 6000 )) -m 0 $OUT
   mount -o loop $OUT RT
   rm -rf RT/lost+found
   cp -va $i/* RT/
   umount RT
   gzip -9 $OUT
done
cp -f new/boot/vmlinuz newcd/boot/isolinux/linux
if which rdev; then RDEV=rdev; else RDEV=new/usr/sbin/rdev; fi
$RDEV newcd/boot/isolinux/linux /dev/ram3
umount RT UCSRC*/new new || true
#rm -rf new

echo Make CD image ...

mkdir -p newcd/KNOPPIX/ newcd/m23
touch newcd/KNOPPIX/KNOPPIX2 newcd/m23image.bz2 newcd/mdk.tb2 newcd/m23.tb2\
      newcd/m23/m23_0.4.99_halfBaked-pre3_knoppix.iso
cp -auv SRC/* newcd/
$DVD || rm -rf newcd/*m23* newcd/mdk* newcd/books \
       newcd/boot/isolinux/*m23*
find newcd/KNOPPIX -size 0 | xargs rm -f

i="
s/^KBDMAP german.kbd/#&/"
case "$lang" in de) i="" ;; esac
sed -e "s/lang=[a-z]\+/lang=$lang/$i" SRC/boot/isolinux/isolinux.cfg > newcd/boot/isolinux/isolinux.cfg
umount SRC || true
mkisofs -pad -l -r -J -m Demos -m LinuxTag -m Talks -V "$CDVER" -no-emul-boot \
-boot-load-size 4 -boot-info-table -b boot/isolinux/isolinux.bin \
-c boot/isolinux/boot.cat -hide-rr-moved -o knoppix-$CDVER.iso newcd $FNAME

#rm -rf  KNOPPIX isolinux.cfg isolinux.bin SRC UCSRC* minirt24.gz

echo New CD image in knoppix-$CDVER.iso

query "Do You want to record new CD" no
case "$answer" in
    [yY]*)
    echo "cdrecord -v speed=50 dev=$CDRW driveropts=burnfree -eject knoppix-$CDVER.iso"
    cdrecord -v speed=50 dev=$CDRW driveropts=burnfree -eject knoppix-$CDVER.iso
esac