#!/usr/bin/perl die "usage: create [-test ] [ -restart ] rpm_dir build_dir rpm_list\n" unless $#ARGV >= 2; # Check for test if ($ARGV[0] eq '-test') { $test = '--justdb --noscripts --notriggers'; shift; } else { $test = ''; } # Check for restart if ($ARGV[0] eq '-restart') { $restart = 1; shift; } else { $restart = 0; } # Where to find the RPMS $rpm_dir = shift; die "invalid rpm_dir specified\n" unless (-d $rpm_dir); # Where the disk image is to be built: $build_dir = shift; die "invalid build_dir specified\n" unless (-d $build_dir); # The list of RPMS to install: $rpm_list = shift; die "invalid rpm_list specified\n" unless (-f $rpm_list); unless ($restart) { print "# Removing the old root\n"; system ("rm -rf $build_dir"); system ("mkdir $build_dir"); print "# Initializing the RPM database\n"; system ("mkdir -p $build_dir/var/lib/rpm"); system ("rpm --initdb --root=$build_dir"); print "# Removing old log files\n"; system ("rm -f todo"); system ("rm -f done"); } print "# Installing RPMS now. No errors allowed!\n"; # Open the files if ($restart) { system ("cp -f todo /var/tmp/todo.$$"); $rpm_list = "/var/tmp/todo.$$"; open DONE, ">>done"; } else { open DONE, ">done"; } open LIST, "<$rpm_list"; sub died { my $done = $_[0]; open TODO, ">todo"; print TODO $done; while () { print TODO $_; } close TODO; close LIST; close DONE; unlink "/var/tmp/todo.$$" if ($restart); die; } while () { $done = $_; chomp; # Run a script if encountered # convention is to always have them in /root of # the build image root. if (m/^(###--->>> )(.*$)/) { if ( -x "$build_dir/root/$2" ) { print "# Running: $build_dir/root/$2\n"; system ("chroot $build_dir /root/$2"); # system ("rm -f $build_dir/$2"); } } # Skip comments if (m/^\s*#/) { print "$_\n"; print DONE $done; next; } print "Installing $_\n"; die unless(m/^\S+/); $rpm = $&; $options = "$' $test"; if (! (-f "$rpm_dir/$rpm")) { print "Missing rpm: $rpm_dir/$rpm\n"; died($done); } if (system ("rpm --root=$build_dir -i $rpm_dir/$rpm $options")) { died($done); } print DONE $done; } close LIST; close DONE; unlink "/var/tmp/todo.$$" if ($restart); print "# Install Done. Remember to properly edit your fstab file!!!\n";