#!/usr/bin/perl

use MDK::Common;
use lib "../perl-install";
use keyboard;

my $lib = (arch() =~ /x86_64/ ? "lib64" : "lib");
my $tmp = "/tmp/rescue_tmp";
my $rescue = "rescue.clp";

my $sudo = '';
if ($>) {
    $sudo = "sudo";
    $ENV{PATH} = "/sbin:/usr/sbin:$ENV{PATH}";
}

BEGIN { undef *_ }
sub __ { print @_, "\n"; system(@_) }
sub _ { __ @_; $? and die }

sub installown($$) {
    my ($own, $dir) = @_;
    return if -e "$tmp$dir/" . basename($own);
    mkdir_p("$tmp$dir");
    _ "cp -rL $own $tmp$dir";
}

sub install_perl_script {
    my ($script, $dir) = @_;
    my @gi_modules;
    foreach (`../tools/get-needed-drakx-modules ../perl-install /usr/lib/libDrakX $script`) {
	chomp;
	my ($local, $dest) = split "\t";
	installown($local, dirname($dest || $local));
	push @gi_modules, "$tmp$dest" if $dest;
    }    
    installown($script, $dir);
    system('../tools/simplify-drakx-modules', @gi_modules, "$tmp$dir/$script");
}

_ "$sudo rm -rf $tmp" if -e $tmp;
_ "mkdir $tmp";
_ 'find . -name "*~" | xargs rm -f';
mkdir_p($tmp . chomp_($_)) foreach cat_("dirs");
_ "cp -a tree/* $tmp";
_ "find $tmp -name 'CVS*' | xargs rm -rf";
_ "perl devices.pl $tmp/dev";
_ "mkfifo $tmp/dev/initctl";
substInFile { s/DISTRIB_DESCR/$ENV{DISTRIB_DESCR}/ } "$tmp/etc/issue";

{
    _ "cd ../mdk-stage1 && make rescue-gui dhcp-client";
    -e "../kernel/all.kernels" or die "use ./update_kernel in gi/kernel first\n";

    $ENV{MAIN_KERNEL} = chomp_(`cat ../kernel/RPMS/.main`);

    _ "../tools/install-xml-file-list list.xml $tmp";
}

my %keytable_conflicts;
my @less_important_keytables = qw(am_old am_phonetic no-dvorak fr_CH-latin1);
foreach (keyboard::loadkeys_files()) {
    my ($dir, $fname) = (dirname($_), basename($_));
    my ($name) = $fname =~ /(.*)\.kmap\.gz/ or next;
    next if member($name, @less_important_keytables);
    if (my ($short) = $name =~ m|(.+?)[\W_]|) {
	$keytable_conflicts{$short} and warn("conflict between $keytable_conflicts{$short} and $name for short name $short (choosing the first)\n"), next;
	$keytable_conflicts{$short} = $name;
	# create the short name based on the long one
	symlinkf($fname, "$tmp$dir/$short.kmap.gz");
    }
}

foreach (cat_("aliases")) {
    chomp; my ($f, $dest) = split;
    symlink $dest, "$tmp$f";
}


if (my ($LANGUAGE) = map { if_(/LANGUAGE_(.*)/, $1) } keys %ENV) {
    substInFile {
	$_ = "export LANGUAGE=$LANGUAGE\n" . "export LC_ALL=$LANGUAGE\n" if /^#LANGUAGE/;	
    } "$tmp/etc/rc.sysinit";
}

if ($ENV{PARTIMAGE_RPM}) {

    _ "rpm2cpio $ENV{PARTIMAGE_RPM} | (cd $tmp ; cpio -idu ./usr/sbin/partimage)";
    my $server = 'partimaged';
    $server = 'leia';

    my $default_dir = '/data/box';
    my $partimage_dir = $ENV{PARTIMAGE_DIR} || $default_dir;
    my @local_dirs = map { "/tmp/image$_" } split(' ', $partimage_dir);
    my $local_dir = $local_dirs[0];
    my $local_dirs = join(' ', @local_dirs);

    substInFile {
	$_ = <<EOF if /^\s*rescue-gui/;
  if grep -q save_all /proc/cmdline; then
      partimage_whole_disk -s $server save_all $default_dir
  fi
  if grep -q rest_all /proc/cmdline; then
      if [ -d $local_dir ]; then
          partimage_whole_disk rest_all $local_dirs
      else
          partimage_whole_disk -s $server rest_all $partimage_dir
      fi
  fi
EOF
    } "$tmp/etc/rc.sysinit";
}

_ "$sudo chown root.root -R $tmp/*";

exit 0 if $ARGV[0];

_ "mkisofs -quiet -D -R $tmp | create_compressed_fs - 65536 $rescue 200 2>/dev/null";
#_ "$sudo rm -rf $tmp";
ic/switching_to_urpmi'>topic/switching_to_urpmi</option>
<option value='topic/unlabeled-1.1.1'>topic/unlabeled-1.1.1</option>
<option value='topic/v_webmin_0_87'>topic/v_webmin_0_87</option>
<option value='topic/x86_64-branch'>topic/x86_64-branch</option>
<option value='user/animtim/designWork'>user/animtim/designWork</option>
<option value='user/colin/rescue-systemd'>user/colin/rescue-systemd</option>
<option value='user/ennael/mga6'>user/ennael/mga6</option>
<option value='user/erwan/bug-13680'>user/erwan/bug-13680</option>
<option value='user/jibz/aarch64'>user/jibz/aarch64</option>
<option value='user/martinw/mga6'>user/martinw/mga6</option>
<option value='user/pterjan/arm64'>user/pterjan/arm64</option>
</select> <input type='submit' value='switch'/></form></td></tr>
<tr><td class='sub'>Mageia Installer and base platform for many utilities</td><td class='sub right'>Thierry Vignaud [tv]</td></tr></table>
<table class='tabs'><tr><td>
<a href='/software/drakx/?h=13.20'>summary</a><a href='/software/drakx/refs/?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628'>refs</a><a href='/software/drakx/log/perl-install?h=13.20'>log</a><a href='/software/drakx/tree/perl-install?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628'>tree</a><a class='active' href='/software/drakx/commit/perl-install?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628'>commit</a><a href='/software/drakx/diff/perl-install?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628'>diff</a><a href='/software/drakx/stats/perl-install?h=13.20'>stats</a></td><td class='form'><form class='right' method='get' action='/software/drakx/log/perl-install'>
<input type='hidden' name='h' value='13.20'/><input type='hidden' name='id' value='81e56d63ebae2009dec2336065e21bc178faa628'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/software/drakx/commit/?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628'>root</a>/<a href='/software/drakx/commit/perl-install?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628'>perl-install</a></div><div class='content'><div class='cgit-panel'><b>diff options</b><form method='get'><input type='hidden' name='h' value='13.20'/><input type='hidden' name='id' value='81e56d63ebae2009dec2336065e21bc178faa628'/><table><tr><td colspan='2'/></tr><tr><td class='label'>context:</td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><table summary='commit info' class='commit-info'>
<tr><th>author</th><td>Willy Sudiarto Raharjo &lt;willysr@mandriva.com&gt;</td><td class='right'>2006-01-18 10:25:08 +0000</td></tr>
<tr><th>committer</th><td>Willy Sudiarto Raharjo &lt;willysr@mandriva.com&gt;</td><td class='right'>2006-01-18 10:25:08 +0000</td></tr>
<tr><th>commit</th><td colspan='2' class='sha1'><a href='/software/drakx/commit/perl-install?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628'>81e56d63ebae2009dec2336065e21bc178faa628</a> (<a href='/software/drakx/patch/perl-install?id=81e56d63ebae2009dec2336065e21bc178faa628'>patch</a>)</td></tr>
<tr><th>tree</th><td colspan='2' class='sha1'><a href='/software/drakx/tree/?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628'>6567c339866c3b2146c5d59c7698601e19ed59ac</a> /<a href='/software/drakx/tree/perl-install?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628'>perl-install</a></td></tr>
<tr><th>parent</th><td colspan='2' class='sha1'><a href='/software/drakx/commit/perl-install?h=13.20&amp;id=2f9e1a09c12a6f8cef47d08f8700a69c7eb1ab79'>2f9e1a09c12a6f8cef47d08f8700a69c7eb1ab79</a> (<a href='/software/drakx/diff/perl-install?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628&amp;id2=2f9e1a09c12a6f8cef47d08f8700a69c7eb1ab79'>diff</a>)</td></tr><tr><th>download</th><td colspan='2' class='sha1'><a href='/software/drakx/snapshot/drakx-81e56d63ebae2009dec2336065e21bc178faa628.tar'>drakx-81e56d63ebae2009dec2336065e21bc178faa628.tar</a><br/><a href='/software/drakx/snapshot/drakx-81e56d63ebae2009dec2336065e21bc178faa628.tar.gz'>drakx-81e56d63ebae2009dec2336065e21bc178faa628.tar.gz</a><br/><a href='/software/drakx/snapshot/drakx-81e56d63ebae2009dec2336065e21bc178faa628.tar.bz2'>drakx-81e56d63ebae2009dec2336065e21bc178faa628.tar.bz2</a><br/><a href='/software/drakx/snapshot/drakx-81e56d63ebae2009dec2336065e21bc178faa628.tar.xz'>drakx-81e56d63ebae2009dec2336065e21bc178faa628.tar.xz</a><br/><a href='/software/drakx/snapshot/drakx-81e56d63ebae2009dec2336065e21bc178faa628.zip'>drakx-81e56d63ebae2009dec2336065e21bc178faa628.zip</a><br/></td></tr></table>
<div class='commit-subject'>Updated</div><div class='commit-msg'></div><div class='diffstat-header'><a href='/software/drakx/diff/?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628'>Diffstat</a> (limited to 'perl-install')</div><table summary='diffstat' class='diffstat'><tr><td class='mode'>-rw-r--r--</td><td class='upd'><a href='/software/drakx/diff/perl-install/share/po/id.po?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628'>perl-install/share/po/id.po</a></td><td class='right'>45</td><td class='graph'><table summary='file diffstat' width='45%'><tr><td class='add' style='width: 60.0%;'/><td class='rem' style='width: 40.0%;'/><td class='none' style='width: 0.0%;'/></tr></table></td></tr>
</table><div class='diffstat-summary'>1 files changed, 27 insertions, 18 deletions</div><table summary='diff' class='diff'><tr><td><div class='head'>diff --git a/perl-install/share/po/id.po b/perl-install/share/po/id.po<br/>index 54ba1f8fd..61386831e 100644<br/>--- a/<a href='/software/drakx/tree/perl-install/share/po/id.po?h=13.20&amp;id=2f9e1a09c12a6f8cef47d08f8700a69c7eb1ab79'>perl-install/share/po/id.po</a><br/>+++ b/<a href='/software/drakx/tree/perl-install/share/po/id.po?h=13.20&amp;id=81e56d63ebae2009dec2336065e21bc178faa628'>perl-install/share/po/id.po</a></div>