Hardcore Linux

Anything about Ubuntu, Centos, openSuSe and Fedora

Show Hidden Icons from the Ubuntu’s Unity System Tray

Initially, since Ubuntu 11.04, I tried Unity several time and force myself to like it, but I can’t. Done several tweak to make it useful then, but when 12.04 came out, Unity if getting more usable and faster.

And another thing about Unity, is that I hides several icons from the default system tray, most of them place under the messaging menu icon ( the one that looks like a mail envelope), which includes pidgin, a multi-platform instant messaging client. I’ve tried several howtos to show it back to the system tray, but still I failed. Then read this acticle from ask ubuntu (here), and it works!.

Here’s how:

1. Via the console/terminal while under your login account, invoke:

$> gsettings set com.canonical.Unity.Panel systray-whitelist "['all']"

2. You can also use dconf-editor, which is included in the dconf-tool package, install it using either the “Ubuntu Software Center” or via console with the command:

$> sudo apt-get install dconf-tools

3. On dconf-editor, go to Desktop -> Unity -> Panel, and replace the value of systray-whitelist to “['all']“.

4. Done.

Folder Monitoring Script using Inotifywait

Though it is not failsafe nor flawless, but currently it is working great for me. Here’s a script that enables to monitor the events from a specified folder/directory.

First install the inotify-tools:

apt-get install inotify-tools

Here’s my current code, feel free to enhance.


#!/bin/bash
# monitor file changes in a target directory

if [ "$*" = "" ]; then
 echo "File Monitoring"
 echo "USAGE: $0 <target directory>" | sed "s/.\///g"
 echo ""
 exit 0
fi

LOGDIR="$HOME/.log"

if [ ! -d $LOGDIR ]; then
 mkdir -p $LOGDIR
fi

TARGET_DIR="$*"
LOGNAME="$LOGDIR/`date -I`.log"

inotifywait -m -r --format '%T %e %w%f' --timefmt '%F %T' -e modify -e move -e create -e delete $TARGET_DIR | while read line
do
echo "$line" >> $LOGNAME
done

exit 0

Converting Multiple Images via BASH Script

Previously, I posted a flawed script that be able to convert images and lower their resolution as well, though it works for me, but found it very problematic sometimes. Here’s another script I made to perform same purpose: Convert the image to either jpg|png|pdf|tif and has an option to modify the quality [1% to 100%].

example:

converting all images in /home/user/Desktop/rawimg to PDF with 50% quality

$> convert2.sh /home/user/Desktop/rawimg pdf 50

Here’s my script:

 

#!/bin/bash
TARGET_LOCATION="$1"
TARGET_TYPE="$2"
QUALITY="$3"
if [ "$1" = "" ] ; then
 echo "$0 <image location> <image type> [quality] "
 echo "convert a specific folder that contains images to different format and quality"
 echo "[imagetype] - can be either pdf jpg png tif"
 echo "[quality] - from 1 to 100%, default is 100%"
 exit
fi
if [[ $2 =~ jpg|png|pdf|tif ]] ; then
 MODE=1
else
 echo "please select image type from jpg,png,pdf or tif"
 exit
fi
if [ "$3" = "" ]; then
 QUALITY="100"
fi
find $TARGET_LOCATION -maxdepth 1 -type f > /tmp/tmpfile
cat /tmp/tmpfile | \
while read FILENAME; do
# echo "convert '$FILENAME' -quality $QUALITY '$FILENAME.$TARGET_TYPE'"
 BARENAME=$(echo "$FILENAME" | cut -d'.' -f1)
 EXTENSIONNAME=$(echo ${FILENAME: -4} | tr '[A-Z]' '[a-z]')
 if [[ $EXTENSIONNAME =~ jpg|png|pdf|tif ]]; then
 convert "$FILENAME" -quality $QUALITY "$BARENAME.$TARGET_TYPE"
 fi
done
rm -f /tmp/tmpfile
exit 0

 

  

keyboard: can’t emulate rawmode for keycode 240

Installing fresh Ubuntu 11.10 and check out what Unity and Gnome-shell has to offer, everything works great until I found something..syslog error message appears very frequent: “keyboard: can’t emulate rawmode for keycode 240“.  I remember having this problem in my previous Ubuntu 11.04 installation on my Lenovo z370 laptop, thought it’s gone back then..but to the point on installing newer kernel which is Linux kernel 3.1.

As I’m going to compile Linux kernel again to make everything work. I found a much simplier solution. Here’s how:

1. Install dkms (Dynamic Kernel Module Support Framework)

$> sudo apt-get install dkms 

2. Download the ideapad-laptop package which supposed to be fore natty narwhal but still working greate on oneiric.

$> cd ~/Downloads

$> wget https://launchpad.net/~lexical/+archive/ideapad/+build/2529783/+files/ideapad-laptop-dkms_0.1-1ubuntu1~foshan2_all.deb

$> sudo dpkg -i  ideapad-laptop-dkms_0.1-1ubuntu1~foshan2_all.deb

3. Reboot for everything to work in effect.

4. Done.

 

Change Gnome3 Background via script.

Previously using gconftool-2 to replace the current desktop wallpaper via a script (normally a starting bash script). But with Gnome3 its not working anymore. As an alternative or should I say the proper way to do it in Gnome3 is via dconf-tools. Here’s the sample command via console:

$> gsettings list-recursively

will list all known schema and keys

$> gsettings list-keys org.gnome.desktop.background

will list all keys under the defined schema.

$> gsettings get org.gnome.desktop.background picture-uri

to change the value, enter this command:

$> gsettings set org.gnome.desktop.background picture-uri "file:///path/filename"

Done.

Lxpanel freeze after closing LibreOffice document.

As of Ubuntu 11.04, the package lxpanel 0.5.6 and Libreoffice 3.3.x, the bug still exist, freezing lxpanel after saving and closing current  ODF files. I suspected lxpanel bug, looking it over the Internet and haven’t found any confirmation that it actually does the freezing. While seeking answers over the Internet I’ve found this bug thread: (click here), which fixes my problem, I’m not 100% sure it will work on all cases though, but good enough to give it a try.

1. Install the necessary libraries and tools to compile the lxpanel 0.5.8 from  source.

sudo apt-get install libgtk2.0-dev libmenu-cache1-dev intltool

2.  Download the lxpanel 0.5.8 source from here, of check the newest version here.

3. Compile the source code. Go to the folder of lxpanel source and perform the following command:

./configure --prefix=/usr
make
sudo make install

4. Logout the current session or reboot your machine to confirm.

5. Done.

 

Mount All Available CIFS Shares using GVFS

Here’s a bash script that will automatically mount all available SAMBA shares that has access permission for the current user.   The script composes of two part: (1) The script itself and (2) the user’s credentials.

But current problem is that the user must store the password to access the SAMBA shares in the keyring before the script runs smoothly. It requires the user to access the any of the permitted shares and store the password permanently to the keyring, then add the script to the Startup Applications(System Settings -> Startup Applications)

Autfile is a simple text file contain the following:

username = myuser
password = mypass
domain = localdomain
servername = localserver

Here’s the code:

#!/bin/bash
ARGS="$*"

BASEDIR="/home/rnartos/.scripts/uicsmb"
OPTYPE=""
CMDTYPE=""
FILTERARGS=`echo "$ARGS" | sed 's/ /#/g' | sed 's/-/ -/g'`
AUTHFILE="$BASEDIR/authfile"
NETBASENAME="WinShares"



if [ ! -f $AUTHFILE ]; then
   echo "ERROR: neither default or user-defined authfile not exist."
   exit 0
fi

for CMD in $FILTERARGS; do
   MCMD=`echo $CMD | sed 's/#/ /g'| awk '{print $1}' `

   #umount
   if [ "$MCMD" = "-u" ]; then
      OPTYPE=" -u "
   fi

   #help
   if [ "$CMD" = "-h"  ]; then
     echo "GFVS WinShares - rnartos"
     echo "$0 -u -a <authfile> -h"
     echo "-u umount current shares"
     echo "-a process authentication file"
     echo "-h this help message."
     exit 0
   fi

   #authfile
   if [ "$MCMD" = "-a"  ]; then
     PCMD=`echo $CMD | sed 's/#/ /g'| awk '{print $2}' `
     if [ "$PCMD" = ""  ]; then
        echo "ERROR:  parameters for -a <authfile>"
     else
         if [ -f $PCMD ]; then
             AUTHFILE="$PCMD"
         else
           echo "$PCMD authfile not exist."
           exit 0
         fi
     fi
   fi
done


SERVERNAME=`cat $AUTHFILE | grep servername | sed 's/=//g' | awk '{print $2}'`
DOMAINNAME=`cat $AUTHFILE | grep domain | sed 's/=//g' | awk '{print $2}'`
USERNAME=`cat $AUTHFILE | grep username | sed 's/=//g' | awk '{print $2}'`
PASSWORD=`cat $AUTHFILE | grep password | sed 's/=//g' | awk '{print $2}'`
CHECKMOUNT=`gvfs-mount -l | grep "smb:"`
GETIP=`nmblookup $SERVERNAME | grep -v "query" | awk '{print $1}'`
GETSHARES=`smbclient --debuglevel=0 -A $AUTHFILE -L $SERVERNAME -I $GETIP -g  2>/dev/null | grep "Disk" | sed 's/|/ /g' | awk '{print $2}'`
WINSHARENAME="$HOME/$NETBASENAME/$DOMAINNAME/$SERVERNAME"

if [ ! -d $WINSHARENAME ];  then
   mkdir -p $WINSHARENAME
fi


for NAMES in $GETSHARES; do

   CHECKSHARE=`smbclient //$SERVERNAME/$NAMES -A $AUTHFILE -c '' 2> /dev/null | grep 'DENIED'`

   if [ "x$CHECKSHARE" = "x" ]; then
     if [ "$OPTYPE" = "" ]; then
         if [ "$CHECKMOUNT" = ""  ]; then
           CMDTYPE="mounting"
         fi
     else
        CMDTYPE="umounting"
     fi
     if [ "$CMDTYPE" = "" ]; then
        echo "Shares Already mounted."
        exit 0
     else
        echo "$CMDTYPE $NAMES"
	if [ "$OPTYPE" = "" ]; then
           gvfs-mount $OPTYPE smb://$SERVERNAME/$NAMES 2> /dev/null
           GVFSNAME=`echo $NAMES | tr '[:upper:]' '[:lower:]'`
           ln -sf "$HOME/.gvfs/$GVFSNAME on $SERVERNAME" $WINSHARENAME/$NAMES
        else
           gvfs-mount $OPTYPE smb://$SERVERNAME/$NAMES 2> /dev/null
        fi
     fi
   fi
done

exit 0 

Novell iManager workstation on Ubuntu 11.04

Currently unning a Novell eDirectory  LDAP service and wonder how to use iManager on your Ubuntu workstation.

Here’s how:

1. Download the latest iManager Workstation for Linux in Novell Download Center

2. Extract the package (for me usually in $HOME/Desktop)

3. Install the necessary packages and libraries for alien (alien, libstdc++5, gcc), installing alien package also includes rpm in the requirements.

4.  Prepare NICI for installation.

$> cd  $HOME/Desktop/imanager
$> cd  NICI/linux
$> sudo alien -d --scripts nici.i386.rpm
$> sudo dpkg -i nici_2.7.3-1.01_i386.deb

5. Modify the current  iManager.sh in the bin folder ($HOME/Desktop/imanager/bin) and remove the word  “function” in every functions of the script.

example:

function CHECK_PERMISSIONS()
{
 echo "Test permissions" > $IMANAGER_BIN_NATIVE_DIR/perm.txt
 ....
}

should be

CHECK_PERMISSIONS() 
{ 
echo "Test permissions" > $IMANAGER_BIN_NATIVE_DIR/perm.txt 
.... 
}

5.  In the STARTMANAGER() function, remove the CHECK_NICI;

6.  Save the script and do  some test run.

$> cd $HOME/Desktop/imanager/bin
$> ./iManager.sh

7. Done.

Ubuntu 11.04 Shutdown and Restart Problem with CIFS

UPDATE(07/29/2011): The GRUB thing didn’t work at all, back to basic trapping signal via upstart scripts in /etc/init/dbus.conf.  I tried it before using /etc/init/network-manager.conf but on Ubuntu 10.10, it’s not working anymore. Here’s another test and works for me.

1. Modify the current /etc/init/dbus.conf.

$> sudo vi /etc/init/dbus.conf

2. Add a pre-stop script, which looks like this:

pre-stop script
       trap "TERM signal" TERM
      /bin/umount -a -t cifs -l -f
      trap - TERM
end script 

3. Save the script and have a test.

4. Done.

UPDATE(07/28/2011): Found a better alternative via GRUB, link here. Mainly you just need to modify the  /etc/default/grub. Here’s the details:

1. Edit the /etc/default/grub

$> sudo vi /etc/default/grub

2. Add “reboot=pci” on the GRUB_CMDLINE_LINUX line, it should look something like this:

... GRUB_CMDLINE_LINUX="reboot=pci" ...

3. Update the grub

$> sudo update-grub

 

4. Done

—————

It’s an ancient bug (here), which still exist in Ubuntu 11.04, or even in other distros. When you got a mounted samba shares before the shutdown or restart process, the machine waits for around 10 minutes before it complete the operation. Very troublesome that’s why I tried various workaround but none of them  works with Ubuntu 11.04. Not even the /etc/rc6.d/K*  or the upstart /etc/init configurations, nor the old python script I posted before (here’s the link).

After few considerations, I made a desperate workaround, creating a script that triggers before the /sbin/shutdown, /sbin/reboot and /sbin/restart commands.

1. Rename the current shutdown, reboot and restart commands in /sbin.

#> mv /sbin/shutdown /sbin/shutdown2
#> mv /sbin/reboot /sbin/reboot2
#> mv /sbin/restart /sbin/restart2 

2. Then create scripts with names of the previous commands in /sbin, which contains the following:

#!/bin/sh
umount -t cifs -a -f -l
/sbin/shutdown2 $@
exit 0 

3. Make similar script for reboot and restart command which also points to /sbin/reboot2 and /sbin/restart2.

4.  Until the dbus implementation of stop on deconfiguring-networking comes to Ubuntu 11.04, which I think working with
Ubuntu 11.10 oneiric. I think this is the least workaround that works for me.

5. Done

Ubuntu 11.04 Missing Indicators or System Tray Items

GMail Notifier and Vuze are some of my mostly used application, and when I upgraded my previously 10.04 to 11.04 system (Ubuntu), I noticed that some of my currently running application that has system tray icon or indicator gone in the Unity side panel and in the system tray area. Googled it and found this link: Ubuntu 11.04 Fix:  Show All Icons/Indicators Notification Area.

The quickest way to deal with it is the following:

1.  From console:

$> gsettings set com.canonical.Unity.Panel systray-whitelist "['all']"

2. Then refresh the Unity. Press Alt-F2 and type:

 unity --replace

3. Done.

Follow

Get every new post delivered to your Inbox.

Join 341 other followers

%d bloggers like this: