Tuesday, 4 March 2014

Old Scripts (2006) - that probably still work - gets slackware current

This goes back when I still actively developed ISlack/NetSecL and is a script that fetches all of the packages that were current from the Slackware current tree. Just reminds me how many times Perl saved me from doing complex tasks at my job and on personal projects. It is an excellent language for parsing not only this. Note the license test is taking 1/3 from the actual code itself.

Here is the config file (tgzget.cfg) and how it actually looked like:
; Config::Simple 4.58
; Mon May 15 23:36:03 2006

lastupdate=Sat May 13 21:00:28 CDT 2006\\n

mirror=ftp://mirrors.unixsol.org/slackware/slackware-current/

And the script itself:

#!/usr/bin/perl # # # islackup - Perl script to parse the changelog and download the new current slackware packages. It #"remembers" the date of the last successfull download and continues from there. # Copyright (C) 2006 Iuri Stanchev # #This program is free software; you can redistribute it and/or #modify it under the terms of the GNU General Public License #as published by the Free Software Foundation; either version 2 #of the License, or (at your option) any later version. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. use Config::Simple; $cfg = new Config::Simple('tgzget.cfg'); $lastup = $cfg->param("lastupdate"); $mirror = $cfg->param("mirror"); system ("rm -f ChangeLog.txt"); system ("wget ftp://mirrors.unixsol.org/slackware/slackware-current/ChangeLog.txt"); open(OUTF,"ChangeLog.txt") or dienice("Can't open survey.out: $!"); @ary = <OUTF>; @files = (); close(OUTF); $i = 0; $die = 0; $newup =0; foreach $line (@ary) { if ($line =~ m/$lastup/){$die++;} if ($newup == 0){ $newupl = substr($line, 0, 3); if ($newupl =~ m/Mon/|$newupl =~ m/Tue/|$newupl =~ m/Wed/|$newupl =~ m/Thu/|$newupl =~ m/Fri/|$newupl =~ m/Sat/|$newupl =~ m/Sun/) { $newup++; $cfg->param("lastupdate", "$line"); } } if ($die == 0){ $tree = substr($line, 0, 1); if ($tree =~ m/a/|$tree =~ m/d/|$tree =~ m/e/|$tree =~ m/f/|$tree =~ m/k/|$tree =~ m/l/|$tree =~ m/n/|$tree =~ m/t/|$tree =~ m/x/) { @file = split(/:/,$line); @files[$i] = @file[0]; # print @file[0]; system ("wget $mirror/@file[0]"); $i++;} } if ($die == 1){ $cfg->write(); } }