From 3b945cc83e7babef2b9e69b2bd75568855f154c6 Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Wed, 21 Jan 2004 10:33:04 +0000 Subject: remove unneeded stuff anymore --- grpmi/grpmi.pl | 219 -------------------------- grpmi/rpm/Makefile | 13 -- grpmi/rpm/Makefile.PL | 52 ------- grpmi/rpm/grpmi_rpm.pm | 14 -- grpmi/rpm/grpmi_rpm.xs | 405 ------------------------------------------------- 5 files changed, 703 deletions(-) delete mode 100755 grpmi/grpmi.pl delete mode 100644 grpmi/rpm/Makefile delete mode 100644 grpmi/rpm/Makefile.PL delete mode 100644 grpmi/rpm/grpmi_rpm.pm delete mode 100644 grpmi/rpm/grpmi_rpm.xs (limited to 'grpmi') diff --git a/grpmi/grpmi.pl b/grpmi/grpmi.pl deleted file mode 100755 index d72a4615..00000000 --- a/grpmi/grpmi.pl +++ /dev/null @@ -1,219 +0,0 @@ -#!/usr/bin/perl -#***************************************************************************** -# -# Copyright (c) 2002 Guillaume Cottenceau (gc at mandrakesoft dot com) -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2, as -# published by the Free Software Foundation. -# -# 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 General Public License for more details. -# -# You should have received a copy of the GNU 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. -# -#***************************************************************************** - -use strict; -use MDK::Common; - -use curl_download; -use grpmi_rpm; - -use lib qw(/usr/lib/libDrakX); -use ugtk2 qw(:all); -$::isStandalone = 1; - -@ARGV or die "usage: ", basename($0), " [--no-verify-rpm] <[-noupgrade] PACKAGE>...\n"; - -c::bind_textdomain_codeset('grpmi', 'UTF8'); -sub translate { - my ($s) = @_; - my $r = $s ? c::dgettext('grpmi', $s) : ''; - c::set_tagged_utf8($r); - $r; -} -sub sprintf_fixutf8 { - my $need_upgrade; - $need_upgrade |= to_bool(c::is_tagged_utf8($_)) + 1 foreach @_; - if ($need_upgrade == 3) { c::upgrade_utf8($_) foreach @_ }; - sprintf shift, @_; -} -sub N { - my $s = shift @_; my $t = translate($s); - sprintf_fixutf8 $t, @_; -} -sub utf8ize { c::set_tagged_utf8($_[0]); $_[0] } -sub mexit { ugtk2::exit(undef, @_) } - -sub interactive_msg { - my ($title, $contents, $yesno) = @_; - my $d = ugtk2->new($title); - my $lines; $lines++ while $contents =~ /\n/g; - my $l = Gtk2::Label->new($contents); - gtkadd($d->{window}, - gtkpack_(Gtk2::VBox->new(0,5), - 1, $lines > 20 ? gtkset_size_request(create_scrolled_window($l), 300, 300) : $l, - 0, gtkpack(create_hbox(), - ref($yesno) eq 'ARRAY' ? map { - my $label = $_; - gtksignal_connect(Gtk2::Button->new($label), clicked => sub { $d->{retval} = $label; Gtk2->main_quit }) - } @$yesno - : $yesno ? (gtksignal_connect(Gtk2::Button->new(N("Yes")), clicked => sub { $d->{retval} = 1; Gtk2->main_quit }), - gtksignal_connect(Gtk2::Button->new(N("No")), clicked => sub { $d->{retval} = 0; Gtk2->main_quit })) - : gtksignal_connect(Gtk2::Button->new(N("Ok")), clicked => sub { Gtk2->main_quit }) - ))); - $l->set_justify('left'); - $d->main; - return $d->{retval}; -} - -$> and interactive_msg(N("Error..."), - N("You need to be root to install packages, sorry.")), mexit -1; - -grpmi_rpm::init_rcstuff() and interactive_msg(N("RPM initialization error"), - N("The initialization of config files of RPM was not possible, sorry.")), mexit -1; - -$ENV{HOME} ||= '/root'; -my @grpmi_config = map { chomp_($_) } cat_("$ENV{HOME}/.grpmi"); - -my $mainw = ugtk2->new('grpmi'); -my $label = Gtk2::Label->new(N("Initializing...")); -my $progressbar = gtkset_size_request(Gtk2::ProgressBar->new, 400, 0); -gtkadd($mainw->{window}, gtkpack(gtkadd(create_vbox(), $label, $progressbar))); -$mainw->{rwindow}->set_position('center'); -$mainw->sync; - -my $exitstatus = -1; -my $forced_exitstatus; - - -# -=-=-=---=-=-=---=-=-=-- download potential URL's, and verify signatures -=-=-=---=-=-=-- - -my $cache_location = '/var/cache/urpmi/rpms'; -my $url_regexp = '^http://|^https://|^ftp://'; -my $nb_downloads = int(grep { m,$url_regexp, } @ARGV); -my $download_progress; - -foreach my $arg (@ARGV) { - if ($arg =~ m,$url_regexp,) { - $download_progress++; - my $url = $arg; - $arg = "$cache_location/" . basename($url); - retry_download: - $label->set(N("Downloading package `%s' (%s/%s)...", basename($url), $download_progress, $nb_downloads)); - select(undef, undef, undef, 0.1); $mainw->flush; #- hackish :-( - my $res = utf8ize(curl_download::download($url, $cache_location, - sub { $_[0] and $progressbar->set_fraction($_[1]/$_[0]); $mainw->flush })); - if ($res) { - my $results = interactive_msg(N("Error during download"), -N("There was an error downloading package: - -%s - -Error: %s -Do you want to continue (skipping this package)?", $url, $res), - [ N("Yes"), N("No"), N("Retry download") ]); - $results eq N("No") and goto cleanup; - $results eq N("Retry download") and goto retry_download; - $arg = "-skipped&$arg&"; - } - } - -} - - -# -=-=-=---=-=-=---=-=-=-- verify signatures -=-=-=---=-=-=-- - -if (!member('--no-verify-rpm', @ARGV)) { - my $yes_to_all; - foreach my $arg (@ARGV) { - if ($arg !~ /^-/) { - if (-f $arg) { - $yes_to_all and next; - $label->set(N("Verifying signature of `%s'...", basename($arg))); $mainw->flush; - if (my $res = utf8ize(grpmi_rpm::verify_sig($arg))) { - my $results = interactive_msg(N("Signature verification error"), -N("The signature of the package `%s' is not correct: - -%s -Do you want to install it anyway?", - basename($arg), $res), - [ N("Yes"), N("Yes to all"), N("No") ]); - $results eq N("No") and $arg = "-skipped&$arg&"; - $results eq N("Yes to all") and $yes_to_all = 1; - } - } else { - interactive_msg(N("File error"), -N("The following file is not valid: - -%s - -Do you want to continue anyway (skipping this package)?", - $arg), 1) or goto cleanup; - $arg = "-skipped&$arg&"; - } - } - } -} - - -# -=-=-=---=-=-=---=-=-=-- install packages -=-=-=---=-=-=---=-=-=- - -if (grep { /^[^-]/ } @ARGV) { - $label->set(N("Preparing packages for installation...")); $mainw->flush; - my $nb_installs = int(grep { /^[^-]/ } @ARGV); - my $install_progress; - - sub install_packages_callback { - my ($msg) = @_; - my $retval; - my %actions = ( 'conflicts' => sub { - interactive_msg(N("Conflicts detected"), -N("Conflicts were detected: -%s - -Install aborted.", - utf8ize(join("\n", split(/\|/, $1))))); - $forced_exitstatus = -1; - return 1; - }, - 'inst-start' => sub { $install_progress++; - $label->set(N("Installing package `%s' (%s/%s)...", $1, $install_progress, $nb_installs)); - $mainw->flush }, - 'inst-progress' => sub { - $1 =~ /(\d+) (\d+)/; - $progressbar->set_fraction($1/$2); $mainw->flush - }, - ); - $msg =~ /^$_ (.*)/ and return &{$actions{$_}} foreach keys %actions; - print STDERR "unknown msg:<$msg>\n"; - return 0; - } - - my $res = chomp_(utf8ize(grpmi_rpm::install_packages(\&install_packages_callback, @ARGV))); - if ($res) { - interactive_msg(N("Problems occurred during installation"), N("There was an error during packages installation:\n\n%s", $res)); - goto cleanup; - } -} - -# -=-=-=---=-=-=---=-=-=-- cleanup -=-=-=---=-=-=-- -$exitstatus = 0; -cleanup: -if (!member('noclearcache', @grpmi_config)) { - my @toclean = map { s/^-skipped&([^&]+)&$/$1/; if_(/^\Q$cache_location/, $_) } @ARGV; - if (@toclean && ($forced_exitstatus || $exitstatus)) { - interactive_msg(N("Cleanup"), -N("Cleanup question: there was an error during installation, do you want to -remove the %d downloaded package(s)? -(they are located in %s)", scalar(@toclean), $cache_location), 1) or goto exiting; - } - unlink @toclean; -} -exiting: -mexit($forced_exitstatus || $exitstatus); diff --git a/grpmi/rpm/Makefile b/grpmi/rpm/Makefile deleted file mode 100644 index 3bf1b972..00000000 --- a/grpmi/rpm/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -.PHONY: clean - -grpmi_rpm: %: %.xs - test -e Makefile_c || perl Makefile.PL INSTALLDIRS=$(INSTALLDIRS) - $(MAKE) -f Makefile_c - -install: - test -e Makefile_c || perl Makefile.PL INSTALLDIRS=$(INSTALLDIRS) - $(MAKE) -f Makefile_c install - -clean: - test ! -e Makefile_c || $(MAKE) -f Makefile_c clean - rm -f *~ *.o diff --git a/grpmi/rpm/Makefile.PL b/grpmi/rpm/Makefile.PL deleted file mode 100644 index b5022502..00000000 --- a/grpmi/rpm/Makefile.PL +++ /dev/null @@ -1,52 +0,0 @@ -use ExtUtils::MakeMaker; -use Config; - -my $rpm_cflags = '-I/usr/include/rpm'; -my $rpm_libs = '-lrpm -lrpmdb -lrpmio -lpopt'; - -ccompile('#include - #include - ', - 'rpmdb db;', - $rpm_cflags, - $rpm_libs) - or - die_('rpm devel environment is needed'); - - -WriteMakefile( - 'NAME' => 'grpmi_rpm', - 'LIBS' => [ $rpm_libs ], - 'VERSION_FROM' => 'grpmi_rpm.pm', # finds VERSION - 'OBJECT' => 'grpmi_rpm.o', - 'INC' => $rpm_cflags, - 'OPTIMIZE' => '-O2 -Wall -Werror -g', - 'MAKEFILE' => 'Makefile_c', -); - - - - -# Taken from Makefile.PL from Gtk-Perl -sub ccompile { - my ($headers, $main, $cflags, $libs) = @_; - my $fname = "temctest"; - my $r; - chomp($cflags, $libs); - open(CTEST, ">$fname.c") || return 0; - print CTEST <<"EOTEST"; -$headers - -int main (int argc, char* argv[]) { -$main; -} -EOTEST - close(CTEST); - $r = system("$Config{cc} -o $fname $fname.c $cflags $libs 2>/dev/null 1>/dev/null"); - warn("RUNNING: $Config{cc} -o $fname $fname.c $cflags $libs\n") if $ENV{VERBOSE}; - unlink($fname, "$fname.c"); - return $r == 0; -} - -sub chomp_ { my @l = map { my $l = $_; chomp $l; $l } @_; wantarray ? @l : $l[0] } -sub die_ { die "\n **ERROR**: @_\n\n" } diff --git a/grpmi/rpm/grpmi_rpm.pm b/grpmi/rpm/grpmi_rpm.pm deleted file mode 100644 index 91d15a6b..00000000 --- a/grpmi/rpm/grpmi_rpm.pm +++ /dev/null @@ -1,14 +0,0 @@ -package grpmi_rpm; - -use strict; -use vars qw($VERSION @ISA); - -require DynaLoader; - -@ISA = qw(DynaLoader); -$VERSION = '1.0'; - -bootstrap grpmi_rpm $VERSION; - -1; - diff --git a/grpmi/rpm/grpmi_rpm.xs b/grpmi/rpm/grpmi_rpm.xs deleted file mode 100644 index 72b4de28..00000000 --- a/grpmi/rpm/grpmi_rpm.xs +++ /dev/null @@ -1,405 +0,0 @@ -/* -*- c -*- - * - * Copyright (c) 2002 Guillaume Cottenceau (gc at mandrakesoft dot com) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, as - * published by the Free Software Foundation. - * - * 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 General Public License for more details. - * - * You should have received a copy of the GNU 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. - * - ******************************************************************************/ - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "EXTERN.h" -#include "perl.h" -#include "XSUB.h" - -#undef Fflush -#undef Mkdir -#undef Stat -#include -#include - -#include -#undef _ -#define _(arg) dgettext("grpmi", arg) - -#define streq !strcmp - -char * my_asprintf(char *msg, ...) -{ - char * out; - va_list args; - va_start(args, msg); - if (vasprintf(&out, msg, args) == -1) - out = ""; - va_end(args); - return out; -} - - -char * init_rcstuff_(void) -{ - char * rpmrc; - - rpmrc = getenv("RPMRC_FILE"); - if (rpmrc && !*rpmrc) - rpmrc = NULL; - if (rpmReadConfigFiles(rpmrc, NULL)) - return _("Couldn't read RPM config files"); - - return ""; -} - - -/* bad bad bad.. duplicated code from gi/perl-install/c/stuff.xs */ -char* std_to_utf8(char* s) -{ - iconv_t cd = iconv_open("UTF-8", nl_langinfo(CODESET)); - char* retval = s; - if (cd != (iconv_t) (-1)) { - size_t s_len = strlen(retval); - /* the maximum expansion when converting happens when converting - tscii to utf-8; each tscii char can become up to 4 unicode chars - and each one of those unicode chars can be 3 bytes long */ - char *buf = alloca(4 * 3 * s_len); - { - char *ptr = buf; - size_t ptr_len = 4 * 3 * s_len; - if ((iconv(cd, &s, &s_len, &ptr, &ptr_len)) != (size_t) (-1)) { - *ptr = 0; - retval = buf; - } - } - iconv_close(cd); - } - return strdup(retval); -} - -/* these are in rpmlib but not in rpmlib.h */ -int readLead(FD_t fd, struct rpmlead *lead); -int rpmReadSignature(FD_t fd, Header *header, short sig_type); - -char * verify_sig_(char * file) -{ - struct rpmlead lead; - Header sig; - HeaderIterator sigIter; - const void *ptr; - int_32 tag, type, count; - char result[8*BUFSIZ]; - FD_t fd, ofd; - int i; - const char *tmpfile = NULL; - unsigned char buffer[8192]; - int gpg_sig = 0; - - fd = fdOpen(file, O_RDONLY, 0); - if (fdFileno(fd) < 0) { - return _("Couldn't open file\n"); - } - memset(&lead, 0, sizeof(lead)); - if (readLead(fd, &lead)) { - return _("Could not read lead bytes\n"); - } - if (lead.major == 1) { - return _("RPM version of package doesn't support signatures\n"); - } - - i = rpmReadSignature(fd, &sig, lead.signature_type); - if (i != RPMRC_OK && i != RPMRC_BADSIZE) { - return _("Could not read signature block (`rpmReadSignature' failed)\n"); - } - if (!sig) { - return _("No signatures\n"); - } - - if (makeTempFile(NULL, &tmpfile, &ofd)) - return _("`makeTempFile' failed!\n"); - - while ((i = fdRead(fd, buffer, sizeof(buffer))) != 0) { - if (i == -1) { - fdClose(ofd); - fdClose(fd); - unlink(tmpfile); - return _("Error reading file\n"); - } - if (fdWrite(ofd, buffer, i) < 0) { - fdClose(ofd); - fdClose(fd); - unlink(tmpfile); - return _("Error writing temp file\n"); - } - } - fdClose(fd); - fdClose(ofd); - - for (sigIter = headerInitIterator(sig); headerNextIterator(sigIter, &tag, &type, &ptr, &count); ptr = headerFreeData(ptr, type)) { - switch (tag) { - case RPMSIGTAG_PGP5: case RPMSIGTAG_PGP: case RPMSIGTAG_GPG: - gpg_sig = 1; - case RPMSIGTAG_LEMD5_2: case RPMSIGTAG_LEMD5_1: case RPMSIGTAG_MD5: - case RPMSIGTAG_SIZE: - break; - default: - continue; - } - - i = rpmVerifySignature(tmpfile, tag, ptr, count, result); - if (i != RPMSIG_OK) { - unlink(tmpfile); - return std_to_utf8(result); - } - } - unlink(tmpfile); - if (!gpg_sig) - return _("No GPG signature in package\n"); - else - return ""; -} - - -void rpmError_callback_empty(void) {} - -int rpmError_callback_data; -void rpmError_callback(void) { - if (rpmErrorCode() != RPMERR_UNLINK && rpmErrorCode() != RPMERR_RMDIR) { - write(rpmError_callback_data, rpmErrorString(), strlen(rpmErrorString())); - } -} - -SV * install_packages_callback_data = NULL; -int install_packages_callback(char * msg, ...) __attribute__ ((format (printf, 1, 2))); -int install_packages_callback(char * msg, ...) -{ - int i; - char * out; - dSP; - - va_list args; - va_start(args, msg); - if (vasprintf(&out, msg, args) == -1) - out = ""; - va_end(args); - - if (!SvROK(install_packages_callback_data)) - return 0; - ENTER; - SAVETMPS; - PUSHMARK(SP); - XPUSHs(sv_2mortal(newSVpv(out, 0))); - PUTBACK; - free(out); - i = call_sv(install_packages_callback_data, G_SCALAR); - SPAGAIN; - if (i != 1) - croak("Big trouble\n"); - else - i = POPi; - PUTBACK; - FREETMPS; - LEAVE; - return i; -} - -char * install_packages_(char ** packages) -{ - void * rpmRunTransactions_callback(const void * h, const rpmCallbackType what, const unsigned long amount, const unsigned long total, const void * pkgKey, void * data) { - static FD_t fd; - - switch (what) { - case RPMCALLBACK_INST_OPEN_FILE: - return fd = fdOpen(pkgKey, O_RDONLY, 0); - case RPMCALLBACK_INST_CLOSE_FILE: - fdClose(fd); - break; - case RPMCALLBACK_INST_START: - install_packages_callback("inst-start %s", basename(pkgKey)); - break; - case RPMCALLBACK_INST_PROGRESS: - install_packages_callback("inst-progress %ld %ld", amount, total); - break; - default: - break; - } - return NULL; - } - char * returnmsg; - rpmdb db; - rpmTransactionSet rpmdep; - rpmDependencyConflict conflicts; - int num_conflicts; - rpmProblemSet probs = NULL; - char ** pkg; - int noupgrade = 0; - - if (rpmdbOpen("", &db, O_RDWR, 0644)) { - if (rpmErrorCode() == RPMERR_DBOPEN) - return _("Couldn't open RPM DB for writing (not superuser?)"); - else - return _("Couldn't open RPM DB for writing"); - } - - if (!(rpmdep = rpmtransCreateSet(db, NULL))) { - returnmsg = _("Couldn't start transaction"); - goto install_packages_cleanup; - } - - for (pkg = packages; pkg && *pkg; pkg++) { - if (streq(*pkg, "-noupgrade")) - noupgrade = 1; - else { - Header h; - int isSource, major; - char *file = *pkg; - char *LocalName = basename(file); - FD_t fd; - - if (file[0] == '-') - continue; - - fd = fdOpen(file, O_RDONLY, 0); - if (fdFileno(fd) < 0) { - returnmsg = my_asprintf(_("Can't open package `%s'\n"), LocalName); - goto install_packages_cleanup; - } - switch (rpmReadPackageHeader(fd, &h, &isSource, &major, NULL)) { - case 1: - returnmsg = my_asprintf(_("Package `%s' is corrupted\n"), LocalName); - goto install_packages_cleanup; - default: - returnmsg = my_asprintf(_("Package `%s' can't be installed\n"), LocalName); - goto install_packages_cleanup; - case 0: - rpmtransAddPackage(rpmdep, h, NULL, file, !noupgrade, NULL); - } - fdClose(fd); - noupgrade = 0; - } - } - - if (rpmdepCheck(rpmdep, &conflicts, &num_conflicts)) { - returnmsg = _("Error while checking dependencies"); - goto install_packages_cleanup; - } - if (conflicts) { - int i; - char * conflict_msg = strdup("conflicts "); - for (i=0; inumProblems; i++) { - const char * thispb = rpmProblemString(&(probs->probs[i])); - msg = my_asprintf("%s%s\n", returnmsg, thispb); - free(returnmsg); - returnmsg = msg; - } - goto install_packages_cleanup; - } - - rpmdbClose(db); - return ""; - - install_packages_cleanup: - rpmdbClose(db); - return returnmsg; -} - - -/************************** Gateway to Perl ****************************/ - -MODULE = grpmi_rpm PACKAGE = grpmi_rpm -PROTOTYPES : DISABLE - -char * -init_rcstuff() - CODE: - RETVAL = init_rcstuff_(); - OUTPUT: - RETVAL - -char * -verify_sig(pkg) -char * pkg - CODE: - RETVAL = verify_sig_(pkg); - OUTPUT: - RETVAL - -char * -install_packages(callback, ...) -SV * callback - PREINIT: - int i; - char ** pkgs; - CODE: - install_packages_callback_data = callback; - pkgs = malloc(sizeof(char *) * items); - for (i=1; i