Tag Archives: linux

Persist your screen brightness settings in Linux

If you like me have a machine running Linux OS and want to be able to persist your screen’s brightness setting, here is a small script that does the trick. (I don’t know if that feature lacks only in Ubuntu running in a Dell XPS 15 l502x or common to all Linux laptops)

Initially the problem is that once you reboot the machine, you lose the brightness setting and you have to manually adjust again. Annoying!

With the following instructions, you’ll be able to fix that. Tested in Ubuntu 13.10.

Copy these following three scripts in your Desktop folder (Or in the same folder) and give them execution permission:

RESET script (brightness-reset.sh):

# Author: Hanine HAMZIOUI ALMADANY <hanynowsky@gmail.com>
# This script sets the brightness in Ubuntu as it is not persistent upon reboot

# In order to manually execute these commands below, the user must be root

# Brightness values are integers that range from 0 to 15

if [ -f $CUSTOMBRIGHTNESS ];then echo $(cat $CUSTOMBRIGHTNESS) > /sys/class/backlight/acpi_video0/brightness
else echo $DEFAULT_BRIGHTNESS > /sys/class/backlight/acpi_video0/brightness
exit 0

Brightness RUN (brightness-run.sh)


# Persist Brightness value in Ubuntu 13.10
# Author Hanine HAMZIOUI ALMADANY <hanynowsky@gmail.com>

if [ -f "brightness-reset.sh" ]; then
sudo cp -v brightness-reset.sh /etc/init.d/ && sudo chmod +x /etc/init.d/brightness-reset.sh
else echo "brightness-reset file does not exist, it must be in the same folder. Terminating..."; exit 0;

if [ -f "brightness-save.sh" ]; then
sudo cp -v brightness-save.sh /etc/init.d/ && sudo chmod +x /etc/init.d/brightness-save.sh
else echo "brightness-save file does not exist, it must be in the same folder. Terminating..."; exit 0;

sudo ln -s /etc/init.d/brightness-save.sh /etc/rc0.d/K10brightness-save # Brightness SAVE Symbolic link to RC 0
sudo ln -s /etc/init.d/brightness-save.sh /etc/rc6.d/K10brightness-save # Brightness SAVE Symbolic link to RC 6

rawfile=`cat /etc/rc.local | grep "/etc/init.d/brightness-reset.sh"`
if [ -z "$rawfile" ]; then
sudo sed -e 's/exit 0//g' -i /etc/rc.local
sudo echo "#Reset screeen brightness" >> /etc/rc.local
sudo echo "/etc/init.d/reset-brightness.sh" >> /etc/rc.local
sudo echo "exit 0" >> /etc/rc.local
else echo "RC.LOCAL file is already customized to reset brightness at startup...If you think otherwise, do it manually again!"

exit 0;

BRIGHTNESS Save (brightness-save.sh)


# Author: Hanine HAMZIOUI ALMADANY <hanynowsky@gmail.com>
# Target: Ubuntu 13.10 and below
# Script that saves the last brightness value used

mkdir -p $(dirname $CUSTOMBRIGHTNESS)
cat /sys/class/backlight/acpi_video0/brightness > $CUSTOMBRIGHTNESS
exit 0;


chmod +x ~/Desktop/brightness-*

And finally; from your terminal again:

bash ~/Desktop/brightness-run.sh

You will be prompted for your user password.

Now adjust brightness ti a certain value and reboot. 😉


Ubuntu 13.10 Saucy on Dell XPS L502X

This post mentions some issues and fixes after upgrading to Ubuntu 13.10.

For Ubuntu 13.04 and previous versions, please refer to the corresponding post.

Nvidia Optimus:

– First of all, once the upgrade has completed, the user should workaround bumblebee to make it work:

When you run optirun command, you get an error message like this:

error while loading shared libraries: libturbojpeg.so: cannot open shared object file: No such file or directory

Open a Terminal and type:

sudo ln -s /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0 /usr/lib/x86_64-linux-gnu/libturbojpeg.so


sudo ln -s /usr/lib/i386-linux-gnu/libturbojpeg.so.0 /usr/lib/i386-linux-gnu/libturbojpeg.so


SD Card Reader:

Up to 13.04, the SD card reader was not really functional, unless you boot up with the card inserted. This bug has been fixed in Kernel 3.12 and should be backported soon to 13.10. Patience.

We’d be updating this post by this week-end, with useful information.

QT Application with Java. Possible? Yes QT Jambi does it.

If you’ve never heard about it, you can build rich cross-platform GUIs with Qt Jambi., while coding in Java. What?
Yes, QT Jambi is a QT Binding to Java, allowing you to develop QT GUI using Java instead of C++.
It practically is the same thing as Java-Gnome library which is a GTK+ binding.

QT Jambi is still maintained as opposite to rumors. And the last snapshot was build on 11 November 2012.
If you want to give it a shot, the following is a ‘get started’ tuto:


  • OS: Ubuntu 12.10 AMD64
  • Desktop: Unity
  • IDE 1: Netbeans 7.3
  • JDK: Oracle JDK 1.7.u10
  • IDE 2: Eclipse Juno

First, install Qt Jambi from its PPA:

sudo add-apt-repository ppa:qtjambi-community/libqtjambi-snapshots && sudo apt-get update && sudo apt-get install --install-suggests libqtjambi-snapshot qtjambi-examples-snapshot qtjambi-designer-snapshot ant-qtjambi-snapshot libqtjambi-redist-snapshot

Then, use this script, to tell your JDK where to find corresponding QT libraries used by QT Jambi:


#| Title: CopyJambi
#| Author: Hanine HAMZIOUI
#| Contact: <hanynowsky@gmail.com>
#| Date:  Sat 15 Dec 2012 03:57:00 AM WET
#| License: GNU GPL v3+
#| Description: Create symlinks to QT libs in default JDK for Jambi.
#| Version: 1.0
#| Environment: Netbeans 7.3 on Ubuntu 12.10 AMD64
#| Compliance: bash, zsh, ksh, dash, sh

# sudo add-apt-repository ppa:qtjambi-community/libqtjambi-snapshots
# sudo apt-get update
#sudo apt-get install --install-suggests libqtjambi-snapshot qtjambi-examples-snapshot qtjambi-designer-snapshot ant-qtjambi-snapshot libqtjambi-redist-snapshot

# Pick the JDK path
if [ -n "${JAVA_HOME}" ]; then jdk=${JAVA_HOME}
    if [ -d "/usr/lib/jvm/default-java" ]; then jdk=/usr/lib/jvm/default-java
    else whiptail --msgbox "No JAVA_HOME was found. Script will abort." "$LINES" "$COLUMNS"; exit 0

# Two Temporary files that receive names of libraries to be copied

# Get the names of libraries to be copied
ls /usr/lib/x86_64-linux-gnu/ | grep libQt | sed -e '/.prl$/g' -e '/.a$/g' -e '/[0-9].[0-9]$/g' | perl -ne 's/^$//g || print' > ${tmp1}
ls /usr/lib/x86_64-linux-gnu/ | tr '[:upper:]' '[:lower:]' | grep libqt | sed -e '/.prl$/g' -e '/.a$/g' -e '/[0-9].[0-9]$/g' | perl -ne 's/^$//g || print' >> ${tmp1}
ls /usr/lib/jni |  tr '[:upper:]' '[:lower:]' | grep trolltech > ${tmp2}
ls /usr/lib/jni |  tr '[:upper:]' '[:lower:]' | grep jambi >> ${tmp2}

# Create symbolic links to QT libraries
while read line; do
sudo ln -v -s /usr/lib/x86_64-linux-gnu/${line} /usr/lib/${line}
sudo ln -v -s /usr/lib/x86_64-linux-gnu/${line} ${jdk}/jre/lib/amd64/${line}
done < ${tmp1}
echo "Copied ${count} QT libraries Symbolic links"

# Create symbolic links to Jambi Libraries
while read inline; do
sudo ln -v -s /usr/lib/jni/${inline} ${jdk}/jre/lib/amd64/${inline}
sudo ln -s -v /usr/lib/jni/${inline} /usr/lib/${inline}
done < ${tmp2}
echo "Copied ${i} Jambi QT libraries Symbolic links"

# Remove temporary files
if [ -f ${tmp1} ] || [ -f ${tmp2} ]
    then rm -v ${tmp1}; rm -v ${tmp2}

# Make sure the user system is amd64
arch=$(uname -i)
if [ "${arch}" = "x86_64" ]; then eval OPERATION
else whiptail --msgbox "Your system architecture is not AMD64. Script will not continue. Abort." "$LINES" "$COLUMNS"
exit 0

The above script will create symbolic links in your JDK path. If you want you can copy the libraries instead of just symlinking them.

Next step is to create a Java Project in Netbeans and import Qt Jambi library in classpath as well as QT Jambi Demos library. (You’ll find them in /usr/share/java/)


Here is a screenshot of a demo example :


You can test with a simpler example (Hello World):

package jambi;

import com.trolltech.qt.gui.*;

public class HellowWorld {

public static void main(String args[]) {
QPushButton hello = new QPushButton("Hello World!");
hello.resize(120, 40);
hello.setWindowTitle("Hello World");


When running a QT Jambi java file, you might encounter this error :
# A fatal error has been detected by the Java Runtime Environment:
# SIGSEGV (0xb) at pc=0x00007f6b95e362ba, pid=10602, tid=140100171314944
# JRE version: 7.0_10-b18
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.6-b04 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libQtGui.so.4+0x2602ba] QWidgetPrivate::deleteTLSysExtra()+0x3a
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
# An error report file with more information is saved as:
# /home/hanine/Workspace/test/jambi/hs_err_pid10602.log
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp

Yet, entering : ulimit -c unlimited does not help at all. It sounds like an old bug related to Java HotSpot, where a zip file is read and modified in the same time. In other situations this bug is overriden using -Xmx option (e.g. -Xmx2900m : Maximum Memory : 2.9 GB )
E.G: java -Xmx:1864m -Xms:1864m myapp.jar sets minimum & maximum java memory heaps to 1864 MB for myapp.jar.
So, it appears that in almost all cases, a java file with the following statements will produce this error:

 public static void main(String args[]) {

        Wiggly d = new Wiggly(null);


So to get rid of this error, change the code to look like this instead (Still investigating on the root problem though):

 public static void main(String args[]) {
        new Wiggly(null).show();


Running your Qt Application from terminal

When you clean and build with Netbeans, you’d get a Jar File in your project workspace, in a folder named dist.
Make this jar file executable : chmod +x /path/to/this/jar/file.jar
and run it from terminal: java -jar /path/to/this/jar/file.jar

Qt Application executed as a JAR file.

Qt Application executed as a JAR file.

Eclipse Juno IDE

You can achieve the same thing using Eclipse if it’s your preferred IDE. Just make sure you install qt-jambi from Launchpad PPA and run the above script:

  • – Use the script from above or just download it from here : QtJambiCopierSCript
  • – Save it in your Desktop and run : bash ~/Desktop/jambicopy.sh
  • – Follow instructions if any.
  • – Open Eclipse Juno, Create a Java Project and add external libraries from /usr/share/java/
  • – Adding the qtjambi.jar and qtjambi-examples.jar does the job.


GUI Designer

Unlike Java-Gnome binding library which does not yet integrate with GUI designer GLADE, Qt Jambi integrates with QT Designer.
If you followed instructions above, go to your Terminal and type:



bash /usr/bin/qtjambi-designer.sh

This will launch QT Jambi Designer. Henceforth, you can start designing visually your GUI. Once finished, save the work as a "*.jui" file, which you would reuse as your Application UI.
Normally, Qt Designer produces a file with "*.ui" extension; but QT Jambi team has modified the thing with custom modifications that allow better integration and generation of UI java files.
We will cover this later in this same post.
Thanks for reading.
N.B: Qt Jambi Community website is down since yesterday (14th December).
You can browse other useful resources that will get you accustomed to QT Jambi quickly: QT JAMBI RESOURCES

A lazy way to debianize a Java application ( JDebianizer )

As a heavy user of Debian based system like Ubuntu, if you’re developing Java Swing applications and want to distibute them to end users either for testing purposes or as a stable software, the first thing you think about is the Debian archive. Distributing Java software as JAR files may not be the best thing towards Debian OS and its derivatives users.

You still have many helper scripts like javahelper ( sudo apt-get install javahelper ) which is itself a bunch of scripts (jh_something), each one having a specific purpose, to help you package your Java application as a Debian file. Besides, it gets irritating to use embedded package installers which do not respect to an extent the system packaging policies and which steals some of your freedom in that matter.

So, What about using only one script that semi-automates the debian packaging for us?
Well, in the recent post Bomico, we gave mention of a tiny Java application that had to be debianized in order to be natively installed in Ubuntu 12.04. To achieve this, we wrote a small script ( JDebianizer script ) that semi-automates debian packaging for us.

Java DEbianizer
The follwoing is the so-called JDebianizer script as it was snapshot the first time. If you want to get the updated script please go to JDebianizer Github REPO:


# Title		:	JDebianizer
# Description 	: 	Script tested only in Ubuntu. 
# 			This script is for Java developers who want to package a simple application for Ubuntu users as a Debian 				file.
# Rules			DO NOT execute this script with root power (sudo). 
#			The script will try to install md5deep needed to generate md5 sums.
#			If no internet connection, md5sums will be used instead.
#			JDebianizer is  onsole-only, so run it from Terminal or any other Shell.
#			Script is compliant only with BASH & KSH. Don't run it with SH, ZSH, DASH..).
# Usage		:	In order to run the JDebianizer, switch to current directory that contains the script
# 			and enter: 
# 			./jdebianizer 
# 			or: 
# 			cd /path/to/containing/folder && bash jdebianizer			
# Dependencies	:	md5deep, whiptail, zenity		
# Author 	: 	Hanine HAMZIOUI <hanynowsky@gmail.com> حنين
# Version 	: 	1.0a
# License	:	GNU GPL V3+
# Date created	:	Wed 14 Nov 2012 12:40:32 AM WET 

# ----------------- TODO -----------------------------

# TODO 1- add support for several icon sizes
# TODO 2- add support for verbosity
# TODO 3- add support for javadoc: jh_installjavadoc
# TODO 4- add support for many config files
# TODO 5- add support for other application folders (/etc /usr/share/menu)

# -------------- Global variables ----------------------
JDVERSION="JDebianizer 1.0. \nCopyright (C) 2012 - 2013. Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
JDebianizer is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Written by Hanine HAMZIOUI."
ROWS=$(echo "$LINES" | bc )
COLS=$(echo "$COLUMNS" | bc)

# ----------------Re-execute the SCRIPT-----
echo "JDebianzier filename is: $0"
filename=$(echo "$0" | sed -e 's/ /\\ /g' )
echo "Modified JDebianizer filename is: $filename"
if [ -f "$filename" ]; then eval bash "$filename"
else echo "Path to file is incorrect or contains trailing spaces. (e.g. ~/Ubuntu One/jdebianizer)"; exit 0

# ----------------JAYATANA INSTALLER --------
JDKPATH=$(echo $JAVA_HOME | grep .)

sudo apt-get -y install openjdk-7-jdk libunity-dev libxt-dev gcc make ant subversion 
sudo update-java-alternatives -s java-1.7.0-openjdk-amd64 
svn checkout $JAYATANADD 
sudo ant install -buildfile $JAYABUILD -v
sudo ant config -v 
sudo update-alternatives --config java 
sudo update-alternatives --config javac
sudo ant install -Djava.home.7=/usr/lib/jvm/java-7-openjdk-amd64 -f $JAYABUILD -v -l $JAYALOG
sudo ant config -Djava.home.7=$JDKPATH -buildfile $JAYABUILD -v -l $JAYALOG
sudo chmod 777 $JAYALOG
echo "Jayatana Installation finished. Run a Java Swing Application and check if it is integrated with global menu."
whiptail --msgbox "Jayatana Installation finished. Run a Java Swing Application and check if it is integrated with global menu.\nA log file : $JAYALOG was created." "$LINES" "$COLUMNS"

if [ -d "$JAVA_HOME/jre/lib/endorsed" ] 
	then CHECKJAYA=$(ls $JAVA_HOME/jre/lib/endorsed/* | grep "jayatana")
		if [ -n "$CHECKJAYA" ]
			then whiptail --yesno "Seems like Jayatana is already installed. Proceed anyway?" 20 80 --title "Jayatana" --backtitle "Jayatana Installation Check"
				if [ "$?" = 0 ] 
					then echo "Trying to re-install Jayatana"; eval JAYAINSTALL
					else echo "Aborted by $USER"; eval restartscript
			else echo "Seems like Jayatana is not installed."; eval JAYAINSTALL
	else echo "Jayatana seems to be not installed yet for your default JRE."; eval JAYAINSTALL

sudo ant deinstall -buildfile $JAYABUILD -v
sudo ant deconfig -buildfile $JAYABUILD -v
sudo ant deconfig -Djava.home.7=$JDKPATH -buildfile $JAYABUILD -v -logfile $JAYALOG
echo "Jayatana uninstallation has finished."

# DELETE Jayatana Folder created by subversion checkout
whiptail --yesno "Delete Jayatana Folder too?" "$LINES" "$COLUMNS" --backtitle "Ubuntu Global Menu Support for Java Swing Applications" --title "JDebianizer"
if [ "$?" = 0 ]; then mv $HOME/jayatana $HOME/.local/share/Trash/files/
elif [ "$?" = 1 ]; then echo "Jayatana Folder is kept by $USER , you can delete it later : ~/jayatana";
else echo "Jayatana Folder is kept by $USER , you can delete it later : ~/jayatana";

echo "$JDKPATH : is your default JDK." 
echo $(java -version)

eval COMMON;
whiptail --yesno "Install/Uninstall Jayatana (ESCAPE or CTRL+C to cancel)" "$LINES" "$COLUMNS" --yes-button "Install" --no-button "Uninstall" --backtitle "Ubuntu Global Menu Support for Java Swing Applications" --title "JDebianizer"
case "$?" in 
0) eval INSTALLCOM; exit 0;;
1) eval UNINSTALLCOM;eval UNDIR;exit 0;;
255) echo "Aborted by $USER";exit 0;; # code returned by ESCAPE is 255

jayamain() { # "${DESKTOP,,}"
if [ "${DESKTOP}" = "unity" ] || [ "${DESKTOP}" = "Unity" ]; then eval RUNINST
	else echo "Your Desktop environment is ${DESKTOP}. You cannot Install Jayatana. (Required: Unity Shell)"

# -------------------------- ARGS -----------
for arg in $@
		case "$arg" in
			--version|--v|--V) unset arg; echo -e "$JDVERSION"; exit 0;;
			--help|--h|--?|-?) echo -e "Run the script and follow instructions if any.\nUSAGE: \n./jdebianizer [OPTION...]\n\nOPTIONS: \n--v, --version Show the package version\n--c, --clean Remove files created by JDebianizer\n";exit 0;;
			--clean|--c) echo -e "Removing JDebianizer files";
				if [ -f "$LOGFILE" ]; then rm -v $LOGFILE 
					else echo "No Log File found."
				if [ -f "$CONFIGFILE" ]; then rm -v $CONFIGFILE 
					else echo "No Config File Found."
				exit 0;;
			-v|--verbose) echo -e "Running in Verbose mode.";exit 0;; # TODO set the var to be used with whiptail
			"") break;;
argfu "$@";

# Make sure the user has copied jar libraries if any and main executable package jar in a given folder
start() {
# clear the screen
tput clear
# Move cursor to screen location X,Y (top left is 0,0)
tput cup 2 15
# Set a foreground colour using ANSI escape
tput setaf 3
echo "JDebianizer. 1.0. (Debianize your Java Application)"
tput cup 3 15
tput setaf 5
echo "https://github.com/hanynowsky/jdebianizer"
tput sgr0
tput cup 5 17
# Set reverse video mode
tput rev
echo "I M P O R T A N T - N O T I C E"
tput sgr0
tput cup 7 15
echo "A. Create a folder and put your executable Java program as well as its dependencies (jar file libraries) in it"
tput cup 8 15
echo "B. The executable jar file should have the same lowercase name as the package. E.g: logism.jar"
tput cup 9 15
echo "C. Prepare a 48x48 PNG image to be used as the icon of your Java application"
tput cup 10 15
echo "D. You can eventually add documentation files you want to include in the debian package."
# Set bold mode 
tput bold
tput cup 13 15
echo "1. Start JDebianzer"
tput cup 14 15
echo "2. Exit JDebianzer"
tput cup 15 15
echo "3. Install Jayatana (Ubuntu Global Menu Support for Java Swing Applications)"
tput cup 17 15
read -p "Enter your choice [ 1 / 2 / 3 ]  " choice
if [ "$choice" = "1" ] ; then echo "Starting JDebianizer..."
elif [ "$choice" = "3" ] ; then tput sgr0; echo "Starting Jayatana installer..."; eval jayamain
elif [ "$choice" = "2" ] ; then exit 0
else echo "exiting JDebianizer"; exit 0
tput clear
tput sgr0
tput rc
eval start;

whiptail --yesno "Welcome to JDebianizer. First of All, copy your package's main executable jar file (Must have the same name as the package name), as well as its dependency jar libraries, in the same folder (example: /home/yourusername/mypackagejars_folder), then select 'yes'. Clicking no means you still have not done so." "$LINES" "$COLUMNS" --clear
if [ "$?" -eq 0 ]; then echo "Great! Let us continue then."
else echo "Existing script. Retry when you're ready."; exit 0;

if [ $exitcode = 0 ]; then echo "$USER said okay: $exitcode"
elif [ ${exitcode} = 1 ]; then echo "$USER said NO - Canceled: $exitcode"; exit 0
else echo "$? - Continue...";

# ---------------CONFIG File ------------------
zenity --forms --text="Package Properties" --add-entry="Package-Name" --add-entry="Version" --add-entry="Maintainer-Name" --add-entry="Maintainer-Surname" --add-entry="Email" --add-entry="Homepage" --window-icon $ZWINICON --title "JDebianizer" > $TEMPFILE
eval exitoption;
echo "Grabbed Package Properties"

while read line; do
	if [[ "$line" =~ ^[^#]*= ]] 
		name[i]=$(echo $line | cut -d'=' -f 1) 
		array[i]=$(echo $line | cut -d'=' -f 2)
		# echo "${array[i]}"

cat $TEMPFILE | sed -e 's#|#\n#g' > $LOGFILE
while read line; do
    	array[i]=$(echo "${line}")
	if [ -z "${array[i]}" ] 
		then echo "No field should be empty. Please Retry."; exit 0
		else echo "${array[i]}"
done < $LOGFILE

echo "The entered item 1 is: ${array[0]}" | tr '[:upper:]' '[:lower:]'
echo "The entered item 2 is: ${array[1]}" | tr '[:upper:]' '[:lower:]'
echo "The entered item 3 is: ${array[2]}"
echo "The entered item 4 is: ${array[3]}"
echo "The entered item 5 is: ${array[4]}"
echo "The entered item 6 is: ${array[5]}"

if [ -f "$CONFIGFILE" ] 
	then whiptail --yesno "Config File Exists. Overwrite it?" 20 50
		if [ "$?" -eq 0 ] 
			then eval packpropform; eval lineasvar
			else eval parseconfig; echo "Found config file for package ${array[0]}" 
	else echo "CONFIG FILE does not exist. Please enter package properties values."; eval packpropform; eval lineasvar

PACKNAME=$(echo "${array[0]}" | tr '[:upper:]' '[:lower:]')  	# Package name : must be lowercase  "${PACKNAME,,}"
upperpackname=$(echo "${PACKNAME}" | sed 's/\([a-z]\)\([a-zA-Z0-9]*\)/\u\1\2/g')
PVERSION=$(echo "${array[1]}" | tr '[:upper:]' '[:lower:]') 	# Package Ubuntu version
ROOTDIR=$(echo $HOME/Desktop/$PACKNAME"_"$PVERSION | grep .)	# Root folder to debianize
MAND="man"							# Workaround for key word man
mfname=$(echo "${array[2]}" | tr '[:lower:]' '[:upper:]')
msname=$(echo "${array[3]}" | sed 's/\([a-z]\)\([a-zA-Z0-9]*\)/\u\1\2/g')
maintainer="$msname $mfname"
memail=$(echo "<${array[4]}>" | tr '[:upper:]' '[:lower:]')
homepage=$(echo "${array[5]}" | tr '[:upper:]' '[:lower:]')

# --------------- Append Config File ------------------ 
echo "[PACKAGE]" > "$CONFIGFILE" # TODO before appending check for duplicates by PACKNAME
echo "MFNAME=${mfname}" >> "$CONFIGFILE"
echo "MSNAME=${msname}" >> "$CONFIGFILE"
echo "MEMAIL=${memail}" >> "$CONFIGFILE"
echo "HOMEPAGE=${homepage}" >> "$CONFIGFILE"

# ------------- Desktop File variables ----------------
PICON="/usr/share/icons/hicolor/48x48/apps/$PACKNAME.png"		# Desktop file Icon
COMMENT=$(echo "${PACKNAME} $PVERSION - A Java based Application" sed 's/\([a-z]\)\([a-zA-Z0-9]*\)/\u\1\2/g')	
									# Desktop file comment
GENAME=$(echo "${PACKNAME}"|sed 's/\([a-z]\)\([a-zA-Z0-9]*\)/\u\1\2/g')	# Desktop file generic name
DNAME=$(echo "${PACKNAME}"| sed 's/\([a-z]\)\([a-zA-Z0-9]*\)/\u\1\2/g')	# Desktop file application name - First letter is 
									# Uppercase "${DNAME^^[PATTERN]}"
PTYPE="Application"							# Desktop file type
DVERSION="1.0" 								# Desktop file version

# We can create them using : mkdir $ROOTDIR/{DEBIAN,usr{share{man{man1},icons,doc{$PACKNAME},$PACKNAME{lib},applications},bin}}
if [ ! -d "$ROOTDIR" ]; then mkdir -p $ROOTDIR; sudo chmod -R 777 $ROOTDIR # Unlock root folder
else echo "Root folder exists. OK. Skipping."; sudo chmod -R 777 $ROOTDIR; sudo chown $USER:$USER -R $ROOTDIR
if [ ! -d "${BINDIR}" ]; then mkdir -p ${BINDIR}
else echo "bin folder exists. OK. Skipping."
if [ ! -d "${DEBDIR}" ]; then mkdir -p ${DEBDIR}
else echo "DEBIAN folder exists. OK. Skipping."
if [ ! -d "$DOCDIR" ]; then mkdir -p $DOCDIR
else echo "doc folder exists. OK. Skipping."
if [ ! -d "$SHAPPDIR" ]; then mkdir -p $SHAPPDIR
else echo "share applications folder exists. OK. Skipping."
if [ ! -d "$MANDIR" ]; then mkdir -p $MANDIR
else echo "man1 folder exists. OK. Skipping."
if [ ! -d "$PACKDIR" ]; then mkdir -p $PACKDIR
else echo "Package folder exists.Ok. Skipping."
if [ ! -d "$LIBDIR" ]; then mkdir -p $LIBDIR; echo "Created lib folder"
else echo "lib folder exists.Ok. Skipping."
if [ ! -d "$DICONDIR" ]; then mkdir -p $DICONDIR; echo "Created icon folder"
else echo "icon folder exists.Ok. Skipping."
eval create_dirs;

# ------------------Copy LIBRARIES & main binary EXECUTABLE-----
sudo chmod 777 -R $ROOTDIR # Give full permission to allow writing
libpath=$(zenity --file-selection --directory --title "Select the folder containing jars")
eval exitoption;
echo "Jar Files Folder Confirmed."
CHECKJARS=$(ls -1 $libpath/*.jar  2>/dev/null | wc -l)
CHECKJAR=$(ls -1 $libpath/$PACKNAME.jar  2>/dev/null | wc -l)
jarscount=$(echo "$CHECKJARS+0" | bc)
if [ -d "$libpath" ] || [ $jarscount -gt 0 ]; then echo "Trying to copy: $libpath/*.jar" $LIBDIR"/" ; 
echo "${CHECKJARS} jar files found"; ls -l ${libpath} | grep "\.jar\$"; # grep "\.jar$"
cp -v $libpath/*.jar $LIBDIR/ # $libpath"/." to cp all content;
else echo "the folder you specified does not contain the necessary jar files."
jarcount=$(echo "$CHECKJAR+0" | bc)
if [ ! $jarcount -eq 0 ]; then mv $LIBDIR"/"$PACKNAME".jar" $PACKDIR"/"$PACKNAME".jar"
else echo "Main jar not found"
CHECKFILES=$(ls -1 $libpath  2>/dev/null | wc -l)
a=$(echo $CHECKFILES+0 | bc)
result=$(echo "$CHECKJARS" | bc)
if [ $a -gt $result ]; then echo "folder has $CHECKFILES files, $CHECKJARS being jars" ;echo "WARNING: $libpath contains non-jar files.";
echo "But we have not copied them. Copied only jar files."
else echo "No files beside jar files on $libpath. Great! Let us continue." 
# --------------------------------------------------------------

echo "Working on: "$ROOTDIR " for debianizing package $PACKNAME" | grep .

# --------------Create a DESKTOP FILE ----------------------
# We can use desktop-file-install to install the desktop file in a given folder
DESKFILE="$ROOTDIR/usr/share/applications/$PACKNAME.desktop"	# Desktop file path name
echo "Creating Desktop file"$DESKFILE
echo "[Desktop Entry]" > $DESKFILE
echo "Type=$PTYPE" >> $DESKFILE
echo "Name=$DNAME" >> $DESKFILE
if [ -z "$CATEGORIES" ] && [ -z $CATOTHER ]; then desktop-file-edit --add-category "Utility;Java;" $DESKFILE
else echo $CATEGORIES
echo "Other categories: " $CATOTHER
echo "GenericName=$GENAME" >> $DESKFILE
echo "Comment=$COMMENT" >> $DESKFILE
echo "Exec=$PACKNAME" >> $DESKFILE
echo "Terminal=false" >> $DESKFILE
echo "Icon=$PICON" >> $DESKFILE
echo "Version=$DVERSION" >> $DESKFILE

MCATGET=$(whiptail --checklist "Choose Main Categories (Desktop File *.desktop). Use space to select and Tab to switch." 25 50 16 "AudioVideo" 0 "Audio" 0 "Video" 0 "Development" 0 "Game" 0 "Graphics" 0 "Office" 0 "Science" 0 "Settings" 0 "Utility" 1 "Network" 0 "Education" 0 "System" 0 --noitem 3>&1 1>&2 2>&3) 
eval exitoption;
echo "Main Desktop categories copied."
ACATGET=$(whiptail --checklist "Choose Additional Categories (Desktop File *.desktop). Use space to select and Tab to switch." "$LINES" "$COLUMNS" 25 "Java" 1 "GTK;GNOME" 0 "Building" 0 "IDE" 0 "Profiling" 0 "Translation" 0 "Calendar" 0 "ContactManagement" 0 "Database" 0 "Dictionary" 0 "Chart" 0 "Email" 0 "Finance" 0 "FlowChart" 0 "PDA" 0 "ProjectManagement" 0 "Presentation" 0 "2DGraphics" 0 "VectorGraphics" 0 "RasterGraphics" 0 "3DGraphics" 0 "TextTools" 0 "InstantMessaging" 0 "Chat" 0 "WebDevelopment" 0 "Music" 0 "Biology" 0 "Chemistry" 0 "ComputerScience" 0 "Electricity" 0 "ImageProcessing" 0 "Physics" 0 "Engineering" 0 "ConsoleOnly" 0 --noitem 3>&1 1>&2 2>&3) 
eval exitoption;
echo "Additional Desktop categories confirmed."
CATEGORIES=$(echo "$MCATGET"";""$ACATGET" | sed -e 's# #;#g' -e 's#"##g')	# Desktop file Categories
CATOTHER=$(whiptail --inputbox "Any other categories to add (Seperate by semi-comma). Leave blank if none." 10 30 3>&1 1>&2 2>&3 | sed -e 's# ##g' -e 's#[^a-zA-Z\;]##g')							# Desktop Other categories

desktop-file-edit --add-category $CATEGORIES $DESKFILE
CATOTHERF=$("${CATOTHER}" | tr '[:upper:]' '[:lower:]')
desktop-file-edit --add-category $(echo "${CATOTHERF}" | sed 's/\([a-z]\)\([a-zA-Z0-9]*\)/\u\1\2/g') $DESKFILE
echo "StartupNotify=true" >> $DESKFILE
echo "X-Ubuntu-Gettext-Domain=$PACKNAME" >> $DESKFILE

LOCICON=$(zenity --file-selection --file-filter "*.png" --title "Select Your package Icon (PNG format and 48x48 resolution)")
eval exitoption;
echo "Desktop Icon confirmed."
if [ -r $LOCICON ]; then cp -v -u $LOCICON "${ROOTDIR}${PICON}"
else echo "No PNG Icon found"; whiptail --msgbox "No PNG found. Exiting" $ROWS $COLS; exit 0

if [ -f "$ROOTDIR/$PICON" ]; then echo "Desktop icon already exists."
else eval pastedicon

if [ -f "$DESKFILE" ]; then whiptail --yesno "Desktop file already exists. Overwrite it?" 20 80
if [ "$?" -eq 0 ]; then rm -v "$DESKFILE"; eval writedeskfile
else echo "Existing Desktop file kept by $USER"
else eval writedeskfile
desktop-file-edit ${DESKFILE}

# -----------------------Create CONTROL file----------------
priority=$(echo "optional" | tr '[:upper:]' '[:lower:]') # All properties are lowercase
architecture=$(echo "all" | tr '[:upper:]' '[:lower:]')
instsize=$(du -s $ROOTDIR | grep -o "^[0-9]*") # size should be appended at the very end
sectionstring=(admin cli-mono comm database debug devel doc editors education electronics embedded fonts games gnome gnu-r gnustep graphics hamradio haskell httpd interpreters introspection java kde kernel libdevel libs lisp localization mail math metapackages misc net news ocaml oldlibs otherosfs perl php python ruby science shells sound tasks tex text utils vcs video web x11 xfce zope)
sectionvalue=$(whiptail --inputbox "Enter the appropriate Control Section amongst the following list (type java if you are not sure):\n\nadmin cli-mono comm database debug devel doc editors education electronics embedded fonts games gnome gnu-r gnustep graphics hamradio haskell httpd interpreters introspection java kde kernel libdevel libs lisp localization mail math metapackages misc net news ocaml oldlibs otherosfs perl php python ruby science shells sound tasks tex text utils vcs video web x11 xfce zope" 25 80 "java" 3>&1 1>&2 2>&3)
for (( s=0; s < ${#sectionstring[*]}; s++ )); do
lowersectv=$(echo "${sectionvalue}" | tr '[:upper:]' ':lower:')
if [ "${lowersectv}" = "${sectionstring[s]}" ] 
then section="${lowersectv}"; echo "It is okay. We have found your control section listed."
else section="java"; echo "Warriga, what you have typed does not figure in the Debian control section list...:(" 2>/dev/null
echo "Control file section property confirmed."

eval sectionget;
eval exitoption;
depends=$(echo -e "libjava-gnome-java (>= 4.1.1), jarwrapper" | zenity --text-info --title "Control File dependencies. separate with comma and space." --editable  --width=700 --height=300)
eval exitoption;
echo "Control file dependencies confirmed."
defscription="Body Mass Index Computer\n
 Check your body mass index with Bomico.\n Bomico is a small program written in Java and interfaced with Swing.\n See Documentation online at https://github.com/hanynowsky/bomico/wiki\r"
description=$(echo -e $defscription | zenity --text-info --title "Control File description (First line must not exceed 80 Characters.)" --editable --width=600 --height=300)
eval exitoption;
echo "Control file description confirmed."
echo "Creating postinst file "$CONTFILE
echo "Package: ${PACKNAME}" >> $CONTFILE
echo "Version: $PVERSION" >> $CONTFILE
echo "Section: ${section}" >> $CONTFILE
echo "Priority: ${priority}" >> $CONTFILE
echo "Architecture: ${architecture}" >> $CONTFILE
echo "Depends: $depends" >> $CONTFILE
echo "Maintainer: $maintainer $memail" >> $CONTFILE
echo "Installed-Size: $instsize" >> $CONTFILE
echo "Homepage: $homepage">> $CONTFILE
echo -e "Description: $description\r" >> $CONTFILE
if [ -f "$CONTFILE" ]; then whiptail --yesno "control file exists. Overwrite it?" 20 80
if [ "$?" -eq 0 ]; then rm -v "$CONTFILE"; eval writecont
else echo "Existing control file kept by $USER"
else eval writecont

# -----------------------Create PREINST file----------------
if [ -f "$PREINSTFILE" ]; then rm -v $PREINSTFILE
else echo "postinst file not present. Going ahead..."
echo "Creating preinst file "$PREINSTFILE
echo "#!/bin/sh -e" > $PREINSTFILE
echo "echo 'preinst is executing'" >> $PREINSTFILE
echo "javahome=\$(echo \$JAVA_HOME)" >> $PREINSTFILE
echo "javadef=\"/usr/lib/jvm/default-java/jre/bin/java\"" >> $PREINSTFILE
echo "if [ -n \"\$javahome\" ] || [ -f \"\$javadef\" ]; then echo \"your JAVA_HOME is \$javahome\"" >> $PREINSTFILE
echo "else whiptail --yesno 'ERROR: JAVA_HOME seems to be not set. Or no JRE is installed.\n Do you want to install OpenJDK JRE?' 25 50" >> $PREINSTFILE
echo "if [ \"\$?\" -eq 0 ]; then sudo apt-get install -y openjdk-7-jre" >> $PREINSTFILE
echo "else echo 'Please Install a Java JRE and re-install this package again.'; exit 0" >> $PREINSTFILE
echo "fi" >> $PREINSTFILE
echo "fi" >> $PREINSTFILE
echo "exit 0;" >> $PREINSTFILE

# -----------------------Create POSTINST file----------------
if [ -f "$PINSTFILE" ]; then rm -v $PINSTFILE
else echo "postinst file not present. Going ahead..."
echo "Creating postinst file "$PINSTFILE
echo "#!/bin/sh -e" >> $PINSTFILE
echo "echo postinst is executing" >> $PINSTFILE
echo "LOGUSER=\`who | sed -e 's#-##g' -e 's#tty##g' -e 's#pts##g' -e 's#[0-9()\:]##g' -e 's#^[ \t]*##' -e 's#[ \t]*\$##' | grep . -m 1\`" >> $PINSTFILE
echo "BPATH=/usr/share/$PACKNAME/$PACKNAME.jar" >> $PINSTFILE
echo "DPATH=/usr/share/applications/$PACKNAME.desktop" >> $PINSTFILE
echo "LDPATH=\$HOME/.local/share/applications" >> $PINSTFILE
echo "LDFPATH=\$HOME/.local/share/applications/$PACKNAME.desktop" >> $PINSTFILE
echo "sudo chmod +x \$BPATH" >> $PINSTFILE
echo "sudo chmod 644 \$DPATH" >> $PINSTFILE
echo "cp \$DPATH \$LDPATH" >> $PINSTFILE
echo "echo Logged user is \$LOGUSER" >> $PINSTFILE
echo "sudo chown \$LOGUSER:\$LOGUSED \$LDFPATH" >> $PINSTFILE #echo "sudo chown \$LOGUSER:\$LOGUSER \$LDFPATH" >> $PINSTFILE
echo "exit 0;" >> $PINSTFILE

# -----------------------Create PRERM file----------------
if [ -f "$PRERMFILE" ]; then rm -v $PRERMFILE
else echo "prerm file not present. Going ahead..."
echo "Creating prerm file "$PRERMFILE
echo "#!/bin/sh -e" >> $PRERMFILE
echo "echo prerm is being executed" >> $PRERMFILE
echo "exit 0;" >> $PRERMFILE

# -----------------------Create POSTRM file----------------
if [ -f "$POSTRMFILE" ]; then rm -v $POSTRMFILE
else echo "postinst file not present."
echo "Creating Postrm file "$POSTRMFILE
echo "#!/bin/sh -e" >> $POSTRMFILE
echo "echo postrm is executing" >> $POSTRMFILE
echo "# Remember that if symlinks are used , an embedded IF dealing with symlink must be used -L" >> $POSTRMFILE
echo "LDFILE=\$HOME/.local/share/applications/$PACKNAME.desktop" >> $POSTRMFILE
echo -e "if [ -d "\$PHOME" ]; then sudo chmod 777 -R \$PHOME; rm -r \$PHOME \n else echo '$PACKNAME home folder not found' \n fi \n if [ -f "\$LDFILE" ]; then rm \$LDFILE \n else echo '$PACKNAME.desktop in local folder not found' \n fi  " >> $POSTRMFILE
echo "exit 0;" >> $POSTRMFILE
echo 'creator was executed'.

# -----------------Create the FAKE BINARY------------------
if [ -f "$FBINARY" ]; then rm -v $FBINARY
else echo "Fake binary $FBINARY file not present."
echo "Creating fake binary file $FBINARY"
echo "#!/bin/sh" >> $FBINARY
echo "export EXECBIN=/usr/share/$PACKNAME" >> $FBINARY
echo "argfu(){
for arg in \$@
case \$arg in
--version|--v|--V) unset arg; echo '${upperpackname} $PVERSION'; exit 0;;
--help|--h|--?|-?) echo 'Run the script and follow instructions if any.\nCheck Manual (man $PACKNAME).'; exit 0;;
'') break;;
argfu \$@;" >> $FBINARY
echo "java -jar \$EXECBIN/$PACKNAME.jar \$*" >> $FBINARY

# ---------------- AUTHORS File ---------------
echo "$maintainer $memail" > $DOCDIR/AUTHORS
echo "Surname FAMILYNAME <authoremailusername@domain.ext>" | zenity --text-info --title "Other Authors" --editable --height=200 --width=490 >> $DOCDIR/AUTHORS
if [ -f "$DOCDIR/AUTHORS" ]; then whiptail --yesno "AUTHORS file exists. Overwrite it?" "$LINES" "$COLUMNS"
if [ "$?" -eq 0 ]; then eval writeauth
else echo "The existing AUTHORS file is kept."
else eval writeauth

# ---------------- COPYRIGHT File ----------
PSOURCE=$(whiptail --inputbox "Enter Package Source code repository here: " 25 50 "http://" 3>&1 1>&2 2>&3)
PLICENSE=$(whiptail --radiolist "Choose Copyright License" 25 50 14 "BSD" 0 "GPL" 0 "GPL-1" 0 "GPL-2" 0 "GPL-3" 1 "LGPL" 0 "LGPL-2" 0 "LGPL-2.1" 0 "LGPL-3" 0 "GFDL-1.3" 0 "GFDL-1.2" 0 "GFDL" 0 "Artistic" 0 "Apache-2.0" 0 --noitem 3>&1 1>&2 2>&3)
echo "Format: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=REVISION" > $DOCDIR/copyright
echo "Upstream-Name: $PACKNAME" >> $DOCDIR/copyright
echo "Upstream-contact: $maintainer $memail" >> $DOCDIR/copyright
echo "Source: $PSOURCE" >> $DOCDIR/copyright
echo -e "\n" >> $DOCDIR/copyright
echo "Files: *" >> $DOCDIR/copyright
cyear=$(date +%Y)
echo "Copyright: Copyright $cyear $maintainer $memail" >> $DOCDIR/copyright
echo "License: $PLICENSE" >> $DOCDIR/copyright
echo " " >> $DOCDIR/copyright
echo -e "\n" >> $DOCDIR/copyright
echo "You should have received a copy of the GNU License
 along with $PACKNAME.  If not, see <http://www.gnu.org/licenses/>.
 On Debian systems, the complete text of the GNU General
 Public License version can be found in /usr/share/common-licenses/" >> $DOCDIR/copyright
if [ -f "$DOCDIR/copyright" ]; then whiptail --yesno "Copyright file exists. Overwrite it?" "$LINES" "$COLUMNS"
if [ "$?" -eq 0 ]; then eval writecopy
else echo "The existing Copyright file is kept."
else eval writecopy

# --------------------README File ------------
READMETEXT=$(echo "" | zenity --text-info --title "Edit README file" --editable)
echo -e "${upperpackname}. ${PVERSION}\n" > $DOCDIR/README
echo "Description: $READMETEXT" >> $DOCDIR/README
echo "Homepage: $homepage" >> $DOCDIR/README

if [ -f "$GZFILE" ] && [ -f "$GZFILE.gz" ]; then whiptail --yesno "$GZFILEN & $GZFILEN.gz files exist. Overwrite GZIPED file?" "$LINES" "$COLUMNS"
if [ "$?" -eq 1 ]; then rm -v "$GZFILE"
else whiptail --yesno "Gzip existing $GZFILEN file (yes) & Create new $GZFILEN file (no)" "$LINES" "$COLUMNS"
if [ "$?" -eq 0 ]; then gzip -v -f -9 $GZFILE
else eval $GZFUN; gzip -v -f -9 $GZFILE
elif [ ! -f "$GZFILE" ] && [ -f "$GZFILE.gz" ]; then whiptail --yesno "$GZFILEN.gz file exist. Overwrite it?" "$LINES" "$COLUMNS"
if [ "$?" -eq 1 ]; then echo "Keeping exisiting $GZFILEN.gz"
else eval $GZFUN; gzip -v -f -9 $GZFILE
elif [ -f "$GZFILE" ] && [ ! -f "$GZFILE.gz" ]; then whiptail --yesno "$GZFILEN file exist. Overwrite it?" "$LINES" "$COLUMNS"
if [ "$?" -eq 1 ]; then gzip -v -f -9 $GZFILE
else eval $GZFUN; gzip -v -f -9 $GZFILE
elif [ ! -f "$GZFILE" ] && [ ! -f "$GZFILE" ]; then $GZFUN; gzip -v -f -9 $GZFILE
else echo "Nothing done for $GZFILEN file."
eval gzaction

# ------------------- NEWS File --------------
TODAY=$(echo $(date +%a", "%d" "%b" "%Y" "%H:%M:%S" "%z))
echo -e "${upperpackname} $PVERSION:

	Fixes and New Features:
	Initial support for Ubuntu Global Menu.
	Creation of .desktop installation file.
	5 Formulas to calculate the BMI.
	Export BMI follow-up.
	Mediocre Audio support (Will be improved in future).
	Fixed Some layout issues." > $DOCDIR/NEWS

readmev=$(cat $DOCDIR/NEWS | zenity --text-info --title "Edit NEWS File" --editable --width=500 --height=500) 
echo -e "$readmev" > $DOCDIR/NEWS
eval gzaction

# ------------------- CHANGELOG.DEBIAN File --------------
echo "Writing changelog.Debian"
echo -e "$PACKNAME ($PVERSION) stable; urgency=low

  * Updated Exit Action.
    Closes: #999999

  * Added New Icons.

 -- $maintainer $memail  $TODAY" > $DOCDIR/changelog.Debian
readclog=$(cat $DOCDIR/changelog.Debian | zenity --text-info --title "Edit changelog.Debian File" --editable --width=500 --height=500) 
echo -e "$readclog" > $DOCDIR/changelog.Debian

eval gzaction

# ------------------- TODO_File --------------
TODOLIST=$(echo -e "1- Add feature X.\n" | zenity --text-info --title "TODO LIST EDITOR" --editable)
echo -e "\n" >> $DOCDIR/TODO
if [ -f "$DOCDIR/TODO" ]; then whiptail --yesno "TODO file exists. Overwrite it?" 20 80
if [ "$?" -eq 0 ]; then eval writetodo
else echo "The existing TODO file is kept."; export readtodo=$(cat $DOCDIR/TODO | zenity --text-info --title "Edit TODO File" --editable --width=500 --height=500); echo -e "$readtodo" > $DOCDIR/TODO
else eval writetodo

# ------------------THANKS File ----------------
THANKSTEXT=$(echo -e "1- Special thanks go to: \n" | zenity --text-info --title "THANKS File EDITOR" --editable)
if [ -f "$DOCDIR/THANKS" ]; then whiptail --yesno "THANKS file exists. Overwrite it?" 20 80
if [ "$?" -eq 0 ]; then eval writethanks
else echo "The existing THANKS file is kept."; export readthx=$(cat $DOCDIR/THANKS | zenity --text-info --title "Edit THANKS File" --editable --width=500 --height=500); echo -e "$readthx" > $DOCDIR/THANKS
else eval writethanks

# ----------------- MANUAL File---------------------

MANDATE=$(date "+%Y-%m-%d")
SHORTDESC=$(whiptail --inputbox "Manual file Short description: " "$LINES" "$COLUMNS" "Body Mass Index Computer")
LONGDESC=$(whiptail --inputbox "Manual file Long description: " "$LINES" "$COLUMNS" "A tiny Java application that calculates your body mass index.")

echo ".SH NAME" >> $MANFILE
echo "${upperpackname} - ${SHORTDESC}" >> $MANFILE
echo ".B" >> $MANFILE
echo ".I ${PACKNAME}" >> $MANFILE
echo "[OPTIONS]" >> $MANFILE
echo ".I ${PACKNAME}" >> $MANFILE
echo "${LONGDESC}" >> $MANFILE
echo "\." >> $MANFILE
echo "Help options" >> $MANFILE
echo ".TP" >> $MANFILE
echo "\\\fB\-?\\\fR, \\\fB\-\-help\\\fR" >> $MANFILE
echo "Show help options" >> $MANFILE
echo ".PP" >> $MANFILE
echo "Application options" >> $MANFILE
echo ".TP" >> $MANFILE
echo "\\\fB\--version\\\fR, \\\fB\-\-v\\\fR" >> $MANFILE
echo "Show version info." >> $MANFILE
echo "- ${maintainer} (${memail:1:(( ${#memail} - 2 ))}) - ${homepage}" >> $MANFILE
manv=$(cat $MANFILE | zenity --text-info --title "Edit Manual File" --editable --width=500 --height=500) 
echo -e "$manv" > $MANFILE
eval gzaction

# ----------------- Other DOCS ---------------------------
otherdocs=$(zenity --file-selection --title "Select other files to include - Cancel if none" --multiple)
transodocs=$(echo "$otherdocs" | sed 's#|# #g')
if [ -z "$otherdocs" ]; then echo "No other doc files selected"
else cp -u -v -t $DOCDIR/ $transodocs

# -----------------------CORRECT PERMISSION---------------
sudo chmod 755 -R $ROOTDIR
if [ -f $ROOTDIR/DEBIAN/md5sums ]; then sudo chmod 644 -c $ROOTDIR/DEBIAN/md5sums
else echo "md5sums does not exist."

sudo chmod 644 -v $ROOTDIR/DEBIAN/control
sudo chmod 644 -v $ROOTDIR/usr/share/doc/$PACKNAME/*
sudo chmod 644 -v $ROOTDIR/usr/share/applications/*
sudo chmod 644 -v $ROOTDIR/usr/share/icons/hicolor/48x48/apps/*
sudo chmod 644 -v $ROOTDIR/usr/share/$MAND/man1/*
sudo chmod 644 -v $ROOTDIR/usr/share/$PACKNAME/lib/*;
if [ -f "$JARPATH" ]; then echo "$JARPATH jar is found";
sudo chmod ugo-x -c $ROOTDIR/usr/share/$PACKNAME/$PACKNAME".jar" # remove execution right from executables but add it with postinst
else echo "$JARPATH not found or owner/perm problem"

# ---------- MD5 SUMS FILE for all files in usr folder.----
hasdeep=$(dpkg -s md5deep 2>/dev/null | grep "md5deep" -m 1) # INSTALL md5deep UTILITY - To generate MD5 sums
if [ -z "$hasdeep" ]; then sudo apt-get install -y md5deep
	else echo "md5deep is already installed"
export MATCH=$ROOTDIR"/"
if [ -f "$ROOTDIR/DEBIAN/md5sums" ]; then echo "md5sums exists. removing it"; sudo rm -v $ROOTDIR/DEBIAN/md5sums
	else echo "md5sums file does not exist" 
echo "Creating md5sums file."

md5deep -r $ROOTDIR | sed -e '/DEBIAN/g' -e "s#$MATCH##g" | perl -ne 's/^$//g || print' | tee $ROOTDIR/DEBIAN/md5sums;
LINES=$(ls -R $ROOTDIR | grep ^"$ROOTDIR/usr" | sed -e 's/^[.]//g' -e 's/[:]$//g') # HIDDEN DIRS NOT SUPPORTED by PATTERN
for line in $LINES; do
	if [ -d "$line" ]; then md5sum $line/* | sed -e "s#$MATCH##g" >> $ROOTDIR/DEBIAN/md5sums
	else echo "Directory. Skip."
perl -ne 's/^$//g || print' -i $ROOTDIR/DEBIAN/md5sums # Should be replaced by sed or awk

if [ -f "/usr/bin/md5deep" ]; then eval md5deeper 
else eval md5classic

chmod 644 $ROOTDIR/DEBIAN/md5sums
echo "MD5 Sums written in: " " $ROOTDIR/DEBIAN/md5sums"  

# ------------- DEBIAN PACKAGER---------------
echo "Executing debian builder"
fakeroot dpkg-deb -v --build $ROOTDIR

# ------------- LINTIAN ----------------------  
echo "Executing Lintian & Desktop file validator"
datum=$(eval echo $(date +%Y/%m/%d/:%H:%M:%S))
echo $datum > $LOGFILE
lintian -v -i $ROOTDIR.deb | tee -a $LOGFILE | zenity --progress --text "Validating $PACKNAME..." --percentage 10 --pulsate --auto-close --no-cancel
desktop-file-validate $ROOTDIR/usr/share/applications/$PACKNAME.desktop >> $LOGFILE 
linte=$(cat $LOGFILE | grep "E:")
lintw=$(cat $LOGFILE | grep "W:")
if [ -n "$linte" ]; then lemsg="ERRORS"; export nsicon="error"
elif [ -n "$lintw" ]; then lwmsg="WARNINGS"; export nsicon="error"
else lmsg="no errors, nor warnings."; export nsicon="emblem-default"
FINSTALTEXT="finished Debianization of $PACKNAME at $datum with $lmsg$lemsg / $lwmsg. Check $LOGFILE though for warnings (W:) or errors (E:) and correct them by running JDebianizer again. If not, proceed with the Debian file installation. "
notify-send -u low -a JDebianizer -i $nsicon "JDebianizer" "Finished with $lmsg.\n$lemsg\n$lwmsg" -t 1000
whiptail --textbox $LOGFILE 20 80
whiptail --msgbox "$FINSTALTEXT" 20 80
whiptail --yesno "Install the_produced Debian file? $ROOTDIR.deb" 20 80
if [ "$?" -eq 0 ]; then echo "Trying to install the Debian file.";sudo dpkg -i $ROOTDIR.deb
else whiptail --textbox "Script finished. You can install the produced Debian file manually." 20 80

# ---------RE-EXECUTE THE SCRIPT ------------------
eval restartscript
exit 0;

If you feel like it’s a good idea, don’t hesitate to join the repository channel JDebianizer Github REPO and contribute to it. The script actually works fine for simple Java Swing applications, but needs many enhancements.


For now the script supposes your Java application is already built (E.g: ANT) and that you have in hands a main JAR file (your app) and eventually some libraries it depends on and you want to debianize the whole as one package.

  • Script must not be executed root power (sudo).
  • The Option (Jayatana Install {Ubuntu Global Menu Integration for Java Swing Apps}) requires internet connection.
  • JDebianizer is Console-only, so it must be run from Terminal or any other Shell.
  • JDebianizer is not compliant with ZSH.

For your Packaging culture

Mobile Broadband Modem Huawei e173 / e173s on Ubuntu 12.10 Quantal

Recently, I have been using the mobile broadband modem HUAWEI E173S in order to connect to Internet through 3G Cellular UMTS network.

It worked fine in Ubuntu 12.04 Precise Pangolin, but did not in 12.10 Quantal Quetzal.

I was though able to connect the modem thanks to the 3G utility : SAKIS3G and later through the Gnome Network Manager using a former version of Modem Manager packaged for Ubuntu.

  1. Download sakis3g : http://www.sakis3g.org/
  2. Uncompress the downloaded archive and put sakis3g file in your desktop directory.
  3. copy the sakis3g script to /usr/bin/ in order to execute it from Terminal: sudo cp ~/Desktop/sakis3g /usr/bin/
  4. Give it execution rights : sudo chmod 777 /usr/bin/sakis3g
  5. create a configuration file for your modem: gksudo gedit /etc/sakis3g.conf
  6. Append the following on the following on the newly created file:

    These settings are for the Operator Meditel so you have to modify the custom APN, the username, the password that correspond to your Mobile Operator and eventually the USBMODEN identification depending on whether you own the e173 or e173s model.

    To identify your moden while plugged (Notice that when you plug the modem, you need to wait for several seconds before it gets recognized – probably because modem-manager switches the USB stick key from USB Storage to USB Modem), type in Terminal :


    This will give you something like this :

    Bus 002 Device 008: ID 12d1:1c05 Huawei Technologies Co., Ltd. E173s 3G broadband stick (modem on)

    Copy the vendor ID and Product ID. (E173 & E173s have different product Ids).

  7. save the file and run sakis3g: sudo sakis3g connect
  8. In order to disconnect, run : sudo sakis3g disconnect
  9. If you want to be assisted through an interactive configuration, run: sudo sakis3g --interactive


However, if though you succeed in connecting with sakis3G, Ubuntu Software Center, Empathy IM and Software Updater will not be able to connect to Internet because they get Internet route from Network Manager. In order to loop the route, create a new Wireless Network and connect to it. This wireless network must be AD-HOC and SHARED to OTHER COMPUTERS.


And oh Gosh! In order to activate the Mobile Broadband Internet connection, I must send an SMS to a certain operator number. So how coud I send SMS with the Mobile Broadband Modem?

Hopefully, there is gammu and its graphical interface wammu.

So first thing to do is : sudo apt-get nstall gammu wammu
Then create a configuration file for gammu : gedit .gammurc
and append the following (reference : http://wammu.eu/phones/huawei/4562/):
port = /dev/ttyUSB0
connection = at115200
synchronizetime = yes
logfile = ~/gammu.log
logformat = textalldate
use_locking =
gammuloc =

Info: Make sure that the attached port is correct. You can use the command
dmesg|grep tty

Network Manager must be killed in order to liberate the port ttyUSB0:
sudo stop network-manager
then, start wammu:
gksudo wammu
Then, from the menu: PHONE -> Connect



Info: You can achieve a manual configuration through the Phone Wizard in WAMMU. But be sure before that Network-Manager is killed.


What if you did not like SAKIS3G and want to use the Network Manager.

For now Ubuntu Packaged version of ModemManager is buggy and is responsible for Huawei e173 connection failure.

All you need to do is replace this version by a former one. Get it from LAUNCHPAD, through this link (this amd64 package, if you have a 32bits system, replace amd64 by i368 in the link below):


– Uninstall the current installed version (0.6):

sudo apt-get remove modemmanager

and install the downloaded version (0.5.2) by double cliking on the debian file.
Reboot. Plug your modem, wait for 30 seconds. Connect through the Network Manager applet. You’re done.
You will be later prompted to update modemmanager. Don’t, untill the bug is fixed.
To make sure you installed version 5.2, run this command:
dpkg -s modemmanager

Calculate your Body Mass Index

Bomico is a tiny java application that computes an individual’s body mass index based on some measurements.

The application is free software released under GPL 3.

You can contribute to it if you want to. Checkout the code at https://github.com/hanynowsky/bomico . You must register to GitHub in order to become a contributor (it’s free for open source projects).

If you want just to install it: you can download it here : https://github.com/hanynowsky/bomico/downloads

Note that if you’re running Ubuntu 12.04, Bomico supports Ubuntu Global menu and thus HUD. Be sure before installation, you have a Java JRE installed (Oracle JRE or OpenJDK 6 or 7).

After installation you can check that installation was completed by typing the following command in your Terminal:

bomico --version

If you download and want to run the jar file, (supposing you have set your java home classpath already), copy the jar file (bomico_1.0.2.jar) to your desktop and do as follows, in a terminal:

java -jar ~/Desktop/bomico_1.0.2.jar

bomico-screenshot (Ubuntu 12.04)