This is my perl script to check for new official patched packages.
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This is my perl script to check for new official patched packages.
The various solutions out there for keeping a slackware system up to date seem way too complicated and heavy to me. I just wanted a simple cron job that tells me there's a new patch. My script is a small fraction of the code of the other systems and is easily customizable. It's doesn't do any security or integrity checking, but I personally don't care. Just thought I'd share this.
update: some fixes.
Code:
#!/usr/bin/perl
use warnings;
use strict;
use feature ":5.10";
###
### Reports applicable patches for installed packages and tries to download the patches to /tmp.
### Author: Thomas Rowe
### License: public domain
###
# Edit these constants.
use constant {
HOST => "ftp.cerias.purdue.edu",
PATH => "/pub/os/slackware/slackware-12.2/patches/packages",
LOCAL_PATCHES => "/var/tmp",
DO_UPGRADES => 0 # Whether to try and run upgradepkg. Otherwise, just try and fetch.
};
use Net::FTP;
sub splitname {
my $name = shift;
my @k = qw/name version arch build/;
my %pieces = map { shift @k => $_ } ($name =~ /^([\w\+-]+)-([^-]+)-([^-]+)-(\d+)_*.*$/);
return %pieces;
}
sub version_cmp {
my ($a, $b) = @_;
my @vera = split /\./, $a;
my @verb = split /\./, $b;
return 0 if @vera ~~ @verb;
while (@vera and @verb) {
my $na = shift @vera;
my $nb = shift @verb;
my ($na_digits, $na_other_str, $na_pldigits) = ($na =~ /^(\d+)(\D*)(\d*)/);
$na_digits //= 0;
$na_other_str //= '';
$na_pldigits //= 0;
my ($nb_digits, $nb_other_str, $nb_pldigits) = ($nb =~ /^(\d+)(\D*)(\d*)/);
$nb_digits //= 0;
$nb_other_str //= '';
$nb_pldigits //= 0;
return $na_digits <=> $nb_digits if ($na_digits != $nb_digits);
return $na_other_str cmp $nb_other_str if ($na_other_str ne $nb_other_str);
return $na_pldigits <=> $nb_pldigits if ($na_pldigits ne $nb_pldigits);
}
# resort to assuming the longer version string is higher.
if (@vera) {
return 1;
}
elsif (@verb) {
return -1;
}
else {
return length $a <=> length $b;
}
warn "The version string parser choaked on these strings!: $a % $b";
return undef;
}
sub is_upgrade {
my ($a, $b) = @_;
my %old = splitname $a;
my %new = splitname $b;
if ($old{name} && $new{name} && $old{name} eq $new{name}
and version_cmp($old{version}, $new{version}) == -1
|| $old{build} < $new{build}
|| $old{arch} ne $new{arch}) {
return 1;
}
return 0;
}
MAIN: {
my $ftp = Net::FTP->new(HOST)
or die "Cannot connect: $@";
$ftp->login("anonymous",'-anonymous@')
or die "Cannot login: ", $ftp->message;
$ftp->cwd(PATH)
or die "Cannnot cwd: ", $ftp->message;
my @patches = grep { defined } map { /(\S+)\.tgz$/; $1 } $ftp->dir;
my @installed = map { (split '/', $_)[-1] } glob("/var/log/packages/*");
my @unapplied;
foreach my $patch (@patches) {
# Don't care about already installed patches.
next if $patch ~~ @installed;
push @unapplied, $patch if grep { is_upgrade $_, $patch } @installed;
}
foreach (@unapplied) {
say;
if ($ftp->get("$_.tgz", LOCAL_PATCHES . "/$_.tgz")) {
say "fetched: " . LOCAL_PATCHES . "/$_.tgz";
}
else {
say STDERR "Couldn't fetch $_ from " . HOST . PATH . ": " . $! . $ftp->message;
}
if (DO_UPGRADES) {
system "upgradepkg " . LOCAL_PATCHES . "/$_.tgz";
}
}
}
Last edited by kingkongrevenge; 02-07-2009 at 03:50 PM.
Reason: fix code
You're right, my parser was far too naive. It's fixed. At least as far as I know.
Quote:
Out of curiosity, what is so complicated and heavy about...
slackpkg is something like 1,500 lines of code, is not very comprehensible (IMHO), maintains its own database, requires configuration, and spews a lot of unnecessary text. This script is about 100 lines of simple code and does everything I (and probably most people) need.
Take it for what it's worth, which isn't much as I just tossed it off in a couple hours out of boredom. I'm sure it's still buggy. Just thought I'd share. I like it better than slackpkg.
slackpkg has been around for some time and has been thoroughly tested.
That's the point, really. Fun with tossing out perl scripts is one thing, and it may be just fine for personal use. I love doing it myself. But what "probably most people" need is a thoroughly tested, secure way of keeping their system up to date. Slackpkg provides that and more. It needs to be configured by uncommenting one line in one file. And what does it matter what "unnecessary text" it "spews"? Noone actually has to read it. QA and testing are what really make the difference between messing about with coding and writing actual production software.
I'm not trying to harsh on you. Thanks for sharing. It's just that stable, well-tested, secure software is what slack is all about. Slackpkg spent quite a few releases in /testing before it was deemed stable and effective enough to be moved into the standard tree. A lot of us put a lot of value in that development cycle.
Distribution: Slackware 14 (Server),OpenSuse 13.2 (Laptop & Desktop),, OpenSuse 13.2 on the wifes lappy
Posts: 781
Rep:
Can't understand why kingkingrevenge is getting such a hard time here. For goodness sake, so he has written a script and has decided to share it. All kudos to him for doing so. What he certainly doesn't need is 'destructive criticism'. I suppose that plenty of the people using Slackware know of slackpkg, and are happy with it. Kingkongrevenge is pretty obviously looking for a simpler solution that works for him, and is happy to share his work for the benefit of the community, and for other people, who maybe like himself are looking for something just that little bit simpler.
And the argument about slackpkg being stable and tested, is pretty mute really. After all, it too likely started off as one persons need to find the solution to a problem, and has taken a while to get where it is now. You never know, this script might be the next big thing in a few iterations time, so how about cutting the guy some slack (no pun intended) and supporting rather than criticising.
Can't understand why kingkingrevenge is getting such a hard time here. For goodness sake, so he has written a script and has decided to share it. All kudos to him for doing so. What he certainly doesn't need is 'destructive criticism'. I suppose that plenty of the people using Slackware know of slackpkg, and are happy with it. Kingkongrevenge is pretty obviously looking for a simpler solution that works for him, and is happy to share his work for the benefit of the community, and for other people, who maybe like himself are looking for something just that little bit simpler.
And the argument about slackpkg being stable and tested, is pretty mute really. After all, it too likely started off as one persons need to find the solution to a problem, and has taken a while to get where it is now. You never know, this script might be the next big thing in a few iterations time, so how about cutting the guy some slack (no pun intended) and supporting rather than criticising.
What you just wrote was kind of self-implied. I'm not telling him not to write his own. I'm not telling him not to share. I was specifically concentrating on two points he made. Reinventing the wheel shouldn't really be taken any offense to because he knows he's not creating anything original - he's just trying his own script. I love perl myself and I think this is quite a nifty script. Really, no need to start sympathy wars here. He's not a 5-year old (probably ) and doesn't need any protection.
As I said in my post, I wasn't criticizing him for posting this. I was reacting to him saying that his short script was better for most people than slackpkg (about which I thought he used some pretty disparaging comments), and explained why I disagreed.
slackpkg deserves some criticism. All the chatter is in poor taste; not very unix-y. There are no simple reporting options (that's why I needed to write this). And it's A LOT of code and complexity to do something that's pretty simple.
slackpkg deserves some criticism. All the chatter is in poor taste; not very unix-y. There are no simple reporting options (that's why I needed to write this).
I've used that for quite some time now. It has an option to "just check: Are updates available -- reports back yes or no
Its default may be to download any available
that's what I do. I've never tried its opt to also auto install the updates.
I prefer to run (as root) upgradepkg /tmp/slackupdate/*.tgz
after the updates are downloaded and I've looked at the changelog and I've verified /etc/slackupdate_blacklist
(any pkgs I've blacklisted that slackupdate does not download [works nicely, impressive actually] so that I am safe to run the above upgradepkg command.
Conservative me. it's 1 the reasons I'm a Slackware user.
I get your point about a simple and quick checker. If you search this forum for posts that contain by me, my username, you'll find one on a Perl script that I began (didn't yet finish) for exactly this same thing.
Near approx give or take a year and a half ago dated, said thread.
Many others back then chimed in, shared their "simple" solutions as well. IOW you might find the thread interesting. Gotta run now. But if more time later on, I'll find the thread and post a link here to it.
slackpkg deserves some criticism. All the chatter is in poor taste; not very unix-y. There are no simple reporting options (that's why I needed to write this). And it's A LOT of code and complexity to do something that's pretty simple.
I agree with you. Bash is not powerful enough to keep the code concise. Look at sbopkg and their update checker. It's massive. Why? -- because Bash is simply not the right language to use IMHO, but the guys decided to go with bash, so they could use dialogs and easily integrate with the rest of the shell scripts.
I agree with you. Bash is not powerful enough to keep the code concise. Look at sbopkg and their update checker. It's massive. Why? -- because Bash is simply not the right language to use IMHO, but the guys decided to go with bash, so they could use dialogs and easily integrate with the rest of the shell scripts.
I agree, I think COBOL would be a much better choice, its so good the state of California uses it and its extremely stable since it has been around since the 60's or so
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.