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

Thursday, May 26, 2016

How to Mount Mac OS X's HFS+ Partition in Ubuntu 14.04 LTS

To mount HFS+ partition, one first needs to install the necessary package:
$ sudo apt-get install hfsprogs

Next, create the mounting directory
$ sudo mkdir /media/mntpoint

Next, mount the partition
$ sudo mount -t hfsplus -o force,rw /dev/sdXY /media/mntpoint
where sdXY can be something like sda1, sda2, sda3, sdb1, sdb2, sdb3, etc.

To unmount, run the command
$ sudo umount /media/mntpoint

If you are not sure whether the exfat partition you are looking for is /dev/sda1 or /dev/sda2, then you could also run
$ sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL

Thursday, April 21, 2016

How to Mount EXFAT partition on Ubuntu 16.04 LTS

To mount exfat partition on Ubuntu, simply install the necessary packages:
$ sudo apt-get install exfat-fuse exfat-utils

If you need to mount it from the command line, you could do
$ sudo mkdir /media/exfat
$ sudo mount -t exfat /dev/sdxx /media/exfat
where /dev/sdxx could be /dev/sda1 or /dev/sda2, or so on.

If you are not sure whether the exfat partition you are looking for is /dev/sda1 or /dev/sda2, then you could also run
$ sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL

This should do it!

How to Upgrade to Ubuntu 16.04 LTS from 14.04 LTS

Finally, the day has come. Ubuntu 16.04 LTS has been just released today. In this post, I will cover how to upgrade your two-years old system 14.04 LTS to the shin new 16.04 LTS.

First, verify that release upgrader is set to lts
$ cat /etc/update-manager/release-upgrades

The last line should read
Prompt=lts

Next, make sure that your system is up to date
$ sudo apt-get upgrade -y

Next, if you are using Ubuntu Desktop, run
$ sudo update-manager -d

If you are using Ubuntu Server, run
$ sudo do-release-upgrade -d

That's it!

Monday, March 28, 2016

How to Enable Search History Feature with Bash

Assume your ~/.bash_history file has the following content:
gcc test.c
gcc -g test.c
cat test.c
vim test.c
ssh root@localhost
ssh root@192.168.1.1
g++ test.cpp
g++ test.cxx

Now, say you type
$ gcc[up arrow]

Normally, the [up arrow] key will simply give you the last command, that is
$ g++ test.cxx

However, this is quite annoying. When you type gcc first and pressing the [up arrow] should intuitively tell bash to search for all the previous commands starting with gcc. What you probably expected was
$ gcc -g test.c
or
$ gcc test.c

Well, there is a way to do this. Edit your ~/.bashrc file and add the following lines:
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'

NOTE: if you are on Mac OS X, append the above two lines to ~/.bash_profile instead.

Save the file and exit bash. Now when you restart bash, you should see search history feature enabled. That is, when you type
$ gcc[up arrow]
will show you
$ gcc -g test.c

Another [up arrow] will show you
$ gcc test.c

Similarly, typing
$ ssh[up arrow]
will show
$ ssh root@192.168.1.1

One more [up arrow] will yield
$ ssh root@localhost

Sunday, March 27, 2016

How to Build and Add Custom C Library

For those who are familiar with Matlab, you may know the functions tic and toc. These two functions are used to print out elapsed time in between tic and toc. Let us implement this in C and create a library, so that we can use these functions easily later.

First, create tictoc.c file with the following:
#include <tictoc.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>

/* indicates whether tic has been called */
static int tic_flag = 0;

/* tic timeval */
static struct timeval start;

void tic() {
    tic_flag = 1;
    if (gettimeofday(&start, NULL)) {
        fprintf(stderr, "libtictoc: error from gettimeofday()\n");
    }
}

void toc() {
    if (tic_flag == 0) {
        fprintf(stderr, "libtictoc: tic() has not been called\n");
        return;
    }
    struct timeval end;
    if (gettimeofday(&end, NULL)) {
        fprintf(stderr, "libtictoc: error from gettimeofday()\n");
        return;
    }
    printf("Time elapsed: %lfs\n", 
            (double) (end.tv_sec-start.tv_sec)
            + (double)(end.tv_usec-start.tv_usec)/1000000.0);
}


Next, create tictoc.h file with the following:
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

#ifndef _TICTOC_H_
#define _TICTOC_H_

extern void tic();
extern void toc();

#endif // _TICTOC_H_

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

Note that the first three lines and the last three lines in the header enable C++ compatibility.

Now, let's see if we can compile this
$ gcc -c -Wall  -I . tictoc.c
You should see it compile successfully, and tictoc.o file has been created.

Make sure you have binutils installed on the system. For Ubuntu/Debian, simply run
$ sudo apt-get install -y binutils

For Mac OS X, run
$ brew install binutils

To create a library file, we run
$ ar -cvq libtictoc.a tictoc.o

This command will use tictoc.o file to create libtictoc.a library file. To examine the newly created file, run
$ ar -t libtictoc.a
You should see tictoc.o file listed.

We are now ready to copy the library file and the header file into the default user library and include folders.
$ sudo cp libtictoc.a /usr/local/lib
$ sudo cp tictoc.h /usr/local/include

Finally, we test whether the library works well. Create a test.c file with the following:
#include <tictoc.h>
#include <unistd.h>
int main() {
    tic();
    sleep(1);
    toc();
    sleep(2);
    toc();
    return 0;
}


Let's try to compile it
$ gcc -Wall test.c
You should see some error saying undefined reference to tic and toc. This is because we have not told gcc to look for libtictoc library. 

Well, let's do it.
$ gcc -Wall -l tictoc test.c
The -l option tells gcc to search for library, and the proceeding string (tictoc) preceded by lib will be the name of the library. That means, -l tictoc is asking gcc to look for a library file named libtictoc within the default library folders. Since we have copied over libtictoc.a file into /usr/local/lib, which is one of the default library search folders, gcc will be able to locate it. To find out the default load library path is, look into /etc/ld.so.conf file.

Note that .a extension is used for static library whereas .so extension is used for dynamically linked library.

It should compile now. Let's run it and see if it actually works.
$ ./a.out
You wills see something like time elapsed 1s and 3s, just as you expected!

Sunday, March 20, 2016

How to Read CPU Temperature in Ubuntu 14.04 LTS

Install the necessary package
$ sudo apt-get install lm-sensors 

Start the sensors
$ sudo sensors-detect
$ sudo service kmod start

Print out the measurement
$ sensors

That's it!

How to Setup Personal Cloud Server on Ubuntu 14.04 LTS using OwnCloud

This post is based on https://youtu.be/aotBluDGAAE.

First, download the latest build of owncloud, which is 9.0.0 at the time of writing this post.
$ wget https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2

Extract the file using tar
$ tar fxj owncloud-9.0.0.tar.bz2

Install necessary packages (^ key is not a mistake below)
$ sudo apt-get install lamp-server^ php5-gd php5-curl php5-intl php5-mcrypt php5-imagick -y

During the installation of SQL server, it will ask for the root password. Make a note of this password, as it will be used in the setup later on.

Upload the directory to the server
$ sudo cp -rfp owncloud /var/www/html/

Change the permission of the server
$ sudo chown -R www-data:www-data /var/www/html/owncloud

A security measure
$ sudo a2enmod rewrite

Modify the apache configuration file
$ sudo vim /etc/apache2/apache2.conf

Change AllowOverride option to All under <Directory /var/www/>

Restart the server.
$ sudo service apache2 restart

Open up a web browser, and go to the address: http://server_ip/owncloud
where server_ip is the IP address of the owncloud server you just setup

Setup the administrator. In the first box, choose owncloud admin username and password. In the second box, enter root as the username and SQL password from the previous step.

That's it! When you install the desktop or mobile client, make sure to enter the server address as http://server_ip/owncloud.



NOTE: if you have firewall setup, you may need to open up the TCP port 80.

Thursday, March 3, 2016

How to Boot into Console Mode in Ubuntu

If you want to change the default boot option of Ubuntu Desktop into a console mode, here is how:

1. Backup the grub file
$ sudo cp -n /etc/default/grub /etc/default/grub.bk

2. Open up the grub file
$ sudo vim /etc/default/grub

3. Modify the menu entries
a) Comment out GRUB_CMD_LINE_LINUX_DEFAULT="quiet splash"
b) Change GRUB_CMD_LINE_LINUX="" to GRUB_CMD_LINE_LINUX="text"
c) Uncomment GRUB_TERMINAL=console

When complete, the file should look something like below:
...
GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX="text"

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
GRUB_TERMINAL=console
...

4. Update grub
$ sudo update-grub

Only for Ubuntu 15.10 or up that uses systemd:
$ sudo systemctl enable multi-user.target --force
$ sudo systemctl set-default multi-user.target

5. Reboot and see if it works
$ sudo reboot

By the way, to start GUI, simply run the following command after logging into the console
$ sudo service lightdm start

Tuesday, March 1, 2016

How to Debug Remote using gdbserver

In this post, I will go through the method of debugging remotely using gdbserver. This is useful when you want to debug a program that constantly requires user's input. For example, consider the simple program test.c below:

#include <stdio.h>
int main (int argc, char** argv) {
    printf("input a positive number: ");
    int i;
    scanf ("%d", &i);
    for (; i>0; i--)
       printf("%d\n", i); 
return 0;
}

This program will require a user input and behave accordingly. Let's start debugging this remotely.

First, we need to compile it of course,
$ gcc -g test.c

Next, we need to install gdbserver
$ sudo apt-get install gdbserver -y

Let's run gdbserver and open up connection
$ gdbserver :1234 a.out 10
It should be waiting for connection to be made on port 1234. Don't forget the argument to the program, which is 10 in this case.

Now, we will open up another terminal and start gdb of a.out binary we just compiled
$ gdb -q

In the gdb prompt, run
(gdb) target remote :1234
(gdb) b test.c:7
(gdb) c

Now, you will see interactive gdb running on one of the terminal windows and the program running on the other!

Sunday, February 28, 2016

How to Compile the Latest Development Version of GNU Package - Findutils

In this post, I will discuss how to download and compile the latest development version of findutils GNU package. Findutils package consists of find, locate, updatedb, and xargs. More info and stable releases of this package can be found at http://www.gnu.org/software/findutils/. This post intends to help people contribute to free and open source packages and programs, as GNU/Linux and GPL have changed the world significantly, and we can be all part of the movement. Although I will only discuss the Findutils package here, most of other GNU packages can be obtained in the similar manner.

The instruction here will be based on Ubuntu 14.04 LTS 64bit version.
We need to install necessary packages first as usual:
$ sudo apt-get install -y autoconf automake git gettext m4 dejagnu autopoint bison texinfo

If you are trying to build the package on Mac OS X, you will need to install development tools first.
$ sudo xcode-select --install

Then you would want to install homebrew.
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then, you will need to install the necessary packages with
$ brew install autoconf automake git gettext dejagnu bison texinfo

Finally, you will need to create a symlink of autopoint
$ sudo ln -s /usr/local/Cellar/gettext/0.19.7/bin/autopoint /usr/local/bin/autopoint

Now, you are ready to follow along for both Linux and Mac OS X.

We will download the latest development version using git
$ git clone git://git.sv.gnu.org/findutils

When complete, go to the findutils directory and run bootstrap
$ cd findutils && ./bootstrap

It will probably complain about gettext version.
autopoint: *** The AM_GNU_GETTEXT_VERSION declaration in your configure.ac
               file requires the infrastructure from gettext-0.19.3 but this version
               is older. Please upgrade to gettext-0.19.3 or newer.
autopoint: *** Stop.

To see what version of gettext is currently installed, we can run
$ gettext --version
I am getting 0.18.3 as of now. This is the latest version available from the Ubuntu repository. We can manually install the newer version by building the executable from the source.

Let's then download and build the latest gettext!
$ cd .. && wget https://ftp.gnu.org/gnu/gettext/gettext-latest.tar.gz

Unarchive the source files
$ tar xfz gettext-latest.tar.gz

Let's configure it!
$ mkdir gettext-0.19.7/build && cd gettext-0.19.7/build
$ ../configure

When complete, we can compile it
$ make -j 2
where the number 2 represents the desired # of cores to use when compiling.

By the way, if you intend to debug the source code, you may want to define a macro DEBUG
$ make -j 2 CFLAGS="-D DEBUG -g"
which sets the option -D DEBUG and -g to the compiler.

After some time, it should build successfully. We are now ready to install the latest get text on the system.
$ sudo make install

Finally, we should now have the latest version of gettext
$ gettext --version
which returns 0.19.7 as expected.

OK, let's go back to findutils and continue our process of bootstrapping
$ cd ../../findutils/ && ./bootstrap

The last step is to simply configure and compile!
$ mkdir build && cd build
$ ./configure
$ make -j 2

When complete, we can execute the new program and verify if it works
$ find/find --version
$ xargs/xargs --version
$ locate/locate --version

They all should say version 4.7.0-git as of today. The latest stable release findutils version is 4.6.0 as can be seen from http://ftp.gnu.org/pub/gnu/findutils/.

You could install it on the system if you want, but I would not recommend so, as it is not a stable release version yet.


Thursday, February 18, 2016

Setup SSH Login Email Alert on Ubuntu 14.04 or Debian

Anytime one enables ssh server, the machine will be at great risk from random attempts all around the world. It may be wise to setup an alert mail when someone logs into the machine remotely. In this post, we will look into how to do so.

I will make use of mail.mailutils program to send emails out here, but there are many other alternative mail out packages.
$ sudo apt-get install -y mailutils postfix
When prompted with postfix configuration, just choose the default setting, which is Internet Site.

Next, create a bash script file that will be executed when someone logs in remotely. In this example, I will place it in the /etc/ssh directory.
$ sudo vim /etc/ssh/ssh_alert.sh

Add the following content to the file
#!/bin/bash
# replace with sender's email address
sender="sender_address@some_mail.com"
# replace with recipient's email address
recipient="recipient_address@some_mail.com"
time=$(date)
if [ "$PAM_TYPE" != "close_session" ]; then
# replace with host name
host="ubuntu-server"
subject="SSH Login: $PAM_USER from $PAM_RHOST on $host at $time"

message="SSH login $PAM_USER from $PAM_RHOST at $time on $host"
echo "$message" | mail.mailutils -r "$sender" -s "$subject" "$recipient"
fi

Next, enable execute
$ sudo chmod u+x /etc/ssh/ssh_alert.sh

Now, we need to make sure that the script actually works. To do so, simply run it
$ sudo /etc/ssh/ssh_alert.sh

If you see a message saying that the email was sent successfully, then you can set it up so that a ssh remote login will execute the script and allow the remote login only if the email was successfully sent. To see whether the execution returns successful, type in
$ echo $?
The output of 0 means successful.

When the mail out is successful, open up /etc/pam.d/sshd
$ sudo vim /etc/pam.d/sshd

Add the following line to /etc/pam/sshd
session required pam_exec.so seteuid /etc/ssh/ssh_alert.sh

That's it. You should now receive the email when someone logs into the server through ssh.

Mount NFS Directory from Ubuntu and Mac OS X Clients

Here, I assume that you have set the NFS server following the previous post. In this post, I will show how the client machine can be configured to connect to the NFS directory.

Make sure that the client's IP address is specified in the server's /etc/export file. In the previous post, this should be 192.168.0.101. Also, I am going to assume that the NFS server IP address is 111.111.111.111.

Instructions for Ubuntu Client
First, install necessary package
$ sudo apt-get install -y nfs-common

Create a mount point
$ sudo mkdir -p /mnt/nfs

Mount the NFS directory
$ sudo mount 111.111.111.111:/var/nfs /mnt/nfs

That's it. To unmount, simply type in
$ sudo umount /mnt/nfs


Instructions for Mac OS X Client
First, create a mount point
$ sudo mkdir -p /private/nfs

Mount the NFS directory
$ sudo mount -o resvport,rw -t nfs 111.111.111.111:/var/nfs /private/nfs

That's it. To unmount, simply type in
$ sudo umount /private/nfs


How to Setup Network File System (NFS) on Ubuntu 14.04

In this tutorial, I will cover how to setup Ubuntu 14.04 (either desktop or server edition) as a NFS server.

First, install nfs-kernel-server
$ sudo apt-get install -y nfs-kernel-server

Next, create a directory which will be used as a network file system. In this example, I will use /var/nfs folder
$ sudo mkdir /var/nfs

Change the owner of the directory
$ sudo chown nobody:nogroup /var/nfs

Change the permission of the directory if you want to allow the clients to have access to read/write
$ sudo chomod 777 /var/nfs

Modify the export config file to let it know which directory will be used as NFS
$ sudo vim /etc/exports

Add the following line to the /etc/exports file
/var/nfs 192.168.0.101(rw,sync,no_subtree_check)

Here, I am assuming that this directory will only be accessed by 192.168.0.101. You may want to change this address if you want. Also, make sure to set your DHCP to reserve this IP address to the desired client.

Create NFS table that holds exports
$ sudo exportfs -a

Finally, simply start up the server
$ sudo service nfs-kernel-server start

That's it. In the next post, I will discuss how to connect to NFS directory from the client side.

By the way, you may want to note the server's IP address
$ ifconfig

This IP address will be needed for a client to connect to, which will be discussed din the next post.

Friday, January 29, 2016

How to Compile Fuego 1.1 on Ubuntu 14.04 LTS x64

My dad loves the game of GO, so I decided to let him play it vs AI. I first installed GNU GO on his computer and let him play against it; after a couple of times he played, he complained that GNU GO cannot even count accurately. So I figured I should provide him a better GO AI. That is how I decided to go for Fuego.

To install Fuego, download its source files
$ wget http://downloads.sourceforge.net/project/fuego/fuego/1.1/fuego-1.1.tar.gz

Unzip the source files
$ tar xfc fuego-1.1.tar.gz && cd fuego-1.1

Before configure, we need to install Boost library and build-essential
$ sudo apt-get install libboost-all-dev build-essential -y

Now, let's configure
$ ./configure

You will probably see some error saying 
configure: error: Could not find a version of the library!

The reason is that it cannot find the boost library, so we try to configure with the option
$ ./configure --with-boost-libdir=/usr/lib/x86_64-linux-gnu

The configure should have completed successfully. Let's compile.
$ make

You will probably encounter compilation error saying
GtpEngine.cpp:352:33: error: expected unqualified-id before numeric constant
         xtime_get(&time, boost::TIME_UTC);


We can fix this by replacing all instances of TIME_UTC with TIME_UTC_. Let's fix one by one first. Open the file
$ vim gtpengine/GtpEngine.cpp

Go to line 352 by entering :352 in vim and replace TIME_UTC with TIME_UTC_. Save and exit.

Let's compile again
$ make

This time you will see some error saying
SgPointSetUtil.h:67:25: error: reference 'm_pointSet' cannot be declared 'mutable' [-fpermissive]
     mutable SgPointSet& m_pointSet; // allow temp objects to modify


Let's solve this by removing 'mutable' in the file.
$ vim smartgame/SgPointSetUtil.h

After removing the keyword in line 67, save, and exit and give it another try.
$ make

You will encounter another error
GoGtpEngine.cpp:381:46: error: 'class boost::filesystem::path' has no member named 'native_file_string'
                            << m_sentinelFile.native_file_string() << "'";


This one is easy. If you search for native_file_string() method for Boost in Google, you will see that this method has been deprecated and replaced by string(). So, let's do that.
$ vim go/GoGtpEngine.cpp

In fact, you will have probably encountered another TIME_UTC error, which you can fix now, right? It is in the same file, so it should be easy.

Let's continue.
$ make

You will encounter another error saying
FuegoMain.cpp:65:55: error: invalid conversion from 'bool (*)(const string&) {aka bool (*)(const std::basic_string<char>&)}' to 'boost::enable_if_c<true, void>::type* {aka void*}' [-fpermissive]
     return path(programPath, boost::filesystem::native).branch_path();


This is again due to boost deprecation. One of the easiest ways to fix it for the moment is to replace line 65 with
return boost::filesystem::current_path();

This is not a remedy because this will only work if the executable is called from the same directory. However, let's just focus on compiling at the moment.

By the way, we will also need to include the boost::filesystem header file for the above quick fix to work. Insert the following at, say, line 11 of the FuegoMain.cpp file.
#include <boost/filesystem.hpp>

Let's continue.
$ make

We will encounter another complaint for native_file_string error, so let's fix it and compile again.
$ make

Lastly, we see another error saying
/usr/bin/ld: ../smartgame/libfuego_smartgame.a(libfuego_smartgame_a-SgUctSearch.o): undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line


As the error suggests, it is complaining because pthread library is missing. The easiest way to fix this is to run the g++ command with -lpthread option
$ cd fuegomain
$ g++ -g -O2 -DNDEBUG -Wall -Wextra -L/usr/lib/x86_64-linux-gnu  -o fuego fuego-FuegoMain.o fuego-FuegoMainEngine.o fuego-FuegoMainUtil.o ../gouct/libfuego_gouct.a ../go/libfuego_go.a ../smartgame/libfuego_smartgame.a ../gtpengine/libfuego_gtpengine.a -lboost_program_options -lboost_filesystem -lboost_system -lboost_thread -lpthread
$ cd ..

Let's continue!
$ make

You will most likely successfully compiled it finally! By the way, in order to save some compilation time, you may want to add in -j 2 option for make command, telling it to use 2 cores.


*** EDIT ***
After I created the post, I realized that Fuego website actually has a nice tutorial on building from the source files for Mac OS X and Linux. Furthermore, the latest Fuego source files can only be obtained via svn; these source files fix all of the problems mentioned above, except for the last one. In any case, I have created a script file that will build Fuego from the latest source files and install gogui and openjdk as well. Copy the script below and paste into a new file, say build_fuego_on_Ubuntu_14.04_x64.sh

#!/bin/bash
# this script attempts to compile and install fuego on Ubuntu 14.04 LTS x64


apt-get install -y subversion build-essential autoconf openjdk-7-jdk libboost-all-dev


sudo -u $SUDO_USER bash -c "svn checkout svn://svn.code.sf.net/p/fuego/code/trunk fuego"

cd fuego

#sudo -u $SUDO_USER bash -c "export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/"

sudo -u $SUDO_USER bash -c "autoreconf --force --install"
sudo -u $SUDO_USER bash -c "./configure --with-boost=/usr/lib/x86_64-linux-gnu/ --with-boost-libdir=/usr/lib/x86_64-linux-gnu/"
sudo -u $SUDO_USER bash -c "make -j 2"

cd fuegomain
sudo -u $SUDO_USER bash -c "g++  -g -O2 -DNDEBUG -Wall -Wextra -L/usr/lib/x86_64-linux-gnu/  -o fuego fuego-FuegoMain.o fuego-FuegoMainEngine.o fuego-FuegoMainUtil.o ../gouct/libfuego_gouct.a ../go/libfuego_go.a ../features/libfuego_features.a ../smartgame/libfuego_smartgame.a ../gtpengine/libfuego_gtpengine.a -lboost_program_options -lboost_filesystem -lboost_system -lboost_thread -lpthread"

cd ..
sudo -u $SUDO_USER bash -c "make -j 2"
cd ..
sudo -u $SUDO_USER bash -c "wget http://downloads.sourceforge.net/project/gogui/gogui/1.4.9/gogui-1.4.9.zip"
sudo -u $SUDO_USER bash -c "unzip gogui-1.4.9.zip"
cd gogui-1.4.9/lib

sudo -u $SUDO_USER bash -c "java -jar gogui.jar"


To run this file, simply set the execution flag and execute with sudo
$ chmod u+x build_fuego_on_Ubuntu_14.04_x64.sh
$ sudo ./build_fuego_on_Ubuntu_14.04_x64.sh
 
That's it!

Thursday, January 28, 2016

Function and Alias in Bash

People are lazy in general. Sometimes, it is simply annoying to type long commands in bash with lots of options. Let us see how we can use bash functions and alias to relieve stress of typing too much.

alias helps us to shorten a long command. On Linux, I use $ ls --color=auto -CF commands quite a lot. However, it becomes annoying typing the command repeatedly. What one can do is create an alias to shorten this as
$ alias ls='ls --color=auto -CF'

Now, when you type the command $ ls, it will essentially execute $ ls --color=auto -CF command. In many cases, you may want to write the alias command in ~/.bashrc for Linux and ~/.bash_profile for Mac OS X to be executed every time you open up the terminal. In fact, on my system (Ubuntu 14.04 LTS), the default ~./bashrc file already contains some alias commands as below:
alias ls='ls --color=auto'
...
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'


Hence, the command $ l will actually execute $ ls -CF, which in turn will execute $ ls --color=auto -CF, i.e., $ l is a nested alias for $ ls --color=auto -CF.

By the way, the utility ls is a bit different on a Mac OS X system, since it is a BSD version of ls whereas on Linux it is GNU version of ls. The two are very similar but some of the options are different. In any case, the use of alias is identical, so I will not go into the difference of BSD ls and GNU ls here.

Next up is bash function. Although alias can shorten the commands quite significantly, it does not support arguments. That is when the bash function comes very handy. Consider the example below.

 To search for files and directories, I often use the command $ find / -name name_to_search 2> /dev/null. Again, typing this command repeatedly makes my fingers very tired. I'd like to create an alias for this, but I can't because I need to supply the argument name_to_search and alias does not support it. So, I will need to make a function here.
$ f() { find / -name $1 2> /dev/null; }

Now if I run $ f bash, it will execute the command $ find / -name bash 2> /dev/null. Note that $1 is the first argument, $2 is the second argument, and so forth. For example, the function below will take two arguments.
$ ff() { find / -name $1 -type $2 2> /dev/null; }

Now, if I execute $ ff bash f, this will execute $ find / -name bash -type f 2> /dev/null. Again, you can save these functions in the ~/.bashrc for Linux for ~/.bash_profile for Mac OS X to load the function automatically at the startup of the terminal.

Tuesday, January 26, 2016

How to Build and Install Numpy, Scipy, and Matplotlib Packages on Ubuntu

This is a continuation from the last post on How to build and install the latest version of Python on Ubuntu. If you are simply looking to install Python packages, such as numpy, scipy, and matplotlib, on the default system Python (which is 2.7.6 for Ubuntu 14.04 LTS), the answer is quite simple:
$ sudo apt-get install python-numpy python-scipy python-matplotlib -y

The command will install the packages in the /usr/lib/python2.7/dist-packages directory. With this method, however, you can import those packages from the system default Python (version 2.7.6) but not from newly installed Python (version 2.7.11). Thus, in this post we will go over the steps to build and install the Python packages for the newly installed version.

First, we need to install setuptools package. We will need to download the script and run it.
$ wget https://bootstrap.pypa.io/ez_setup.py && sudo python ez_setup.py

Next, we need to install pip package. We will download the archive, extract, and run the script
$ wget https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
$ tar -xf pip-8.0.2.tar.gz
$ cd pip-8.0.2
$ sudo python setup.py
$ cd ..

Finally, use pip to install the packages
$ sudo pip install numpy scipy matplotlib

It will take quite some time to build, so please be patient. The packages will be installed in /usr/local/lib/python2.7/site-packages directory.

How to Build and Install the Latest Version Python on Ubuntu

Ubuntu 14.04 LTS comes with Python 2.7.6 and 3.4.0 pre-installed. However, sometimes you may wish to install the most recent version, say 2.7.11 as of now along with the default system python. Unfortunately, Ubuntu's repository does not have the most recent version, so you will need to manually build Python from source files. This post will show you how to do so. Note that in this example, I will be installing 2.7.11, but you may want to use a different version as desired.

Before we do anything, let us examine where the system default Python is located and what version it is

$ which python
/usr/bin/python

The which  command shows the file which will be executed upon running the command $ python in shell. This is the default Python file pre-installed on the system. To check its version, run

$ python --version
Python 2.7.6

So, the default version that comes with Ubuntu 14.04 LTS is indeed 2.7.6 and is located in the /usr/bin directory.

OK, let us now start the installation process for the latest version 2.7.11. First, download the Python source archive file
$ wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz

Extract the files
$ tar -xf Python-2.7.11.tgz

Enter the directory
$ cd Python-2.7.11

Before we configure, we must install quite a few packages necessary to build Python successfully. Although not all of the packages below are required, I recommend getting them because they will be needed for installing packages later on, such as numpy, scipy, and matplotlib, which I will cover in the next post.
$ sudo apt-get install -y build-essential gcc-multilib g++-multilib libffi-dev libffi6 libffi6-dbg python-crypto python-mox3 python-pil python-ply libssl-dev zlib1g-dev libbz2-dev libexpat1-dev libbluetooth-dev libgdbm-dev dpkg-dev quilt autotools-dev libreadline-dev libtinfo-dev libncursesw5-dev tk-dev blt-dev libssl-dev zlib1g-dev libbz2-dev libexpat1-dev libbluetooth-dev libsqlite3-dev libgpm2 mime-support netbase net-tools bzip2 libblas-dev liblapack-dev gfortran

Now, configure
$ ./configure

Then build
$ sudo make install

It will take some time to build and install. When complete, we verify whether Python is now updated to 2.7.11 version
$ python --version
Python 2.7.11

Great. So, the question is, did we just overwrite the system's default python? The answer is no; we actually installed the new version on the system side by side from the old one, so the old version is still intact. How do we figure? Simply run

$ which python
/usr/loca/bin/python

The output shows that the command $ python will now execute /usr/local/bin/python, which is different from the old one /usr/bin/python. To verify this, see if we can still run the old one

$ /usr/bin/python --version
Python 2.7.6

So, the old one is still there; if we need to run the old one, we just need to execute it by the full path. This is because the default $PATH environment looks something like this

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

The directory /usr/local/bin, where version 2.7.11 is installed, precedes the directory /usr/bin, where version 2.7.6 is installed. Thus, when we run $ python command, it will execute the Python file in /usr/local/bin, thus running the 2.7.11 version.

Thursday, January 21, 2016

Setup Latex Environment for Ubuntu

I personally use TexWorks for creating and editing TEX documents. I also often use IEEEtran.cls package along with many other related scientific packages, such as subfig, etc. This post will go over how to install these packages successfully in the Ubuntu environment.

First off, add the TexWorks repository
$ sudo add-apt-repository ppa:texworks/stable -y

Install TexWorks and lots of latex-related packages that are frequently used
$ sudo apt-get install -y texworks texlive-fonts-recommended texlive texlive-latex-extra texlive-math-extra texlive-pstricks texlive-science latex-beamer

Download IEEEtran.zip file from http://www.ctan.org/tex-archive/macros/latex/contrib/IEEEtran/ by
$ wget http://mirrors.ctan.org/macros/latex/contrib/IEEEtran.zip

Unzip the file to the latex package location
$ sudo unzip IEEEtran.zip -d /usr/share/texmf/tex/latex/IEEE

Let tex know that the package has been added manually
$ sudo texhash


Now, you should be able to run TexWorks and compile TEX files!

Tuesday, January 19, 2016

Installing Muliple Desktop Environments in Ubuntu

I love to try new things out. In that respect, I love trying different various desktop environments on Ubuntu.

Ubuntu comes default with Unity desktop, but you can install other desktop environments as well. To install Ubuntu desktop environment, simply run
$ sudo apt-get install -y --no-install-recommends desktop_environment_to_install

where desktop_environment_to_install can be any of the following corresponding to the desktop environment in parentheses:
ubuntu-gnome-desktop (GNOME)
kubuntu-desktop (KDE)
ubuntu-desktop (Unity)
ubuntu-mate-desktop (MATE)
xubuntu-desktop (Xfce)
lubuntu-desktop (LXDE)

When you have multiple desktop environments installed, you may be able to choose one at the log-in screen.

Sunday, January 17, 2016

How to Find Configuration Files in Linux (GNOME example)

When you change the computer's setting or configuration, the change must be saved as a file somewhere. This means that if you search through your files system for files that have been created or modified after you have applied the change, you will be able to locate exactly where your setting or configuration is stored on the system.

For example, assume you want to change the font size of the default terminal profile. Well, when you apply the change, this must have changed some file on the system that saves this setting, but what is this file and where is this file even located?

In this post, we will look into ways to locate exactly which files have been modified and how using find command in terminal. The basic idea is pretty simple: you simply look for all files on the system that have been modified since you have applied the change. Here is step by step instructions:

First, create a timestamp file:
$ touch timestamp

When you type
$ ls -l timestamp
you will see the file's modified time, which should be just a second ago.

Next up, you change any setting or configuration. It is recommended that you do one change at a time unless you know what you are doing. I am going to change the font size of the default terminal profile.

Then, look for files that have been modified after the timestamp file by
$ find / -type f -newer timestamp -not -path "/proc/*" -not -path "/run/*" -not -path "/dev/*" 2> /dev/null

The command is very long and intimidating at first glance. Let us break down the command and look at each option one by one:

find / command will search all files and folders in the root directory. Note that if you change the configuration that pertains to a specific user, the file is saved in the user directory, i.e., ~ or /home/username. In this case, you may want to type in find ~ instead.

-type f will search for files only, not directories; this is because the configuration or setting will be saved as a file.

-newer timestamp will only find those that have been modified after that of timestamp file, which we have created in the first step.

-not -path "/proc/*" option will exclude those in the /proc directory from the result; we are doing this because /proc directory contains process information, which change constantly, so we want to opt this directory out. Note that this option only pertains to find /, since find ~ will not search for /proc directory anyway.

-not -path "/run/*" option will exclude those in the /run directory from the result; /run directory contains run-time variable data. This directory may change regardless of the configuration change, so we will opt this directory out as well.

-not -path "/dev/*" option will exclude those in the /dev directory from the result. Note that it is extremely unlikely that the configuration change is saved in either /proc, /run, or /dev directories.

2> /dev/null will ignore any error messages, such as those that complain for permission denied. You may get rid of this option by using sudo. More on this later.

When you prompt the aforementioned command, you will get output something similar to
/home/unixnme/.config/dconf/user
where it is obvious that the first file ~/.config/dconf/user is the configuration setting file that is responsible for terminal profile. Unfortunately, this file is not a simple plain-text configuration file, so it is a bit difficult to open up and read the file. However, you can try the following:

Open up the file with vim
$ vim ~/.conf/dconf/user

Within vim, search the text 'Monospace' by entering
/Monospace
You will most likely see a string Monospace, the default terminal font, within this file. As a matter of fact, this is actually the right file; you will see the font size in number right next to the string. I will cover this in more details in the later post. Quit vim by pressing ESC key and entering
:q!

Although in most cases, the configuration file should be readable by the user, it is not the case all the time. In this case, one will need to invoke sudo
$ sudo find / -type f -newer timestamp -not -path "/proc/*" -not -path "/run/*"

I will cover more details of this ~/.conf/dconf/user file in the later post.