File: aptitude

package info (click to toggle)
zypper 1.14.94-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,464 kB
  • sloc: cpp: 27,415; sh: 718; perl: 133; xml: 109; python: 39; makefile: 14
file content (78 lines) | stat: -rwxr-xr-x 2,634 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl -w
# version 0.9
# (C) 2011-2015 by Bernhard M. Wiedemann <bernhard+aptitude4zypp lsmod de>
# License: GPL v2 or later

use strict;
my $prog=$0; $prog=~s{.*/}{};
my @options=();
my $option;
foreach(@ARGV) {
	last unless ($option || m/^-/);
	if($option) {$option=0} # skip
	if($_ eq "--option") {$option=1}
	push(@options, $_);
}

my $os={};
if(open(my $osfd, "/etc/os-release")) {
	while(<$osfd>) {
		m/^(\w+)="?(.*?)"?$/;
		$os->{$1}=$2;
	}
	close $osfd;
}

sub os_is($)
{
	my ($osstr)=@_;
	return $os->{ID} =~ m/$osstr/i || ($os->{ID_LIKE} && $os->{ID_LIKE} =~/$osstr/i);
}

my @zopt;
my @zopt2;
foreach(@options) {
	shift @ARGV;
	if($_ eq "-s" || $_ eq "--simulate") {push @zopt2, "--dry-run -y"}
	if($_ eq "-d" || $_ eq "--download-only") {push @zopt2, "--download-only"}
	if($_ eq "-y" || $_ eq "--assume-yes") {push @zopt, "--non-interactive"}
	if($_ eq "-q" || $_ eq "--quiet") {push @zopt, "--quiet"}
	if($prog eq "aptitude") {
		if($_ eq "-V" || $_ eq "-v" || $_ eq "--verbose") {push @zopt, "--verbose"}
	} else {
		if($_ eq "-v" || $_ eq "--version" || $_ eq "-V" || $_ eq "--verbose-versions") {push @zopt, "--version"}
	}
	if($_ eq "-u") {system("zypper", "refresh")}
	if($_ eq "--without-recommends") {push @zopt2, "--no-recommends"}
	if($_ eq "--with-recommends") {push @zopt, "--recommends"}
}

my $action=shift;
if($prog eq "aptitude") {
    if(!defined($action)) {exec "/sbin/yast2", "-i"}
} else {
    $action||="";
}

# install, remove are the same
if($action eq "show") {$action="info"}
elsif($action eq "list") {$action="search"}
elsif($action eq "purge") {$action="remove"}
elsif($action eq "hold") {$action="addlock"}
elsif($action eq "unhold") {$action="removelock"}
elsif($action eq "update") {$action="refresh"}
elsif($action eq "upgrade" || $action eq "safe-upgrade") {$action="update"}
elsif($action eq "full-upgrade" || $action eq "dist-upgrade") {$action="dist-upgrade"}
elsif($action eq "download") {$action="install"; unshift(@zopt2, "--download-only");}
elsif($action eq "reinstall") {$action="install"; unshift(@zopt2, "--force");}
elsif($action eq "source") {$action="source-install"}
elsif($action=~m/build-dep(?:ends)?/) {$action="source-install"; unshift(@zopt2, "--build-deps-only");}
elsif($action eq "changelog") {exec qw"rpm -q --changelog", @ARGV}
elsif($action=~m/markauto|unmarkauto|forbid-version|autoclean|autoremove|check|why|why-not/) { print "aptitude '$action' unavailabe in zypper\n"; exit 0 }

foreach my $map (</etc/zypp/apt-packagemap.d/*.pm>) {
	do $map;
}

#system "echo", "zypper", @zopt, $action, @zopt2, @ARGV;
exec "zypper", @zopt, $action, @zopt2, @ARGV;