Peter Blair

Quick launcher for ISO files and kids games

We only run linux at home, but my kids have a few game titles that I’ve stored (err, protected) on disk as ISO files. It’s a real PITA to write down the command line options for my wife to execute when they feel like playing a game, so I’ve thrown together a few quick scripts to allow them to click and launch the application in the autorun.inf file.

But, some of the games fail to run with the executable in the autorun.inf file, so there’s a Perl script that allows for overrides.

Step 1: The launcher
My daughter and I collected some images off of google that match each game. I’ve created a simple bash script that gets linked to the given icon:

#!/bin/bash
~/opt/bin/miso ~/iso/Pajama_Sam_Darkness.iso

Where “miso” is a C application:

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
 
int main(int argc, char ** argv)
{
   char cmd[100];
   if( argc < 1 ){
        exit(1);
   }
   sprintf( cmd, "/home/p/opt/bin/miso.pl %s", argv[1] );
   setuid( 0 );
   system( cmd );
 
   return 0;
}

I’ve chmod’d “miso” to be sticky, and owned by root so that the perl script “miso.pl” will be able to execute as root (Ya ya, I know.. but this isn’t some ultra secure server; it’s our home pc).

miso.pl

#!/usr/bin/perl
use strict;
my $debug = 1;
my $iso = $ARGV[0] || die("Please give iso filename as argument\n");
 
`umount /mnt`;
`mount -o loop $iso /mnt`;
 
my $weirdo = {
        'PAJAMALRS.iso' => '/home/p/.wine/drive_c/Program Files/Atari/Pajama Sam LRS/PajamaLRS.exe',
        'SPYFOX_ozone.iso' => '/mnt/spyozon.exe'
        };
 
`cd /mnt`;
X: for( 1..1 ){
        for my $w ( sort keys %$weirdo ){
                print "Comparing [$iso] with [$w]\n" if $debug;
                if( $iso =~ /$w/ ){
                        print "Executing $weirdo->{$w}\n" if $debug;
                        `sudo -u p wine "$weirdo->{$w}"`;
                        last X;
                }
        }
        `~/opt/bin/miso.sh $iso`;
 }
`cd -`;
`umount /mnt`;

Again, more error checking could be used, but I doubt that either of my daughters are going to use this script to gain local root to the PC.

As you can see, if the name of the ISO matches any of the keys in the hash-map, then the alternative executable is launched. Otherwise, it falls back to:

miso.sh:

#!/bin/bash
umount /mnt
mount -o loop $1 /mnt
 
cd /mnt
AR=$(ls | grep -i autorun.inf)
EXE=$(grep open= $AR | cut -d= -f2 | tr -d \\r\\n)
ls -1 | grep -i $EXE | sudo -u p xargs -n1 wine
cd -
umount /mnt

which looks in the autorun.inf file and executes whichever application is listed there. Note the “sudo -u p xargs -n1 wine”. My local username is “p”. You’ll have to change that ;)


Categorised as: Computers, Perl, Programming, UNIX


Comments are closed.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes