Browse Source

Changed --nz to --no-download, and made sure it works with --no-act .. simulate.

master
freesource 23 years ago
parent
commit
2f2e86fe5f
  1. 436
      SWIM/Safex.pm
  2. 28
      swim

436
SWIM/Safex.pm

@ -35,108 +35,132 @@ sub safex {
my ($commands) = @_;
my %commands = %$commands;
if ($commands->{"x"} || $commands->{"ftp"} || $commands->{"source"} ||
$commands->{"source_only"} || $commands->{"remove"} || $commands->{"r"} ||
$commands->{"purge"} || $commands->{"reinstall"}) {
if ($commands->{"x"} ||
$commands->{"ftp"} ||
$commands->{"source"} ||
$commands->{"source_only"} ||
$commands->{"remove"} ||
$commands->{"r"} ||
$commands->{"purge"} ||
$commands->{"reinstall"}) {
if (!defined @PACKAGES) {
if ($commands->{"search"} || $commands->{"ps"} || $commands->{"research"}
|| $commands->{"refinesearch"}) {
@PACKAGES = "NOPACKAGES";
if (!defined @PACKAGES) {
if ($commands->{"search"} ||
$commands->{"ps"} ||
$commands->{"research"} ||
$commands->{"refinesearch"}) {
@PACKAGES = "NOPACKAGES";
}
else {
@PACKAGES = @ARGV;
}
}
else {
@PACKAGES = @ARGV;
}
}
#print "PACKAGES @PACKAGES $argument\n";
my ($aptor,$arg);
if (defined $argument) {
if ($argument =~ /_/) {
$argument =~ m,(.*)_.*,;
$aptor = $1;
}
else {
if (($argument =~ m,/, && ($commands->{"y"} || $commands->{"z"} ||
$commands->{"ftp"} || $commands->{"nz"})) || defined $aptor_group ||
$commands->{"ftp"} || $commands->{"purge"} || $commands->{"remove"} ||
$commands->{"r"} || $commands->{"reinstall"} ) {
if ($PACKAGES[$#PACKAGES] =~ /_/) {
$PACKAGES[$#PACKAGES] =~ m,(.*)_.*,;
$aptor = $1;
}
else {
$aptor = $PACKAGES[$#PACKAGES];
}
}
else {
$aptor = $argument;
}
}
}
else {
if ($commands->{"y"} || $commands->{"z"} || $commands->{"ftp"} ||
$commands->{"nz"} || $commands->{"purge"} || $commands->{"remove"} ||
$commands->{"r"} || $commands->{"reinstall"}) {
if ($PACKAGES[$#PACKAGES] =~ /_/) {
$PACKAGES[$#PACKAGES] =~ m,(.*)_.*,;
$aptor = $1;
}
else {
$aptor = $PACKAGES[$#PACKAGES];
}
}
}
if ($PACKAGES[$#PACKAGES] =~ m,/,) {
$PACKAGES[$#PACKAGES] =~ m,.*/(.*)$,;
$arg = $1;
foreach (@PACKAGES) {
$_ =~ m,.*/(.*)$,;
shift @PACKAGES;
push(@PACKAGES,$1);
}
}
else {
if ($PACKAGES[$#PACKAGES] =~ /_/) {
$PACKAGES[$#PACKAGES] =~ m,(.*)_.*,;
$arg = $1;
foreach (0 .. $#PACKAGES) {
if ($PACKAGES[$_] =~ /_/) {
$PACKAGES[$_] =~ m,^(.*)_.*$,;
$PACKAGES[$_] = $1;
}
else {
$PACKAGES[$_] = $PACKAGES[$_];
}
#print "PACKAGES @PACKAGES $argument\n";
my ($aptor,$arg);
if (defined $argument) {
if ($argument =~ /_/) {
$argument =~ m,(.*)_.*,;
$aptor = $1;
}
else {
if (($argument =~ m,/, && ($commands->{"y"} ||
$commands->{"z"} ||
$commands->{"ftp"} ||
$commands->{"no-download"})) ||
defined $aptor_group ||
$commands->{"ftp"} ||
$commands->{"purge"} ||
$commands->{"remove"} ||
$commands->{"r"} ||
$commands->{"reinstall"} ) {
if ($PACKAGES[$#PACKAGES] =~ /_/) {
$PACKAGES[$#PACKAGES] =~ m,(.*)_.*,;
$aptor = $1;
}
else {
$aptor = $PACKAGES[$#PACKAGES];
}
}
else {
$aptor = $argument;
}
}
}
}
else {
$arg = $PACKAGES[$#PACKAGES];
foreach (0 .. $#PACKAGES) {
if ($PACKAGES[$_] =~ /_/) {
$PACKAGES[$_] =~ m,^(.*)_.*$,;
$PACKAGES[$_] = $1;
}
else {
$PACKAGES[$_] = $PACKAGES[$_];
}
else {
if ($commands->{"y"} ||
$commands->{"z"} ||
$commands->{"ftp"} ||
$commands->{"no-download"} ||
$commands->{"purge"} ||
$commands->{"remove"} ||
$commands->{"r"} ||
$commands->{"reinstall"}) {
if ($PACKAGES[$#PACKAGES] =~ /_/) {
$PACKAGES[$#PACKAGES] =~ m,(.*)_.*,;
$aptor = $1;
}
else {
$aptor = $PACKAGES[$#PACKAGES];
}
}
}
}
}
$aptor = "DEFINEDONE" if !defined $aptor;
if (($aptor eq $arg) || ($commands->{"search"} ||
$commands->{"ps"} || $commands->{"research"} ||
$commands->{"refinesearch"} || $aptor eq "/.") &&
$PACKAGES[0] ne "NOPACKAGES") {
xyz(\%commands);
}
}
if ($PACKAGES[$#PACKAGES] =~ m,/,) {
$PACKAGES[$#PACKAGES] =~ m,.*/(.*)$,;
$arg = $1;
foreach (@PACKAGES) {
$_ =~ m,.*/(.*)$,;
shift @PACKAGES;
push(@PACKAGES,$1);
}
}
else {
if ($PACKAGES[$#PACKAGES] =~ /_/) {
$PACKAGES[$#PACKAGES] =~ m,(.*)_.*,;
$arg = $1;
foreach (0 .. $#PACKAGES) {
if ($PACKAGES[$_] =~ /_/) {
$PACKAGES[$_] =~ m,^(.*)_.*$,;
$PACKAGES[$_] = $1;
}
else {
$PACKAGES[$_] = $PACKAGES[$_];
}
}
}
else {
$arg = $PACKAGES[$#PACKAGES];
foreach (0 .. $#PACKAGES) {
if ($PACKAGES[$_] =~ /_/) {
$PACKAGES[$_] =~ m,^(.*)_.*$,;
$PACKAGES[$_] = $1;
}
else {
$PACKAGES[$_] = $PACKAGES[$_];
}
}
}
}
$aptor = "DEFINEDONE" if !defined $aptor;
if (($aptor eq $arg) ||
($commands->{"search"} ||
$commands->{"ps"} ||
$commands->{"research"} ||
$commands->{"refinesearch"} ||
$aptor eq "/.") &&
$PACKAGES[0] ne "NOPACKAGES") {
xyz(\%commands);
}
}
}
@ -161,8 +185,12 @@ sub xyz {
}
# error correcting
if ($commands->{"ftp"} && ($commands->{"r"} || $commands->{"remove"} ||
$commands->{"purge"} || $commands->{"reinstall"}) ) {
if ($commands->{"ftp"} &&
($commands->{"r"} ||
$commands->{"remove"} ||
$commands->{"purge"} ||
$commands->{"reinstall"}) ) {
print "swim: --ftp cannot be used with ";
print "-r " if defined $commands->{"r"};
print "--remove " if defined $commands->{"remove"};
@ -171,9 +199,16 @@ sub xyz {
print "\n";
exit;
}
if ((($commands->{"r"} || $commands->{"remove"}) && $commands->{"purge"}) ||
(($commands->{"r"} || $commands->{"remove"}) && $commands->{"reinstall"})
|| ($commands->{"reinstall"} && $commands->{"purge"})
if ((($commands->{"r"} ||
$commands->{"remove"}) &&
$commands->{"purge"}) ||
(($commands->{"r"} ||
$commands->{"remove"}) &&
$commands->{"reinstall"}) ||
($commands->{"reinstall"} &&
$commands->{"purge"})
) {
print "swim: ";
print "-r " if defined $commands->{"r"};
@ -183,13 +218,18 @@ sub xyz {
print "cannot be used together\n";
exit;
}
if (($commands->{"y"} || $commands->{"z"} || $commands->{"x"} ||
$commands->{"nz"}) && ($commands->{"ftp"})) {
if (($commands->{"y"} ||
$commands->{"z"} ||
$commands->{"x"} ||
$commands->{"no-download"}) &&
($commands->{"ftp"})) {
print "swim: -";
print "x" if $commands->{"x"};
print "y" if $commands->{"y"};
print "z" if $commands->{"z"};
print " --nz" if $commands->{"nz"};
print " --no-download" if $commands->{"no-download"};
print " cannot be used with ";
#print "--purge " if defined $commands->{"purge"};
print "--ftp " if defined $commands->{"ftp"};
@ -200,15 +240,18 @@ sub xyz {
print "swim: --source and --source_only cannot be used together\n";
exit;
}
if (($commands->{"source"} || $commands->{"source_only"}) &&
!$commands->{"ftp"}) {
if (($commands->{"source"} ||
$commands->{"source_only"}) &&
!$commands->{"ftp"}) {
print "swim: --";
print "source" if $commands->{"source"};
print "source_only" if $commands->{"source_only"};
print " cannot be used without --ftp\n";
exit;
}
if (($commands->{"y"} || $commands->{"z"} || $commands->{"nz"}) &&
if (($commands->{"y"} || $commands->{"z"} || $commands->{"no-download"}) &&
!$commands->{"x"}) {
print "swim: requires -x option\n";
exit;
@ -232,63 +275,138 @@ sub xyz {
###############
# SAFETY MODE #
###############
if ((($commands->{"x"} || ($commands->{"x"} && $commands->{"y"})) ||
($commands->{"x"} && ($commands->{"r"} || $commands->{"remove"}) ||
($commands->{"x"} && $commands->{"y"} && ($commands->{"r"} ||
$commands->{"remove"})))) &&
!($commands->{"z"} || $commands->{"nz"})) {
my $arg;
my $count = 0;
foreach (@PACKAGES) {
if ($count == 0) {
$arg = "$_";
}
else {
$arg = $arg . " " . "$_";
}
$count++;
}
#########
# STDIN #
#########
if ($commands->{"stdin"}) {
my $term = Term::ReadLine->new("Simple Shell");
my @HISTORY = history(\%commands);
$term->addhistory(@HISTORY);
my @history; push(@history,"$arg");
print "swim: type exit to finish --stdin\n";
my $termcount = 0;
while ($termcount < 1 ) {
$_ = $term->readline('swim: ',"$arg");
push (@history,$_);
$termcount++;
} do { $_ = $term->readline('swim: ');
push (@history,$_);
} while $_ ne "exit";
$arg = $history[$#history - 1];
if ($arg ne $HISTORY[$#HISTORY]) {
if ($arg =~ m,^[^\w],) {
$arg =~ s,^\s+(\w+),$1,;
}
history_print($arg,\%commands);
if ( (
$commands->{"x"} ||
($commands->{"x"} &&
$commands->{"y"}) ||
($commands->{"x"} &&
($commands->{"r"} ||
$commands->{"remove"})) ||
($commands->{"x"} &&
$commands->{"y"} &&
($commands->{"r"} ||
$commands->{"remove"}))
) &&
!($commands->{"z"} || $commands->{"no-download"}) ) {
my $arg;
my $count = 0;
foreach (@PACKAGES) {
if ($count == 0) {
$arg = "$_";
}
else {
$arg = $arg . " " . "$_";
}
$count++;
}
}
#########
# STDIN #
#########
if ($commands->{"stdin"}) {
my $term = Term::ReadLine->new("Simple Shell");
my @HISTORY = history(\%commands);
$term->addhistory(@HISTORY);
my @history; push(@history,"$arg");
print "swim: type exit to finish --stdin\n";
my $termcount = 0;
while ($termcount < 1 ) {
$_ = $term->readline('swim: ',"$arg");
push (@history,$_);
$termcount++;
} do { $_ = $term->readline('swim: ');
push (@history,$_);
} while $_ ne "exit";
$arg = $history[$#history - 1];
if ($arg ne $HISTORY[$#HISTORY]) {
if ($arg =~ m,^[^\w],) {
$arg =~ s,^\s+(\w+),$1,;
}
history_print($arg,\%commands);
}
}
if ( $commands->{"r"} || $commands{"remove"} ) {
system "$apt_get remove -qs $arg";
}
elsif ( $commands->{"purge"} ) {
system "$apt_get --purge remove -qs $arg";
}
elsif ( $commands->{"reinstall"} ) {
system "$apt_get --reinstall install -qs $arg";
}
else {
system "$apt_get install -qs $arg";
}
}
if ( $commands->{"r"} || $commands{"remove"} ) {
system "$apt_get remove -qs $arg";
}
elsif ( $commands->{"purge"} ) {
system "$apt_get --purge remove -qs $arg";
}
elsif ( $commands->{"reinstall"} ) {
system "$apt_get --reinstall install -qs $arg";
}
else {
system "$apt_get install -qs $arg";
}
#############################
# SAFETY MODE DOWNLOAD-ONLY #
#############################
# --download-only and simulate
elsif ($commands->{"no-download"} && !$commands->{"z"} ) {
my $arg;
my $count = 0;
foreach (@PACKAGES) {
if ($count == 0) {
$arg = "$_";
}
else {
$arg = $arg . " " . "$_";
}
$count++;
}
#########
# STDIN #
#########
if ($commands->{"stdin"}) {
my $term = Term::ReadLine->new("Simple Shell");
my @HISTORY = history(\%commands);
$term->addhistory(@HISTORY);
my @history; push(@history,"$arg");
print "swim: type exit to finish --stdin\n";
my $termcount = 0;
while ($termcount < 1 ) {
$_ = $term->readline('swim: ',"$arg");
push (@history,$_);
$termcount++;
} do { $_ = $term->readline('swim: ');
push (@history,$_);
} while $_ ne "exit";
$arg = $history[$#history - 1];
if ($arg ne $HISTORY[$#HISTORY]) {
if ($arg =~ m,^[^\w],) {
$arg =~ s,^\s+(\w+),$1,;
}
history_print($arg,\%commands);
}
}
if ( $commands->{"r"} || $commands{"remove"} ) {
system "$apt_get remove -qds $arg";
}
elsif ( $commands->{"purge"} ) {
system "$apt_get --purge remove -qds $arg";
}
elsif ( $commands->{"reinstall"} ) {
system "$apt_get --reinstall install -qds $arg";
}
else {
system "$apt_get install -qds $arg";
}
}
#####################
# INSTALLATION MODE #
#####################
@ -337,7 +455,7 @@ sub xyz {
if (!($commands->{"ftp"} || $commands->{"purge"} ||
$commands->{"reinstall"})) {
if (!$commands->{"y"}) {
if (!$commands->{"nz"}) {
if (!$commands->{"no-download"}) {
!($commands->{"r"} || $commands{"remove"}) ?
system "$apt_get install $arg" :
system "$apt_get remove $arg";
@ -349,7 +467,7 @@ sub xyz {
}
}
else {
if (!$commands->{"nz"}) {
if (!$commands->{"no-download"}) {
!($commands->{"r"} || $commands{"remove"}) ?
system "$apt_get install -y $arg" :
system "$apt_get remove -y $arg";

28
swim

@ -138,7 +138,7 @@ my($result) =
"x", # simulate apt's actions
"y", # automatic yes for -z
"z", # apt install
"nz", # apt download
"no-download", # apt download
"source", # ftp source and package
"source_only", # ftp only source for package
"diff", # just grab diff for source
@ -1728,12 +1728,12 @@ Usage: swim [--nopager -n]
swim {--search ? (--research || --refinesearch) <pattern(s)>}
[-g] [-n] [--dbpath <dir>] [--root <dir>] [--no]
[--arch <architecture>] [--dists <distribution>]
[-xyrz --remove ? <[--nz]>] [--stdin]
[-xyrz --remove ? <[--no-download]>] [--stdin]
[--purge] [--reinstall] [<\\d{1,}>]
swim {--powersearch --ps ? (--research || --refinesearch) <pattern(s)>}
[-n] [--dir] [--dbpath <dir>] [--root <dir>] [--no]
[--arch <architecture>] [--dists <distribution>]
[-xyrz --remove ? <[--nz]>] [--stdin]
[-xyrz --remove ? <[--no-download]>] [--stdin]
[--purge] [--reinstall] [<\\d{1,}>]
swim {--query -q} [-afpgn --dir] [--total -t] [-i] [-l ? <[--df]>]
[-d] [-c] [--scripts] [--preinst] [--postinst]
@ -1745,7 +1745,7 @@ Usage: swim [--nopager -n]
[--copyright] [--changelog] [--allgroups]
[--arch <architecture>] [--dists <distribution>]
[--stdin] [--extract <ALL|archive|PWD!archive>]
[-xyrz --remove ? <[--nz]>] [--purge] [--reinstall]
[-xyrz --remove ? <[--no-download]>] [--purge] [--reinstall]
[targets | -S ? <\\d{1,}>]
swim {--audit --status -C}
swim {--apt} [--update] [--clean] [--autoclean] [--check]
@ -1800,12 +1800,12 @@ Usage: swim [--nopager -n]
swim {--search ? (--research || --refinesearch) <pattern(s)>}
[-g] [-n] [--dbpath <dir>] [--root <dir>] [--no]
[--arch <architecture>] [--dists <distribution>]
[-xyrz --remove ? <[--nz]>] [--stdin]
[-xyrz --remove ? <[--no-download]>] [--stdin]
[--purge] [--reinstall] [<\\d{1,}>]
swim {--powersearch --ps ? (--research || --refinesearch) <pattern(s)>}
[-n] [--dir] [--dbpath <dir>] [--root <dir>] [--no]
[--arch <architecture>] [--dists <distribution>]
[-xyrz --remove ? <[--nz]>] [--stdin]
[-xyrz --remove ? <[--no-download]>] [--stdin]
[--purge] [--reinstall] [<\\d{1,}>]
swim {--query -q} [-afpgn --dir] [--total -t] [-i] [-l ? <[--df]>]
[-d] [-c] [--scripts] [--preinst] [--postinst]
@ -1817,7 +1817,7 @@ Usage: swim [--nopager -n]
[--copyright] [--changelog] [--allgroups]
[--arch <architecture>] [--dists <distribution>]
[--stdin] [--extract <ALL|archive|PWD!archive>]
[-xyrz --remove ? <[--nz]>] [--purge] [--reinstall]
[-xyrz --remove ? <[--no-download]>] [--purge] [--reinstall]
[targets | -S ? <\\d{1,}>]
swim {--audit --status -C}
swim {--apt} [--update] [--clean] [--autoclean] [--check]
@ -1921,7 +1921,7 @@ usage:
-x - simulate apt-get installation
-y - answer yes to all apt-get prompts
-z - get and install package using apt-get
--nz - only download package when using apt-get
--no-download - only download package when using apt-get
--purge - remove the installed package, and the
package's configuration files
--remove
@ -1959,7 +1959,7 @@ usage:
-x - simulate apt-get installation
-y - answer yes to all apt-get prompts
-z - get and install package using apt-get
--nz - only download package when using apt-get
--no-download - only download package when using apt-get
--ftp - download package
--source - download source package
--source_only - only download source package
@ -2132,13 +2132,13 @@ Usage: swim [--nopager -n]
[-g] [-n] [--dbpath <dir>] [--root <dir>] [--no]
[--arch <architecture>] [--dists <distribution>]
[--ftp ? --source | --source_only ? <[--diff]>]
[-xyrz --remove ? <[--nz]>] [--stdin] [--apt2df]
[-xyrz --remove ? <[--no-download]>] [--stdin] [--apt2df]
[--df2apt] [--purge] [--reinstall] [<\\d{1,}>]
swim {--powersearch --ps ? (--research || --refinesearch) <pattern(s)>}
[-n] [--dir] [--dbpath <dir>] [--root <dir>] [--no]
[--arch <architecture>] [--dists <distribution>]
[--ftp ? --source | --source_only <[--diff]>]
[-xyrz --remove ? <[--nz]>] [--stdin] [--apt2df]
[-xyrz --remove ? <[--no-download]>] [--stdin] [--apt2df]
[--df2apt] [--purge] [--reinstall] [<\\d{1,}>]
swim {--query -q} [-afpgn --dir] [--total -t] [-i] [-l ? <[--df]>]
[-d] [-c] [--scripts] [--preinst] [--postinst]
@ -2150,7 +2150,7 @@ Usage: swim [--nopager -n]
[--arch <architecture>] [--dists <distribution>]
[--ftp ? --source | --source_only ? <[--diff]>]
[--stdin] [--extract <ALL|archive|PWD!archive>]
[-xyrz --remove ? <[--nz]>] [--purge] [--reinstall] [--apt2df]
[-xyrz --remove ? <[--no-download]>] [--purge] [--reinstall] [--apt2df]
[--df2apt] [targets | -S ? <\\d{1,}>]
swim {--audit --status -C}
swim {--ftp} [--Contents <DF|directory>] [--Packages <DF|directory>]
@ -2267,7 +2267,7 @@ usage:
-x - simulate apt-get installation
-y - answer yes to all apt-get prompts
-z - get and install package using apt-get
--nz - only download package when using apt-get
--no-download - only download package when using apt-get
--ftp - download package
--source - download source package
--source_only - only download source package
@ -2309,7 +2309,7 @@ usage:
-x - simulate apt-get installation
-y - answer yes to all apt-get prompts
-z - get and install package using apt-get
--nz - only download package when using apt-get
--no-download - only download package when using apt-get
--ftp - download package
--source - download source package
--source_only - only download source package

Loading…
Cancel
Save