"hist|history" => \$history,
"cmd|command|c=s" => \$command,
"apt-help" => sub{say `apt-get --help`; help()},
- "showLog" => \$showLog
+ "showLog" => \$showLog,
+ "list" => \&list_sys_installed
+
);
my $packages = join ' ', @ARGV;
$data_dir .= "/" if $data_dir && $data_dir !~ m/ \/$/;
$packages = $2;
}
if ( !$command || $command eq 'install' && !$packages )
-{say "Hey ", RED, $ENV{USER}, RESET,"! What you wanna do? Maybe try option [ $0 --help ]?";exit 0}
+{say "Hey ", RED, $ENV{USER}, RESET,"! What you wanna do? Maybe try option [ $0 --help ]?";exit 0}
$| = 1; # Disable buffering on STDOUT.
my @res = split "\n", $result;
my $log = 1; my $output =""; my ($aptResult, $f_app_ins, $f_app_rem, $appRemoved,$appInstalled);
-
+
foreach my $next(@res){
if($next =~ m/sudo: a terminal is required to read the password;/){
die $next
if($appInstalled){
my @installed = split ',', $appInstalled;
foreach my $package(@installed){
- my $info = `apt-cache show $package`;
+ my $info = `apt-cache show $package`;
$info =~ m/^Description[-\w]*:\s*(.*?)\./ms; my $desc = $1;
$info =~ m/(^Version\s*:.*?\n)/ms; my $ver = $1; $ver =~ m/.*?:(.*)/; my $version = $1;
$info =~ m/(^Origin\s*:.*?\n)/ms; my $origin = $1;
- $info =~ m/(^Depends\s*:.*?\n)/ms; my $depends = $1;
- $info =~ m/(^Recommends\s*:.*?\n)/ms; my $recommends = $1;
+ $info =~ m/(^Depends\s*:.*?\n)/ms; my $depends = $1;
+ $info =~ m/(^Recommends\s*:.*?\n)/ms; my $recommends = $1;
$info =~ m/(^Filename\s*:.*?\n)/ms; my $filename = $1;
$info =~ m/(^Maintainer\s*:.*?\n)/ms; my $maintainer = $1;
my $log_row = "$date`$package`$version`$desc`\n$ver$origin$depends$recommends$filename$maintainer`~\n";
if($appRemoved){
my @removed = split ',', $appRemoved;
foreach my $package(@removed){
- my $info = `apt-cache show $package`;
+ my $info = `apt-cache show $package`;
$info =~ m/^Description[-\w]*:\s*(.*?)\./ms; my $desc = $1;
$info =~ m/(^Version\s*:.*?\n)/ms; my $ver = $1; $ver =~ m/.*?:(.*)/; my $version = $1;
- $info =~ m/(^Filename\s*:.*?\n)/ms; my $filename = $1;
+ $info =~ m/(^Filename\s*:.*?\n)/ms; my $filename = $1;
my $log_row = "$date`$package`$version`$desc`$filename~";
$CNF->parse(undef,qq(
<< CNF_APP_APT_REMOVED_PACKAGES <DATA> __HAS_HEADER__
return $txt . ' ' x $l . " | ";
}
+sub list_sys_installed {
+ my (@ret, @ret_installed);
+ my @res = map { /^(\S+)/ }
+ split( "\n", `dpkg --get-selections | grep -w "install"` );
+ my $distro_install_date = `stat \/ | grep \"Birth\"`;
+ $distro_install_date =~ s/Birth:\s//;
+
+ say
+"Current after system $distro_install_date date User installed packages (dpkg --get-selections | grep -w \"install\"):\n";
+ foreach my $package (@res) {
+ my $r = `whatis $package 2>&1`;
+ if ( $r !~ /nothing\sappropriate\.\s*$/ ) {
+ $r =~ s/^\s*|\s*$//gm;
+ $ret[@ret] = $package;
+ my $info = `zgrep \"install $package\" /var/log/dpkg.log*`;
+ #say $r;
+ if($info){
+ # Is in dpkg log and past birth, definitely was installed after the ubuntu/mint/debian distro.
+ #say $info;
+ my @date = ($info =~ /(\S+):(\S*\s\S*)/m);
+ my $cdate = CNFDateTime::_toCNFDate($date[1],$TZ);
+ say $r, " [Installed: ", $cdate->toSchlong(), " (", $cdate->toDateTimeFormat(),")]";
+ $ret_installed[@ret_installed] = [$package, $cdate];
+ }
+ }
+ }
+ return \@ret_installed;
+}
+
sub createDataCNFFile {
my @content = <DATA>;
$CNF->parse( undef, \@content );
say qq(Apt Installation with PerlCNF v.).CNFParser::VERSION().qq(
This script runs sudo apt install, keeping in CNF data script format an log, of apt-get packages installed.
-Useful is also tool to list all what have installed using it, to output to an bash script format.
+Useful is also tool to list all what hase been installed using it,
+ to output to an bash script format .
So when that new computer arrives, you edit and run that bash script, on it to install, what commonly use.
Note - You can modify this script to suit your needs for provided default options.
Available options:
--help|? - This Help.
--apt-help - To obtain available apt-get commands to ie. -> apt-get --help
- --data_dir={\$path} - Where to log history, default is "$data_dir".
+--data_dir = { \$path } - Where to log history, default is "$data_dir" .
--data_file={name} - Name of log to use, default is "$data_file".
--showLog - Prints the whole log sofar to the STDOUT, useful if --xz=1.
--tz|timezone={zone} - Timezone to use, default is "$TZ".
--hist|history - Display the CNF data log data, other options are ignored.
--generate-batch - Generate install batchfile from history.
- --cmd|command|c={apt command} The default apt-get command to use is assumed to be 'install',
+ --cmd|command|c={apt command} The default apt-get command to use is assumed to be 'install',
followed by packages or list of packages.
+--list - List user installed all packages, regardless of utility .
);
exit
}