注意:

The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.

Portage Git Mirror

From Funtoo
Jump to navigation Jump to search

Setting up local git mirror

This tutorial explains how to save bandwidth when several local computers need to pull updates from a single remote git repository.

Use case

The more local funtoo instances you are maintaining, the more useful this will be to you. This -- along with a local Portage_Distfiles_Mirror -- can make maintaining multiple funtoo instances much faster, much more bandwidth efficient, and much less burdensome to upstream resources.

Terminology used herein

Following terms should be adapted

Terms Definition
git.lan The git-daemon local mirror host
localhost Any local host
nobody Owner user of .git files
/home/git-mirrors Base path of git-daemon

Local mirror

Prepare directories and get portage tree

root # mkdir /home/git-mirrors
root # chown nobody /home/git-mirrors
root # su -s /bin/sh nobody
user $ cd /home/git-mirrors
user $ git clone --mirror --bare git://github.com/funtoo/ports-2012.git portage.git

For security purposes we will use the nobody user .

git-daemon configuration

   /etc/conf.d/git-daemon
GITDAEMON_OPTS="--syslog --verbose --enable=receive-pack --export-all"
GITDAEMON_OPTS="${GITDAEMON_OPTS} --base-path=/home/git-mirrors /home/git-mirrors --interpolated-path=/home/git-mirrors"
GIT_USER=nobody
GIT_GROUP=nobody

Service configuration

To start daemon with a mirror machine boot add git-daemon to default runlevel

root # rc-update add git-daemon default

To make changes start immediately just run rc

root # rc

Pull from remote

If desired, the local mirror can be updated periodically using cron. This example updates daily:

   /etc/cron.daily/funtoo-sync.sh
#!/bin/sh
cd /home/git-mirrors/portage.git
su nobody -s "/bin/sh" -c "git fetch"

Then make the file executable:

root # chmod +x /etc/cron.daily/funtoo-sync.sh

You can also update the local mirror using emerge --sync or eix-sync if you have app-portage/eix installed.

Cloning from the local git mirror

In order to get a funtoo instance to sync with the local git mirror, the instance's portage directory will need some work.

The following is used with any funtoo instance you wish to use your local git mirror for its tree. This will change the git remote origin to point to your local git.lan origin, and then start using it. (This is an updated method which obviates the need to create a /usr/portage.old copy of the existing /usr/portage directory.)

Local clone from git.lan:

root # cd /usr/portage
root # git clone --depth 1 git://git.lan/portage.git tmp
root # rm -r .git
root # mv tmp/.git .
root # git reset --hard
root # chown -R portage:portage /usr/portage
root # eix-sync
   Note

Use emerge --sync if you do not have app-portage/eix installed.

A less reliable method is to leverage git's ability to switch between remote repositories. It can lead to conflicts and is generally more difficult to deal with if you're unfamiliar with git.

   Note

github.com/funtoo/ports-2012 uses funtoo.org as its main branch. github.com/funtoo/ports-2017 uses master. Substitute --track funtoo.org with --track master in the below command for the ports-2017 portage tree.

Local clone from git.lan:

root # cd /usr/portage
root # git remote show origin
root # git remote rm origin
root # git remote add --track funtoo.org origin git://git.lan/portage.git
root # git remote show origin
root # git branch --set-upstream-to=origin/master master
root # emerge --sync