Setting up a Git Repository on A Remote Server

Git is a wonderful distributed version control system and we can have a personal repository quickly set up without any technical difficulties. However at times we may need to work on shared development model where multiple people need commit access to the code. In such cases we would need a centralized repository store.

By following  the given steps we will be able to set up a shared git repository accessible over SSH.

  • First a user needs to be created to hold the git repository (multiple repositories can also be set up under the same git user). Next a password need to be set up for the same user. Since this user will  never log on using shell, a password which is secure, random, very long string is a good option.
$ sudo /usr/sbin/useradd -c "Git Version Control" -d /home/git -m -s /bin/bash git
$ sudo passwd git
  • Next login as git user and create the project directory to hold the repository and then initialize that directory as a barebones (blank) git repository
$ mkdir -p /home/git/projects/myproject1.git
$ cd /home/projects/myprojects.git
$ /usr/bin/git --bare init
  • Set up the .ssh directory for the git user to hold the authorized_keys file with the public ssh keys for the user allowed to log in a git user and access the repository
$ cd /home/git
$ mkdir .ssh
$ chmod -R 700 .ssh
$ touch .ssh/authorized_keys
$ chmod 644 .ssh/authorized_keys
  • Finally change the shell of the git user to git-shell so that interactive logins for the user are not possible and only selected remote git commands are allowed.
$ /usr/bin/chsh -s /usr/bin/git-shell

Add the public key of the user(s) to the authorized key file. These users will be able to access the repository. Now all that needs to be done is to clone the repository and start working. Following command can be used to clone the repository on a *nix box. The 7652 is the port number where ssh daemon is listening. If your port is the default, 22, you can skip this port number.

$ git clone ssh://git@myhost.mydomain.com:7652/home/git/projects/myproject1.git/
Posted in FLOSS | Tagged , | Leave a comment

Time-zone Setting in Linux and BSDs from Shell

Often the default time-zone in a linux and bsd system does not match our preferences. On a system which we have installed ourself, we may have selected the appropriate time-zone during installation, but as systems administrators we often get our hands on a system which is pre-installed and after taking over we want to change the time-zone to something which we are comfortable understanding and co-relating various system events in the time of our comfort.

The time-zone of  the system is determined by a file called “/etc/localtime”, which a binary file. In order to change the time-zone, we need to replace this file with an appropriate file of our time-zone. All time-zone files are found in “/usr/share/zoneinfo”.

On some systems “/etc/localtime” is a copy and in some cases a hard link of one of the time-zone found in “/usr/share/zoneinfo” directory. In OpenBSD, “/etc/localtime” is a symlink to one of the files in “/usr/share/zoneinfo”. I prefer the symlink approach, you can pick any of the methods to make appropriate “/etc/localtime” file available.

In order to change the time-zone of my system from UTC to IST, I did the following.

$ sudo ln -sf/usr/share/zoneinfo/Asia/Kolkata /etc/localtime

In case you accidentally delete the “/etc/localtime” file, the timezone of the system reverts to UTC and upon having the correct file present again, it will reflect the correct timezone again. See below (I did this on a RHEL 6 machine) –

$ date
Wed Dec 18 13:56:05 IST 2013
$ sudo rm -f /etc/localtime
$ date
Wed Dec 18 08:36:29 UTC 2013
$ ls -l /etc/localtime
ls: cannot access /etc/localtime: No such file or directory
$ sudo ln -sf /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
$ date
Wed Dec 18 14:07:03 IST 2013

 

Posted in FLOSS, Tips/Code Snippets | Tagged , , , , , , | Leave a comment

FreeBSD 9.1 on Thinkpad T420

beastieVery recently I was thinking of trying FreeBSD operating system on a laptop as a desktop system. FreeBSD is an excellent UNIX class of operating systems primarily used as a server on internet. Among other things the operating system posses excellent memory management features, ZFS and LLVM etc.

I have installed various BSD class of operating systems earlier also, but when I installed FreeBSD 9.1 this time, I noticed that the default disk partitioning options have changed in the installer. By default if the automatic partitioning option is chosen, FreeBSD creates GPT (GUID Partition Table). I decided to proceed with all default options except the timezone settings were changed to IST.

At the end of the install, the system refused to boot from the hard disk. I thought this is because the BIOS may be configured to use the UEFI (Unified Extensible Firmware Interface) being configured in BIOS as the laptop had windows 7 installed in it. I tried changing the setting to – disable, EUFI/legacy, legacy – but still the laptop did not boot. Upon my research on the internet I came across – https://wiki.freebsd.org/UEFI. Here it was mentioned that –

Partitions not seen. When using GPT, FreeBSD will create a protective MBR. This MBR has one partition entry covering the whole disk. FreeBSD marks this partition active. This causes at least some UEFI implementations to ignore the GPT. To fix this the partition needs to be marked inactive. This should be fixed as of r251588, to be confirmed.

Running

fdisk /dev/sda0

from the live mode in FreeBSD confirmed that there is an MBR partition created and the flag 80 (active) has been set on it. I booted from a linux CD and ran

fdisk -l /dev/sda0

to confirm that this is indeed the case. So I used linux fdisk to remove the active flag (toggle option), but this did not help me.

At this moment I decided to drop this issue here and take the easy way out in order to get the operating system installed. During the installation this time I chose manual partitioning –

  • deleted all partition
  • changed the partitioning scheme to MBR (the default was GPT)
  • created a FreeBSD partition on it with further two partitions (slices) within the FreeBSD disk area
    • one as type freebsd-swap
    • other freebsd-ufs (mounted at /).

During the end of the installation an option to go to shell for additional installation is provided. I selected that option and then ran the

sysinstall

utility and selected options as follows –

sysinstall -> Configure -> Packages -> FTP -> Main Site

Selected all the desired software and finished the installation. The reboot took me straight to FreeBSD.

Enabling UTF-8

The available locales can be checked using the locale command. In order to find out the UTF-8 locale which are installed –

# locale -a | grep UTF-8|grep US
en_US.UTF-8

In order to add the support for this locale, following lines need to be added in /etc/login.conf –

:charset=UTF-8:\
:lang=en_US.UTF-8:

Finally run the –

#cap_mkdb /etc/login.conf

Now in order to use these following two environment variables can be set –

LANG=en_US.UTF-8
GDM_LANG=en_US.UTF-8

Installing X windows and Windows Managers

Since I wanted to get a graphical desktop on the laptop, I need to install X windows, a window manager and some other graphical tools like browser etc.

# pkg_add -r x11 ratpoison awesome stumpwm firefox

Configuring X and starting is done as below –

# X -configure
# cp /root/xorg.conf.new /etc/xorg.conf
# cat ~/.xinitrc
export LC_ALL=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
exec /usr/local/bin/ratpoison

Following two lines needs to be added to

/etc/rc.conf

for the X to work correctly –

hald_enable="YES"
dbus_enable="YES"

and then finally

startx

to launch the X. May be later on I will install one of the display managers to facilitate graphical login.

So I am ON with freebsd and now I can start learning/exploring this further and may be try some of the other BSDs along with this as multiboot. I have not really worked on BSDs from quite sometime. I expect this to be a good refresher.

Posted in FLOSS | Tagged | Leave a comment

Raspberry Pi And Me

I bought a Raspberry Pi somewhere in March this year. After a very hectic schedule, I managed to find few hours yesterday evening to explore it. I bought the following accessories in order to use it –

  • A Belkin 4-port powered USB Hub
  • Netgear Wireless USB Micro Adapter
  • Dell LCD Monitor (wall mounted). This was a cheap VGA based
  • HDMI to VGA converter. Raspberry Pi has HDMI port, so I needed a converted to attach it to my monitor.
  • A USB A to USB Micro cable to power the Raspberry Pi
  • iBall Wireless USB Keyboard and Mouse
  • 32 GB MicroSD card with a Micro SD to SD card adapter

The LCD and USB hub occupies the power sockets. The Raspberry Pi is powered from the USB hub using a USB A to USB micro cable. The two USB ports on the Raspberry Pi have been occupied with the USB Hub and iBall wireless adapter for Keyboard and Mouse. The Netgear wireless adapter has been connected to the USB Hub and so is my external HDD for extra storage.

I am using Raspbian (a variant of Debian meant for Raspberry Pi), distributed by the the Raspberry Pi Foundation, which is a little different from the images by Raspbian project.

I had (and still have) some problems with booting while my monitor is connected, perhaps because the HDMI to VGA converter is drawing too much power from the RPi. I need to look into it later.

The initial idea of using it as a light weight desktop environment is not going to work because of lack of flash support, and speed related issues. Although HTML 5 videos can be played, they need a separate configuration for the installed browser Midori. More on that configuration later.

In general it is a bit slower because all the applications are not designed to use the GPU effectively and the processor is too slow by even the standards of a high end mobile phone. Although I am typing this blog post on RPi using Midori web browser, I can feel the slowness while trying to add pictures as an attachment which needs JavaScripts to be processed at client side. I tried opening up the Yahoo Mail earlier today, it worked but it was very slow, almost unusable.

However, I have observed that it is ok for teaching programming to kids and also I can perhaps run it as a headless media player using XBMC and so on. For now I have installed Perl, Python and FreeBasic programming environments on this. All of which should work through command line effectively.

I will make further posts sharing my experience on this credit card size device.

Stay tuned.

Posted in RaspberryPi | Tagged | 1 Comment

Creating a DEB package for Oracle Java

Linux based operating systems comes by default with Open JDK installations. Often it is necessary for various developmental needs to install the Oracle Java. Oracle only supplies two installations of Java for Linux based operating systems – a rpm and a tar.gz binary distribution.

For RPM based distributions it is fairly easy to have the uniform setup on a large farm of servers, but on DEB based distributions a lot of manual work needs to be done at each host after unpacking the tar.gz file such as updating the alternatives etc to make the Oracle Java a default Java installation.

I have been thinking about how to deploy Oracle Java SDK on multiple Debian servers in a standardized way i.e by creating a DEB file.

A search on Debian Packages revealed the existence of a tool called – “make-jpkg”, a part of “java-package” package. This tool is capable of creating a DEB package from this tar.gz file. Here is how I created the package –

$ sudo apt-get install fakeroot java-package

I downloaded the Oracle Java Standard Edition  on my Linux Mint Debian Edition (LMDE) virtual machine.

Next I ran the command –

$ fakeroot make-jpkg --full-name "Ajitabh Pandey" --email "ajitabh@unixclinic.com" /home/ajitabhp/Downloads/jdk-7u25-linux-x64.tar.gz

I got an error stating “No Matching Plugin was found”

Just above this error message the plugin path was given for various plugins used by this utility – “make-jpkg”. The plugins were in /usr/share/java-package directory in the form of “.sh” files (shell scripts). I next opened each shell script to try and decipher them and found the possible problem in the plugins “/usr/share/java-package/oracle-j2*.sh”. The following pattern picked up from “/usr/share/java-package/oracle-j2sdk.sh” was the culprit –

"jdk-7u"[0-9]"-linux-x64.tar.gz") # SUPPORTED
j2se_version=1.7.0+update${archive_name:6:1}${revision}
j2se_expected_min_size=180 #Mb
j2se_priority=317
found=true
;;

If you see this pattern, it clearly indicates that it is only supporting up to update 9 of the JDK and the JDK I downloaded was update 25. So I added the following lines just below the above lines to add the support for my version.

"jdk-7u"[0-9][0-9]"-linux-x64.tar.gz") # SUPPORTED
j2se_version=1.7.0+update${archive_name:6:2}${revision}
j2se_expected_min_size=180 #Mb
j2se_priority=317
found=true
;;

There are two differences, one in first line and the second in second line. I am sure you will be able to spot them and decipher them.

After making similar changes in the other oracle* files I ran the make-jpkg as mentioned above and it created a DEB file – oracle-j2sdk1.7_1.7.0+update25_amd64.deb, which is deploy-able with the usual “dpkg -i”.

Changing the Default Java Installation to the Oracle Installation

After installing the package, you may want to change some alternatives in order to make the Oracle JDK and associated JRE installations as defaults. As the default version of Java may be something different. You can check the current version of java and its provider by –

$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
$ file `which java`
/usr/bin/java: symbolic link to `/etc/alternatives/java'
$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 46 Aug 16 20:18 /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java

First find out the name of the available installations –

$ /usr/sbin/update-java-alternatives -l
j2sdk1.7-oracle 317 /usr/lib/jvm/j2sdk1.7-oracle
java-1.6.0-openjdk-amd64 1061 /usr/lib/jvm/java-1.6.0-openjdk-amd64

We will switch our default Java to “j2sdk1.7-oracle” with the following command –

$ sudo /usr/sbin/update-java-alternatives -s j2sdk1.7-oracle

Now you can check your Java version by

$ java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
$ file `which java`
/usr/bin/java: symbolic link to `/etc/alternatives/java'
$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 41 Aug 16 20:22 /etc/alternatives/java -> /usr/lib/jvm/j2sdk1.7-oracle/jre/bin/java

Posted in FLOSS, Tips/Code Snippets | Tagged , , | 1 Comment