/[fai]/trunk/scripts/install_packages
ViewVC logotype

Contents of /trunk/scripts/install_packages

Parent Directory Parent Directory | Revision Log Revision Log


Revision 753 - (hide annotations) (download)
Fri Aug 31 13:23:40 2001 UTC (11 years, 8 months ago) by lange
File size: 4297 byte(s)
add new type taskinst: install new task packages
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 311 @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 106 my $packlist = join(' ',@{$list{$type}});
70 lange 2 if ($packlist) {
71 lange 753 execute("$rootcmd $command{$type} $packlist");
72 lange 2 }
73     }
74    
75 lange 595 # remove prelaoded files
76     foreach $entry (@preloadrmlist) {
77     my ($url, $directory) = @$entry;
78     $url =~ m#/([^/]+$)#;
79     my $file = "$directory/$1";
80     print "rm $file\n" if $verbose;
81     unlink $file || warn "Can't remove $file\n";
82     }
83    
84 lange 534 # check if all went right
85 lange 614 execute("$rootcmd dpkg -C");
86 lange 311 # clean apt-get cache
87 lange 614 execute("$rootcmd apt-get clean");
88 lange 2 # - - - - - - - - - - - - - - - - - - - - - - - - - - -
89     sub readconfig {
90    
91     my $filename = shift;
92     my ($package,$type);
93    
94     open (FILE,"$filename") || warn "ERROR $0: Can't read config file: $filename\n";
95     print "$0: read config file $filename\n" if $verbose;
96    
97     while (<FILE>) {
98 lange 311 next if /^#/; # skip comments
99 lange 414 s/#.*$//; # delete comments
100 lange 311 next if /^\s*$/; # skip empty lines
101 lange 2 chomp;
102     /^PRELOAD\s+([^\s]+)\s+([^\s]+)/ and push(@preloadlist, [$1, $2]),next;
103 lange 595 /^PRELOADRM\s+([^\s]+)\s+([^\s]+)/ and push(@preloadrmlist, [$1, $2]),next;
104 lange 2 /^PACKAGES\s+([^\s]+)/ and $type = $1,next;
105 lange 534 warn "PACKAGES .. line missing in $filename\n",next unless $type;
106 lange 2 push @{$list{$type}}, split;
107     }
108     }
109 lange 106 # - - - - - - - - - - - - - - - - - - - - - - - - - - -
110     sub execute {
111    
112 lange 311 # execute a command or only print it
113 lange 106 my $command = shift;
114     my $error;
115    
116 lange 513 $verbose && print "$command\n";
117     $test && return;
118    
119     $error = system "$command";
120 lange 534 warn "ERROR: $error $?\n" if $error;
121 lange 513 }
122     # - - - - - - - - - - - - - - - - - - - - - - - - - - -
123     sub dselectupgrade {
124    
125     my ($package,$action,$list);
126 lange 548 my $tempfile = "$FAI_ROOT/tmp/dpkg-selections.tmp";
127 lange 513
128     while (@{$list{$type}}) {
129     $package = shift @{$list{$type}};
130     $action = shift @{$list{$type}};
131     $list .= "$package $action\n";
132 lange 106 }
133 lange 513
134 lange 534 open TMP, "> $tempfile" || die " Can't write to $tempfile";
135 lange 513 print TMP $list;
136     close TMP;
137    
138 lange 614 execute("$rootcmd dpkg --set-selections < $tempfile");
139 lange 753 execute("$rootcmd $command{$type}");
140 lange 534 unlink $tempfile;
141 lange 106 }

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5