From: <ale...@us...> - 2003-12-06 15:49:58
|
Update of /cvsroot/morphix/morph-scripts In directory sc8-pr-cvs1:/tmp/cvs-serv25384 Modified Files: minimod-gen.pl Added Files: debwrap Log Message: adding debootstrap wrapper, minimod-gen changes --- NEW FILE: debwrap --- #!/bin/sh # Mainmodule generator/Debootstrap wrapper #, not unlike the great yet underrated minimod generator # Do note that this one is non-interactive. It's quicker and I'm lazy # # Uses debootstrap to make a new mainmodule, depending on arguments given # # Copyright Alex de Landgraaf, 2003 <alextreme at xs4all dot nl> # licensed under the GNU GPL v2, see www.gnu.org for details # With thanks to the makers of the ABS guide usage() { echo "Usage:" echo echo "debwrap -d /file/newdir [SUITE [ MIRROR] ]" echo " - debootstrap new directory, apply changes for mainmodule, don't build one" echo "debwrap -c /file/newdir MainModule-fubar.mod [SUITE [ MIRROR] ]" echo " - same as '-d', but also create a mainmodule from the directory" echo echo "debwrap -dl /file/newdir /file/packagelist [SUITE [ MIRROR] ]" echo " - same as '-d', but apt-get every file in the package list" echo " (newline seperated list of debian packages)" echo "debwrap -cl /file/packagelist /file/newdir MainModule-fubar.mod [SUITE [ MIRROR] ]" echo " - '-dl' and '-c' combined, you get the drill" echo echo "debwrap -dls /file/newdir /file/packagelist [SUITE [ MIRROR] ]" echo " - same as '-dl', but also copies your /etc/apt/sources.list over" echo "debwrap -cls /file/packagelist /file/newdir MainModule-fubar.mod [SUITE [ MIRROR] ]" echo " - guess :)" } if [ $# -eq 0 ] || [[ $1 != "-d" && $1 != "-c" && $1 != "-dl" && $1 != "-cl" && $1 != "-dls" && $1 != "-cls" && $1 != "-apt-get-list" ]] then usage fi MYNAME=$0 run_chrooted_apt() { cp $MYNAME $1/debwrap cp $2 $1/apt-list chroot $1/ sh ./debwrap -apt-get-list ./apt-list rm $1/apt-list rm $1/debwrap } # takes the directory to setup as first argument # suite (woody/sarge/sid) as second # mirror as third (not needed) debootstrap_setup() { mkdir $1 debootstrap $2 $1 $3 mkdir $1/MorphixCD rmdir $1/initrd rmdir $1/opt rmdir $1/tmp ln -s var/tmp $1/tmp mkdir $1/morphix if [[ $3 != "" ]] then echo "deb $3 $2 main contrib non-free" >> $1/etc/apt/sources.list else echo "deb http://ftp.debian.org/debian/ $2 main contrib non-free" >> $1/etc/apt/sources.list fi echo "#!/bin/sh" >> $1/morphix/loadmod.sh echo "echo \"Chrooting to MainModule\"" >> $1/morphix/loadmod.sh echo "chroot /mnt/main sh /morphix/init.sh" >> $1/morphix/loadmod.sh echo "#!/bin/sh" >> $1/morphix/init.sh echo "# Put stuff to load at boottime here" >> $1/morphix/init.sh echo "$2" >> $1/morphix/main_module echo "This module has been automatically generated by debwrap" >> $1/morphix/main_module echo "This module has been automatically generated by debwrap" >> $1/morphix/README echo "Put any info for morphers here. For morphix stuff see www.morphix.org" >> $1/morphix/README } # takes the directory to setup as first argument # suite (woody/sarge/sid) as second (not needed) # mirror as third (not needed) do_debootstrap() { if [[ $2 != "woody" && $2 != "sarge" && $2 != "sid" ]] then debootstrap_setup $1 "sid" $3 else debootstrap_setup $1 $2 $3 fi } build_module() { mkisofs -R -U -V "Morphix" -P "Morphix" -hide-rr-moved -cache-inodes -no-bak -pad $1 | nice -5 create_compressed_fs - 65536 > $2 } libX_patch() { mkdir usr/lib/backup mv usr/lib/libGL.* usr/lib/backup mkdir usr/X11R6/lib/backup mv usr/X11R6/lib/libGL.* usr/X11R6/lib/backup/ mkdir usr/X11R6/lib/modules/extensions/backup mv usr/X11R6/lib/modules/extensions/libGLcore.a usr/X11R6/lib/modules/extensions/backup/ mv usr/X11R6/lib/modules/extensions/libglx.a usr/X11R6/lib/modules/extensions/backup/ } add_sources() { cp /etc/apt/sources.list $1/etc/apt/sources.list } ### start of selectors ### # flag directory [suite [ mirror ]] if [[ $1 == "-d" && $2 != "" ]] then do_debootstrap $2 $3 $4 fi ### should only be used by the script itself, will cause chaos otherwise ### # this is run while chrooted in the fresh debootstrap # also attempts to patch libX *FIXME* # flag file-list # we could use some kind of xml file to add/remove packages... if [[ $1 == "-apt-get-list" && $2 != "" ]] then apt-get update while read line do if [ $line == *REMOVE ] then {$line/REMOVE/} apt-get purge $line else apt-get --yes install $line fi done < $2 apt-get clean libX_patch fi # flag directory modulename.mod [suite [ mirror ]] if [[ $1 == "-c" && $2 != "" && $3 != "" ]] then do_debootstrap $2 $4 $5 build_module $2 $3 fi # flag directory packagelist [suite [ mirror ]] if [[ $1 == "-dl" && $2 != "" && $3 != "" ]] then do_debootstrap $2 $4 $5 run_chrooted_apt $2 $3 fi # flag directory packagelist modulename.mod [suite [ mirror ]] if [[ $1 == "-cl" && $2 != "" && $3 != "" && $4 != "" ]] then do_debootstrap $2 $5 $6 run_chrooted_apt $2 $3 build_module $2 $4 fi # flag directory packagelist [suite [ mirror ]] if [[ $1 == "-dls" && $2 != "" && $3 != "" ]] then do_debootstrap $2 $4 $5 add_sources $2 run_chrooted_apt $2 $3 fi # flag directory packagelist modulename.mod [suite [ mirror ]] if [[ $1 == "-cls" && $2 != "" && $3 != "" && $4 != "" ]] then do_debootstrap $2 $5 $6 add_sources $2 run_chrooted_apt $2 $3 build_module $2 $4 fi Index: minimod-gen.pl =================================================================== RCS file: /cvsroot/morphix/morph-scripts/minimod-gen.pl,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** minimod-gen.pl 24 Sep 2003 23:20:21 -0000 1.3 --- minimod-gen.pl 6 Dec 2003 15:49:55 -0000 1.4 *************** *** 21,28 **** our $moddir; ! our @cmdlist; our %filelist; our @deblist; ! our @deblist_list; our @debfiles_list; --- 21,32 ---- our $moddir; ! ! # option 1: copy our %filelist; + # option 2: cmd + our @cmdlist; + # option 3: deb our @deblist; ! # option 4: deblist our @deblist_list; our @debfiles_list; *************** *** 31,34 **** --- 35,40 ---- our @loclist; our @localfilelist; + # option 5: homedir + our $homedir; if ($> != 0) { *************** *** 39,42 **** --- 45,111 ---- main(); + sub main { + our $type; + our $ret; + + print ("\n\tWelcome to the interactive Morphix minimodule generator\n\n"); + + # Check necessary programs (create_compressed_fs, mkisofs) + + my $ccfs = qx|which create_compressed_fs 2>&1|; + my $mkisofs = qx|which mkisofs 2>&1|; + + if (($ccfs =~ /no create_compressed_fs in/) || ($mkisofs =~ /no mkisofs in/)) { + die("Can't find create_compressed_fs and / or mkisofs, install these to run the minimodule generator\n"); + } + + do { + $ret = setup_new_module(); + } while $ret != 1; + + do { + print("Please add an action to the minimodule:\n"); + print("1) Copy a file/dir to the mainmod at boot, or overwrite one if it exists\n"); + print("2) Enter a command to be executed at boot\n"); + print("3) Enter one or more debian packages to be added (experimental, needs dpkg-deb)\n"); + print("4) Enter a filename containing a list of debian packages to download and add\n"); + print("5) Enter a directories name, all files in it will be available in morph's homedir\n"); + print("9) Build the module and exit\n"); + print("0) Abort without building the module\n\n"); + print("> "); + chomp($type = <STDIN>); + print("\n"); + + if ($type == 1) { + add_copy(); + } + if ($type == 2) { + add_cmd(); + } + if ($type == 3) { + add_deb(); + } + if ($type == 4) { + add_deblist(); + } + if ($type == 5) { + add_homedir(); + } + if ($type == 9) { + generate_module(); + print("The generator will now exit\n"); + exit 1; + } + if ($type == 0) { + print "Aborted..."; + exit 1; + } + } + while (1); + exit 0; + } + + # done before the GUI is shown, used as work directory + sub setup_new_module { our $i; *************** *** 70,73 **** --- 139,201 ---- } + ### start option section ### + + # first option: copy a directory over at boottime + + sub add_copy { + our $src; + our $dest; + our $input; + + while(1) { + print "Enter a filename to be included (the new file), newline to stop\n"; + print "> "; + chomp($src = <STDIN>); + print "\n"; + if ($src eq "") { + last; + } + if (!(-e $src)) { + print "Can't find $src, lets try again\n"; + redo; + } + + print "Enter in which dir it will be placed, or what file it will replace (with path!)\n"; + print "> "; + chomp($dest = <STDIN>); + print "\n\n"; + + $filelist{"$src"} = "$dest"; + + our $break = ""; + while ($break eq "") { + print "Do you want to add another file? (or l for list)\n"; + print "y/N/l > "; + chomp($input = <STDIN>); + if ($input eq "y" || $input eq "Y") { + $break = "false"; + } + if ($input eq "n" || $input eq "N" || $input eq "") { + $break = "true"; + } + if ($input eq "l" || $input eq "L") { + while (($src,$dest) = each(%filelist)) { + print("Source: $src Destination: $dest\n"); + } + print "\n"; + } + }; + if ($break eq "true") { + last; + } + } + + if (keys %filelist == 0) { + print "No files were entered..."; + } + } + + # second option: execute a command at boottime + sub add_cmd { our $cmd; *************** *** 111,147 **** } } - sub add_deblist { - our $src; - our $input; - our $line; - - while(1) { - print "Enter a filename containing a list of debian packages\n"; - print "All packages in this list will be downloaded from your apt\n"; - print "mirror in /etc/apt/sources.list and unpacked into a minimod\n"; - print "Make sure you have apt-get update && apt-get upgrade ed your system\n"; - print "> "; - chomp($src = <STDIN>); - print "\n"; - if ($src eq "") { - last; - } - if (!(-e $src)) { - print "Can't find $src, lets try again\n"; - redo; - } - else { - last; - } - } - open(SOURCE, "< $src") - or die "Couldn't open $src for reading: $!\n"; ! while(defined ($line = <SOURCE>)) { ! chomp $line; ! @deblist_list = (@deblist_list,$line); ! } ! close(SOURCE); ! } sub add_deb { --- 239,244 ---- } } ! # third option: extract a debian package and overlay it at boottime sub add_deb { *************** *** 194,204 **** } } ! sub add_copy { our $src; - our $dest; our $input; while(1) { ! print "Enter a filename to be included (the new file), newline to stop\n"; print "> "; chomp($src = <STDIN>); --- 291,308 ---- } } ! ! # forth option: overlay a set of debian packages, which are found & downloaded ! # using the hosts source.list ! ! sub add_deblist { our $src; our $input; + our $line; while(1) { ! print "Enter a filename containing a list of debian packages\n"; ! print "All packages in this list will be downloaded from your apt\n"; ! print "mirror in /etc/apt/sources.list and unpacked into a minimod\n"; ! print "Make sure you have apt-get update && apt-get upgrade ed your system\n"; print "> "; chomp($src = <STDIN>); *************** *** 206,327 **** if ($src eq "") { last; ! } if (!(-e $src)) { print "Can't find $src, lets try again\n"; redo; } ! ! print "Enter in which dir it will be placed, or what file it will replace (with path!)\n"; ! print "> "; ! chomp($dest = <STDIN>); ! print "\n\n"; ! ! $filelist{"$src"} = "$dest"; ! ! our $break = ""; ! while ($break eq "") { ! print "Do you want to add another file? (or l for list)\n"; ! print "y/N/l > "; ! chomp($input = <STDIN>); ! if ($input eq "y" || $input eq "Y") { ! $break = "false"; ! } ! if ($input eq "n" || $input eq "N" || $input eq "") { ! $break = "true"; ! } ! if ($input eq "l" || $input eq "L") { ! while (($src,$dest) = each(%filelist)) { ! print("Source: $src Destination: $dest\n"); ! } ! print "\n"; ! } ! }; ! if ($break eq "true") { last; } } ! if (keys %filelist == 0) { ! print "No files were entered..."; } ! } ! sub build_module { ! our $outfile; ! our $input; ! FILENAME: ! print "Enter the output filename of the module (MorphixMini-foo-bar.mod):\n"; ! print "> "; ! chomp ($outfile = <STDIN>); ! if (-e $outfile) { ! print "This file exists! Are you sure?\n"; ! print "y/N > "; ! chomp ($input = <STDIN>); ! if ($input ne "y" && $input ne "Y") { ! goto FILENAME; } } - print "Building module, please wait...\n"; - system "mkisofs -R -U -V \"Morphix Mini\" -P \"Morphix\" -hide-rr-moved -cache-inodes -no-bak -pad $_[0] | nice -5 create_compressed_fs - 65536 > $outfile"; } ! sub main { ! our $type; ! our $ret; ! ! print ("\n\tWelcome to the interactive Morphix minimodule generator\n\n"); ! ! # Check necessary programs (create_compressed_fs, mkisofs) ! ! my $ccfs = qx|which create_compressed_fs 2>&1|; ! my $mkisofs = qx|which mkisofs 2>&1|; ! ! if (($ccfs =~ /no create_compressed_fs in/) || ($mkisofs =~ /no mkisofs in/)) { ! die("Can't find create_compressed_fs and / or mkisofs, install these to run the minimodule generator\n"); ! } ! ! do { ! $ret = setup_new_module(); ! } while $ret != 1; ! do { ! print("Please add an action to the minimodule:\n"); ! print("1) Copy a file/dir to the mainmod at boot, or overwrite one if it exists\n"); ! print("2) Enter a command to be executed at boot\n"); ! print("3) Enter one or more debian packages to be added (experimental, needs dpkg-deb)\n"); ! print("4) Enter a filename containing a list of debian packages to download and add\n"); ! print("5) Build the module and exit\n"); ! print("0) Abort without building the module\n\n"); ! print("> "); ! chomp($type = <STDIN>); ! print("\n"); ! ! if ($type == 1) { ! add_copy(); ! } ! if ($type == 2) { ! add_cmd(); ! } ! if ($type == 3) { ! add_deb(); ! } ! if ($type == 4) { ! add_deblist(); ! } ! if ($type == 5) { ! generate_module(); ! print("The generator will now exit\n"); ! exit 1; ! } ! if ($type == 0) { ! print "Aborted..."; ! exit 1; ! } ! } ! while (1); ! exit 0; ! } sub get_repos { --- 310,359 ---- if ($src eq "") { last; ! } if (!(-e $src)) { print "Can't find $src, lets try again\n"; redo; } ! else { last; } } + open(SOURCE, "< $src") + or die "Couldn't open $src for reading: $!\n"; ! while(defined ($line = <SOURCE>)) { ! chomp $line; ! @deblist_list = (@deblist_list,$line); } ! close(SOURCE); ! } ! # fifth option: use a directory as homedir ! sub add_homedir { ! our $src; ! our $input; ! while(1) { ! print "Enter a dir to use as homedirectory, newline to stop\n"; ! print "> "; ! chomp($src = <STDIN>); ! print "\n"; ! if ($src eq "") { ! last; ! } ! if (!(-e $src)) { ! print "Can't find $src, lets try again\n"; ! redo; } + + $homedir = $src; + last; } } ! ### end option section ### ! # gets the list of repositories in /etc/apt/sources.list sub get_repos { *************** *** 348,351 **** --- 380,385 ---- } + # gets the list of packages to be downloaded + sub download_list { our $package = $_[0]; *************** *** 380,383 **** --- 414,419 ---- } + # actually download the debs necessary + sub download_debs { our $item; *************** *** 452,460 **** print "Select the main module for which this mini module will be generated:\n"; print "1) LightGUI\n"; ! print "2) HeavyGUI\n"; ! print "3) Gamer\n"; ! print "4) Bare\n"; ! print "5) ALL (generic minimodule, works on everything :o)\n"; ! print "6) Enter your own\n"; print "[1-5] > "; chomp($input = <STDIN>); --- 488,497 ---- print "Select the main module for which this mini module will be generated:\n"; print "1) LightGUI\n"; ! print "2) Gnome\n"; ! print "3) KDE\n"; ! print "4) Gamer\n"; ! print "5) Bare\n"; ! print "6) ALL (generic minimodule, works on everything :)\n"; ! print "7) Enter your own\n"; print "[1-5] > "; chomp($input = <STDIN>); *************** *** 466,480 **** } if ($input == 3) { ! $maintag = "Gamer\n"; } if ($input == 4) { ! $maintag = "Bare\n"; } if ($input == 5) { ! $maintag = "ALL\n"; } if ($input == 6) { while ($maintag eq "") { ! print "Enter the /morphix/main_module tag, or ALL for all main modules\nMake sure the tag is exactly correct! "; print "> "; chomp($maintag = <STDIN>); --- 503,520 ---- } if ($input == 3) { ! $maintag = "KDE\n"; } if ($input == 4) { ! $maintag = "Gamer\n"; } if ($input == 5) { ! $maintag = "Bare\n"; } if ($input == 6) { + $maintag = "ALL\n"; + } + if ($input == 7) { while ($maintag eq "") { ! print "Enter the /morphix/main_module tag, or ALL for all main modules\nMake sure the tag is exactly correct, otherwise the module won't load! "; print "> "; chomp($maintag = <STDIN>); *************** *** 514,525 **** --- 554,572 ---- print OUT "#!/bin/sh\n\#\n# This file has been generated by minimod-gen.pl\n\n"; + ### the copy option + while (($src,$dest) = each(%filelist)) { $basename = (split/\//,$src)[-1]; print OUT "cp -a \"\$1\"/morphix/files/$basename $dest\n"; } + + ### the cmd/execute option + foreach $cmd (@cmdlist) { print OUT "$cmd\n"; } + ### the debianpackage list option + if (scalar @deblist_list != 0) { mkdir ("$moddir/morphix/deb",0755) || die "cannot mkdir $moddir/morphix/deb: $!"; *************** *** 573,576 **** --- 620,626 ---- elsif (scalar @deblist != 0) { mkdir ("$moddir/morphix/deb",0755) || die "cannot mkdir $moddir/morphix/deb: $!"; + + ### the single-deb option + foreach $src (@deblist) { system "dpkg-deb -x $src $moddir/morphix/deb/"; *************** *** 578,581 **** --- 628,642 ---- print OUT "cp -as \"\$1\"/morphix/deb/* /var/tmp/trans/\n"; } + + ### homedir copy option + + if ($homedir ne "") { + system("cp -r $homedir $moddir/homedir"); + print OUT "cp -r \"\$1\"/homedir/.[a-zA-Z]* /home/morph/\n"; + print OUT "cp -r \"\$1\"/homedir/* /home/morph\n"; + print OUT "cp -r \"\$1\"/homedir/.[a-zA-Z]* /etc/skel/\n"; + print OUT "cp -r \"\$1\"/homedir/* /etc/skel\n"; + print OUT "chown -R morph.users /home/morph\n"; + } print OUT "\necho \"MiniModule loaded\""; close OUT; *************** *** 594,596 **** --- 655,680 ---- build_module($moddir); + } + + # builds the final module + + sub build_module { + our $outfile; + our $input; + + FILENAME: + print "Enter the output filename of the module (MorphixMini-foo-bar.mod):\n"; + print "> "; + chomp ($outfile = <STDIN>); + + if (-e $outfile) { + print "This file exists! Are you sure?\n"; + print "y/N > "; + chomp ($input = <STDIN>); + if ($input ne "y" && $input ne "Y") { + goto FILENAME; + } + } + print "Building module, please wait...\n"; + system "mkisofs -R -U -V \"Morphix Mini\" -P \"Morphix\" -hide-rr-moved -cache-inodes -no-bak -pad $_[0] | nice -5 create_compressed_fs - 65536 > $outfile"; } |