Friday, May 14, 2010

Fedora RPM Packaging In A Nutshell

I have talked about RPM and DEB in some of my older posts. Actually RPM and and DEB are installable packages analogous to .exe files for windows. In this post I won't teach you how to build an rpm but I will give you a vague idea and point out some resources and tutorial to get you started. Let us do it in a question-answer way.

Q. What do I need to build a rpm package?
A. The most important thing you need is the source code of the application. You will also need the packages required to build the application from the source a.k.a. the dependencies.

Q. Why should I build an rpm?
A. Not everyone is a techie like you. People have the habit of double clicking the stuff. rpm is for those people and it saves the effort of installing everything from scratch and remembering dependencies.

Q. How hard is it?
A. The general packaging procedure is not very hard but still sometimes packaging can take quite sometime. More dependencies increase difficulty of the package.

Q. From where should I start?
A. You can start by checking out the tutorial at https://fedoraproject.org/wiki/A_Short_RPM_Tutorial. A more advanced tutorial can be found at https://fedoraproject.org/wiki/How_to_create_an_RPM_package but if you are looking for a summary then this post will suffice.

Q. So, tell me how do I build rpm for an application?
A. That depends somewhat on the distro because every distro has different packaging guidelines. I will talk about Fedora here.
To create a package, you need to have a spec file first. Spec file consist of details about the package such as its name, version, dependencies, the way it is going to install etc. You can check out some spec files created by me here. Once you have created a spec file properly, you can easily create a package by rpmbuild command.

Q. How do I set up a nice packaging environment on my distro?
A. Again that is distro dependent. Being a hard core Fedora fan I will tell you how do setup the packaging environment on Fedora. Just fire the following commands:
yum install @development-tools
yum install rpm-build rpmdevtools
rpmdev-setuptree

Q. I have the setup the packaging environment, what next?
A. Once you have created a packaging environment, you'll get a directory named rpmbuild in your home folder. Inside this folder you'll see several other folders. You need to put the archived source code along with relevant patches in SOURCE folder. After that you need to fire the following commands assuming that you are currently in SOURCES folder:
cd ../SPECS
rpmdev-newspec

This will create a spec file for the corresponding app. Now you need to fill the spec file with correct details. For this check out http://fedoraproject.org/wiki/PackagingGuidelines

Q. I have written a spec file. How do I get src.rpm and rpm from it?
A. Once you are sure about your spec file then you can get rpms using a very simple command:
rpmbuild -ba

You can find the rpm and src.rpm in relevant folders inside rpmbuild directory.

Well, there you go! You have the rpms ready to be used. Have fun!

Share/Save/Bookmark

Sunday, April 25, 2010

Automating Your Job, The CRON Way!

Often you require to do some stuff periodically like backups or maintenance work. It might be a bit difficult if you have to do it manually every time. You have to have a working net connection if you are doing it remotely or you need to be physically present in front of your computer system. Then you have to repeat certain tasks which you do every day. Won't it be nice if you could just put everything in a simple script that could run automatically every time. CRON comes to your rescue here. CRON is nothing but a text file consisting of the path of scripts to be executed and the time according to which it'll be executed. First of all let me tell you some of the most general commands for setting up a cron table.

crontab -e --> Edit your crontab file.
crontab -l --> Show your crontab file.
crontab -r --> Remove your crontab file.
crontab -v --> Display the last time you edited your crontab file

There is a fixed format for the way an entry has to be made in a cron file. I found an interesting way of showing it here which I am replicating.

* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

You can also use special entries. Below is a list for them:

Entry          Description             Equivalent To

@reboot  Run once, at startup.  None

@yearly  Run once a year  0 0 1 1 *

@annually  (same as @yearly)  0 0 1 1 *

@monthly  Run once a month  0 0 1 * *

@weekly  Run once a week  0 0 * * 0

@daily          Run once a day          0 0 * * *

@midnight  (same as @daily)  0 0 * * *

@hourly  Run once an hour  0 * * * *

A sample cron file looks like this.
Share/Save/Bookmark

Monday, April 5, 2010

Git For Newbies

Note: This is not a complete guide for git. It will just help you getting started and using gitorious.org smoothly.


Introduction

Git is a versioning system. It is an ideal tool for managing projects, revisions and stuff like that. Anyone who wants to contribute can clone the code repository, make the changes or add some code and request for merge. This way bug fixes can be done and new features can be added. Gitorious provides open source infrastructure for hosting open source projects that use Git. The central entity in Gitorious is the project, which contains one or more top-level repositories and any repositories managed by the project's contributors.


Cloning A Repository on gitorious.org

We will use gitorious.org's hosted git for example. First of all you need to register yourself with gitorious.org which is a straight forward step. We are going to use ownCloud, a KDE project, for illustration. Next, go to http://gitorious.org/owncloud/owncloud and click on "Clone this repository on Gitorious" from the right sidebar. Congrats! you have created a clone for yourself.


Cloning A Repository On Your Local Machine

We have to do this the hard way. I am considering the Ubuntu Linux in my mind. First of all we need to install git. For that fire the following command
sudo apt-get install git-core

Once you get the git on your system, let us now create the clone. For that fire:
git clone git://gitorious.org/owncloud/owncloud.git

Now that you have the code, you can start with the bug-fixes and contribute code.


Commit To Local Git

After you make the changes to the code or add some file, you'll need to commit that to your local git repo. If you have added some files then you have to tell git to track the new files by using the following command:
git add file-name.

Once the files are added then you can commit to the git repo by firing the following command:
git commit -a

You'll be presented with a file where you have to describe the changes you made. Keep it short and to the point.


Pushing To Gitorious

Now you can push the changed repository to the gitorious.org repo by:
git push git@gitorious.org:path-to-your-repo.git master

This will push the repo from your system to gitorious.org. Now request a merge from the right sidebar. Someone will look at your request and your work will be added to the main repo if found fit.
Share/Save/Bookmark
 
Creative Commons License
blog.adityapatawari.com by Aditya Patawari is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 India License.