Archive for the ‘Linux’ Category

Lighttpd and gitweb

Tuesday, July 21st, 2009

I’ve begun playing around with git, and so far I’ve really liked it. I wanted a way to start sharing my repository and also be able to browse through it via a web browser. The answer turns out comes shipped with git: gitweb. It’s nothing fancy like gitorious or github but it is 100% functional and is exactly what I wanted. And since I know I’ll be setting this up again someday here’s what I did:

Assumptions: You run Lighttpd, you have a project you’ve been keeping track of with git, and you are not a grue.

First, grab the latest version of git and extract it, then run the following commands to install gitweb to your cgi-bin folder.

$ cd git-someVersion ;# as yourself
$ make prefix=/usr gitweb/gitweb.cgi ;# as yourself
# cp gitweb/git* /var/www/cgi-bin/ ;# as root

Next edit the /var/www/cgi-bin/gitweb.cgi file – basically I needed to change some paths to get the resources loading correctly. At around line 85:

#URI of stylesheets
our @stylesheets = ("gitweb.css")
our $logo = "git-logo.png"
our $favicon = "git-favicon.png"

Change these to be:

#URI of stylesheets
our @stylesheets = ("../gitweb.css")
our $logo = "../git-logo.png"
our $favicon = "../git-favicon.png"

There are other settings that you will probably want to change in this file such as $home_link_str, but they are not required for gitweb to function correctly. The cgi file is documented well enough to figure out what changes will do what. So next up is the lighttpd.conf:

Make sure cgi.assign is enabled and set to use perl:

cgi.assign = ( ".pl" => "/usr/bin/perl",
".cgi" => "/usr/bin/perl" )

Next setup the redirects and aliases for gitweb (still editing in lighttpd.conf):

url.redirect += ( "^/gitweb$" => "/gitweb/" )
alias.url += (
"/gitweb.css" => "/var/www/cgi-bin/gitweb.css",
"/git-logo.png" => "/var/www/cgi-bin/git-logo.png",
"/git-favicon.png" => "/var/www/cgi-bin/git-favicon.png",
"/gitweb/" => "/var/www/cgi-bin/gitweb.cgi",
)
$HTTP["url"] =~ "^/gitweb/" { cgi.assign ("" => "") }

This will let you go to http://servername/gitweb and view your now empty code repository (be sure to restart the server first!). To populate this repository (or add a new project) do the following on the server:

cd /var/git
mkdir project_name.git
cd project_name.git
git init

Now you if you refresh your browser you should see one project, that has no commits and a description that says “Unnamed repository; edit this…”. To change the description edit .git/description from the project_name.git directory. Now there are two things left to do. Back on your development machine (the one with your local git project) we need to tell it that the project is stored on our server:

git remote add origin ssh://servername/var/git/project.git

And lastly, commit to the server:

git push origin master

Now your gitweb should have some files and revisions histories. You can also share your project with other developers now by pointing them to your webserver.

How to backup and restore a lot of data on to dvds

Tuesday, June 30th, 2009

I’ve recently decided to backup a bunch of files stored on my server to dvds. Since I really didn’t feel the need to install X or any sort of associated desktop I decided to attempt this all on the command line. Here’s my process:

Tar up whatever needs to be backed up into a single tar file:

tar -cvf file.tar ./dir

Next split it into dvd sized chunks. This is only needed if your tar file is greater than 4.3gib. In my case it was about 14gib. Also 4.3gib = 4.7gb, so I don’t recommend messing with the –byte parameter unless you’re using dual layer or some other media type:

split --byte=4300m file.tar filePrefix

Now there should be several files ready to burn to dvd, which you can do with:

growisofs -Z /dev/dvd -r -J -allow-limited-size ./file

Since this is for backup purposes it is a good idea to use md5sums to make sure everything is correct:

md5sum ./file; md5sum /media/dvd/file

Finally in order to restore the tar file, first copy all dvds to the same directory (again I would md5sum to make sure the copies are correct) and:

cat filePrefix* > file.tar

Untar and enjoy! Now this isn’t the most convenient way of storing backups. I’d like to be able to browse the files on the dvd, but it seemed like too much work to figure out good spots to stop copying the file system onto the dvds. For now this will do, should my disk drive start failing I should have a great starting point to recover from.