~solevis

Serveur GIT sur NetBSD

Ca fait un petit moment que j’y pensais, et c’est maintenant chose faite : J’utilise GIT pour gérer mes divers projets (ça se bouscule pas au portillon) et surtout la doc et le blog. Pour les deux derniers ça m’enlève une grosse épine du pied, je ne suis plus obligé d’être sur le serveur pour éditer ou ajouter du contenu. De plus grâce aux hooks je peux générer chaque contenu dès que je push sur le serveur.

Comme il n’y a pas de réel howto pour installer un simple serveur git sur NetBSD, je me suis permis d’en rediger un :


Installation de GIT

root# pkgin in scmgit

ou

root# cd /usr/pkgsrc/devel/scmgit
root# make install clean

Configuration du système

Création d’un utilisateur git :

root# groupadd git
root# useradd -m -g git git

Creation d’un dépôt GIT

Création d’un dépôt:

user% su - git
git% mkdir /home/git/repos/
git% git init --bare /home/git/repos/foo.git

Pour rendre le dépôt public :

git% touch /home/git/repos/foo.git/git-daemon-export-ok

Daemon GIT

Lancement du serveur :

git% /usr/pkg/libexec/git-core/git-daemon --base-path=/home/git/repos/ --listen=votre_ip

Si tout marche pour le mieux, on créé un script rcng dans /etc/rc.conf:

root# $EDITOR /etc/rc.d/gitdaemon
#!/bin/sh
#
# PROVIDE: gitdaemon
# REQUIRE: DAEMON

. /etc/rc.subr

name="gitdaemon"
rcvar=$name
pidfile="/var/run/$name.pid"
command="/usr/pkg/libexec/git-core/git-daemon"
command_args="--detach --base-path=/home/git/repos --user=git --group=git --pid-file=$pidfile"

load_rc_config $name
run_rc_command $1

On applique les bon droits :

root# chmod 755 /etc/rc.d/gitdaemon

On l’ajoute dans rc.conf :

root# echo "gitdaemon=YES" >> /etc/rc.conf

On le lance :

root# /etc/rc.d/gitdaemon start

Recuperation du dépôt sur un client lambda

Tout simplement :

user% git clone git://mon.serveur/foo.git

Recuperation du dépôt puis push via SSH

On ajoute notre clef publique sur le serveur :

user% su - git
git% mkdir /home/git/.ssh/
git% $EDITOR /home/git/.ssh/authorized_keys

On récupère le dépôt via ssh :

user% git clone ssh://git@mon.serveur:port/home/git/repos/foo.git

On test :

user% cd foo
user% touch bar
user% git add bar
user% git commit

On positionne la branche :

user% git push origin master

On push :

user% git push