| 1 |
lange |
2 |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
# $Id$ |
| 4 |
|
|
#********************************************************************* |
| 5 |
|
|
# |
| 6 |
lange |
534 |
# install_packages -- read package config and install packages via apt-get |
| 7 |
lange |
2 |
# |
| 8 |
|
|
# This script is part of FAI (Fully Automatic Installation) |
| 9 |
lange |
595 |
# (c) 2000-2001, Thomas Lange, lange@informatik.uni-koeln.de |
| 10 |
lange |
2 |
# |
| 11 |
|
|
#********************************************************************* |
| 12 |
|
|
# This program is free software; you can redistribute it and/or modify |
| 13 |
|
|
# it under the terms of the GNU General Public License as published by |
| 14 |
|
|
# the Free Software Foundation; either version 2 of the License, or |
| 15 |
|
|
# (at your option) any later version. |
| 16 |
|
|
# |
| 17 |
|
|
# This program is distributed in the hope that it will be useful, but |
| 18 |
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 |
|
|
# General Public License for more details. |
| 21 |
|
|
# |
| 22 |
|
|
# You should have received a copy of the GNU General Public License |
| 23 |
|
|
# along with this program; see the file COPYING. If not, write to the |
| 24 |
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 25 |
|
|
# MA 02111-1307, USA. |
| 26 |
|
|
#********************************************************************* |
| 27 |
|
|
|
| 28 |
|
|
# PRELOAD feature from Thomas Gebhardt <gebhardt@hrz.uni-marburg.de> |
| 29 |
|
|
|
| 30 |
lange |
595 |
# main part |
| 31 |
lange |
2 |
$| = 1; |
| 32 |
lange |
753 |
# order of commands to execute |
| 33 |
|
|
@commands = qw/taskinst install remove dselect-upgrade/; |
| 34 |
|
|
%command = ( |
| 35 |
|
|
install => 'apt-get -y --fix-missing install', |
| 36 |
|
|
remove => 'apt-get -y --purge remove', |
| 37 |
|
|
"dselect-upgrade" => 'apt-get -y dselect-upgrade', |
| 38 |
|
|
"taskinst" => 'tasksel -n install', |
| 39 |
lange |
2 |
); |
| 40 |
|
|
|
| 41 |
lange |
534 |
# currently no test, always execute |
| 42 |
|
|
$test = 0; |
| 43 |
|
|
|
| 44 |
lange |
2 |
$verbose=$ENV{verbose}; |
| 45 |
|
|
$FAI_ROOT = $ENV{FAI_ROOT}; |
| 46 |
|
|
$classpath = "/fai/package_config"; |
| 47 |
lange |
753 |
$rootcmd = ($FAI_ROOT eq "/" ) ? '' : "chroot $FAI_ROOT"; |
| 48 |
lange |
902 |
@classes = grep { !/^#|^\s*$/ } split(/[\s\n]+/,$ENV{classes}); |
| 49 |
lange |
2 |
|
| 50 |
lange |
311 |
# read all package config files |
| 51 |
lange |
335 |
foreach (@classes) { |
| 52 |
lange |
106 |
my $filename = "$classpath/$_"; |
| 53 |
lange |
2 |
&readconfig($filename) if -f $filename; |
| 54 |
|
|
} |
| 55 |
|
|
|
| 56 |
lange |
311 |
# get file, which must exist before installing packages |
| 57 |
lange |
595 |
foreach $entry (@preloadlist,@preloadrmlist) { |
| 58 |
lange |
2 |
my ($url, $directory) = @$entry; |
| 59 |
lange |
513 |
execute("wget -nv -P$FAI_ROOT/$directory $url"); |
| 60 |
lange |
2 |
} |
| 61 |
|
|
|
| 62 |
lange |
753 |
# call apt-get or tasksel for each type of command whith the list of packages |
| 63 |
|
|
foreach $type (@commands) { |
| 64 |
lange |
513 |
if ($type eq "dselect-upgrade") { |
| 65 |
|
|
dselectupgrade(); |
| 66 |
|
|
next; |
| 67 |
|
|
} |
| 68 |
|
|
|
| 69 |
lange |
906 |
$packlist = join(' ',@{$list{$type}}); |
| 70 |
lange |
902 |
|
| 71 |
|
|
if ($type eq "install") { |
| 72 |
|
|
# check for packages, that don't exists |
| 73 |
lange |
906 |
my $plist = $packlist; |
| 74 |
|
|
$plist =~ s/[+-] / /g; # remove +- suffix from package names |
| 75 |
|
|
my $misspelt = qx{$rootcmd apt-cache show $plist 2>&1 1>/dev/null}; |
| 76 |
lange |
902 |
$misspelt =~ s/W: Unable to locate package //g; |
| 77 |
|
|
$misspelt =~ s/\n/ /g; |
| 78 |
|
|
warn "These unknown packages are removed from the installation list: $misspelt\n" if $misspelt; |
| 79 |
|
|
# remove misspelt package names from packlist |
| 80 |
|
|
my %misspelt = map { $_ => 1 } split /\s+/,$misspelt; |
| 81 |
lange |
906 |
grep { $misspelt{$_} or $newlist .= "$_ "} @{$list{install}}; |
| 82 |
|
|
$packlist = $newlist; |
| 83 |
lange |
2 |
} |
| 84 |
lange |
902 |
|
| 85 |
|
|
execute("$rootcmd $command{$type} $packlist") if $packlist; |
| 86 |
lange |
2 |
} |
| 87 |
|
|
|
| 88 |
lange |
595 |
# remove prelaoded files |
| 89 |
|
|
foreach $entry (@preloadrmlist) { |
| 90 |
|
|
my ($url, $directory) = @$entry; |
| 91 |
|
|
$url =~ m#/([^/]+$)#; |
| 92 |
|
|
my $file = "$directory/$1"; |
| 93 |
|
|
print "rm $file\n" if $verbose; |
| 94 |
|
|
unlink $file || warn "Can't remove $file\n"; |
| 95 |
|
|
} |
| 96 |
|
|
|
| 97 |
lange |
534 |
# check if all went right |
| 98 |
lange |
614 |
execute("$rootcmd dpkg -C"); |
| 99 |
lange |
902 |
# clean apt cache |
| 100 |
lange |
614 |
execute("$rootcmd apt-get clean"); |
| 101 |
lange |
2 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 102 |
|
|
sub readconfig { |
| 103 |
|
|
|
| 104 |
|
|
my $filename = shift; |
| 105 |
|
|
my ($package,$type); |
| 106 |
|
|
|
| 107 |
|
|
open (FILE,"$filename") || warn "ERROR $0: Can't read config file: $filename\n"; |
| 108 |
|
|
print "$0: read config file $filename\n" if $verbose; |
| 109 |
|
|
|
| 110 |
|
|
while (<FILE>) { |
| 111 |
lange |
311 |
next if /^#/; # skip comments |
| 112 |
lange |
414 |
s/#.*$//; # delete comments |
| 113 |
lange |
311 |
next if /^\s*$/; # skip empty lines |
| 114 |
lange |
2 |
chomp; |
| 115 |
|
|
/^PRELOAD\s+([^\s]+)\s+([^\s]+)/ and push(@preloadlist, [$1, $2]),next; |
| 116 |
lange |
595 |
/^PRELOADRM\s+([^\s]+)\s+([^\s]+)/ and push(@preloadrmlist, [$1, $2]),next; |
| 117 |
lange |
2 |
/^PACKAGES\s+([^\s]+)/ and $type = $1,next; |
| 118 |
lange |
534 |
warn "PACKAGES .. line missing in $filename\n",next unless $type; |
| 119 |
lange |
2 |
push @{$list{$type}}, split; |
| 120 |
|
|
} |
| 121 |
|
|
} |
| 122 |
lange |
106 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 123 |
|
|
sub execute { |
| 124 |
|
|
|
| 125 |
lange |
311 |
# execute a command or only print it |
| 126 |
lange |
106 |
my $command = shift; |
| 127 |
|
|
my $error; |
| 128 |
|
|
|
| 129 |
lange |
513 |
$verbose && print "$command\n"; |
| 130 |
|
|
$test && return; |
| 131 |
|
|
|
| 132 |
|
|
$error = system "$command"; |
| 133 |
lange |
534 |
warn "ERROR: $error $?\n" if $error; |
| 134 |
lange |
513 |
} |
| 135 |
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 136 |
|
|
sub dselectupgrade { |
| 137 |
|
|
|
| 138 |
|
|
my ($package,$action,$list); |
| 139 |
lange |
548 |
my $tempfile = "$FAI_ROOT/tmp/dpkg-selections.tmp"; |
| 140 |
lange |
513 |
|
| 141 |
|
|
while (@{$list{$type}}) { |
| 142 |
|
|
$package = shift @{$list{$type}}; |
| 143 |
|
|
$action = shift @{$list{$type}}; |
| 144 |
|
|
$list .= "$package $action\n"; |
| 145 |
lange |
106 |
} |
| 146 |
lange |
513 |
|
| 147 |
lange |
534 |
open TMP, "> $tempfile" || die " Can't write to $tempfile"; |
| 148 |
lange |
513 |
print TMP $list; |
| 149 |
|
|
close TMP; |
| 150 |
|
|
|
| 151 |
lange |
614 |
execute("$rootcmd dpkg --set-selections < $tempfile"); |
| 152 |
lange |
753 |
execute("$rootcmd $command{$type}"); |
| 153 |
lange |
534 |
unlink $tempfile; |
| 154 |
lange |
106 |
} |