Howto pause pm-suspend when program is running

I have a backintime running every hour. Sometimes, it’s running when I suspend/hibernate the machine. The suspend will fail, because backintime refuses to suspend. BIT will fail because network is pulled down. Then we have backintime running forever, and suspend/hibernate failing forever too(until you kill BIT manually).

This script will wait until backintime is done, and then let the computer suspend/hibernate.

/etc/pm/sleep.d/01_backintime:

#!/bin/bash
case "${1}" in
  hibernate|suspend)
    while pgrep -f "/usr/bin/backintime "; do
      sleep 5
    done
  ;;
esac

exit 0

Remember to make the file executable.

disable screen saver when looking at flash videos(youtube, vimeo, etc)

Run this script at startup of Gnome.

#!/bin/bash

# cleanup any bad state we left behind if the user exited while flash was running
gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool true

turn_it_off=0
sleepcomputer0=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_computer_ac`
sleepdisplay0=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_display_ac`

# run loop forever
while true; do
  # interval between checks
  sleep 30
  SS_off=0
  # make id variable of window in focus
  current_window_id=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | cut -d" " -f5`
  # make pid array of every command with libflashplayer in full(-f) command
  for pid in `pgrep -f libflashplayer` ; do
    # check if window in focus is our libflashplayer
    if [ $pid == `xprop -id $current_window_id | grep PID | cut -d" " -f3` ]
      then SS_off=1
    fi
  done

# check to see if xine is being used
#  if pgrep xine > /dev/null; then
#    SS_off=1
#  fi
#
# check to see if current application is fullscreen
#  current_window_id=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | cut -d" " -f5`
#  if xprop -id $current_window_id | grep "_NET_WM_STATE_FULLSCREEN" > /dev/null; then
#    SS_off=1
#  fi

  # read current state of screensaver
  ss_on=`gconftool-2 -g /apps/gnome-screensaver/idle_activation_enabled`

  # change state of screensaver as necessary
  if [ "$SS_off" = "1" ] && [ "$ss_on" = "true" ]; then
    gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool false
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_ac --type int 0
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_display_ac --type int 0
    turn_it_off=1
  elif [ "$SS_off" = "0" ] && [ "$ss_on" = "false" ] && [ "$turn_it_off" = "1" ]; then
    gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool true
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_ac --type int $sleepcomputer0
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_display_ac --type int $sleepdisplay0
    turn_it_off=0
  fi
done

Reference: http://ubuntuforums.org/showthread.php?p=10832670#post10832670

unmount network/encrypted storgage when suspending

Some file systems hangs on resume from suspend/hibernate, especially network file systems and FUSE-filesystems(encfs by example). I’ve created a script to unmount file systems when suspending/hibernating:

sudo touch /etc/pm/sleep.d/20_unmount_storage
sudo chmod +x /etc/pm/sleep.d/20_unmount_storage
sudo nano /etc/pm/sleep.d/20_unmount_storage

/etc/pm/sleep.d/20_unmount_storage:

#!/bin/bash
#
# Script which unmounts network storage before suspend and hibernate.
#
# Arve Seljebu 7. May 2011

PATH=/sbin:/usr/sbin:/bin:/usr/bin

# Which mountpoints we want to umount
MOUNTPOINT[0]=/media/storage/encfs
MOUNTPOINT[1]=/media/storage
#MOUNTPOINT[2]=/media/storage2
# User to run from (user who mounted them)
USER=username

if [ ! -x /bin/mountpoint ]; then
  echo "Did not find executable /bin/mounpoint"
  exit 0
fi

case "${1}" in
  hibernate|suspend)
    for i in "${MOUNTPOINT[@]}"
    do
    # check if the mountpoint is mounted
    echo "Checking if mountpoint $i is mounted..."
    sudo -u $USER mountpoint $i > /dev/null
    if [ "$?" == "0" ]; then
      # try to umount with fusermount, if not succsessful, try with umount
      echo "Mountpoint $i mounted, umounting..."
      fusermount -u $i
      if [ "$?" != "0" ];
      then umount $i
      fi
    fi
  done
  echo "Done..."
  exit 0
  ;;
  resume|thaw)
  # nothing
  ;;
esac

Remove title from Firefox when maximized(Chrome style)

Add this to CompizConfig under “Window Decorations” in the field “Decoration windows”:

(any)&!(class=Firefox&state=maxvert&role=browser)

Toggle maximize with Alt-F10. If you hide the “Menu Bar”, you can show it with Alt Gr-F10. This allows for semi-full-screen-mode.

This was tested with Firefox 4 on Linux Mint 10. Install with:

sudo add-apt-repository ppa:mozillateam/firefox-stable
sudo apt-get update
sudo apt-get install firefox ubufox

References:
http://www.webupd8.org/2011/03/firefox-4-get-tabs-in-title-bar-like.html
http://community.linuxmint.com/tutorial/view/337

Roundcube and automatic addressbook

With automatic addressbook plugin on roundcube, I could not create the MYSQL table. I’m running Ubuntu 10.04 LTS, with mysql-server 5.1.41. Got error message:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '--!40008
   --ON DELETE CASCADE
   --ON UPDATE CASCADE
)' at line 15

Found this solution at roundcubeforum.net.

Use this command to create table:

CREATE TABLE `collected_contacts` (
  `contact_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `changed` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
  `del` tinyint(1) NOT NULL DEFAULT '0',
  `name` varchar(128) NOT NULL,
  `email` varchar(128) NOT NULL,
  `firstname` varchar(128) NOT NULL,
  `surname` varchar(128) NOT NULL,
  `vcard` text,
  `user_id` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`contact_id`),
  KEY `user_collected_contacts_index` (`user_id`,`email`),
  CONSTRAINT `collected_contacts_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

encfs over sshfs on Linux Mint 10

With standard config you get:
fusermount: bad mount point /folder/name: Permission denied

Uncomment user_allow_other from /etc/fuse.conf, and add user to fuse(get read access to /etc/fuse.conf):

sudo nano /etc/fuse.conf
sudo adduser your_username fuse

Log out, and log back in. Check that you’ve got added to fuse:

id | grep fuse

Mount:

sshfs -oallow_other host:/folder/to/mount /mountpoint
encfs /folder/to/encrypted /mountpoint/decrypted