Recent posts (max 20) - Browse or Archive for more

Scripting konsole and tabs

At work I want to launch two programs in separate tabs in konsole from a script, so I whipped this one up:

#!/bin/bash

checkfile() {
  if [ ! -f $1 ]; then
    echo "could not find $1"
    exit 99
  else
    echo "OK"
  fi
}

# Check for App1 XML
echo -n "Checking for App 1 XML... "
XMLA=/domain/DM.xml
checkfile ${DEVROOT}/${XMLA}

# Check for App2 XML
echo -n "Checking for App 2 XML... "
hostname=$(hostname)
XMLB=/domain/DM_${hostname}.xml
checkfile ${DEVROOT}/${XMLB}

# Launch Konsole
echo -n "Launching konsole... "
K=$(dcopstart konsole-script)

[ -z "${K}" ] && exit 98
# Create second tab and resize
SDA=$(dcop $k konsole currentSession)
SDB=$(dcop $k konsole newSession)
dcop $K $SDA setSize 121x25

# Let bash login, etc.
sleep 1

# Rename the tabs
dcop $K $SDA renameSession "App 1"
dcop $K $SDB renameSession "App 2"

# Start services, letting user watch
echo -n "starting app1... "
dcop $K konsole activateSession $SDA
dcop $K $SDA sendSession "echo -ne '\033]0;DEV (${hostname})\007' && clear && starter $XMLA"
sleep 2
echo -n "starting app2... "
dcop $K konsole activateSession $SDB
dcop $K $SDB sendSession "echo -ne '\033]0;DEV (${hostname})\007' && clear && starter $XMLB"
echo done.

The funky echo commands will set the application title to "DEV (hostname)" while the tab title is set with renameSession.

Delay Before RPM Installs

I wanted the user to have a chance to abort an install, for the ones that insist on using rpm vs yum.

%if <something>
%else
%global fake %%(for i in {1..100}; do echo " "; done)
%{echo:%{fake}WARNING: RPM will not properly require vendor drivers! }
%global fake %%(for i in {1..5}; do echo " "; done)
%{echo:%{fake}}
%global fake %(sleep 10)
%endif

Have RPM Require an Environmental Variable

$(warning RHEL4 is no longer supported!)
$(warning The driver RPMs no longer support RHEL4 and the RPM that is generated will not properly require them.)
ifeq ($(TARGET_RHEL_OVERRIDE),)
$(warning If you are OK with that, then you can re-run with TARGET_RHEL_OVERRIDE=1)
$(error RHEL4 is no longer supported!)
endif

Python deepcopy broken

Well, that was annoying... spent a long time last Friday and today to find out that Python 2.7's copy.deepcopy doesn't play well with xml.dom.minidom. See this bug report.

The workaround is to use "doc.cloneNode(True)" instead.

RPM Compression

The other day at work I noticed that at the end of an RPM build, it seemed to hang. It turns out, it was compressing the files to create the installer. I'd rather not have it do that if I am building development versions since they only get scp'd to a lab environment.

Even if it does compress, I'd like to have feedback as to what it is doing. So I added these lines to my .spec file. They should be easy enough to tweak and add to a system-level macros file.

Background: We had "dev" appended to the version number already, so this was the easiest way to do it:

%if 0%(echo %{rpm_version} | grep -c dev)
%define _source_payload w0.gzdio %%{echo:Skipping source RPM compression...}
%define _binary_payload w0.gzdio %%{echo:Skipping binary RPM compression...}
%else
%define _source_payload w9.gzdio %%{echo:Maximum source RPM compression...}
%define _binary_payload w9.gzdio %%{echo:Maximum binary RPM compression...}
%global _enable_debug_packages 0
%global _debug_package %{nil}
%endif

So now my RPMs are about four times as large as they were, but are built a lot faster.

Email your new IP address with TomatoUSB

So my router is now TomatoUSB and I wanted an alert when the IP changed. Sure, I could probably put something local on the router, but where's the fun in that?

So I put together a quick python script to drop me an email if the IP ever changes. Yes, TomatoUSB supports various Dynamic DNS services, but doesn't seem to natively support "email me."

So on the DDNS setup page, I chose the "Custom URL" service, and I put in "http://192.168.90.99/IPCHECKS?new_ip=@IP" as the URL (the internal address of an Apache server running WSGI.

I have a custom config file /etc/httpd/conf.d/wsgi_IP as follows:

WSGIScriptAlias /IPCHECKS /var/www/wsgi/IP.wsgi

<Directory "/var/www/wsgi/">
  WSGIApplicationGroup %{GLOBAL}
  Order deny,allow
  Deny from all
  Allow from 192 127 ::1
</Directory>

HOPEFULLY that means none of you can change what I think my IP address is. ;)

Here's the actual python script (/var/www/wsgi/IP.wsgi):

from __future__ import print_function
from cgi import parse_qs, escape
import socket
import smtplib

# This is RevRagnarok's ugly IP checker.
# Tomato (firmware) will post to us with a "new_ip" parameter
# At this point, I want to see manually that the IPs change, not have it autoupdate
# Note: I had to enable HTTP sending email in SELinux:
# setsebool -P httpd_can_sendmail 1

def application(environ, start_response):
    parameters = parse_qs(environ.get('QUERY_STRING', ''))
    if 'new_ip' in parameters:
        newip = escape(parameters['new_ip'][0])
    else:
        newip = 'Unknown!'
    start_response('200 OK', [('Content-Type', 'text/html')])
    # Look up DNS values
    oldip = socket.gethostbyname('revragnarok.com') # Yes, IPv4 only
    # Compare
    changed = ''
    if newip != oldip:
        changed = 'IP changed from {0} to {1}.'.format(oldip, newip)
    if changed:
        e_from = 'root@revragnarok.com'
        e_to = ['firewall-reports@revragnarok.com']
        e_msg = """Subject: IP Address change detected

{0}""".format(changed)
        # I considered a try/catch block here, but then what would I do?
        smtpObj = smtplib.SMTP('localhost')
        smtpObj.sendmail(e_from, e_to, e_msg)
    else:
       changed = '(unchanged)'
       changed = 'IP is {0} (unchanged).'.format(newip)
    return [changed]

And don't forget, if you use SELinux, fix permissions on the script, and allow the webserver to send email:

[root@webserver wsgi]# ls -Z IP.wsgi 
-rw-r--r--. root root system_u:object_r:httpd_sys_script_exec_t:s0 IP.wsgi
[root@webserver wsgi]# setsebool -P httpd_can_sendmail 1

Optional requirements for RPM

(Wow, it's been over a year since my last blog post...)

At work, I have a program that optionally could use the Qt libraries, but I didn't want my RPM to actually require libqt-mt.so like it wanted to. And RPM doesn't seem to support an "OptRequires" or something similar... so here's my hack of a solution.

I put this script named find-requires into my project's "build" subdirectory so it is included in the "Source" tarball that rpmbuild will be using. I wrote it to be expandable.

#!/usr/bin/perl -w
use strict;
use IPC::Open2;

# This quick script will run the native find-requires (first parameter)
# and then strip out packages we don't want listed.

open2(\*IN, \*OUT, @ARGV);
print OUT while (<STDIN>);
close(OUT);
my $list = join('', <IN>);

# Apply my filter(s):
$list =~ s/^libqt-mt.so.*?$//mg;

print $list;

Then put in your .spec file this, which will call our script with the original script as the first parameter:

# Note: 'global' evaluates NOW, 'define' allows recursion later...
%global _use_internal_dependency_generator 0
%global __find_requires_orig %{__find_requires}
%define __find_requires %{_builddir}/%{?buildsubdir}/build/find-requires %{__find_requires_orig}

Problems with Perl 5's switch

I was trying to use perl's __DATA__ subsection and was receiving the following warnings/errors:

readline() on unopened filehandle DATA
main::DATA used only once

Well, after fighting with it for like 20 minutes, I did a Google search. After wandering around different mailing list archives, etc, I finally found a hint of a solution.

Apparently, using "Switch" (via "use Switch;") does some kind of behind-the-scenes magic that breaks __DATA__ section stuff. :(

I didn't find anything in perldoc Switch that indicated it was a known bug. However, it is v5.8.5 so fairly old (2004, from RHEL 4.5) and the Switch documentation says it is from 2003.

Annoying tho.

sudo: sorry, you must have a tty to run sudo

Ran into this the other day at work on RHEL5. Unfortunately, net searches come up with a not-so-great answer - "just comment out Defaults requiretty." Don't you think it's there for a reason?

The reason is that without having TTY control characters interpreted, unless you are using the "NOPASSWD" option, sudo cannot mask out your password and it will be printed to your screen for all to see!

The simplest (and most proper IMHO) work-around is to simply use "ssh -t" instead of "ssh" in your command line that is calling sudo on the remote machine.

Screen

Screen is a useful tool when remoting into a Unix box. It's been around forever, and I'm just going to document the .screenrc that I use here:

altscreen
autodetach on
hardstatus alwayslastline "%{= bY}%3n %t%? @%u%?%? [%h]%?%=%c"
vbell on
startup_message off
pow_detach_msg "Screen session of $LOGNAME $:cr:$:nl:ended."
defscrollback 10000
nethack on
zmodem off
caption always '%{= bY}%-Lw%{= bm}%50>%n%f %t%{-}%+Lw%<'
dinfo
fit
defmonitor on
verbose on

Don't end filenames or directories with spaces

Yeah... my Ruby script that I posted before made a bunch of directories with spaces at the end. And then when I fixed the bug, I had directories with and without spaces at the end. Bad things happen...

Cannot delete file: Cannot read from the source file or disk.

PAR2 file mover

This is my first Ruby script... please feel free to contact me with feedback.

It will read a PAR2 parity file and move all the files in it to a subdirectory. The original thing I asked for:


I know you can currently download into subdirectories based on ID3 tags. I would love to be able to have downloads go into subdirectories based on the PAR2 file that "covers" them.

Example, all files downloaded overnite into a huge directory:

AAA.PAR2
AAA 01-16.mp3
AAA 02-16.mp3
...
AAA 16-16.mp3
AAA.nfo
AnnoyinglyNamedNothingLikeAAAButInThePARFileAnyway.nfo
BBB.PAR2
BBB 01-92.mp3
BBB 02-92.mp3
...
BBB 92-92.mp3
BBB.nfo
...
XXY.PAR2
XXY.mp3
XXY.txt

So I would want them moved into the subdirectories "AAA", "BBB", "XXY", etc. It wouldn't be perfect but it would be a great start for what I do to process my inbound stuff.

If not, how about dumping some log file I can parse in perl or ruby that gives me "AAA.LOG" which lists the files that went with AAA.PAR2 ?


Of course, being a borderline OCD engineer, I didn't just solve the problem but also put together a full object-oriented infrastructure to parse and process PAR2 files. I've only handled one packet type defined in the PAR2 specifications, but put in place a Par2BasePacket with an interface that all the other packet types can be derived from.

Without further delay, see the attached code (sorry, my install doesn't support syntax highlighting of ruby and I don't have time now - but you can paste the code into this online highlighter).

Using Kompare

So I was using Python to do some pretty diffs (will post that some time soon) and a coworker pointed out the program Kompare on Linux. I don't normally use Linux as a desktop, only servers. Anyway, it gives me an awesome interface, almost as good as the TortoiseSVN diff viewer I am used to. It can take the output of svn diff and then will find the original files and show you graphically all the changes.

The command I have been using:

svn diff | kompare -o -

Arduino Project

I'm thinking about starting an Arduino project. I don't want to reveal details yet. But it won't be all that cool, just something I want.

I was really liking the BlackWidow until I read that it is not 802.11b/g but b only, which would slow my network down too much. FAIL guys. :(

So now I need to decide - do I get a Ethernet shield for $46 and then load OpenWRT into a $25 802.11n router? Then if the project fails, I still can re-use the router as a bridge somewhere else... or do I splurge and spend $90 for a "real" Arduino 802.11g unit?

I Hate Java

(Originally posted 27 Nov 09, lost in server mishap, found in Google's cache of this page)

So for some reason this evening, my favorite RSS Reader (RSSOwl 2) wouldn't run... and that scares me. I use it to peruse probably 60-80 websites daily.

Anyway, it just wouldn't run. No error messages. Didn't even look like Windows would give it a chance. Never showed up in Task Manager. Well, I was using a beta, so I uninstalled it and installed the newly released 2.0. Still no luck. Nothing at all.

Decided to try it from the command line, to see if the helps:

Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/Object

That's nice and descriptive - WTF? Remembering that RSSOwl is built on the Java IDE Eclipse, I decided to make sure I have the newest Java. I am running Windows 7, which is fairly new, so maybe something happened there. Doesn't explain why I've been running it since its release with no problems up to now... In fact, I notice that running java from the command line gives me the same error.

BTW, Google was useless, a bunch of posts about Java from 2005, or talk about the SDKs and/or rt.jar. None seemed to apply.

So I install the latest, which is "Java 6 Update 17" - an odd numbering scheme, I will get back to that. With a fresh install, the plugin works in Firefox. Java.com has a link to check your JVM too. That crashed Firefox. So I copy the URL and try Internet Explorer. Crashed that too. Drop to the command line to try java - same error.

Open up the control panel to add/remove programs, and I see that there are 4 or 5 versions of Java installed. Why? Shouldn't "Update 17" be sufficient instead of also having Updates 2, 5, 7, and 13 also? (I don't remember the exact numbers).

After uninstalling all of them, and then installing the newest, everything works fine, including RSSOwl and the JVM check page:

RevRagnarok@Jotunheim ~
$ java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)

One note: I think Update 17 was the first one to be installed/updated after the upgrade from Vista to Win7. That may be related to why there was such weirdness... but I still don't agree with an update not removing all the previous ones.

RHEL/CentOS/VMWare pissed me off

(Originally posted 25 Oct 09, lost in server mishap, found in Google's cache of this page)

I cannot believe that a point release would hose me up so badly...

More than 4 serial ports under Linux

(Originally posted 24 Oct 09, lost in server mishap, found in Google's cache of this page)

So at work I am using a PCI104 octal serial port board. It's pretty cool that Linux now supports those OOB, but I had problems; I only saw the first two ports!

After doing a bunch of research; I finally found the problem. I had assumed it was something with the chipset itself. However, it is a problem with the default kernel build from RHEL/CentOS. They only allow up to four by default! To get more (up to 32 with the RHEL/CentOS kernel), you have to add to the command line in GRUB:

8250.nr_uarts=12

Again, that can be up to 32. I chose 12 because "traditionally" the mobo could have up to four. That made the two on the mobo ttyS0 and ttyS1, so the octal card has ttyS4 to ttyS11. So ttyS2 and ttyS3 are unused. A quick check with dmesg | grep ttyS will show them being allocated.

Side note: You can check how many the default is by doing grep CONFIG_SERIAL_8250 /boot/config-`uname -r` and looking for CONFIG_SERIAL_8250_RUNTIME_UARTS. CONFIG_SERIAL_8250_NR_UARTS is the maximum you can have without rebuilding the kernel.

Maybe I'll get inspired and blog sometime about the cool stuff I did with udev so that I can configure a box and then the software would just "know" where which serial port the (external device) was on by calling /dev/projectname/extdevice .

Strange Software Install Issue (Installer silently hangs)

I've been having a strange install issue with the ATI Catalyst software. It's documented here on the AMD site: http://forums.amd.com/game/messageview.cfm?catid=279&threadid=125401&forumid=11

However, forums like that have a great history of disappearing when I need them most, so a summary is also now here.

Setup was totally hanging. I tried all kinds of things to trace what was happening. Then this wonderful post came along:

From Wiink:


I signed up to post in this thread since I was having the exact same issue and was really frustrated over it. I have a 4890 and have always used Ati graphics cards, never had any issues and drivers always installed flawlessly until one day i decided to update from 9.8 to the current 9.12.

I'd go through the usual uninstall methods using the ati uninstaller and then follow up with driver sweeper. Click on the exe for the 9.12 suite and it would unpack/extract then an hourglass for about 5 seconds and then nothing. I would see InstallManagerApp.exe running in the taskmanager and my hdd light would be lit, but that was about it....no install. Tried many times and nothing worked. Drove me absolutely crazy. Checked and re-checked all the cleanup, c++ redist and .net stuff....All in order and still same results - nothing.

Then I came across this thread about not having full admin permission for registry changes needed for some software installs even though I am the only user and Admin of this pc. When installing the 9.12 Catalyst Suite, it needs to change something in the registry that was now being blocked , so I ran this fix posted here and my problems were solved immediately on both my Vista and my XP Pro machines. Just remember to create a fresh system restore point before applying it. I was so happy to have the issue fixed I had to share. It specifies Vista in the post, but it worked for my Xp Pro as well flawlessly. Took about 20 minutes and fixed! And sorry for the wall of text. Just do a reboot after running the cmd file and try to install the catalyst 9.12 suite again, should work now.

Post by Michael G. Simmons: http://social.msdn.microsoft.com/forums/en-US/vbexpress2008prerelease/thread/c273b0e1-7f46-4065-afaf-4edf285d2531

There is a quick fix for this and any other permission issues that occur with Vista. I've seen this happen with several different installs under Vista including VS 2005 and Orcas. The problem is for some reason regisry permissions are given to the user msiserver. You can reset each entry manually, but that is a major pain. It's much easier just to fix the entire registry by using the SubInACL utility. Basically, you can use the utility to add administrator permissions to every key in the registry.

  1. Download and install the SubInACL utility.

2.Create a new text file named fix_registry_permissions.cmd and add the following text to it and save it.

    cd /d "%programfiles%\Windows Resource Kits\Tools"
    subinacl /subkeyreg HKEY_LOCAL_MACHINE /grant=administrators=f /grant=system=f
    subinacl /subkeyreg HKEY_CURRENT_USER /grant=administrators=f /grant=system=f
    subinacl /subkeyreg HKEY_CLASSES_ROOT /grant=administrators=f /grant=system=f
    subinacl /subdirectories %SystemDrive% /grant=administrators=f /grant=system=f
    subinacl /subdirectories %windir%\*.* /grant=administrators=f /grant=system=f
  1. Run the file by double-clicking on it.

That's it. It will take several minutes to finish, but at the end all registry keys will be accessable to the administrator and system, as it should be.

My Dell XPS Gen 3 won't boot from CD-ROM!

To: Some friends of mine.

Any ideas on this head-scratcher?

My Dell XPS (getting really old, I know) won't boot from CD-ROM. I have tried 3-4 different CDs. One of the CDs has multiple boot images on it and none of them boot.

Here's the weird part - I can get the boot loaders to work! The Ghost ones will say "Loading PC-DOS..." and then the CD drive just stops spinning. The multiboot one gives me all the menus, but as soon as it tries to launch something, it hangs in the same way. Even good ol' DOS 6.22 says "Loading MS-DOS..." and hangs. I tried my CentOS 4 installer DVD - I get the boot menus, I type "linux rescue" and then it just sits there.

My config is multiple SATA drives and two PATA CDs. I have even disabled the master and then I have the same issue with the secondary (it won't touch the secondary if the master is enabled, even if no CD in master). Same thing.

And here it gets even weirder... I booted from a USB key with Ghost on it just fine; I'm doing my backups now. WTF?!?!

Various suggestions came back... then a few days later, I found the solution!

You've GOT to be shitting me... I fixed it!

http://support.dell.com/support/downloads/download.aspx?c=us&l=en&s=gen&releaseid=R104585&SystemID=DIM_PNT_P4_XPS_G3&servicetag=&os=WW1&osl=en&deviceid=308&devlib=0&typecnt=0&vercnt=8&catid=-1&impid=-1&formatcnt=1&libid=1&fileid=135030

I didn't install this BIOS release from over 4 years ago (I have A06), but look at the changelog:

"1. Prevent boot issues when USB devices with media readers are present."

Lo and behold, I plugged my monitor in a few weeks ago. Which has a (useless) built-in USB hub and media reader! I never would've expected something like that to happen! So my guess is that the BIOS tries to enumerate the drives somehow to map to INT13 and hangs up! When I yanked the USB cable from the monitor, CDs booted just fine!!?!?

I thought the USB hub was useless before because it powers off with the monitor - now it is a downright HINDRANCE!

RPMBuild stupidity

OK, this just pisses me off. It's plain dumb - rpmbuild expands macros before stripping comments. So what happened to me today (and I wasted an hour on) was that a multi-line macro was being inserted into a comment!

Based on a quick search of bugzilla at readhat, I'm not the only one - see 74949 and 99100. They say WONTFIX but that's just dumb in my not-so-humble opinion.

So now you know. If you are making a spec file for an RPM:

%files
# %build

will screw you over like it did me. You need to:

%files
# %%build