Archive for August, 2007

switched over to git

August 19, 2007

I just switched over to git from cvs after a long period of putting it off. Git, so far, seems a lot easier and more intuitive to use rather than cvs. One thing I hated about cvs was that long CVS_IMPORT variable that you had to input. Git seems to be a lot more user-friendly and works well with ssh too.

Advertisements

my first ebuild

August 4, 2007

I have been using gentoo for quite a while and really love it, it gives you all the tools and more you would need. I especially love how easy it is to emerge stuff, all the dependencies are automatically installed without problems. I remember back in the days when I used Mandrake, I would have to search for hours trying to find which packages depended on which, and then manually install each one. It was really painful. Gentoo’s portage reminds me of FreeBSD’s ports that I used for half a year before switching. Gentoo, however has a much better package management system that FreeBSD, I think. Anyways, because I run a server at home, it is also behind a router, which assigns an ip address using dhcp everytime it boots up. The only way my computer can function as a server is if its DMZ ip address is set to the server. Therefore, I would have to manually update that ip address every time it is changed. Well, since computers are so good at automation, I decided to write a script in python that updates that the DMZ’s ip address every time it starts. Writing the script was relatively easy, because of python’s great urllib2 module, which can do almost anything involving http. The way Gentoo works is, it has a special folder inside /etc/init.d that have special scripts that are formatted just as if you are starting a service. For instance, to start apache, you would type:


$ /etc/init.d/apache2 start

This file also depends on a file in /etc/conf.d/ with the same name that supplies its global variables. Using ntp-client as an example, I was able to write up two files that call that script at start-up. Since this is a Gentoo-specific program, I also decided to write an ebuild, just for practice and to see what it looks like. Well, let me just say that my initial effort was fruitless. Thanks to the article on gentoo-wiki, I was able to with ease create an overlay in /usr/local/portage. When I looked at similar ebuilds, I realized that they have the syntax of a bash script, except they have custom names for installing and compiling packages. For instance, the make utility is called emake, and no use of tar is necessary, the key command is unpack. Well, initially I used dobin, which installs a file in /usr/bin, doconfd, installing in /etc/conf.d, and doinitd, installing in /etc/init.d. However, I realized soon that the files in conf.d and init.d actually have the same name, which they cannot have in the tar archive. I luckily found out they had newconfd and newinitd, which as a second argument specifies the destination file. Therefore, I could have two files with different names in the archive, but when they are installed, they will have the same name, just different paths. However, to my disappointment, when I tried to emerge the package, it said that they could not find the files in the current directory. Apparently, the current directory is known as $S (source) and the destination is $D. $S in turn translates into $WORKDIR/$P, whereas $WORKDIR is the the directory being worked on, and $P is just the name of the ebuild. In turn, through a regular cp command I realized that I needed $WORKDIR rather than $S as my current working directory. Changing into $WORKDIR worked quite well. Please check out my ebuild here.