Installing Gnome 3.16 in Ubuntu 15.04

Update:  Please follow up with this post to purge all your residual config files related to Unity desktop environment from your system.

I've made a mistake during my fresh Ubuntu 15.04 installation as I picked the default graphical shell, the Unity flavour instead of Ubuntu Gnome 15.04, the Gnome flavour. Why so? I need to have a lean, optimized, and without much tweaking with sensible default desktop environment. I've tried Fedora 22 where Gnome 3 is the default graphical environment and had very good experience with it. Compare to Unity, it's more well-integrated and feels more cohesive.

Meanwhile, with Unity, I always have bad user experience since it was first release until now. It's quite resource intensive and buggy. If you don't have good optimized driver support for your graphic card, especially laptop, Compiz will make you cry. Yes, it's getting better these days but there still a few major annoyances with its default settings, especially that bloody freaking Unity Launcher.

My beef with Unity Launcher is the behaviour of auto-hide and the revealing sensitivity. Regardless how much I've tweak the sensitivity, out of ten times, maybe around 4 or more, whenever I moved my mouse over to the left or rather moused over the hot spot, the Launcher will not show up. Somehow the way the Launcher intercept the hot spot and its timing does not work the way as other launchers or dockers. This was made worse as there is no way to disable the auto-hide animation of the Launcher, which is perceivably slow. Not only the frustration of moving your mouse in a way within a limited hot spot to reveal the Launcher, you've to wait for it to slowly hide itself.

Enough rants.

Let's us proceed with installation or upgrade of Gnome 3.16. But first, let's check what are the version available in the default Ubuntu Vivid repository. As shown below, default Gnome version in default repository is still version 3.14. If you want version 3.16 from default repository, you'll have to upgrade to Ubuntu 15.10.
$ apt-cache show gnome-shell | grep Version
Version: 3.14.4-0ubuntu1

Before you install Gnome 3.16, you must first install version 3.14 using the default repository and purge the Unity desktop through cross-grading from Ubuntu to Ubuntu Gnome. I learned it the hard way that both desktop environments cannot coexists at the same time. Not sure why but there is a bug where you can't login to the Gnome desktop environment.
$ sudo apt-get install ubuntu-gnome-desktop
$ sudo apt-get purge ubuntu-default-settings
$ sudo apt-get purge ubuntu-desktop
$ sudo apt-get autoremove

Once you've install Gnome 3.14 and reboot, make sure you can login through the Gnome Display Manager (GDM) successfully. Next, we proceed with upgrading by adding the Gnome 3 staging Personal Package Archives (PPA). Note that this is staging PPA, things will break, so your mileage may vary (YMMV).
$ sudo add-apt-repository ppa:gnome3-team/gnome3-staging
$ sudo add-apt-repository ppa:gnome3-team/gnome3

Next, you'll need to update and dist-upgrade the system. You must use dist-upgrade command to resolve all necessary dependencies, this include removing of unused packages.
$ sudo apt-get update
$ sudo apt-get dist-upgrade

Go to a terminal console by pressing Ctrl + Alt + F1 to restart the GDM manually. Alternatively, you can just reboot the system. Login again to the Gnome 3.16 desktop environment to confirm our upgrade has been successfully.
$ sudo service gdm restart

Check our Gnome version.
$ gnome-shell --version
GNOME Shell 3.16.2

If you messed up the upgrade which eventually break the system (trust me it will somehow for some unknown reasons), for example, you can't see the login screen, just downgrade the Gnome 3 installation by purging Gnome 3 staging PPA. Consider the downgrade as rollback to version 3.14.
$ sudo apt-get install ppa-purge
$ sudo ppa-purge ppa:gnome3-team/gnome3-staging
$ sudo ppa-purge ppa:gnome3-team/gnome3

If you encounter any login issue with any desktop environments even through you've successfully logged in before, you'll need to remove the .Xauthority file. Go to the virtual console (Ctrl + Alt + F1), login using the same account credential and delete the .Xauthority file. Logout and switch to the graphical virtual console (Ctrl + Alt + F7) and try to login again.
$ rm -rf .Xauthority

Chinese Input Method (IBus) in Ubuntu 15.04

In the midst of migrating and consolidate all my personal stuff into the new but used lappy (more on that in future posts), I've struggled for the past few days but managed to get the Chinese input method through IBus to work in Ubuntu 15.04. The guide by Pinyin Joe (PYJ) helped a lot but you've to extract the instructions specifically for Ubuntu 15.04. While PYJ recommended Fcitx Input Framework for latest Ubuntu, I still prefer IBus as it came installed by default.

First, you'll have to install the Chinese language related files. See the below screenshot for visual details.
  1. Press the Super/Windows key.
  2. Type Language Support and press Enter.
  3. In the Language tab, click the Install / Remove Languages button.
  4. In the Installed Languages, select Chinese (simplified) and Chinese (traditional) and click Apply Changes.

The next step is to install the Pinyin input method for IBus input framework. While there many Chinese input methods, the Pinyin is the easiest as it's based on phonetic (pronunciation) rather than graphological (stroke order).

What are the available Pinyin input method for IBus framework in Ubuntu?
$ apt-cache search pinyin | grep ^ibus
ibus-sunpinyin - sunpinyin engine for ibus
ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
ibus-pinyin - Pinyin engine for IBus

You can install all three but it will be a hassle later to switch between input methods using the Super/Windows + Space key. Is best to use install one Chinese input method so that you can just easily toggle between English and Chinese input methods. Now, that leads us to the next question, which Pinyin input methods should be install?

Forget about the ibus-pinyin input method. This is a fundamental and limited. For example, you can't even input the phrase "看法" (opinion) without having to key in each individual word separately. ibus-libpinyin is a newer and better Pinyin input method, which also include Chinese ZhuYin (Bopomofo), using phonetic notation which still popular in Taiwan. Lastly, ibus-sunpinyin, which uses SLM (Statistical Language Model) to determine the probability of a sequence of words when you key in the Pinyin. We'll use the Sun Pinyin method for this setup guide.

Installation is straightforward, just apt-get install it.
$ sudo apt-get install ibus-sunpinyin

Next, we need to enable above installed input method through Text Entry Settings, which is located at the top right panel, see screenshot below.

Click the '+' button and type in 'chi' to show all Chinese input source. However, the SunPinyin we've just installed does not show up in Text Entry. You have to logout and re-login to the Unity Desktop environment again. I missed this step while following the guide by PYJ and wasted quite a few days redoing and retracing my steps again and again.

Logout and re-login again and go back to the Text Entry Settings again. This time the Sun Pinyin will be shown in the input sources list as shown. Note that restarting Unity without logging out did not work. You have to really logout and try again.

After this, clicking language selection on top right panel will show the SunPinYin selection. As mentioned before, to toggle between two input methods, just use the Super/Windows + Space Key.

Launch Gedit and toggle to SunPinyin, you can now input Chinese characters in Ubuntu 15.04.

On a related note, I've been using Fedora 22 for the past 9 months as my primary GNU/Linux distros. The whole GNOME desktop environment feels more integrated and polish compare to Ubuntu 15.04's Unity desktop environment. Pity though, I really like Fedora 22 but I've to switch to Ubuntu due to more up to date software packages and choices.

Linux Containers (LXC) in Ubuntu 15.04

Last month, I've been trying out LXC in Fedora 22 (F22) with some limitations and missing features. I tried but failed to get unprivileged container to work and there is no RPM packages for LXD. Although you can compile the code and create RPM yourself, but is not worth the time spend in doing so. Hence, is best to switch to the Ubuntu which has the latest LXC support since the one of the project leaders, Stéphane Graber, is working for Canonical Ltd, the company that manage Ubuntu.

Installation is pretty much straightforward, just apt-getting it.
$ sudo apt-get install lxc

Checking the default LXC configuration. Compare to LXC in F22, the Cgroup memory controller was enabled by default and the kernel is still using 3.19 compare to 4.0.1.
$ lxc-checkconfig 
Kernel configuration not found at /proc/config.gz; searching...
Kernel configuration found at /boot/config-3.19.0-10-generic
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled
Multiple /dev/pts instances: enabled

--- Control groups ---
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled

--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled

Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig

One of the issue encounterd for LXC in F22 is the installation did not create the default lxcbr0 bridge interface. Not so in Ubuntu.
$ cat /etc/lxc/default.conf | grep = lxcbr0

Checking the activated bridge interface, lxcbr0.
$ brctl show
bridge name     bridge id               STP enabled     interfaces
lxcbr0          8000.000000000000       no

Instead of creating a new LXC container as root user, we can create unprivileged containers as normal or non-root user.
$ lxc-create -n test-ubuntu -t ubuntu
lxc_container: conf.c: chown_mapped_root: 3394 No mapping for container root
lxc_container: lxccontainer.c: do_bdev_create: 849 Error chowning /home/ang/.local/share/lxc/test-ubuntu/rootfs to container root
lxc_container: conf.c: suggest_default_idmap: 4534 You must either run as root, or define uid mappings
lxc_container: conf.c: suggest_default_idmap: 4535 To pass uid mappings to lxc-create, you could create
lxc_container: conf.c: suggest_default_idmap: 4536 ~/.config/lxc/default.conf:
lxc_container: conf.c: suggest_default_idmap: 4537 lxc.include = /etc/lxc/default.conf
lxc_container: conf.c: suggest_default_idmap: 4538 lxc.id_map = u 0 100000 65536
lxc_container: conf.c: suggest_default_idmap: 4539 lxc.id_map = g 0 100000 65536
lxc_container: lxccontainer.c: lxcapi_create: 1320 Error creating backing store type (none) for test-ubuntu
lxc_container: lxc_create.c: main: 274 Error creating container test-ubuntu

From the above error, we need to define the uid mappings for both user and group. Duplicate the LXC's default.conf to our own home directory and add in the mapping.
$ mkdir -p ~/.config/lxc
mkdir: created directory ‘/home/ang/.config/lxc’
$ cp /etc/lxc/default.conf ~/.config/lxc/
$ echo "lxc.id_map = u 0 100000 65536" >> ~/.config/lxc/default.conf
$ echo "lxc.id_map = g 0 100000 65536" >> ~/.config/lxc/default.conf
$ echo "$USER veth lxcbr0 2" | sudo tee -a /etc/lxc/lxc-usernet
ang veth lxcbr0 2

Checking back our own user's default.conf config file.
$ cat ~/.config/lxc/default.conf = veth = lxcbr0 = up = 00:16:3e:xx:xx:xx
lxc.id_map = u 0 100000 65536
lxc.id_map = g 0 100000 65536

Try to create our unprivileged container again. As the error indicate below, unprivileged containers can only be created through the download template.
$ lxc-create -n test-ubuntu -t ubuntu
This template can't be used for unprivileged containers.
You may want to try the "download" template instead.
lxc_container: lxccontainer.c: create_run_template: 1108 container creation template for test-ubuntu failed
lxc_container: lxc_create.c: main: 274 Error creating container test-ubuntu

Re-run the command to create the container but using the download template. This will take a while.
$ lxc-create -t download -n test-ubuntu -- -d ubuntu -r trusty -a amd64
Setting up the GPG keyring
Downloading the image index
Downloading the rootfs
Downloading the metadata
The image cache is now ready
Unpacking the rootfs

You just created an Ubuntu container (release=trusty, arch=amd64, variant=default)

To enable sshd, run: apt-get install openssh-server

For security reason, container images ship without user accounts
and without a root password.

Use lxc-attach or chroot directly into the rootfs to set a root password
or create user accounts.

Start the container in daemon or background mode. It seems we have error here.
$ lxc-start -n test-ubuntu -d
lxc-start: lxc_start.c: main: 344 The container failed to start.
lxc-start: lxc_start.c: main: 346 To get more details, run the container in foreground mode.
lxc-start: lxc_start.c: main: 348 Additional information can be obtained by setting the --logfile and --logpriority options.

Restart the container again in foreground mode.
$ lxc-start -n test-ubuntu -F
lxc-start: start.c: print_top_failing_dir: 102 Permission denied - could not access /home/ang.  Please grant it 'x' access, or add an ACL for the container root.
lxc-start: sync.c: __sync_wait: 51 invalid sequence number 1. expected 2
lxc-start: start.c: __lxc_start: 1164 failed to spawn 'test-ubuntu'
lxc-start: lxc_start.c: main: 344 The container failed to start.
lxc-start: lxc_start.c: main: 348 Additional information can be obtained by setting the --logfile and --logpriority options.

To fix this, we need to grant access to our $HOME directory.
$ sudo chmod +x $HOME

Let's us try again.
$ lxc-start -n test-ubuntu -d
$ lxc-attach -n test-ubuntu

Compare to Fedora 22, LXC in Ubuntu 15.04 is easier to setup although we still need to reconfigure it to enable unprivileged container creation. In short, if you want good LXC support, use Ubuntu 15.04.

Case-insensitive Tab Completion in Bash

In Ubuntu, there are several default folders created when you added a new user, listing as shown. All this while, whenever I need to access one of these folders, I always need to capitalize the first character to trigger the tab completion.
$ ls
Desktop/  Documents/  Downloads/  Music/  Pictures/  Public/  Templates/  Videos/  examples.desktop

That day, while setting up another Ubuntu installation, it dawned on me to check whether case-insensitive works for tab completion in Bash? As usual, Google and AskUbuntu did not fail me. Yes, we can do that in Bash. So many years of using Ubuntu and it never occurs for me to raise such question?

To enable case-insensitive, just set completion-ignore-case for the Readline init file, .inputrc.
$ if [ ! -a ~/.inputrc ]; then echo "\$include /etc/inputrc" > ~/.inputrc; fi
$ echo "set completion-ignore-case On" >> ~/.inputrc

While we're looking into this, there are also another option, completion-map-case, which treats hypens ('-') and underscores ('_') as equivalent.

The final .inputrc file should look like below.
$include /etc/inputrc
set completion-ignore-case on
set mark-symlinked-directories on

Symfony Installation For Developer and System Administrator

Symfony, the PHP framework which has won the PHP framework market share as quite a few crucial PHP projects already transitioned or use either Symfony2 framework or its components. While I'm not a fan of Symfony due to its Javaism which introduces unnecessary complexity and divert from the original PHP design principles, but you can't ignore the influences it brought to PHP world.

Four years ago, I was evaluating it for a new project, but decided to go with CodeIgniter and Kohana due to project size and time frame. Always go for something you're familiar with instead venturing into new unknown territory. The money and time spent does not justify it. Everyone wants it fast, cheat, and don't really care about longevity of any projects. Enough ramblings, let us revisit the installation.

There are many ways to install or use Symfony framework but the recommended way is to use the Symfony installer. Although installation through Composer (deprecated), PEAR (deprecated), or GNU/Linux distros packages are still feasible.

First, getting the Symfony installer which you can obtain by downloading the binary directly and install locally. Popularized by those developer who want to have a universal quick installation method between GNU/Linux and MacOS. The Curl's -LsS parameter means that to download from a location (-L), silently (-s), but show errors (-S). Go to Explain Shell for the full parameters details.
$ sudo curl -LsS -o /usr/local/bin/symfony
$ sudo chmod a+x /usr/local/bin/symfony

Quick and convenient right? Indeed for developer point of view who want to bootstrap any application using Symfony framework quickly. However, for a system administrator, this is a big no-no, especially in production server, where priorities are targeted towards stability and security. Why so? Note that we should always verify the authenticity of any downloaded installer to check for any corruption or tampering. While there is way to verify Symfony components, we can't seem to find it for Symfony installer. Hence, such installation method, while convenient, lack assurances.

If you're a system administrator, surely you will prefer the default packages that come with your GNU/Linux distros. For sure, you are guarantee of well-tested and automated security updates. Something that is not possible if you install the Symfony framework manually where you've to keep track of any security advisories. The trade-off is that you've to stick with legacy but stable version of the framework which may not be supported anymore.

For example, in Fedora 22, which was release few weeks back, the available Symfony version is 2.5.11. Unfortunately, after checking release schedule and roadmap checker, there will be no support of security fixes after July 2015 and is advisable to upgrade to version 2.7.x.
$ dnf info php-symfony | grep Version
Version     : 2.5.11

If you're starting a new Symfony project, are you going to use the default and outdated Symfony packages that comes with your distro? Surely not. Who in the right mind will develop against an unsupported version? And furthermore, developer always like fancy new toys.

This is one of the dilemma when the distro packages is not catching up with the release cycle of the software. Another good example is in Fedora 22, there are still packages for PEAR channel for Symfony, where this is not supported anymore due to the transition to Composer. I'm not sure why Symfony 2.5 was selected but obviously there is a mismatch between the Fedora 22 and Symfony release timeline. Also, I think Centos 6 or 7 will have the similar unsupported version.
$ dnf search symfony | grep channel
php-channel-symfony.noarch : Adds symfony project channel to PEAR
php-channel-symfony2.noarch : Adds channel to PEAR

In the end, stick to the simpler way, using the Symfony installer, even though you may be some security risk but that can be prevented by verifying its components and using Security Advisories Checker tool..