Who says GUI Programming in shell is difficult ?

Today, I wanted a quick utility to help me enter passwords for encfs during mount.
I was looking for something plain, simple and userfriendly.
At the end I ended up to use the shell for it.

Yes, using dialog/Xdialog you can be a GUI programmer in minutes.

If the text is scrambled, you can download the script here.

Cheers!

#!/bin/bash

  1. encfsmount - A simple frontend for encfs
  2. (C) Ritesh Raj Sarraf July 2005

  1. Available only under the GPL

PATH="/bin:/sbin:/usr/bin:/usr/sbin:/home/rrs/bin"  
export PATH

XDIALOG_HIGH_DIALOG_COMPAT=1  
export XDIALOG_HIGH_DIALOG_COMPAT

  1. && exec sudo "$0" "$@"

ASKPASS=`which ssh-askpass`;  
CRYPT="/mnt/windoze/.linuxrc";  
TARGET="/var/tmp/.linuxrc";  
FUSERMOUNT=`which fusermount`;  
ENCFS=`which encfs`;  
ARGS="-u";

#set -vx

DIALOG=`which dialog`;  
[ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"

mount()  
{ # This is one good way to use dialog to accept passwords # But for some
reason encfs isn't able to read the password # supplied by dialog # Hence, I'm
using ssh-askpass to get the password #$ENCFS $CRYPT $TMP --extpass=`$DIALOG
--title "Password" --password --inputbox "Enter Password" 18 45 2`;

# This uses ssh-askpass $ENCFS $CRYPT $TARGET --extpass=$ASKPASS;

}

check_mount()  
{ # Since encfs isn't returning good exit status # I'm using this hack to
figure out if the mount # passed or failed. grep -i encfs /etc/mtab;
retval=$?;

case $retval in 0) $DIALOG --wrap --title "Information"\ --msgbox
"Successfully Mounted!" 10 41;; 1) $DIALOG --wrap --title "Information"\
--msgbox "Mount Failed!" 10 41;;  
esac  
}

prelim_mount_check()  
{ grep -i encfs /etc/mtab; retval=$?;

case $retval in 0) $DIALOG --wrap --title "Caution"\ --yesno "ALREADY
MOUNTED!\nDo you want to umount ?" 0 0

case $? in 0) umount; esac;; 1) #$DIALOG --wrap --title "Information"\
#--yesno "Do you want to mount crypt ?"\ #case $? in # 0) mount; check_mount;;
#esac;; esac }

umount()  
{ $FUSERMOUNT -u $TARGET;  
}

ask_passwd()  
{ $DIALOG --wrap --title "Password"\ --help "Contact Author Ritesh Raj
Sarraf\nEmail: rrs@researchut.com"\ --inputbox "Please enter your password" 18
45 2 > /tmp/passwd.$$;

retval=$?;  
$INPUT=`cat /tmp/passwd.$$`; #rm -f /tmp/passwd.$$;

case $retval in 0) mount;; #echo "Password is '$input'";; 1) echo
"Cancelled";; 255) echo "Box Closed";;  
esac  
}

main()  
{ $DIALOG --wrap --title "Question"\ --help "Contact Author Ritesh Raj
Sarraf\nEmail: rrs@researchut.com"\ --yesno "Do you want to mount your
encrypted filesystem ?" 0 0

case $? in 0) prelim_mount_check;; 255) $DIALOG --wrap --title "Aborted"\
--infobox "Cancelled"  
esac  
}

main
Categories: Programming  Tags: shell 

Go for (a) geek lover(s)!

This article is one among the many articles proving why geeks are the best men. There are many more available on the net to prove it. But for me, my time hasn’t tickled yet

Categories: Fun 

Linux-Nepal

Linux Nepal is a non-profit organization dedicated to promoting GNU/Linux in the kingdom of the Himalayas, Nepal.

Categories: General  Tags: Linux Nepal 

Professional Services

I’m available as a freelance consultant. Here’s a list of services I offer. You can email me for details.

Categories: General 

Open Source Is SHIT

Yes, that’s rightly mentioned in the title. I’m not a fucking good speaker but this link might be good enough for explanations on why ESR and his open source fundas are shit.

Follow the facts, not the hype.

Free Software has always been about user rights and RMS has done great job.
For me personally, it’s been FSF because of which today what I am. Being a dumb chap from a rural town in a rural state of India and born in a complete business family, I had never dreamt of becoming a computer professional anyway. It was FSF and RMS’ idealisms that brought me today to where I am.

[Read More]
Categories: Rant Computing 

Ritesh Sarraf ticketed

So finally I got caught sleeping in the office besides my computer adjacent to the desk. Great days are these

Awake whole night doing work and taking subsequent naps in the day, especially in your cube at office is funny.
And yes, it also gets you good names like druggist, afimchi et cetera

Ritesh Sarraf
Sleeping

Ritesh Sarraf
Sleeping

Categories: Fun 

Is it the way you blog ?

Today, blogging is one of the hottest topic.

Day in day out people are blogging. Statistics on the net show that every 7 seconds an article is posted to a blog.

But what exactly is a blog ?

A search at my laptop’s local dictionary server yielded two definitions :

rrs@laptop:~ $ dict blog

2 definitions found

From WordNet ® 2.0 (August 2003) [wn]:

blog n : a shared on-line journal where people can post diary entries about their personal experiences and hobbies [syn: {web log}]

[Read More]
Categories: General