Enable java6 for chrome in osx

Upgrading to 10.8.2 will install java7 and disable java6. Java7 is only 64 bit, chrome is 32 bit.

Fix:

sudo mkdir -p /Library/Internet Plug-Ins/disabled
sudo mv /Library/Internet Plug-Ins/JavaAppletPlugin.plugin /Library/Internet Plug-Ins/disabled
sudo ln -sf /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin /Library/Internet Plug-Ins/JavaAppletPlugin.plugin
sudo ln -sf /System/Library/Frameworks/JavaVM.framework/Commands/javaws /usr/bin/javaws

NOTE: Enabling java6 might introduce security holes.
Reference: http://support.apple.com/kb/HT5559

Remove annoying update pop-ups from Ubuntu Oneiric(12.04)

Open /etc/xdg/autostart/update-notifier.desktop, find NoDisplay and edit it to false.

...
Icon=update-notifier
Exec=update-notifier
Terminal=false
Type=Application
Categories=
NotShowIn=KDE;
NoDisplay=false
X-GNOME-Autostart-Delay=60
X-Ubuntu-Gettext-Domain=update-notifier

Update-notifier will then show up in the application gnome-session-properties, where it can be disabled. When disabled, a modified version of update-notifier.desktop is written to ~/.config/autostart/.

Manual recovery from Windows 7 System Image Backup(VHD) using Ubuntu/Linux

Windows 7 system image backup saves the whole windows partition in raw format inside a VHD-file(Virtual Hard Disk). The VHD format is also used in virtual environments, as Hyper-V and Virtualbox. Unfortunately Windows system restore is limited in the capability to restore to another disk layout. But with the use of vdfuse in virtualbox-fuse(universe) it’s possible to restore the partitions manually with a Ubuntu Live system. Then you are in complete control yourself, disk layout etc.

This was done to restore a system disk(crashed SSD) to a regular hard drive which was already in use (contained the backups). The partition on the regular hard drive was moved to make room for the system partitions in the beginning, and the backup was mounted through vdfuse and restored with dd.

Walk through
Prepare a Ubuntu Live system(USB, cdrom, etc) and boot it. Partition the new disk with GParted. In my special case, I moved my existing partition to the right/end of disk. Then I noted the new placement:

sudo fdisk -l /dev/sdb

I’m not sure where Windows system image stores (if it does) the MBR, but you could search through the WindowsImageBackup folder for a file of 512 bytes. Most likely, it manually creates the partitions and writes a fresh boot sector. This can also be done by creating the partitions and using a Windows install disc/USB to repair the startup. There should be a 100MB “System reserved” primary partition with bootflag enabled, and the Windows partition itself. Here I just copy the working MBR from the crashed disk:

MAKE SURE YOU KNOW WHICH HARD DRIVE IS WHICH BEFORE USING DD
sudo dd if=/dev/sda of=/dev/sdb bs=512 count=1

Then I added the already moved partition (the data is still there, we just lost the reference to the partition when moving MBR from sda to sdb).

sudo fdisk /dev/sdb

If you haven’t a moved a partition, skip this step: Reboot computer, use an Windows install disk to check the integrity of the moved partition (chkdsk), when done boot Ubuntu again.

Add universe to apt sources(/etc/apt/sources.list):

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ precise universe

archive.ubuntu.com can be replaced with your local mirror. Usually the local mirror is named XX.archive.ubuntu.com, where XX is your country code (no for Norwegian -> no.archive.ubuntu.com).
Update apt and install virtualbox-fuse:

sudo apt-get update
sudo apt-get install virtualbox-fuse

Mount the partition which contains the backup (WindowsImageBackup directory). Find the VHD-files. Create two empty directories and mount the VHD-files(read only):

sudo mkdir /media/f1
sudo mkdir /media/f2
vdfuse -r image-file1.vhd /media/f1
vdfuse -r image-file2.vhd /media/f2

Inside the VHD-files, there is a Partition1 file. This is the raw image of the partition backed up. In f1/f2 you should find one Partition1 file which is 100MB, and another which is the same size as your Windows partition. You could mount these files to look at the backup:

sudo mkdir /media/temp
sudo mount -o loop,ro /media/f1/Partition1 /media/temp
ls /media/temp
sudo umount /media/temp

When ready, use dd to copy its contents to you new partition:

MAKE SURE YOU KNOW WHAT YOU ARE DOING, 
DD DOES NOT CARE ABOUT YOUR IGNORANCE!!
sudo dd if=/media/f1/Partition1 of=/dev/sdXX bs=64M

if is the input file, of is the output file. XX is the partition, one character and one number. sda1 is sda’s first partition, sdc3 is sdc’s third partition.

Umount the partition with the backups, reboot and cross your fingers.

Share wired internet connection wireless

This was done with Atheros AR5001 (ath5k, Linux Mint 10, 2.6.35).

Install hostapd and DHCP-server.

apt-get install hostapd dhcp3-server

/etc/hostapd/hostapd.conf:

interface=wlan0
driver=nl80211
ssid=SSID
hw_mode=g
channel=7
wpa=2
wpa_passphrase=password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
wpa_ptk_rekey=600

/etc/dhcp3/dhcpd.conf:

subnet 10.10.0.0 netmask 255.255.255.0 {
        range 10.10.0.25 10.10.0.100;
        option domain-name-servers 193.213.112.4, 130.67.15.198;
        option routers 10.10.0.1;
}

Add to /etc/default/hostapd:

RUN_DAEMON="yes"
DAEMON_CONF="/etc/hostapd/hostapd.conf"

/etc/default/dhcp3-server:

INTERFACES="wlan0"

/usr/local/bin/ics:

#!/bin/bash

case "${1}" in
  start)
	# stop gnome network manager
	service network-manager stop
	# configure wireless IP
	ifconfig wlan0 10.10.0.1 netmask 255.255.255.0 up
	# start AP and DHCP-server
	service hostapd start
	service dhcp3-server start
	# enable NAT
	echo "1" > /proc/sys/net/ipv4/ip_forward
	iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  ;;
  stop)
	# disable NAT
	echo "0" > /proc/sys/net/ipv4/ip_forward
	iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
	# stop DHCP-server and AP
	service dhcp3-server stop
	service hostapd stop
	# start gnome network manager
	service network-manager start
	# wait 1 second and enable scanning on wireless
	sleep 1
	ifconfig wlan0 up
  ;;
esac

exit 0

Add with to sudoers(with visudo):

# Allow admin users to share internet connection
%admin ALL=NOPASSWD:/usr/local/bin/ics

Add shortcut to desktop with command “sudo /usr/local/bin/ics start” and “sudo /usr/local/bin/ics stop”.

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