Wednesday, June 10, 2015

i3: Launch Android Studio on specific workspace

i3 supports launching specific applications on specific workspace. The problem with Android Studio is that it displays a splash screen and loads the full program, matching applications by title doesn't work in this case.

However, WM_CLASS comes to rescue. Android Studio's WM_CLASS is set to "jetbrains-studio" and we can match that. (This was gathered using xprop.)

Just add the following lines to the end of i3 config file at ~/.i3/config

assign [class="jetbrains-studio"]  2

This makes Android Studio launch by default on Workspace "2".

Tested for : Android Studio 1.2

Sunday, June 7, 2015

Install Debian with Network Install ISO and Grub

What if you want to test an ISO without asking your VPS Provider to put the ISO in their control panel? This is one of the case where directly booting off an ISO image is a better option.

So, let's assume we want to install Debian 8 (amd64) from network. First the server(or perhaps desktop) should have any kind of Linux preinstalled. I am assuming you have a flavor of Linux that is powered by "apt".

Step 1: Install Grub and grub-imageboot

Grub supports booting from ISO images. And, grub-rescueboot makes life easier. Issue the following commands as root:
# apt-get install grub2 grub-imageboot
This will create a new folder on /boot/images where you can put any ISO files and it will be on the meny entry of Grub.

Step 2: Download ISO Image

URL in command below points to minimal CD image (around ~21MB) that can be used to boot latest Debian installer.

# mkdir /boot/images
# wget -P /boot/images http://ftp.debian.org/debian/dists/stable/main/installer-amd64/current/images/netboot/mini.iso

This will download the ISO to /boot/images .

Step 3: Update Grub entry

# update-grub

Step 4: Restart

Now, restart your server and select the Grub entry. If you are doing this on a remote server or VPS, use VNC, it's available in most of the control panels.

grml-rescueboot is an alternative similar to grub-imageboot but it didn't work for me.

Saturday, November 22, 2014

Undefined References to Boost Libraries - Solution

Yesterday, I was trying to compile a C++ source that uses Gnuplot-iostream interface. I issued the following compilation command:
$ g++ -std=c++11 -lboost_iostreams -lboost_system -lboost_filesystem ProcessScheduler.cpp 
/tmp/cchNNC8H.o: In function `__static_initialization_and_destruction_0(int, int)':
ProcessScheduler.cpp:(.text+0xc52): undefined reference to `boost::system::generic_category()'
ProcessScheduler.cpp:(.text+0xc5e): undefined reference to `boost::system::generic_category()'
ProcessScheduler.cpp:(.text+0xc6a): undefined reference to `boost::system::system_category()'
collect2: error: ld returned 1 exit status
I even had libboost-system-dev, libboost-filesystem-dev and libboost-iostreams-dev installed.
After searching for over an hour, I found that the problem was with how new g++ treated the command-line options.

The solution was to change the position of arguments.
$ g++ -std=c++11  ProcessScheduler.cpp  -lboost_iostreams -lboost_system -lboost_filesystem
So, adding linker parameters after source file worked.
The page at Link Options - GCC states that:
-l library [...] It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded. [...]

Saturday, June 28, 2014

Streaming USB webcam on Raspberry PI

I had a USB webcam lying around and a Raspberry Pi. And, I wanted to stream it over my local WiFi network. To do this, I picked up MJPEG-Streamer. Connecting the webcam and issuing 'lsmod' showed this:
$ lsmod
.
.
Bus 001 Device 004: ID 0ac8:3420 Z-Star Microelectronics Corp. Venus USB2.0 Camera
The device is supported by UVC driver.
ls /dev/vid*
/dev/video0
So, we have '/dev/video0' as our webcam.
Let's install some required packages.
On a RPi, I have faced multiple issues trying to install packages without first upgrading the system to the latest state. So, let's upgrade the system first.
$ sudo apt-get update && sudo apt-get upgrade
And, some requirements for MJPEG-Streamer
$ sudo apt-get install subversion imagemagick libjpeg8-dev
Now, let's download the latest source
$ svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer/ mjpg-streamer
$ make
When it finishes, it leaves "mjpeg-streamer" binary to the folder. This may be added to path variable. Now, let's stream. 15fps with hardware MJPEG Compression
$ ./mjpg_streamer -i "./input_uvc.so -d /dev/video0 -f 15 " -o "./output_http.so -w ./www"
If you get the error like this:
The input device does not supports MJPEG mode
You may also try the YUV mode (-yuv option), but it requires a much more CPU power
 Init v4L2 failed !! exit fatal 
 i: init_VideoIn failed
Then we need to add '-y' argument to fallback to software mode.
$ ./mjpg_streamer -i "./input_uvc.so -d /dev/video0 -y -f 15" -o "./output_http.so -w ./www"
You can access the web interface at http://<ip>:8080/ where 'ip' is the IP of the Raspberry Pi server. The frame rate can also be changed by specifying the custom value instead of 15. To stream at different resolution with 30fps:
$ ./mjpg_streamer -i "./input_uvc.so -d /dev/video0 -f 15 -r 960x720" -o "./output_http.so -w ./www"
The best part of MJPEG-Streamer is that you can also use VLC or any other streaming player to watch the stream and you are not limited to a web interface.
Happy streaming.

Saturday, January 5, 2013

WordPress SEO by Yoast and Nginx

Wordpress-SEO by Yoast is a great plugin for search engine optimization. It can generate XML sitemaps on the fly. While on Nginx, I found that I was getting 404 errors when trying to load the sitemap.

The solution was simple. We just need to pass the "sitemap name" as a URI to "index.php" which can be done by simply adding this to "server block":

rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
If you are already using Nginx with Wordpress friendly URLs, these steps are not necessary and redundant.

Wednesday, August 22, 2012

Allow only SCP/SFTP transfers with 'scponly'

scponly restricts users to SCP and SFTP logins by acting itself as a shell and this disables SSH logins. This allows using Filezilla or 'scp' tool to transfer files but restrict SSH logins via SSH clients. Debian has this package as 'scponly'. TO install it:
# apt-get install scponly
Since, we will not be chrooting users, suid binary is not required. So, select no to: Install the chrooted binary /usr/sbin/scponlyc SUID root? <-- No For existing users, do:
# usermod -s /usr/bin/scponly username
To create a new user with scponly:
# useradd -m -s /usr/bin/scponly username
# passwd username

Wednesday, August 1, 2012

Optimized LEMP Installer for Debian/Ubuntu with Virtual Hosts Automator.

LAMP stacks are used widely but they are notorious for being less resource friendly and in the same time, incredibly attracting to script kiddies and part time crackers.

There's a tradition to play with most popular toys rather than one which was designed to be small and less expensive. As a kid, what would you like to steal in a kindergarten: a Spider-Man toy or a small spider miniature?
Leaving aside these arguments, let's move on to the real-valued part. I wrote this script which I think, has the following featured jobs:
(Some literary art)

  • Configures Nginx for performance and static file caching as well as gzipping the output.
  • Installs and PHP-FPM as well as PHP-APC for Opcode Caching
  • Optimizes MySQL for caching queries, while being light on resources.
  • Facilitates interactive virtual hosts creation with dedicated PHP-FPM pool for each user so that each PHP process runs as the owner. This eliminates the need to install FTP server for updating Wordpress or installing plugins. Since, PHP runs as the user owning the script, "wp-config" can be set to very strict permissions like 700.

There's even more...

  • Virtual hosts generation script also has the ability to create MySQL user and database as well as allowing user to import SQL file onto the newly created database for easy migration.
  • PHPMyAdmin installer is also built-in which allows PHPMyAdmin to be installed on specified domain or sub-domain. 
  • This script uses unix sockets instead of TCP which promises some more improvement and lowers TCP overhead within the system. 
  • I have implemented some security practices like "cgi.fixpath_info=0". 
Download the script here and run it as root:
wget https://raw.github.com/aatishnn/lempstack/master/lemp-debian.sh
chmod +x lemp-debian.sh
./lemp-debian.sh
This script works for me but I cannot guarantee that it will work for you too. I am not a Bash expert. Please add some regexp to your brain to ignore my scripting laziness. This is designed to work with Debian and Ubuntu. You may freely use it to suit your needs under the condition that you will thank me. I would be glad if you can share something about this script, test it, debug it or just scold, rebuke or criticize.


Monday, June 4, 2012

Using WiFi just from Linux Terminal

Are you tired of Network Managers that try to reduce pain regarding Wireless connections and end up with unstable or never-connecting Wireless problems? Then, command line comes to the rescue and `wpa_supplicant` as our weapon. Throughout the tutorial, I will be using these random access point details with WPA-PSK:
SSID: linuxdo
Passphrase: myphrase
And, `wlan0` is the wireless interface. Find the one corresponding in your system using `iwconfig`.
Install `wpa_supplicant` for your distro if not installed.
For CentOS/RedHat and other Yum based systems:
# yum install wpa_supplicant

For Debian based systems including Ubuntu:
# apt-get update && apt-get install wpa_supplicant
Now, we need to create the configuration file for `wpa_supplicant`. There is an easy way out using:
# wpa_passphrase linuxdo myphrase >/root/linuxdo.conf
It's the time to connect now. Run `wpa_supplicant` as:
# wpa_supplicant -iwlan0 -c/root/linuxdo.conf
After you get `CTRL-EVENT-CONNECTED`, you should run `dhclient` as:
# dhclient wlan0
This way, you will get a dynamic IP from the router.
Test your internet connection by opening a web browser and loading `linuxdo.blogspot.com`. You will get it.
Since, we are now familiar with `wpa_supplicant` now, disable Wireless in NetworkManager interface to avoid conflicts.

Sunday, May 27, 2012

Installing Octopress on CentOS 6/RedHat/Scientific Linux

Official Octopress website have user-specific installation procedure prone to many errors due to 'rvm' and 'rbenv'. This is the mostly foolproof method to set-up Octopress correctly on Redhat based distros.

Run these as root:
# yum groupinstall 'Development Tools'
# yum install readline-devel zlib zlib-devel openssl openssl-devel libyaml git python-setuptools
# easy_install Pygments
Pygments is not necessary as it uses pygments.rb. (Thanks to @octopress)

Now, run these as normal user:
$ wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p320.zip
$ unzip ruby-1.9.2-p320.zip 
$ cd ruby-1.9.2-p320
$ ./configure --prefix=/usr --with-openssl-include=/usr/include/openssl --with-openssl-lib=/usr/lib64/openssl/engines --disable-option-checking --disable-pthread
$ make
If you are using 32-bit, then replace '--with-openssl-lib=/usr/lib64/openssl/engines' to '--with-openssl-lib=/usr/lib/openssl/engines'.

Again, run these as root:
# make install
Again, run these as normal user:
$ git clone git://github.com/imathis/octopress.git octopress
$ cd octopress
Now, as root:
# gem install bundler
# bundle install
# rake install
Lastly, as normal user:
$ rake install
Now, follow Configuring Octopress. That's it. You have installed Octopress on your system. Leak: I will soon be moving this blog to Octopress and will be hosting it on GAE.

Saturday, May 26, 2012

Better fonts in Chrome For Linux

Make a file .fonts.conf in your home directory and add this to it:
<match target="font">
  <edit name="autohint" mode="assign">
      <bool>true</bool>
    </edit>
    <edit name="hinting" mode="assign">
      <bool>true</bool>
    </edit>
    <edit mode="assign" name="hintstyle">
      <const>hintslight</const>
   </edit>
</match>
Now, restart Chrome to see the changes.

Install Java Browser plugin for Firefox 64-Bit in CentOS/Redhat

Download the latest 64-bit RPM package from main Java homepage. Install it as:
rpm -ivh <package-name>.rpm
And, add the plugin to Firefox with:
# cd /usr/lib64/mozilla/plugins
# ln -s $(find / -mount -name libnpjp2.so)
If 'ln -s $(find / -mount -name libnpjp2.so)' fails, then, first find the file 'libnpjp2.so' and supply the path as:
# ln -s <path-to-libnpjp2.so>

Restart your browser and you will have the working Java plugin for Firefox.

Install Log.io on CentOS

Searching for a simple online log viewer, I found log.io. Documentation has a recipe to install log.io on Ubuntu 11.10 but it doesn't match uniformly for CentOS. Seems like many things are hard-coded. So, I began to hack into it to make it working and I succeeded.

Installation Procedure:
# yum install gcc make openssl-devel git
# mkdir ~/downloads 
# cd downloads 
# wget "http://nodejs.org/dist/v0.6.11/node-v0.6.11.tar.gz" 
# tar -xzvf node-v0.6.11.tar.gz
# cd node-v0.6.11/ 
# ./configure
If it complains about missing libraries or anything else and doesn't succeeds, install the required libraries using Yum.
# make
# make install
# ln -s /usr/local/bin/node /usr/local/bin/nodejs
# wget http://npmjs.org/install.sh
# chmod +x install.sh
# ./install.sh
# PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
# rm -f /usr/bin/npm
# ln -s /usr/local/bin/npm /usr/bin/npm
# useradd -d /home/logio logio
# usermod -G adm logio
# npm config set unsafe-perm true
# npm install -g --prefix=/usr/local git://github.com/NarrativeScience/Log.io.git
# chmod -R 777 /var/log/log.io/

It's done. Now, start the server using:
# log.io server start

The server is now started. Allow access to port 8993 as:
# iptables -A INPUT -p tcp --dport 8993 -j ACCEPT

Hurray!. Head over to http://:8993 and see the power of nodejs.
Similarly, install Log.io on another machine and start the harvester with:
# log.io harvester start
Tested on CentOS 6.

Install latest Skype on CentOS

Download static archive of Skype from main skype website.The latest version while writing this tutorial was skype_staticQT-2.2.0.99.To download, you can do:
# cd /tmp
# wget http://www.skype.com/go/getskype-linux-beta-static
# cd /opt
# tar jxf /tmp/skype_static-2.2.0.99.tar.bz2
# rm /tmp/skype_static-2.2.0.99.tar.bz2
# ln -s skype_staticQT-2.2.0.99 skype
To make it easy to launch Skype and remove shared library related errors, do this:
# ln -s /opt/skype /usr/share/skype
# ln -s /opt/skype/skype /usr/bin/skype
# ln -s /usr/lib/libtiff.so.3 /usr/lib/libtiff.so.4
Even if you are running 64 bit CentOS version, you should install some 32 bit libraries as:
# yum install glibc.i686 alsa-lib.i686 libXv.i686 libXScrnSaver.i686 libSM.i686 libXi.i686 libXrender.i686 libXrandr.i686 freetype.i686 fontconfig.i686 zlib.i686 glib2.i686 libstdc++.i686 libtiff.i686 qt.i686 qt-x11.i686 pulseaudio-libs.i686 pulseaudio-libs-glib2.i686 alsa-plugins-pulseaudio.i686 
And, if you have CentOS media available:
# yum --disablerepo=\* --enablerepo=c6-media install glibc.i686 alsa-lib.i686 libXv.i686 libXScrnSaver.i686 libSM.i686 libXi.i686 libXrender.i686 libXrandr.i686 freetype.i686 fontconfig.i686 zlib.i686 glib2.i686 libstdc++.i686 libtiff.i686 qt.i686 qt-x11.i686 pulseaudio-libs.i686 pulseaudio-libs-glib2.i686 alsa-plugins-pulseaudio.i686 

Now, you should have a working Skype. Run it as:
# skype
Tested on CentOS 6.2

Friday, May 25, 2012

Delta RPMs on Yum

Delta, in sense of file, refers to the difference between two versions of the file. So, if you have a file and its delta, you can create a new file with all the changes included.

Delta RPMs are exactly the same. Consider a package 'yum-1.2.30-x86-64.rpm' and another updated package 'yum-1.2.31-x86-64'. A delta RPM of this package will be able to recreate the new updated Yum package from the older package available in the system. Since Delta RPMs are just the difference in two packages, they are small in size(in most cases). So, delta RPMs are useful if you have a congested, slow or limited bandwidth.

Enabling the use of Delta RPM in Yum:
We need 'yum-presto' plugin to enable delta RPMs. Install it as:
# yum install yum-presto
Now, try updating your system as:
# yum update
You will see that the download size will reduce dramatically and updates will be faster. That's how Delta RPM works.

Tested on CentOS 6.2.

Zypper implements delta RPMs by default. So, openSUSE users need not to be worry and there is nothing to enable for openSUSE systems.

SSH : Allow only certain users to log in

There are numerous user accounts that exist in a Linux system. You will not want to allow every user to log in via SSH.
Let's talk about the scenario: I have many users in my Linux box but real person-related users are root, alice and bob. So, to allow only them to connect via SSH, edit '/etc/ssh/sshd.conf' and add the following line at the end of the file:
AllowUsers root alice bob

Allow Root Login by SSH Keys only

IF you want to allow root login via SSH keys only while disabling password-based login, edit /etc/ssh/sshd.conf to reflect following change:
Original:
PermitRootLogin yes
Change:
PermitRootLogin without-password

Thursday, May 24, 2012

Install Flash Plugin for Firefox installed from tar.bz2 archive

If you have installed Firefox from the official download (firefox--.tar.bz2) at /opt or similar location and if you are using 64bit version of Linux, then the 64 bit version of Flash Player will not work with Firefox. The solution is to use 32bit version of flash plugin. Here is how you do in Yum based systems:
# rpm -ivh http://linuxdownload.adobe.com/linux/i386/adobe-release-i386-1.0-1.noarch.rpm 
# yum remove flash-plugin
# yum --disablerepo=adobe-linux-x86_64 --enablerepo=adobe-linux-i386  install flash-plugin
If you have a running Firefox window, restart it and you will get your flash plugin back. Tested on CentOS 6.2.

Wednesday, May 23, 2012

Gtk-WARNING in Firefox: Unable to locate theme engine

If you are getting warnings like these:
(firefox:4486): Gtk-WARNING **: Unable to locate theme engine in module_path: "clearlooks"
Install package 'gtk2-engines.i686'.

Tuesday, May 22, 2012

Enable Caching in Yum

It is a good idea to enable caching in Yum as it keeps downloaded packages locally and is useful if you have slow connections. The default behavior is to delete downloaded packages. To enable caching, turn 'keepcache=0' into 'keepcache=1' in /etc/yum/yum.conf as:
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
...
...
So, all the downloaded data will reside in 'cachedir' location.

Install latest VLC on CentOS 6

RPMForge provides latest VLC version for CentOS system. Install corresponding RPMForge repository as:

64-bit:
rpm -ivh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
32-bit:
rpm -ivh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
Now, install VLC as:
yum install vlc
Hurrah! You have a working best media player.