Skip navigation

Tag Archives: Linux

I was always worried about having to go up in a unix directory tree with cd ../. Then I was introduced to this project at work where I noticed that I was doing so much cd-ing around. Sometimes I went so deep in the directory tree I had this scary feeling inside that I’d get lost in a dark pit (true story).

I wanted a better way to do it. So I did what anyone these days would do. But the best the internet could offer were using pusd/popd, aliasing multiple ../s to ..n and using CDPATH. None of these felt natural enough.

So on one boring evening at work I started to scratch my own itch. I started to do it in python but I ended up in a simpler, much better solution. A function for my bashrc.

I call it za because …

cd to za

cd to za (image: markhillary flickr)

you can use za to jumpback any number of directories up to your $HOME directory. Just put the following function in your .bashrc

za 2 #will jump 2 directories up
za #will jump one directory up

Just see it in action.

za-in-action

za in action

Hope you find it useful.

PS: My blog marked 6 years to yesterday (8th August 2012). I’m out of (a year?) long block with this post :)

Update (07-03-2014): There’s a Fish Shell port of Za now.

I was really fascinated by the stuff I have read about Truecrypt. I wanted to try that but I had two reasons to not do that. First, I had nothing really to hide; Second, I thought my poor hp mini won’t be able to handle encrypting a partition, if not the whole disk. And also I was lazy. My close friends, bro and sis know my password anyway. Sis won’t find anything I don’t want her to and I have no problem others finding those. So the only reason I’d try encrypting is curiosity.

One day I was struck by a fireball of curiosity. And I was looking for ways to make portable, encrypted disk I can even put in Dropbox [referral link]. I found few good howtos with lot of details but what I’m going to put together will be an easier howto for a better virtual disk that is encrypted on-the-fly.

I am using Ubuntu 10.04 Lucid Lynx so there maybe a leetle Ubuntu specific things that I’m not sure of. The process has commands that can destroy your data if not used with care. I have tried this and it works perfect for me. If you manage to screw things up in the process that should be purely because you are stupid or careless or even both. And that was my disclaimer.

Alright let’s go make it.

We need dmsetup and cryptsetup installed for this.
$sudo aptitude install dmsetup cryptsetup

Once the installation process is finished we can start making our encrypted vitual disk.

1)
First we create a file with random data in it. You can chose a size that matches your needs. In this example I’m making a 20MB virtual disk so I will create a 20MB file in this step.

$ dd if=/dev/urandom of=~/sekret bs=1M count=20

Here, the dd command creates 20 1MB blocks and fill it with random data. ~/sekret means that we create the filee named sekret in your home directory. You can chose a file name you like and also a path you like.

2)
Next we need to create a block device from the file. For that find a free loop device with
$ sudo losetup -f

And use that loop device and create the block device. Let’s assume /dev/loop0 is free.
$ sudo losetup /dev/loop0 ~/sekret

3)
Now we need to luks format the device. FYI: LUKS stands for Linux Unified Key System.
$ sudo cryptsetup luksFormat -c aes-cbc-essiv:sha256 /dev/loop0

This will warn you that the data in /dev/loop0 are gonna be overwritten. Hope you are confident enough to say yes. Then you are required to enter a pass-phrase for this encrypted this. Chose a powerful pass-phrase here. And then confirm the pass-phrase. The process will report success if we are lucky.

4)

Map the crypto partition using

$ sudo cryptsetup luksOpen /dev/loop0 mycrypt

To be sure about the success run
$ sudo dmsetup ls

This will output something like mycrypt (252, 0).

5)
Now we create file system on the device we created.
$ sudo mkfs.ext3 /dev/mapper/mycrypt

This will create EXT3 file system on the device. You can format it with your choice of file system. At the successful finishing of formatting, we have our own encrypted disk ready to use.

6)
We can mount it with..
$ sudo mount /dev/mapper/mycrypt /media/sekret

7)
Once you are done adding juicy stuff on your device you should unmount it AND REMOVE THE DEVICE FILE.
$ sudo umount /mnt/sekret
$ sudo cryptsetup luksClose mycrypt
$ sudo losetup -d /dev/loop0

Once you have created an encrypted disk, to use next time you only have to follow the steps 2), 4) and 6). Once you are done using the device, unmount with step 7).

I have put an encrypted virtual disk in my Dropbox and it works pretty well. Maybe you’d like to try that too. To use it in Dropbox, copy the encrypted virtual disk file (~/sekret in our case) in to your Dropbox directory.

I have put together a bash script to automate the process and I named it crysp :). You have to run the script as root so use sudo when running it. I might be an evil bastard trying to destroy your data so take a look at the script before you run. With the script you can easily mount and unmount the encrypted devices similar to the usage of mount/umount commands. I have added a dirty hack to allow read/write access to the device from Nautilus. To use this, change chanux to your login name in line 08 in the script.

Find the source in it’s Google Code repository. There’s a version that prevents the existence of thumbnails related to the encrypted disk. check crysp-no-thumb branch for that.

Update: 27-01-2013 Updated the script and put it on a github gist.

Usual Chanux crap

I always used SCIM input method with sayura sinhala input scheme. But it had weird bug that screws up almost all the text input areas (My friend @gaveen pointed out it’s SCIM related). So the people who new about iBus told me to try it but as always I didn’t have time to try it on my previous ubuntu 9.04 installation. iBus came default on ubuntu since Karmic Koala (9.10) and since I switched to Lucid Lynx (10.04) it was the right time to check iBus-sayura out.

As lazy as I’ve become I chose seemingly easier way of installing ibus-sayura. I used the ibus-sayura unstable PPA on launchpad to install. And it worked, සෙටිපිකට් ඇත්ත. So you too can take the easier route.

The actual How-to

Step 1 – install
First, to add the PPA repository your system run the following command in a terminal (Applications > Accessories > Terminal)

</p>
<p>$sudo add-apt-repository ppa:skhome/ibus-sayura-debianised-alfa</p>
<p>

Then update package list with

</p>
<p>$sudo aptitude update</p>
<p>

Then comes the installing step.

</p>
<p>$sudo aptitude install ibus-sayura</p>
<p>

(Yeah, you are right. You can use apt-get instead of aptitude)
Step 2 – Launch and use

Now you are ready to use sayura. Go to System > Preferences > Ibus Preferences*.  Select the input method tab. Find Sinhala,Sinhalese in “Select an input method” drop down list and select sayura there. And now press add button. Close the preferences window if you want to :P.

You’ll see a little keyboard icon on upper panel. Click on it and select sayura and enjoy typing sinhala.

*If this is your first I bus run it will ask whether to start ibus daemon. You should say yes. Then it might present another scary message with following  commands.

<br />
export GTK_IM_MODULE=ibus<br />
export XMODIFIERS=@im=ibus<br />
export QT_IM_MODULE=ibus<br />

If IBus doesn’t work, you’ll have to run these commands in a terminal like we did in the beginning and log out and log in again. Don’t forget to keep your fingers crossed, literally. Now you may want to try the step 2 again.

Hacking is always fun. That’s why I always lose focus on everything once I find something to hack around. And that’s why I spent whole last night trying to figure out how to mimic Window focus event in a shell script. Though this is completely new to _me_, you maybe very much comfortable with implementing it :) . If so please let me know in comments.

Anyway here is my story.

I found this nice command line IM client called centerIM (Thanx @chathuraw for info). Once I got it set up I was just scanning on it’s documentation page & came across this interesting part “External actions & auto-responses“. I wrote a script right away for GUI notifications, inspired by notify.pl script for irssi. Here is the script if you are interested.

Since the load of IM messages was very high at a time & It was useless when the terminal window with centerIM was already focused (which means I’m chatting on centerIM) I was thinking of getting notifications only when centerIM window is not in focus. Few Google searches lead me to very limited resources & I chose xwininfo & xdpyinfo commands for my work.

Workaround: I’m using gnome for now & so gnome-terminal as my terminal emulator. I had to set Edit >Pprofile Preferences > Title & command option to keep initial title, in order to have “Terminal” as the terminal window name all the time.

And ran xininfo to get following output.

chanux@nim:~$ xwininfo -name Terminal

xwininfo: Window id: 0x3800003 "Terminal"

 Absolute upper-left X:&nbsp; 0
 Absolute upper-left Y:&nbsp; 52
 Relative upper-left X:&nbsp; 0
 Relative upper-left Y:&nbsp; 27
 Width: 1280
 Height: 691
 Depth: 24
 Visual Class: TrueColor
 Border width: 0
 Class: InputOutput
 Colormap: 0x20 (installed)
 Bit Gravity State: NorthWestGravity
 Window Gravity State: NorthWestGravity
 Backing Store State: NotUseful
 Save Under State: no
 Map State: IsViewable
 Override Redirect State: no
 Corners:&nbsp; +0+52&nbsp; -0+52&nbsp; -0-25&nbsp; +0-25
 -geometry 156x37+0+25

This can be used to get the window id of the window which runs the script.

Then I can find the focused window at the moment as following.

chanux@nim:~$ xdpyinfo |grep focus
focus:&nbsp; window 0x3800004, revert to Parent

I fetched the window IDs with a little bit more work.

Anyway the problem I had is that, I get 0x3800003 (at this example) or likewise for the Terminal window id & even when the Terminal id is focused I get 0x3800004 as the focused window id. Yes I know with some more work I can manage to handle that & come to a point that I can compare those window Ids to check for the focused window. But I really like to know why that difference come up. Anyone have an explanation? Or anyone like to mess with this?

Following is the way I fetched window ids from above outputs

chanux@nim:~$ xwininfo -name "Terminal" | grep xwininfo | cut -d " " -f 4
0x3800003
chanux@nim:~$ xdpyinfo | grep focus | cut -d " " -f 4 | sed s/,//
0x3800004

Here I came up with part two of “Use Portable Firefox profile with GNU/Linux“(Now I feel ashamed for calling it a hack. Sorry fellas for calling it a hack :D ). This time it’s a shell script which would let you jump between default Firefox porfile & your own Portable Firefox profile which is going to live on your flash drive.

To use it you have to download fp.tar.gz & extract. There are two files in fp directory, one is sfp.sh which is the script & the other is profiles.ini which the script uses in the switching process. Those files are made to be together :). (You need Portable Firefox)

You have to edit path= Line in profiles.ini file. Add the path to your Portable firefox profile & run the script. It works for me & I hope it would work for you too.

Path=/media/CHANUX/FirefoxPortable/Data/profile

Known issues:

  • The Extension versions you use may conflict with the Firefox version on the host machine.
  • You won’t take the plugins (ex: Flash, Java) with you(I’m still tryiing to figure out a way to make it happen).
  • You’ll have to obey the proxy settings of the host machine.
  • You may have to change file permissions [ $ chmod 755 /path_to_script ]
  • In worse case you may have to copy fp folder to host machine.
  • In worst case you may not have enough rights to run shell scripts :( .

known bugs:
When I run this in fedora core 6 I don’t get the functionality for identifying whether Firefox is running when setting/unsetting Portable profile. I couldn’t figure out that little bug yet.

The day before I write this script I was a total idiot of shell scripting. I just read the manuals(Some bash howtos) & wrote it. So you won’t see any cool/advanced tricks in this script.

Notes

It will be more helpful if you read the part 1 of this(Link at top of this post).

I didn’t check this with Firefox 3. (There’s one who use this on Ubuntu hardy with Firefox 3.0)

You don’t need to have Portable Firefox for this. Just having your Firefox profile is enough (If you like it that way :) ).

Big red disclaimer:
Dumb me & all my dumb friends did this & it works just fine. If you are dumber enough to get problems with this just don’t try this or any kind of hacks. Any kind of a damage you do to your system trying this script happens only because you are an extreme fool. SO don’t blame me. Go infront of a mirror instead. :twisted: