Pages

Tuesday, 4 March 2014

Old Scripts (2005) - that probably still work - convert Debian/Ubuntu packages to .tgz Slackware <-> .bz2

Just another of my perl files. As far as I remember I based this work on Alien a package convertor or at least a bit of it.

#!/usr/bin/perl # # #convertpkg - converts Debian packages to .tgz (Slackware) or .bz2 (ISlack), .tgz to .bz2 and .bz2 to .tgz #Copyright (C) 22.10.2005 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. package convertpkg; use strict; use lib '.'; # For debugging, removed by Makefile. use Getopt::Long; # Display usage help. sub usage { print STDERR <<EOF; Description: convertpkg - converts Debian packages to .tgz (Slackware) or .bz2 (ISlack), .tgz to .bz2 and .bz2 to .tgz Usage: convertpkg [options] file [...] Option: Description: file [...] Package file or files to convert. -h, --help Display this help message. Target Package: -b, --to-bz2 Generate a ISlack package. -t, --to-tgz Generate a Slackware tgz package. Examples: Converting ISlack to Slackware package: convertpkg -t example-0.0.0-i386.bz2 Converting Slackware to ISlack package: convertpkg -b example-0.0.0-i386.tgz Converting Debian to Slackware package: convertpkg -t example_0.0.0_i386.deb Converting Debian to ISlack package: convertpkg -b example_0.0.0_i386.deb EOF exit 1; } # Start by processing the parameters. my (%destformats, $new_dest, $new_file, $format, $string1, @pairs, $line1, $line2, $line3, $line4, $line5, $line6, $line7, $line8, $line9, $line10); my $versionbump=1; # Bundling is nice anyway, and it is required or Getopt::Long will confuse # -T and -t. Getopt::Long::Configure("bundling"); GetOptions( "to-bz2|b" => sub { $destformats{bz2}=1 }, "to-tgz|t" => sub { $destformats{tgz}=1 }, "help|h" => \&usage, ) || usage(); # if (! -w '.') { die("Cannot write to current directory. Try moving to /tmp and re-running convertpkg.\n"); } if ($> != 0) { print STDERR "Warning: convertpkg is not running as root!\n"; print STDERR "Warning: Ownerships of files in the generated packages will probably be messed up.\n"; } foreach my $file (@ARGV) { if (! -f $file) { die "File \"$file\" not found.\n"; } # Debian to ? if ($file =~ m/.deb/) { foreach my $format (keys %destformats) { print STDERR "Processing '$file'\n"; $new_file = $file; $new_dest = $file; system ("mkdir debtotgz"); system ("ar p $file data.tar.gz | gunzip > debtotgz/data.tar"); system ("ar p $file control.tar.gz | gunzip > debtotgz/control.tar"); chdir "debtotgz"; system ("tar -xvvf data.tar"); system ("tar -xvvf control.tar"); system ("mkdir install"); system ("mv -f postinst install/doinst.sh"); system ("cat control | grep -A 11 Description: > install/slack-desc"); open(OUTF,"install/slack-desc") or dienice("Can't open survey.out: $!"); @pairs = split(/_/, $file); $line1 = <OUTF>; $line2 = <OUTF>; $line3 = <OUTF>; $line4 = <OUTF>; $line5 = <OUTF>; $line6 = <OUTF>; $line7 = <OUTF>; $line8 = <OUTF>; $line9 = <OUTF>; $line10 = <OUTF>; $line1 = @pairs[0].": ".substr($line1, 13, 30); $line2 = @pairs[0].":".$line2; $line3 = @pairs[0].":".$line3; $line4 = @pairs[0].":".$line4; $line5 = @pairs[0].":".$line5; $line6 = @pairs[0].":".$line6; $line7 = @pairs[0].":".$line7; $line8 = @pairs[0].":".$line8; $line9 = @pairs[0].":".$line9; $line10 = @pairs[0].":".$line10; close(OUTF); open(OUTF,">install/slack-desc") or dienice("Can't open survey.out: $!"); print OUTF "$line1"; print OUTF @pairs[0].": \n"; if ($line2 ne @pairs[0].":") {print OUTF "$line2";} if ($line3 ne @pairs[0].":") {print OUTF "$line3";} if ($line4 ne @pairs[0].":") {print OUTF "$line4";} if ($line5 ne @pairs[0].":") {print OUTF "$line5";} if ($line6 ne @pairs[0].":") {print OUTF "$line6";} if ($line7 ne @pairs[0].":") {print OUTF "$line7";} if ($line8 ne @pairs[0].":") {print OUTF "$line8";} if ($line9 ne @pairs[0].":") {print OUTF "$line9";} if ($line10 ne @pairs[0].":") {print OUTF "$line10";} close(OUTF); system ("rm -f control"); system ("rm -f md5sums"); system ("rm -f mpostrm"); system ("rm -f prerm"); system ("rm -f shlibs"); system ("rm -f control.tar"); system ("rm -f data.tar"); system ("rm -f postrm"); system ("rm -f preinst"); $new_file =~ s/\.deb\b/\.tar/i; system ("tar -cvvf $new_file ."); if ($format eq 'tgz') { $new_dest =~s/\.deb\b/\.tgz/i; system ("gzip $new_file"); chdir ".."; $string1 = $new_dest; $string1 =~ s/_/-/g; system ("mv debtotgz/$new_file.gz $string1"); } elsif ($format eq 'bz2') { $new_dest =~s/\.deb\b/\.bz2/i; system ("bzip2 $new_file"); chdir ".."; $string1 = $new_dest; $string1 =~ s/_/-/g; system ("mv debtotgz/$new_file.bz2 $string1"); } else {die "Unknown type of package - Error 1, $file.\n";} } system ("rm -rf debtotgz"); } #Tgz to Bz2 elsif ($file =~ m/.tgz/) { foreach my $format (keys %destformats) { if ($format eq 'bz2') { print STDERR "Processing '$file'\n"; $new_file = $file; $new_dest = $file; system ("gunzip $file"); $new_file =~ s/\.tgz\b/\.tar/i; $new_dest =~s/\.tgz\b/\.bz2/i; system ("bzip2 $new_file"); system ("mv $new_file.bz2 $new_dest") } else {die "Unknown type of package - Error 2, $file.\n";} } } #Bz2 to Tgz elsif ($file =~ m/.bz2/) { foreach my $format (keys %destformats) { if ($format eq 'tgz') { print STDERR "Processing '$file'\n"; $new_file = $file; $new_dest = $file; system ("bunzip2 $file"); $new_file =~ s/\.bz2\b/\""/i; $new_dest =~s/\.bz2\b/\.tgz/i; system ("gzip $new_file"); system ("mv $new_file.gz $new_dest"); } else {die "Unknown type of package - Error 3, $file.\n";}} } #Oh well ... else { die "Unknown type of package - Error 4, $file.\n"; } }

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(); } }

Thursday, 20 February 2014

OVA and hardware versions

I made a virtual appliance a while ago for a client everything seemed to be working, but there was a slight problem with it, since it was exported in ova and imported back to a ESXi 5.0 it didn't work because of the virtual hardware version. I spent some time figuring what the correct version should be and here is what I found:

 virtualHW.version = "4"                 # essential for ESX 3.5
 virtualHW.version = "7"                 # essential for ESX 4.0
 virtualHW.version = "8"                 # essential for ESX 5.0
 virtualHW.version = "9"                 # essential for ESX 5.1

You will find the hardware version in the VMX file afterwards you can export it back to OVA. Let's cross fingers and hope it works this time.

Thursday, 6 February 2014

Ubuntu Server 12.04 - network settings

I had to setup today a Ubuntu Server 12.04 virtual machine for a client with some of our products pre-installed on it. First thing was that they used IPv4 and second for some reason I was unable to resolve properly. So here is what I did and worked:

I disabled IPv6 putting the following lines in  /etc/sysctl.conf :
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

In /etc/network/interfaces I set the static IPs for the network addapters:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.6
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255

In Ubuntu Server 12.04, any changes made manually to /etc/resolv.conf will be overwritten later by a DNS information manager called resolvconf.

If you want to change the default settings, you could modify files base, head, or 
tail under /etc/resolvconf/resolv.conf.d.

base: Used when no other data can be found
head: Header of default resolv.conf. The server inside will the first ones to check.
tail: entries appended at the end of resolv.conf. In some cases, upgrading from a previous Ubuntu release, will make tail a symlink to original.

After this small changes everything worked as planed.

Monday, 3 February 2014

FreeNAS 9.1.1 and APC ES700

I got a ES700 APC UPS the problem was that I needed to connect it to my FreeNAS server and eventually configure it, but for some reason I couldn't run the service related to the UPS in FreeNAS 9.1.1. And then I found this:

https://bugs.freenas.org/issues/2548

First thing to do before you apply the fix be sure that the UPS is configured on the correct port.
If you turn on "show console messages" in System -> Settings -> Advanced and watch the messages as you plug in the UPS, it should show the FreeBSD device name. 

Second be sure to have the correct profile for the UPS, for me "APC ups 2 Back-UPS ES/CyberFort 350 USB (usbhid-ups)" worked.

Apply the fix:

scp usbhid-ups.xz to somewhere writable, e.g. /var or the main pool
SSH into FreeNAS
unxz usbhid-ups.xz
mountrw /
Btw I noticed that the copy command (the path) in the instructions for the fix was mistaken:
cp usbhid-ups /usr/local/libexec/nut/usbhid-ups
mount -ur /

Start the UPS service.