Monday 31 March 2008

Simple python script for extracting various archive types

Last couple of days I've been compiling lots of software from source and i got very annoyed typing the tar command over and over again so I created simple python script for this purpose. Now I can extract .tar, .tar.gz, .tar.bz2 and .zip archives with just one command. Of course it could be maybe done better with bash and aliases but i wanted to try out python.
Here's the script:unpack script
And the whole code:

#!/usr/bin/env python
#
# simple python script for extracting mostly used types of archives
# this script extracts .tar, .tar.gz, .tar.bz2, .gz and .zip archives
#

import sys # required for fetching command line arguments
import os # required for calling commands for archive extracting

def unpack(s): # this is definition of depack
if (s.find('.tar.gz') != -1): # function. It takes string
os.system("tar -xvvzf " + filename) # filename as argument.
elif (s.find('.tar.bz2') != -1): # functon than calls
os.system("tar -xvvjf " + filename) # appropriate command according
elif (s.find('.tar') != -1): # to file extension
os.system("tar -xvvf " + filename)
elif (s.find('.gz') != -1):
os.system("gunzip" + filename)
elif (s.find('.zip') != -1):
os.system("unzip " + filename)
else: print "Wrong archive or filename" # other types not supported

try: # this is main program
filename = sys.argv[1] # first argument right after
unpack(filename) # 'unpack' command goes in the
except IndexError: # filename string
print "Filename is invalid!" # than the depack function is called

# try-except block is used for handling IndexError exception if no argument is passed

Usage:
./unpack [archive filename]

Sunday 30 March 2008

Cleaning your Debian linux box

Recently i ran out of disk space on my linux partition and i wanted to clean it up to free some space. I knew for sure that junk files exists but wasn't completely sure what files i can remove to keep system from broking. Once again google comes into play. Here is a short description of how to clean up the mess! Im using Debian etch for this walk-through. This is actually just a little reminder.

1. Cleaning residual config packages

Open up Synaptic Package Manager under Desktop -> Administration and enter root password. Under 'Status' filters (lower left part of the screen) select 'residual config', mark all packages, right click and select 'Mark for completely removal' and click apply button.

2. Removing partial packages

Open up terminal and type:

# sudo apt-get autoclean

3. Unnecessary locale data

Just install 'localepurge' package and after installing anything this script will remove unnecessary locale data, all but the ones you selected not to.

4. Removing orphaned packages

Install 'deborphan' package. In Synaptic Package Manager under select 'Filters' under Settings menu, create a new filter and on the right deselect all checkboxes but leave the one that says 'Orphaned' unchecked. Now select this new filter under 'Costum filters' selection and u may remove all those packages.

Thursday 27 March 2008

Installing Debian linux over internet / without cd-rom / netboot

I ordered my kubuntu cd copy, but I wasn't patient enough to wait for it 4-5 weeks so I googled around and found useful tutorials of how to install linux without a cd. Here's the link that explains everything: Large HOWTO

But I decided to write a shorten version mostly just to have my own little reminder if that link gets lost somewhere.
...Googled more around to find interesting distribution. Already had ubuntu installed so decided to go for Debian-sid.

Here are the steps:

1. Get "linux" installer kernel and "initrd.gz" ramdisk from here: Debian Sid netboot mirror and save those two files in c:\boot folder

2. Get Grub4Dos from sourceforge and unpack "menu.lst" and "gldr" files to c:\

3. Append this line at the end of your c:\boot.ini file:

C:\grldr="Start GRUB"

4. Open "menu.lst" file with text editor end append this at the end:

title Debian installer
kernel (hd0,0)/boot/linux ramdisk_size=10934 root=/dev/rd/0 devfs=mount,dall rw --
initrd (hd0,0)/boot/initrd.gz


5. Restart computer and instead booting windows select "Debian installer", and the installation starts.

Quite easy! This procedure can be done for many linux distros. You just need to put those two files (from step 1) of your favourite distro in c:\boot directory and that's it.