summaryrefslogtreecommitdiff
path: root/package-conf.in
blob: 276f1bd50f7b2282f6b5a53ffcb66f6b0319e17a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env perl
#-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-

# Package lister. 
# Designed to be architecture- and distribution independent.
#
# Copyright (C) 2000-2001 Ximian, Inc.
#
# Authors: Richard Bos <allabos@freeler.nl>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

# --- Common stuff --- #


BEGIN {
  $SCRIPTSDIR = "___scriptsdir___";
  if ($SCRIPTSDIR =~ /^___scriptsdir__[_]/)
  {
      $SCRIPTSDIR = ".";
      $DOTIN = ".in";
  }
  
# require "$SCRIPTSDIR/general.pl$DOTIN";
# require "$SCRIPTSDIR/platform.pl$DOTIN";
# require "$SCRIPTSDIR/util.pl$DOTIN";
# require "$SCRIPTSDIR/file.pl$DOTIN";
  require "$SCRIPTSDIR/xml.pl$DOTIN";
}


# --- Tool information --- #

$name = "package";
$version = "___version___";
@platforms = ("redhat-5.2", "redhat-6.0", "redhat-6.1", "redhat-6.2", "redhat-7.0",
              "mandrake-7.2", "suse-7.0", "turbolinux-7.0");

$description =<<"end_of_description;";
List available packages at the system only.  Use the available package update
tooks like; rpm, apt-get, red-carpet, etc to update your system.
end_of_description;

# --- System config file locations --- #

# Where are the tools?

$cmd_pack = &xst_file_locate_tool ("rpm");

# --- Internal configuration variables --- #

# Configuration is parsed/read to, and printed/written from, these temporary variables.

@cf_package = ();


# --- XML scanning --- #

# --- XML printing --- #

sub xml_print
{
  &xst_xml_print_line ("<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?>");
  &xst_xml_print_line ("<!DOCTYPE packages []>\n");
  &xst_xml_print_line ("<packages>");
  &xst_xml_enter ();

  &xst_xml_print_vspace ();
  &xst_xml_print_line ("<!-- Configuration starts here -->\n");

  &xst_xml_print_vspace ();
  &xst_xml_print_line ("<meta>");
  &xst_xml_enter;

  my $number_of_packages = $#cf_package + 1;
  &xst_xml_print_line ("<number>$number_of_packages</number>");
  &xst_xml_leave;
  &xst_xml_print_line ("</meta>");

  &xst_xml_print_vspace ();
  &xst_xml_print_line ("</packagedb>");
  &xst_xml_print_vspace ();
  &xst_xml_enter;

  foreach $entry (@cf_package) {
    &xst_xml_print_line ("<package>");
    &xst_xml_enter;
    &xst_xml_print_line ("<name>$entry->{name}</name>");
    &xst_xml_print_line ("<version>$entry->{vers}</version>");
    &xst_xml_print_line ("<distribution>$entry->{dist}</distribution>");
    &xst_xml_leave;
    &xst_xml_print_line ("</package>");
  &xst_xml_print_vspace ();
  }

  &xst_xml_print_vspace ();
  &xst_xml_leave ();
  &xst_xml_print_line ("</packagedb>");

  &xst_xml_print_vspace ();
  &xst_xml_print_line ("<!-- End of configuration -->\n");

  &xst_xml_print_vspace ();
  &xst_xml_leave ();
  &xst_xml_print_line ("</packages>");
}


# --- Get (read) config --- #

sub get_package
{
  my $dist;
  my $distributor;
  my $name;
  my $pid;
  my $vers;
  my $fd;

  my %cmd_map =
  (
    "rpm" => "rpm -qa --queryformat '%{name},%{version},%{release}\n'",
    "deb" => "unknown"
  );

  my %dist_map =
  (
    "redhat"   => "$cmd_map{rpm}",
    "mandrake" => "$cmd_map{rpm}",
    "suse"     => "$cmd_map{rpm}",
    "debian"   => "$cmd_map{deb}",
    "turbolinux" => "$cmd_map{rpm}",
  );

  ($distributor) = split /-/, $xst_dist;

  $fd = &xst_file_run_pipe_read ("$dist_map{$distributor}");
  die "Could not execute the package query command" if $fd eq undef;

  while (<$fd>)
  {
    chomp $_;
    ($name, $vers, $dist) = split /,/, $_;

    push @cf_package, {
      "name"     => $name,
      "vers"     => $vers,
      "dist"     => $dist,
    };
  }
  &xst_file_close ($fd);
}

sub get
{
  &xst_report ("get_packages");

  &get_package; &xst_print_progress();
  
  &xst_report_end ();
  &xml_print ();
}


# --- Set (write) config --- #

# --- Main --- #

# get, set and filter are special cases that don't need more parameters than a ref to their function.
# Read general.pl.in:xst_run_directive to know about the format of this hash.

$directives = {
  "get"    => [ \&get,    [], "" ],
  "set"    => [ \&set,    [], "" ],
  "filter" => [ \&filter, [], "" ]
    };

$tool = &xst_init ($name, $version, $description, $directives, @ARGV);
&xst_platform_ensure_supported ($tool, @platforms);
&xst_run ($tool);