LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 02-07-2009, 10:39 AM   #1
kingkongrevenge
LQ Newbie
 
Registered: May 2006
Posts: 6

Rep: Reputation: 0
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
 
Old 02-07-2009, 11:55 AM   #2
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,639

Rep: Reputation: Disabled
How will your name parser deal with, for example:

attr-2.4.41_1-i486-1
bind-9.4.2_P2-i486-1
gtk+2-2.12.12-i486-1
k3b-r899444-i486-1

I think it will fail on these.

Out of curiosity, what is so complicated and heavy about:

Code:
slackpkg update
slackpkg upgrade-all   <---This command presents you with a list of packages which have changed
You could easily integrate the first command and a diff of the ChangeLog as a cron job if you wanted an automatic notification of potential updates

Brian
 
Old 02-07-2009, 04:08 PM   #3
kingkongrevenge
LQ Newbie
 
Registered: May 2006
Posts: 6

Original Poster
Rep: Reputation: 0
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.
 
Old 02-07-2009, 09:09 PM   #4
alkos333
Member
 
Registered: Dec 2006
Posts: 271

Rep: Reputation: 31
Good thing the user doesn't have to actually understand what those 1500 lines do, right ? You are reinventing the wheel here.

slackpkg has been around for some time and has been thoroughly tested.
 
Old 02-07-2009, 09:17 PM   #5
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,639

Rep: Reputation: Disabled
Quote:
Originally Posted by alkos333 View Post
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.

Brian

Last edited by BCarey; 02-07-2009 at 09:24 PM.
 
Old 02-08-2009, 05:36 AM   #6
vdemuth
Member
 
Registered: Oct 2003
Location: West Midlands, UK
Distribution: Slackware 14 (Server),OpenSuse 13.2 (Laptop & Desktop),, OpenSuse 13.2 on the wifes lappy
Posts: 781

Rep: Reputation: 98
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.
 
Old 02-08-2009, 05:54 AM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,130

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
+1.
The attitude of the Slack community is the major reason I never stay long.
 
Old 02-08-2009, 07:25 AM   #8
alkos333
Member
 
Registered: Dec 2006
Posts: 271

Rep: Reputation: 31
Quote:
Originally Posted by vdemuth View Post
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.
 
Old 02-08-2009, 07:36 AM   #9
alkos333
Member
 
Registered: Dec 2006
Posts: 271

Rep: Reputation: 31
Quote:
Originally Posted by syg00 View Post
+1.
The attitude of the Slack community is the major reason I never stay long.
What exactly is your problem with the Slackware community? I find it very welcoming and helpful.
 
Old 02-08-2009, 09:28 AM   #10
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,639

Rep: Reputation: Disabled
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.

Brian
 
Old 02-08-2009, 10:45 AM   #11
kingkongrevenge
LQ Newbie
 
Registered: May 2006
Posts: 6

Original Poster
Rep: Reputation: 0
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.
 
Old 02-08-2009, 11:19 AM   #12
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Quote:
Originally Posted by kingkongrevenge View Post
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).
Well, you could try to modify slackpkg.
 
Old 02-08-2009, 01:17 PM   #13
acummings
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 615

Rep: Reputation: 50
http://www.darklinux.net/slackupdate/

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.

Alan.
 
Old 02-08-2009, 02:53 PM   #14
alkos333
Member
 
Registered: Dec 2006
Posts: 271

Rep: Reputation: 31
Quote:
Originally Posted by kingkongrevenge View Post
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.
 
Old 02-08-2009, 03:16 PM   #15
AceofSpades19
Senior Member
 
Registered: Feb 2007
Location: Chilliwack,BC.Canada
Distribution: Slackware64 -current
Posts: 2,079

Rep: Reputation: 58
Quote:
Originally Posted by alkos333 View Post
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do you keep packages that you install up to date and patched? Unregistered Slackware 7 07-27-2008 10:15 PM
official slack packages not on cd moob8 Slackware 3 10-09-2006 10:01 AM
Debian patched kernel vs official Linux Kernel gerald45 Debian 7 10-12-2005 04:45 AM
Perl Script To Check Logs Crashed_Again Programming 0 11-13-2004 03:13 PM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 10:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 05:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration