April 05, 2013

Setting up a debian repository with reprepro

So you're rolling your own?! Let's distribute em to the masses then, you know they want them! I'm using reprepro for distribution, installing is straight forward just check the guide in the link.

The repository I have is located remotely on a server machine, where I can only ssh and scp packages to either my home, or the repository folder. This setup has some drawbacks when scripting for repository update compared to a local database.

When working using ssh and tools like this you should setup ssh_agent as it will be really really help full. So, unless you get off on typing your password to the remote machine all the time, configure ssh agent.

The repository database is present on the repository_server in the normal www directory. /var/www/repository. This is the directory you should use when setting up the repository. The repository user have only write access to the users home folder and the repository server.

repository_user@repository_server:/home/repository_user & repository_user@repository_server:/var/www/repository


The setup for including packages to the remote repository, is that the binary packages  must first be uploaded to the repository server and secondly included in the repository. The upload part is done on your local machine and the inclusion in done remotely.

The first copy part is straight forward using scp

scp package repository_user@repository_server:/home/repository_user

The second part with the package inclusion must be run on the repository_server, you do this by directing the script to the ssh connection:

ssh repository_user@repository_server << ENDSSH
  <your script>
ENDSSH

The following listing is the script that I use to maintain my repository

#!/bin/bash

function die {
    echo $1;
    echo;
    exit 1;
}

package=$1;
repro_dir=$2
user=<repository_user>
host=<repository_server>
ext=deb;
backup_dir=old_packages;
home_dir=/home/$user;

test -z "$package" && test ! -f "$package" && die "No package!";
scp $package $user@$host:$home_dir;
ssh $user@$host << ENDSSH;
test ! -f $package && echo "No package!" && exit 1;
test ! -d $repro_dir && echo "No repository dir!" && exit 1;
test ! -d $backup_dir && mkdir -p $backup_dir;
find $repro_dir -name "${package%.$ext}*.$ext" -exec cp -vf {} $home_dir/$backup_dir \;
md5sum ~/$package > /dev/null;
cd $repro_dir;
reprepro includedeb mk3 ~/$package;
ENDSSH

No comments: