Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Thursday, May 23, 2013

Move the window controls to the left in Chrome on Ubuntu

I regularly switch between using Mac's and Linux machines at home and at work and as such I like to keep my window controls consistent across machines.

My home machine is a Mac running OSX 10.08 and my work Laptop runs Ubuntu Linux 13.04 with Gnome Shell. Both of these desktops have their window controls on the left in the same order:

OSX 10.8

Ubuntu 13.04 + Gnome Shell

This is all nice and harmonious until I install my preferred browser, Google Chrome, on Ubuntu. Chrome places its window controls on the right as per the MS Windows layout. 

Google Chrome + Ubuntu 13.04 + Gnome Shell (Default)

To resolve this you can change the default configuration exposed by Chrome by entering the following command at the terminal:

$ gconftool-2 --set /apps/metacity/general/button_layout --type string "close,minimize,maximize:"

To re-load the configuration you'll need to start a new desktop session (log out or restart). Once this is done your chrome window controls will fit in with the rest of your system.

Google Chrome + Ubuntu 13.04 + Gnome Shell (Modified)

I know I'll want to do this again some time and am writing this here for my own reference, hopefully someone else finds it useful also.

Monday, November 21, 2011

Fixing unmappable character during Java compilation on Ubuntu

In the lab we have a standard header at the top of our source files, a copyright statement and licence. This header contains an ISO 8859-1 encoded copyright character (©).

Normally the header blurs into the background, the exception to this rule is the first time a do a build on a new Ubuntu system and I see the following error:

[javac] /src/com/yourcorp/HelloWorld.java:8: unmappable character for encoding ASCII
[jacac] /* ?? Copyright Yourcorp 2011

The Java compiler is expecting ASCII characters rather than ISO 8859-1. To resolve this error I do the following:
  1. Edit /var/lib/locales/supported.d/local and add:
    en_AU ISO-8859-1
    en_US ISO-8859-1
    
    
  2. Open a terminal and run:
    $ sudo dpkg-reconfigure locales
    
    
  3. Edit /etc/environment and add:
    LANG="EN_US"
    
    
  4. Reboot.
With Ubuntu being so stable these days it's a long time between re-installs so I have posted this here for next time when I forget.

Sunday, June 26, 2011

Run scripts when gnome-screensaver starts or stops in Ubuntu

For a project I have been playing with I need to be able to run a script when gnome-screensaver starts or stops on Ubuntu (10.04).

The gnome-screensaver FAQ provides detail on the dbus signal fired when gnome-screensaver activates and deactivates. The FAQ even has sample perl code to respond to the signal. Unfortunately the sample code polls dbus-monitor which is too inefficient for script I plan to run in the background on my laptop.

Python offers a great dbus library which allows signal receivers to be registered with dbus resulting in an efficient event listener.

On to the script.

Step 1: Setup the required files and directories
  1. Make a directory for your work:
    sudo mkdir -p /opt/ssTrigger
  2. Change yourself the owner of the new directory:
    sudo chown `whoami`:`whoami` /opt/ssTrigger
  3. Create stubs for the scripts to be used
    touch /opt/ssTrigger/ssTrigger /opt/ssTrigger/ssStart /opt/ssTrigger/ssStop
  4. Make the stub scripts executable:
    chmod 755 /opt/ssTrigger/*

Step 2: Edit the ssTrigger script
  1. Open the ssTriger file created earlier:
    gedit /opt/ssTrigger/ssTrigger
  2. Add the following to ssTrigger:
    #!/usr/bin/env python
    from gobject import MainLoop
    from dbus import SessionBus
    from dbus.mainloop.glib import DBusGMainLoop
    from subprocess import Popen
    
    class SSTrigger:
        def __init__(self):
            DBusGMainLoop(set_as_default=True)
            self.mem='ActiveChanged'
            self.dest='org.gnome.ScreenSaver'
            self.bus=SessionBus()
            self.loop=MainLoop()
            self.bus.add_signal_receiver(self.catch,self.mem,self.dest)
        def catch(self,ssOn):
            if ssOn == 1: #Screensaver turned on
                Popen(["/opt/ssTrigger/ssStart"])
            else: #Screensaver turned off
                Popen(["/opt/ssTrigger/ssStop"])
    
    SSTrigger().loop.run()
    
  3. Save and close the file.

Step 3: Set ssTrigger to start when you login:
  1. Open the Startup Applications menu:
    System -> Preferences -> Startup Applications

  2. Click "Add" to create a new startup application.

  3. Enter the following details:
    Name: Screensaver Trigger Script
    Command: /opt/ssTrigger/ssTrigger

  4. Click "Add" to save your new application.

  5. Restart your computer.

Finishing up:
Once you have restarted you can run:
ps aux | grep ssTrigger
Check the output to make sure the ssTrigger script has started at login.

Edit the ssStart and ssStop scripts to run commands as gnome-screensaver starts and stops respectively.

Friday, June 24, 2011

Downgrade to Firefox 3.6 on Ubuntu 11.04 Natty

We have a requirement in the office to downgrade to Firefox 3.6 on some test machines running Ubuntu Natty (11.04). To do this you can pin the firefox and firefox-branding packages to older packages from the Ubuntu Maverick (10.10) release.

Step 1: Edit your software sources to add Maverick
  1. Open your sources.list file:
    sudo gedit /etc/apt/sources.list

  2. Add the folowing three lines:
    # Maverick, used for firefox and firefox-branding 
    deb http://ftp.iinet.net.au/pub/ubuntu/ maverick main 
    deb http://ftp.iinet.net.au/pub/ubuntu/ maverick-updates main

  3. Save and close the file

Step 2: Pin the packages firefox and firefox-branding
  1. Create the pin file for firefox:
    sudo gedit /etc/apt/preferences.d/firefox

  2. Add the following:
    Package: firefox
    Pin: release n=natty
    Pin-Priority: -10
    
    Package: firefox
    Pin: release n=maverick
    Pin-Priority: 900

  3. Save and close the file.

  4. Create the pin file for firefox-branding:
    sudo gedit /etc/apt/preferences.d/firefox-branding

  5. Add the following:
    Package: firefox-branding
    Pin: release n=natty
    Pin-Priority: -10
    
    Package: firefox-branding
    Pin: release n=maverick
    Pin-Priority: 900

  6. Save and close the file.

Step 3: Check your apt policy to make sure it worked
  1. Update your apt cache:
    sudo apt-get update

  2. Show the apt policy for firefox:
    sudo apt-cache policy firefox

    Sample output:
    sudo apt-cache policy firefox
    firefox:
      Installed: 5.0+build1+nobinonly-0ubuntu0.11.04.2
      Candidate: 3.6.18+build2+nobinonly-0ubuntu0.10.10.1
      Package pin: 3.6.18+build2+nobinonly-0ubuntu0.10.10.1
      Version table:
     *** 5.0+build1+nobinonly-0ubuntu0.11.04.2 900
            500 http://ftp.iinet.net.au/pub/ubuntu/ natty-updates/main i386 Packages
            500 http://ftp.iinet.net.au/pub/ubuntu/ natty-security/main i386 Packages
            100 /var/lib/dpkg/status
         4.0+nobinonly-0ubuntu3 900
            500 http://ftp.iinet.net.au/pub/ubuntu/ natty/main i386 Packages
         3.6.18+build2+nobinonly-0ubuntu0.10.10.1 900
            500 http://ftp.iinet.net.au/pub/ubuntu/ maverick-updates/main i386 Packages
         3.6.10+build1+nobinonly-0ubuntu3 900
            500 http://ftp.iinet.net.au/pub/ubuntu/ maverick/main i386 Packages

    The line you are most interested in is "Candidate".
    This indicates the package that apt ranks as the installation candidate.

  3. Repeat this check for firefox-branding
    sudo apt-cache policy firefox-branding

Step 4: Install firefox 3.6
  1. Remove firefox 5.x:
    sudo apt-get remove firefox

  2. Install firefox 3.6:
    sudo apt-get install firefox

And you're done. Enjoy your outdated version of Firefox!


Update - July 24th 2011:

How to reverse the process:
  1. Remove these three (3) lines you added to /etc/apt/sources.list
    # Maverick, used for firefox and firefox-branding 
    deb http://ftp.iinet.net.au/pub/ubuntu/ maverick main 
    deb http://ftp.iinet.net.au/pub/ubuntu/ maverick-updates main
    
  2. Unpin the firefox and firefox-branding packages:
    sudo rm /etc/apt/preferences.d/firefox
    sudo rm /etc/apt/preferences.d/firefox-branding
    
  3. Update your apt cache
    sudo apt-get update
    
  4. Install the latest Firefox:
    sudo apt-get upgrade
    
  5. Close ALL your Firefox windows and re-open Firefox.

Update - December 6th 2011:

From the comments people have posted below I can see that this process works to downgrade Firefox on Ubuntu 11.10 as well as Ubuntu 10.04.

Downgrading packages to the Ubuntu 10.10 release will only work on Ubuntu 11.04 or better. Do not use this procedure on Ubuntu releases older than 11.04. If you try to do this you will be upgrading packages not downgrading.

Friday, April 29, 2011

Lock input without a screen saver in Linux

We came across this problem in the office today. How do we lock the input devices on a Linux machine (we were using Ubuntu 11.04) and keep a the current applications showing and updating? The solution we ended up with was to use xlock.

First you'll need to install xlock:
sudo apt-get install xlockmore
Then run xlock from a terminal with the following options:
xlock -mode blank -geometry 0x0 -timeout 2

The xlock command locks keyboard and mouse input, the flags do the following:
-mode blank displays a blank box in the top left corner of your monitor.
-geometry 0x0 makes the size of the blank box 0x0 pixels.
-timeout 2 sets the timeout (in seconds) for the password prompt if anyone hits a key.

Update 2011-05-02: A second (better) solution

First you'll need to install xtrlock:
sudo apt-get install xtrlock
Then run xtrlock from a terminal:
xtrlock

This will start xtrlock and lock the screen. To unlock the screen type your password and hit enter.

Friday, October 15, 2010

Upgrading from Lucid to Maverick using a local mirror

I maintain a local Ubuntu mirror in our Lab at work. This morning the first user tried to update from Lucid to Maverick. There was a couple of teething issues but with a couple of changes it went off without a hitch.

Step 1: Correctly specify your mirror to the Software Sources dialog:
  1. Open a terminal

    (Applications -> Accessories -> Terminal)
  2. Open your list of mirrors:
    trastle$ sudo gedit /usr/share/python-apt/templates/Ubuntu.mirrors
  3. Add a location for your local mirror. Mine looks like this:
    ...
    #LOC:ADL
    http://adl-mirror/ubuntu-repo/ubuntu/
    ...
  4. Save and close the file.
  5. Close the terminal.

Step 2: Select your mirror in the software sources dialog
  1. Open the software sources dialog
    (System -> Administration -> Software Sources)
  2. Open the "Ubuntu Software" tab
  3. Click the "Download From:" combo box.
  4. Select "Other..."
  5. Select the mirror you just added from the list
  6. Click "Choose Server" at the bottom right.
  7. Click "Close" at the bottom right.
  8. Click "Close" in the information out of date dialog that pops up.

Step 3: Disable all third party sources
  1. Open the software sources dialog
    (System -> Administration -> Software Sources)
  2. Open the "Other Software" tab
  3. Untick every source in the list.
  4. Click "Close" at the bottom right.
  5. Click "Close" in the information out of date dialog that pops up.

Step 4: Do the Upgrade
  1. Ensure your on a network with Internet access as well as access to your mirror.
  2. Open a terminal
    (Applications -> Accessories -> Terminal)
  3. Change to the root user:
    trastle$ sudo -i
  4. Update your available software:
    root# apt-get update 
  5. Do the upgrade
    root# do-release-upgrade 
  6. The following message will appear shortly after starting the upgrade:
    Updating repository information
    WARNING: Failed to read mirror file
    
    No valid mirror found 
    
    While scanning your repository information no mirror entry for the 
    upgrade was found. This can happen if you run a internal mirror or if 
    the mirror information is out of date. 
    
    Do you want to rewrite your 'sources.list' file anyway? If you choose 
    'Yes' here it will update all 'lucid' to 'maverick' entries. 
    If you select 'No' the upgrade will cancel.
    Your using a local mirror so choose Yes
  7. The release upgrade will take some time to complete.

Step 5: Re-enable third party sources
  1. Open the software sources dialog
    (System -> Administration -> Software Sources)
  2. Open the "Other Software" tab
  3. Tick the sources you want to use.
  4. Click "Close" at the bottom right.
  5. Click "Reload" in the information out of date dialog that pops up.
Enjoy your upgraded system.
I hope someone finds this helpful.

Sunday, May 9, 2010

Atheros AR5212 in Ubuntu 10.04 Lucid Lynx

I've just finished a fresh install of Ubuntu Lucid Lynx 10.04 on my crusty old Thinkpad T60. Everything is working great with the exception of my Atheros AR5212 wireless card.

Clicking the network manager applet in the panel I see the wireless listed as "Device not ready". This is tedious.

The solution to this issue is to remove the mainline ATK5K wireless driver from your Kernel and replace it with non-mainline MadWifi driver (source). MadWifi has superior support for the AR5212 card. This shouldn't take you more than about 20 minutes to sort out.
  1. Open a terminal: Aplications -> Accessories -> Terminal
  2. To check on your wireless card and make sure you have the AR5212:
    trastle$ sudo lshw -c network
    The result will look similar to this:
    *-network
        description: Wireless interface
        product: AR5212 802.11abg NIC
        vendor: Atheros Communications Inc.
        physical id: 0
        bus info: pci@0000:03:00.0
        logical name: wifi0
    Now you know your sporting an Atheros AR5212.
  3. Install some software you'll need to build MadWifi:
    trastle$ sudo apt-get install subversion linux-kernel-headers build-essential \
    libssl-dev
  4. Now go to your desktop
    trastle$ cd ~/Desktop 
  5. Make a directory to put the MadWifi source in:
    trastle$ mkdir madwifi-src
  6. Get the latest MadWifi source:
    trastle$ svn checkout http://madwifi-project.org/svn/madwifi/trunk madwifi-src
  7. Change into your new source directory:
    trastle$ cd madwifi-src
  8. Change to the root user:
    trastle$ sudo -i
  9. Blacklist the non working ATH5K drivers:
    root$ echo "# Block ATH5K" >> /etc/modprobe.d/blacklist
    root$ echo "blacklist ath9k" >> /etc/modprobe.d/blacklist
    root$ echo "blacklist ath5k" >> /etc/modprobe.d/blacklist
  10. Change to the MadWifi source directory
    root$ cd /home/[your user]/Desktop/madwifi-src
  11. Build and install the MadWifi driver:
    root$ make && make install -d
  12. Add the MadWifi driver to your Kernel
    root$ echo ath_pci >> /etc/modules

Now save anything else you have been working on and reboot your laptop. After the reboot your wireless will be working nicely.

2010-06-20: Edit added step 10. Thanks Xi.

Saturday, November 21, 2009

Proxy environment variables and sudo in Ubuntu

At work we use a proxy server to access the internet from our test network. We also have an internal Ubuntu mirror on the test network to install updates and packages, this server must be accessed by the test machines directly without the proxy.

Setting up the proxy and the exception for the mirror can be done in a terminal using the environment variables http_proxy, https_proxy, ftp_proxy, and no_proxy.

In Ubuntu these variables are all set in the /etc/environment file. On my test system this file contains the following:

trastle@trastle-test:~$ cat /etc/environment
...
http_proxy="http://webproxy:3128/"
ftp_proxy="ftp://webproxy:3128/"
https_proxy="https://webproxy:3128/"
no_proxy="office-mirror"

Testing that these settings have been applied to the current terminal can be done by calling printenv:

trastle@trastle-test:~$ printenv | grep proxy
http_proxy=http://webproxy:3128/
ftp_proxy=ftp://webproxy:3128/
https_proxy=https://webproxy:3128/
no_proxy=office-mirror

This output shows that all of the required environment variables are set. However when I try to perform an update from the office mirror it fails! The http_proxy is being used to access hosts clearly specified in the no_proxy variable.

trastle@trastle-test:~$ sudo apt-get update
Ign http://office-mirror jaunty Release.gpg
...
Err http://office-mirror jaunty/main Packages
503 Service Unavailable
...
W: Failed to fetch http://office-mirror/ubuntu/dists/jaunty/main/binary-i386/Packages
503 Service Unavailable
...
E: Some index files failed to download, they have been ignored, or old ones used instead.

This all makes more sense when you check the environment variables that sudo is running with:

trastle@trastle-test:~$ sudo printenv | grep proxy
http_proxy=http://webproxy:3128/

For safety sudo runs with an minimal environment. This default list is hard coded into sudo (initial_keepenv_table in env.c if you want to go read the source). Ubuntu patches this list to include http_proxy but not no_proxy. This breaks the ability to get updates from the local mirror. Sudo can be queried to determine which environment variables it preserves by default:

trastle@trastle-test:~$ sudo sudo -V
Sudo version 1.6.9p17
...
Sudoers path: /etc/sudoers
...
Environment variables to preserve:
http_proxy
XAUTHORIZATION
XAUTHORITY
TZ
PS2
PS1
PATH
MAIL
LS_COLORS
KRB5CCNAME
HOSTNAME
HOME
DISPLAY
COLORS
...

The solution to this problem is to modify the list of environment variables that sudo will preserve by editing the /etc/sudoers file and providing an explicit list of which environment variables to be preserved, overwriting the default list. The configuration that must be added to /etc/sudoers is as follows:

Defaults env_keep="no_proxy http_proxy https_proxy ftp_proxy XAUTHORIZATION \
XAUTHORITY TZ PS2 PS1 PATH MAIL LS_COLORS KRB5CCNAME HOSTNAME HOME DISPLAY COLORS"

This will preserve all of the default environment variables as well as no_proxy, https_proxy and ftp_proxy. You can test this setting to prove that sudo is now preserving these extra environment variables by running:

trastle@trastle-test:~$
sudo printenv | grep proxy
http_proxy=http://webproxy:3128/
ftp_proxy=ftp://webproxy:3128/
https_proxy=https://webproxy:3128/
no_proxy=office-mirror

With these additional environment variables preserved updates and installs from the command line using your local mirror and ignoring your proxy server will work like a charm.