29 Jan 2010

packing several unix files into one executable shell script (simple installer)

These 2 scripts are able to pack a directory into a shell script. The shell script can then be executed on another system and will extract the packed files into a target directory, unix permissions will be preserved (tar is used).

What you need:
- sh
- readlink
- dirname
- basename
- tar
- gzip
- uuencode
- uudecode
- cat
- chmod

pack.sh

#!/bin/sh

# $1 is source directory or file
if [ -z "$1" -o ! -e "$1" ]; then
echo "Usage: $0 <target-directory-or-file> <destination-file>"
exit 1
fi

# $2 is dst file
if [ -z "$2" ]; then
echo "Usage: $0 <target-directory-or-file> <destination-file>"
exit 1
fi

# Absolute path to this script. /home/user/bin/foo.sh
SCRIPT=$(readlink -f $0)
# Absolute path this script is in. /home/user/bin
SCRIPTPATH=`dirname $SCRIPT`

WORKINGDIR="$1"
TARGET="."
if [ -f "$WORKINGDIR" ]; then
WORKINGDIR=`dirname $WORKINGDIR`
TARGET=`basename $1`
fi

# pack directory or files into a uuencoded tar.gz archive
cat "$SCRIPTPATH/execute.sh" > "$2"
echo "w $WORKINGDIR $TARGET"
tar -c -C "$WORKINGDIR" -zf - "$TARGET" | \
uuencode "embedded-files.tar.gz" >> "$2"

chmod u+x,g+x "$2"


execute.sh
#!/bin/sh

# $1 is target directory
if [ -z "$1" ]; then
echo "Usage: $0 <target-directory>"
exit 1
fi

# create target directory (if not exists) or exit if we fail
mkdir -p "$1"
if [ $? != 0 ]; then
echo "Failed to create target directory"
exit 3
fi

# Absolute path to this script. /home/user/bin/foo.sh
SCRIPT=$(readlink -f $0)
# Absolute path this script is in. /home/user/bin
SCRIPTPATH=`dirname $SCRIPT`

cd $1;
uudecode "$SCRIPTPATH/$(basename $0)"
tar -xzf "embedded-files.tar.gz"
rm "embedded-files.tar.gz"

exit 0;

25 Dec 2009

Fiddling with bridges for kvm on ubuntu (9.04)

For most virtualization technologies, bridged network interfaces are usefull if a host has to be accessible from outside (ssh for example). Bridging makes this possible.

Install bridge-utils

Disable your primary network interface, create a bridge and link the bridge to the original interface:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual
#    address 10.0.0.33
#    network 10.0.0.0
#    netmask 255.255.255.0
#    gateway 10.0.0.1

#auto eth1
iface eth1 inet dhcp

auto vnet0
iface vnet0 inet static
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
address 10.0.0.33
network 10.0.0.0
netmask 255.255.255.0
gateway 10.0.0.1

22 Dec 2009

ssh keyboard-interactive with no subsequent questions

Some scripts which bootstrap clients into my network need to do many subsequent ssh requests to servers to determine its state and change server values (dns, dhcp, accounts, etc). It can be cumbersome to enter the admin's ssh password again and again, sshpass to the rescue (bash example):

#!/bin/bash
# ask for root password, use it for any further ssh connection
remoteuser='adm' # could be root|admin|sysadmin|etc.
stty -echo
read -p 'Password for '$remoteuser': ' pw
echo
stty echo
export SSHPASS="$pw" # export, so subcommands can use it
unset pw
alias ssh='sshpass -e ssh'

ssh $remoteuser@someserver  'ls -la /tmp' # no password asked if it matches
ssh $remoteuser@otherserver 'ls -la /tmp' # no password asked if it matches

When the script ends the variable «$SSHPASS» will be destroyed. It makes sense to have user and passwords stored locally (ie. ldap/kerberos/nis/etc.).

6 Dec 2009

Dealing with UUIDs in fstab

Since there are more and more removable block devices in use (Memmory Sticks, External HDs, etc.) it makes sense to mount them via UUID, since the device name may vary.

Two tools have been very useful for finding out the UUIDs for a partition:

$ blkid
/dev/loop0: TYPE="squashfs"
/dev/sda1: UUID="D8A03377A0335B68" LABEL="HP_PAVILION" TYPE="ntfs"
/dev/sda3: UUID="4562-2B6E" TYPE="vfat"
/dev/sda4: LABEL="HP_RECOVERY" UUID="4B6E-6BC0" TYPE="vfat"
/dev/sda5: UUID="2e551b01-6f76-4d8e-85cd-7adc6abc9a2d" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda6: UUID="6cb7b571-be94-4882-a504-fddf8fa1388a" TYPE="swap"
/dev/sda7: UUID="402b3442-1432-4676-ab6f-6cb3c403a4f2" TYPE="ext3"
/dev/sda8: UUID="8501e0d1-55b5-4899-8553-37129213d803" TYPE="ext3"
/dev/sdb1: UUID="7868C17F68C13D1E" LABEL="Volume" TYPE="ntfs"
/dev/sdb2: UUID="e1454921-55a4-42af-9484-e6a82eb33329" SEC_TYPE="ext2" TYPE="ext3"
$ sudo vol_id /dev/sda3
ID_FS_USAGE=filesystem
ID_FS_TYPE=vfat
ID_FS_VERSION=FAT32
ID_FS_UUID=4562-2B6E
ID_FS_UUID_ENC=4562-2B6E
ID_FS_LABEL=
ID_FS_LABEL_ENC=

An easy readable list of device names and UUIDs:
$ blkid -s device -s UUID | sed -e 's|:||; s|UUID="||; s|"||'
/dev/sda1 D8A03377A0335B68
/dev/sda3 4562-2B6E
/dev/sda4 4B6E-6BC0
/dev/sda5 2e551b01-6f76-4d8e-85cd-7adc6abc9a2d
/dev/sda6 6cb7b571-be94-4882-a504-fddf8fa1388a
/dev/sda7 402b3442-1432-4676-ab6f-6cb3c403a4f2
/dev/sda8 8501e0d1-55b5-4899-8553-37129213d803
/dev/sdb1 7868C17F68C13D1E
/dev/sdb2 e1454921-55a4-42af-9484-e6a82eb33329

1 Nov 2009

Firefox profile on NFS

Firefox has switched to sqlite3 for some files in the profile. this happened some time ago (AFAIKT it was with FF3). This is quiet bad if you happen to mount your home via NFS, because sqlite is not designed to work well over NFS (locking problems). The sqlite FAQ(5) has this to say about sqlite databases on NFS:

SQLite uses reader/writer locks to control access to the database. (Under Win95/98/ME which lacks support for reader/writer locks, a probabilistic simulation is used instead.) But use caution: this locking mechanism might not work correctly if the database file is kept on an NFS filesystem. ...
And indeed, it does not work for me (debian/ubuntu). The problem is, that bookmarks, history and other things will be corrupt after a network outage or a firefox crash (hello flash, i am looking at you!). I have not found a solution yet, therefore before starting firefow, I will backup all sqlite Databases:

First, you need to install the sqlite3 utility:
$ sudo apt-get install -y sqlite3


in your .profile, declare the following variables:
export PROFILE="myprofilename"
export FIREFOX_PROFILE_DIR=~/.mozilla/firefox
#export FIREFOX_PROFILE_DIR=~/.mozilla/firefox-3.5


Then use the following script to launch firefox:
#!/bin/bash

if [[ -z "$PROFILE" ]]; then
export PROFILE="default"
fi

if [[ -z "$FIREFOX_PROFILE_DIR" ]]; then
export FIREFOX_PROFILE_DIR=~/.mozilla/firefox
fi

# install sqlite 3: sudo apt-get install -y sqlite3
find=$(which find);
sqlite3=$(which sqlite3);

msg="missing or not in \$PATH, aborting";
if [[ -z "$find" ]]; then echo "find $msg"; exit 1; fi
if [[ -z "$sqlite3" ]]; then echo "sqlite3 $msg"; exit 1; fi

for d in $($find $FIREFOX_PROFILE_DIR/ -maxdepth 1 -type d); do

profile=$(echo "$d" | sed -e 's|.*/[^\.]\+\.||')

# remove this conditional statement, if you want all FF profiles backed up.
# sqlite databases in use are locked.
if [[ "$profile" != "$PROFILE" ]]; then
continue;
fi

echo "$profile | $d";

for f in $(find "$d" -iname "*.sqlite"); do
f=$(echo "$f" | sed -e 's/\.sqlite$//; s|.*/||')
if [[ -f "$d/$f.bak.sql" ]]; then rm "$d/$f.bak.sql"; fi
$sqlite3 $d/$f.sqlite .dump > $d/$f.bak.sql
done

done

firefox-3.5 -P $PROFILE

exit 0;

6 Oct 2009

Installing WarZone 2100 v 2.2.3 on Jaunty

Description:
In Warzone 2100, you command the forces of "The Project" in a battle to rebuild the world after mankind has almost been destroyed by nuclear missiles. The game offers campaign, multi-player and single-player skirmish modes. An extensive tech tree with over 400 different technologies, combined with the unit design system, allows for a wide variety of possible units and tactics.

Needs to be compiled from source if you want the latest version. Here is a deb for Jaunty:
http://spliffy.freeshell.net/warzone2100_2.2.3-1_i386.deb

required libraries include (but probably not complete):
libsdl1.2debian-all,libopenal1,libcoin60,libpng12-0,libvorbis-ocaml,libvorbisenc2,libopts25,libphysfs-1.0-0,libsdl-net1.2,libwxgtk2.8-0,libfreetype6,libfontconfig1,gettext

Don't forget the high resolution addon "sequences.wz", it can be obtained from the download page.

$ sudo apt-get install flex bison libsdl1.2-dev libopenal-dev libpng12-dev libvorbis-dev libpopt-dev libphysfs-dev libsdl-net1.2-dev libwxgtk2.8-dev libfreetype6-dev libfontconfig1-dev gettext


Download and install OpenGLC from:
http://downloads.sourceforge.net/project/quesoglc/QuesoGLC%20free/0.7.2/quesoglc-0.7.2-free.tar.bz2?use_mirror=surfnet

$ ./configure --prefix=/usr && make && make install


Then download warzone source at http://wz2100.net/download, unpack and enter the directory.

$ ./configure && make


$ sudo checkinstall


0 - Maintainer: [ root@localhost.localdomain ]
1 - Summary: [ In Warzone 2100, you command the forces of "The Project" in a battle to rebuild the world after mankind has almost been destroyed by nuclear missiles. The game offers campaign, multi-player and single-player skirmish modes. An extensive tech tree with over 400 different technologies, combined with the unit design system, allows for a wide variety of possible units and tactics. ]
2 - Name: [ warzone2100 ]
3 - Version: [ 2.2.3 ]
4 - Release: [ 1 ]
5 - License: [ GPL ]
6 - Group: [ checkinstall ]
7 - Architecture: [ i386 ]
8 - Source location: [ warzone2100-2.2.3 ]
9 - Alternate source location: [ http://wz2100.net/ ]
10 - Requires: [ ]
11 - Provides: [ warzone2100 ]

21 Aug 2009

pidgin xfire plugin for 32 bit ubuntu

As of August 18th, xfire seems to reject protocol version 113 which results in permanent disconnects for the current pidgin xfire plugin. The pidgin guys have fixed it qucikly but, unfortunately, there are no debs for ubuntu. Threfore I have compiled a deb package for ubuntu 9.04 32 bit on:

Linux localhost.localdomain 2.6.28-15-generic #48-Ubuntu SMP Wed Jul 29 08:54:56 UTC 2009 i686  GNU/Linux

pidgin-gfire_0.8.3-1_i386.deb

18 Aug 2009

vim window management

Windows are one of Vim's most convenient features, and learning some commands could prove to be useful. Some of the commands are available from the "Window" menu in gvim, or using the mouse, but using them from the keyboard is often more convenient.

To split a viewport in two, use Ctrl+W,S for a horizontal split or Ctrl+W,V for a vertical split. To move between windows use Ctrl+W followed by the arrow keys or h,j,k,l (but see this previous tip). To close a viewport use Ctrl+W,C.

Ctrl+W,r rotates the windows, and Ctrl+W, shift+R rotates them in the opposite direction. Finally, Ctrl+W,+ and Ctrl+W,- increase and decrease the height of the viewport by one line (in case you are mouse-deprived). If that's too little you can do something like 10,Ctrl+W,+ to increase the height by 10 lines.

3 Aug 2009

Mac OSX

I got this Mac Mini brought in today for testing a new screen capturing solution we might implement.

It turned out to be a very nice experience. I knew these macs are shiny but they seem to be pretty useful too! After some poking around I found out there is an X Server available, an ssh client was there too. So I could instantly launch some remote X apps.

It turned out, that these macs ship by default with Python (2.3.something) and there is a nice IDE called Xcode which is offered by Apple for free of charge.

Furthermore, what got me excited, was the fact that there are many command line tools and a bash (by default). It is possible to read out information about the system's hardware and configuration via «system_profiler» which seems similar to «wmic» on Win32 and «/proc» on linux.

My next laptop will be a mac book!

30 Jul 2009

Selectable area for screenshots on gnome

Install required software:

$ sudo apt-get install zenity scrot xclip


Script for capturing screen areas (change targets at the beginning of the file):
#!/bin/bash

targetdir=/home/public-www/tmp/
targeturi=http://wunderlin.net/tmp/
icon=/usr/share/icons/gnome/22x22/apps/applets-screenshooter.png

# ask for filename
file=$(zenity --title="Screenshot" --width=800 --window-icon=$icon \
--text="Filename:" --filename="$targetdir" --file-selection)

if [[ "$file" == ".png" || -z "$file" ]]; then exit 1; fi

scrot --select "$file"

uri=$(echo "$file" | sed -e 's|'$targetdir'||')

echo "$targeturi$uri" | xclip -i -selection clip-board
# zenity --info --text="$targeturi$uri" --title="Screenshot URL" --window-icon=$icon
echo $file;

exit 0;


Steps for creating a custom hotkey to launch any application in GNOME:
  1. Open "gconf-editor" as the user as you're logged in in GNOME
  2. Go to "apps" -> "metacity" -> "keybinding_commands"
  3. Double click on e.g. "command_1"
  4. Type in the name of the application you want to launch, e.g. "gcalctool", the GNOME calculator
  5. Go to "apps" -> "metacity" -> "global_keybindings"
  6. Double click on e.g. "run_command_1"
  7. Type in e.g. <Control><Alt>c
  8. Note the < and > for the special function keys
  9. DONE! Close the gconf-editor and press CTRL-ALT-c and the calculator should come up

21 Jul 2009

Convert vmdk to vdi files

I am moving away from VMWare Server to VirtualBox. VMWare 2's web interface at first excited me, then I have realized that it depends on platform specific browser plugins. The result is an everywhere available control interface (as long as you have installed the plugin) with the awefull slowness of a web interface. So why not just install a client application which integrates into the platform, is fast and reliable I ask.


VirtualBox seems to fit my needs for a software testing server much better than Vmware Server 2.x.

Migration involves converting VMWare's vmdk disk images to VirtualBox's vdi images. Vmdk images are often split into several files (snapshots, 2GB size limit on NTFS) and mus therefore usually be consolidated into one file again.

Instructions below require some software packages to be installed, on a debian system:

$ sudo apt-get install qemu virtualbox-ose
And vmware must be installed of course. In the example below «multipart.vmdk» is the base file of the vmware image (usually some multipart-S00N.vmdk files would reside in the same directory), «flattened.vdi» is the result and can be used with VirtualBox.

#!/usr/bin/env bash
# $Id$

# debug=1

bin=(vmware-vdiskmanager \
vmware-vdiskmanager \
vmware-vdiskmanager \
qemu-img \
VBoxManage)
cmd=("%s -R %s " \
"%s -d %s " \
"%s -r %s -t 0 %s" \
"%s convert %s -O raw %s" \
"%s convertdd %s %s")
msg_ok=("1. Consistency check." \
"2. Defragment." \
"3. Flattened vmdk files into 1 file: flattened.vmdk" \
"4. Converted flattened.vmdk into raw image." \
"5. Converted raw image into a VirtualBox image (vdi).")
msg_nok=("Failed consistency check of vmware image." \
"Failed to defragment vmware image." \
"Failed to flatten vmdk file." \
"Failed to convert vmdk into raw image." \
"Failed to convert raw image into vdi.")
file_src=("%s.vmdk" "%s.vmdk" "%s.vmdk" "%s-flattened.vmdk" "%s-flattened.bin")
file_dst=("" "" "%s-flattened.vmdk" "%s-flattened.bin" "%s.vdi")

# parameter check
if [[ ! -z "$1" ]]; then
file=$(echo "$1" | sed -e 's/\.vmdk$//')
else
echo "usage: $0 <vmwareimage.vmdk>"
exit 1
fi

# check for required binaries
function isexecutable {
if [[ ! -x "$(which $1)" ]]; then
echo "'$1' is eighter not in your \$PATH, not executable or"
echo "not installed, aborting."
exit 2
fi
}
for (( c=0; c < ${#bin[@]}; c++ )); do
isexecutable "${bin[$c]}"
done

function err {
echo $1
exit 3
}

# run command
function runpart {
exec="$1"
msg_succcess="$2"
msg_error="$3"

echo "$msg_succcess "
echo " executing: $exec"
a=$($exec 2>&1) # && echo "$msg_succcess ($a)" || err "$msg_error"
if [[ $? = 0 ]]; then
echo " $a"
else
echo " Failed execution, aborting."
exit 4
fi
}

echo "Clenaing up ..."
[ -f $(printf "%s-flattened.vmdk" "$file") ] && \
rm $(printf "%s-flattened.vmdk" "$file")
[ -f $(printf "%s-flattened.bin" "$file") ] && \
rm $(printf "%s-flattened.bin" "$file")
[ -f $(printf "%s.vdi" "$file") ] && \
rm $(printf "%s.vdi" "$file")

cat <<EOT
Converting $file.vmdk to $file.vdi. This will take some time ...

EOT

#run all parts
for (( c=0; c < ${#bin[@]}; c++ )); do
from=$(printf "${file_src[$c]}" "$file")
to=$(printf "${file_dst[$c]}" "$file")
if [[ -z "$to" ]]; then
cm=$(printf "${cmd[$c]}" "${bin[$c]}" "$from")
else
cm=$(printf "${cmd[$c]}" "${bin[$c]}" "$from" "$to")
fi

if [[ -n $debug ]]; then
echo "$cm"
echo " ${msg_ok[$c]}"
echo " ${msg_nok[$c]}"
echo ""
continue;
fi

runpart "$cm" "${msg_ok[$c]}" "${msg_nok[$c]}"
done

cat <<EOT
Done. you may delete the following files:
$(printf "${file_dst[2]}" "$file")
$(printf "${file_dst[3]}" "$file")

EOT

exit 0;


That's it, «flattened.vdi» is the disk image for VirtualBox.

Most of the infos were found in the following thread in the VirtualBox forum.

17 Jul 2009

ies4linux on Ubuntu Jaunty

Installing ies4linux on Jaunty is not so straight forward. I have only managed to install IE6 and flash so far (IE1 - IE7 would be available in the same package).

First of all, wine and cabextract are needed:
$ sudo apt-get install -y wine cabextract

then download the ies4 linux package:

cd /tmp
wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
tar zxvf ies4linux-latest.tar.gz
cd ies4linux-*


The version check of wine is looking for re/0\.9\.*/ but wine hited version 1.* some weeks ago, this version check doesn't work, I have disabled it since we are using defenately a newer version. Edit «lib/functions.sh» and comment out the line with wine version check (~ line 36):
--- lib/functions.sh-dist 2009-07-17 17:39:55.283279400 +0200
+++ lib/functions.sh 2009-07-17 17:39:59.917574880 +0200
@@ -33,7 +33,7 @@
# Find where wine is
function find_wine {
which wine &> /dev/null || error $MSG_ERROR_INSTALL_WINE
- wine --version 2>&1 | grep -q "0.9." || warning $MSG_WARNING_OLDWINE
+ # wine --version 2>&1 | grep -q "0.9." || warning $MSG_WARNING_OLDWINE
}

# check for cabextract


Now the installer should work and you can install ies4linux (ie6 + flash + msfonts) to your $HOME directory:

./ies4linux  \
--basedir ~/ies4linux --bindir ~/bin \
--no-desktop-icon --install-corefonts --no-gui


The «--help» and «--full-help» command line arguments do not expose all commandline parameters. All options can be found in the ./ies4linux shell script:
# Get command-line options
while [ $# -gt 0 ]; do
case "$1" in
--install-ie6 | --install-flash) shift;;
--install-ie55) export INSTALLIE55=1; shift ;;
--install-ie5) export INSTALLIE5=1; shift ;;
--install-ie2) export INSTALLIE2=1; shift ;;
--install-ie15) export INSTALLIE15=1; shift ;;
--install-ie1) export INSTALLIE1=1; shift ;;

--install-ie7|--beta-install-ie7) export INSTALLIE7=1; shift ;;
--hack-ie7-proxy-settings) export HACK_IE7_PROXY=1; shift ;;

--no-ie6) export INSTALLIE6=0; shift ;;
--no-flash) export INSTALLFLASH=0; shift ;;
--no-desktop-icon) export CREATE_DESKTOP_ICON=0; shift ;;
--no-menu-icon) export CREATE_MENU_ICON=0; shift ;;
--install-corefonts) export INSTALLCOREFONTS=1; shift ;;

--basedir) export BASEDIR="$2"; shift 2 ;;
--bindir) export BINDIR="$2"; shift 2 ;;
--downloaddir) export DOWNLOADDIR="$2"; changeddownloaddir=1; shift 2 ;;
--wget-flags) export WGETFLAGS="$2"; shift 2 ;;

--no-gui) export IES4LINUX_MODE="automatic"; shift ;;
--no-color) export NOCOLOR=1; shift 1 ;;
--gui) export PREFERRED_GUI=$2; shift 2 ;;
--no-localization)
eval $(load_variables_file "$IES4LINUX/lang/enUS.sh")
shift
;;

--uninstall)
uninstall
exit 0
;;
--locale)
export CHOOSED_IE6_LOCALE=$(echo "$2" | tr a-z A-Z)
shift 2
;;
--list-locales)
echo $IE6_LOCALES | fmt -w 40
exit 0
;;
--debug)
export DEBUG=true
shift
;;
--help | -h)
sh lib/help.sh
exit 0
;;
--full-help)
sh lib/help.sh full
exit 0
;;
*)
echo "Error: unknown option \"$1\""
if echo "$1" | grep '=' >/dev/null; then
echo "Options are not GNU-style"
echo " i.e. don't use: --option=value"
echo " use instead: --option value"
fi
echo "run \"./ies4linux --help\" for more info"
exit 1
;;
esac
done

Ubuntu Jaunty and LSB (Linux Standard Base)

I can't believe it but it's true, LSB is not part of the Jaunty default installation *sigh*

the following command works so nicely if one wants to detect the linux version a script is running on:
$ echo $(lsb_release -rcsi)

but without LSB the command won't work. I am a little bit surprised that it is not common among all linux releases to include LSB (except for the ones going for small footprint like DSL).

Install LSB on jaunty with:

$ sudo apt-get install -y lsb

10 Jul 2009

simplified deb package management

pkg shell script to the rescue. typing often used commands for software management on a debian based (deb) system can be boring an error prone. Some commands might be used often, such as «apt-get install», «apt-cache search» and «dpkg -l», etc. This script exposes the most used commands as easy to remebr commands (pkg* for package *i = install, *s = search, *u = update, etc.).

Modes:
pkgi [parameters] >name< Install package with >name<
pkgs [parameters] >name< Search for package >name<
pkgu Upgrade all packages
pkgl >name< List installed Packages filtered by >name<
pkgr [parameters] >name< Remove installed package
pkgp [parameters] >name< Purge installed package
pkgc Cleanup
pkg setup Setup symlinks
pkg remove|uninstall Remove symlinks

pkg (bash script):
#!/bin/bash

# shortcuts to frequently used package management tools like apt-get,
# dpkg and apt-cache
#
# NOTE: this script does not work if you havb spaces in your path.
#
# $Id$

# usage
function usage {
cat << EOT
usage: (pkgi|pkgs|pkgr|pkgp|pkgl|pkgu) [parameters] [name]

Modes:
pkgi [parameters] <name> Install package with <name>
pkgs [parameters] <name> Search for package <name>
pkgu Upgrade all packages
pkgl <name> List installed Packages filtered by <name>
pkgr [parameters] <name> Remove installed package
pkgp [parameters] <name> Purge installed package
pkgc Cleanup
pkg setup Setup symlinks
pkg remove|uninstall Remove symlinks
Mappings:
pkgi [parameters] <name> sudo apt-get install [parameters] <name>
pkgs [parameters] <name> apt-cache search [parameters] <name>
pkgu sudo apt-get update && sudo apt-get upgrade
pkgl <name> dpkg -l | grep <name>
pkgr [parameters] <name> sudo apt-get remove [parameters] <name>
pkgr [parameters] <name> sudo apt-get remove --purge [parameters] <name>
pkgc sudo apt-get autoremove
Exit Codes
0: success
1: unknown command (install, remove, autoclean, etc.)
2: parameter missing
3: no write permission (needed by setup)
EOT
}

function fn_help {
fn=$(basename $1)
echo -en "usage: $fn "

case $fn in
"pkgi")
echo "[parameters] <name> - Install package with <name>" ;;
"pkgu" )
echo "- Update repository" ;;
"pkgs" )
echo "[parameters] <name> - Search for package <name>" ;;
"pkgl" )
echo "<name> - List installed Packages filtered by <name>" ;;
"pkgr" )
echo "[parameters] <name> - Remove installed package " ;;
"pkgp" )
echo "[parameters] <name> - Purge installed package " ;;
"pkgc" )
echo "- Cleanup" ;;
* )
echo "Unknown program!"
exit 2
;;
esac
}

function remove {
for l in $@; do
p=$(basename $l)
if [[ "$p" == "pkg" ]]; then
continue
fi
rm $l
done

exit 0;
}

# parameters
filename=$(basename "$0");
command=""

if [[ "$filename" == "pkgi" ]]; then command="install"; fi
if [[ "$filename" == "pkgu" ]]; then command="upgrade"; fi
if [[ "$filename" == "pkgs" ]]; then command="search"; fi
if [[ "$filename" == "pkgl" ]]; then command="list"; fi
if [[ "$filename" == "pkgr" ]]; then command="remove"; fi
if [[ "$filename" == "pkgp" ]]; then command="purge"; fi
if [[ "$filename" == "pkgc" ]]; then command="autoremove"; fi

# setup ?
if [[ "$filename" == "pkg" ]]; then
basedir=$(dirname $0)
escaped=$(echo "$basedir" | sed -e 's/\//\\\//g')
pkgs=$(echo $basedir/pkg* | sed -e 's/'$escaped"\/pkg "'//')

if [[ "$1" == "remove" || "$1" == "uninstall" ]]; then
# if [[ $(basename $0) == "pkg" ]]; then
# exit 0;
# fi
#
echo "Removing ..."
remove $pkgs
fi

if [[ "$1" == "setup" ]]; then

# check if we can write to the directory to reate the symlinks
if [[ ! -w "$basedir" ]]; then
echo "No write permission to create symlinks in $basedir";
exit 2;
fi

echo "Installed links"
ls -la $pkgs;

echo
echo "Purging links"
if [[ $(basename $0) != "pkg" ]]; then
exit 0;
fi
# for l in $pkgs; do
# echo $l
# rm $l
# done

echo
echo "creating links"
for l in pkgc pkgi pkgl pkgr pkgp pkgs pkgu; do
echo $basedir/pkg "->" $basedir/$l
ln -s $basedir/pkg $basedir/$l
done
exit 0;
fi

if [[ -z "$1" || "$1" == "-h" || "$1" == "--help" ]]; then
usage;
exit 0;
fi
fi

# show help text ?
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
fn_help "$0"
exit 0
fi

# show help if parameters are missing
if [[ "$filename" == "pkgi" || "$filename" == "pkgs" ||
"$filename" == "pkgr" || "$filename" == "pkg" ||
"$filename" == "pkgs" || "$filename" == "pkgp" ]]; then
if [[ -z "$1" ]]; then
fn_help "$0"
exit 2
fi
fi

# unknown command
if [[ -z "$command" ]]; then
fn_help "$0"
exit 1
fi

# execute
if [[ "$command" == "list" ]]; then
/usr/bin/dpkg -l | grep -v "^r" | \
sed -e 's/\(..\)[ \t]\+\([^ ]\+\)[ \t]\+\([^ ]\+\)[ \t]\+\(.*\)$/\2 - \4/'|\
grep "$1"
elif [[ "$command" == "search" ]]; then
/usr/bin/apt-cache search $@
elif [[ "$command" == "purge" ]]; then
sudo /usr/bin/apt-get remove --purge $@
elif [[ "$command" == "update" ]]; then
sudo /usr/bin/apt-get update $@ && sudo /usr/bin/apt-get upgrade $@
else
sudo /usr/bin/apt-get $command $@
fi

exit 0

12 May 2009

fsv 0.9 deb for Ubuntu 8.10 Interpid (x86)

This package will be built according to these values:

0 - Maintainer: [ root@splatter ]
1 - Summary: [ fsv (pronounced eff-ess-vee) is a file system visualizer in cyberspace. It lays out files and directories in three dimensions, geometrically representing the file system hierarchy to allow visual overview and analysis. fsv can visualize a modest home directory, a workstation's hard drive, or any arbitrarily large collection of files, limited only by the host computer's memory and graphics hardware. ]
2 - Name: [ fsv ]
3 - Version: [ 0.9 ]
4 - Release: [ 1 ]
5 - License: [ GPL ]
6 - Group: [ checkinstall ]
7 - Architecture: [ i386 ]
8 - Source location: [ fsv-0.9 ]
9 - Alternate source location: [ ]
10 - Requires: [ ]
11 - Provides: [ fsv ]


Make sure to install the following packages first:
$ sudo apt-get install -y gtkglarea5-dev libgtkgl2.0-dev libgtk1.2-dev

Download fsv 0.9 deb for Ubuntu x86 8.10 Interpid