Seite wählen

NETWAYS Blog

Sync Git repositories to GitHub

GitHub-Mark-120px-plusWhile we still have our own repositories located at https://git.netways.org it’s reasonable to sync the existing repositories to GitHub targetting a wider audience (and not everyone likes the gitorious web interface either). There are certain requirements syncing git repositories in general:

  • create, update and delete branches
  • create and delete tags
  • don’t always clone the repository but fetch local changes

Aside from that, you’ll need

  • a shell user, e.g. github on a box running the sync
  • ssh key for pushing remote origin
  • small sync script
  • a cronjob for that sync script, e.g. every 5 minutes
  • git binary >= 1.7.10 providing the –prune option

If you are planning to push your local repository (in our example, git.netways.org) to github.com, you’ll also need the following

  • add the public ssh key to your github user at https://github.com/settings/ssh
  • ensure that this user is allowed to push your company’s repositories (make it a team member)

The sync script part is easy thanks to the possibilities git already provides. An older version of the sync script is used for syncing the Icinga Github repositories in a similar fashion. For Icinga, it’s most important to sync the git tags, making the release tarballs available on Github.

#!/bin/bash
REPO_HOME="/data/scm/sync"
declare -A REPOS
# syntax is [github_repo]="netways_repo"
REPOS=([ingraph]="ingraph/ingraph" [lconf]="lconf/lconf" [lconf-icinga-module]="lconf/icinga-module" [lconf-web]="lconf/lconf-web")
cd $REPO_HOME
for REPO_GITHUB in "${!REPOS[@]}"
do
	REPO_LOCAL=${REPOS[$REPO_GITHUB]}
        echo "### Processing repo $REPO_LOCAL"
        if [ ! -d $REPO_LOCAL ]; then
                git clone --bare --mirror git://git.netways.org/$REPO_LOCAL.git $REPO_LOCAL
        fi
        (cd $REPO_LOCAL; git fetch --prune; git push --prune git@github.com:NETWAYS/$REPO_GITHUB.git +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*)
done

git {fetch,push} –prune ensures that deleted branches/tags on the source repository are also deleted on the target repository.
Saving the sync script as /data/scm/sync/create_and_sync allows you to add the following cron job every five minutes:

# su - github
$ crontab -e
# Sync repos to github
*/5 * * * * /data/scm/sync/create_and_sync > /dev/null 2>&1

Ynetways_githubou can check the result watching the development branches at https://github.com/netways for LConf and inGraph – if you’re looking for your own custom git integration, don’t hesitate to contact us 🙂
PS: Another cool way of syncing github repositories is the Icinga Exchange integration!

Hollywood auf der Bash

In diesem Blogpost möchte ich euch zeigen wie Ihr relativ einfach und ohne großen Aufwand auf der Shell eigene Kassenschlager à la Hollywood produzieren könnt. Dafür benötigte Tools stehen auf den gängigen Linux-Distributionen bereits über die Standard Utilities (util-linux bzw. util-linux-ng) zur Verfügung.
Den Großteil der Zeit eines Filmregisseurs beansprucht natürlich die aufwändige und oft kräftezehrende Produktion der einzelnen Filmszenen, wir benutzen hierzu unsere virtuelle Kamera namens script.
Script steht eigentlich für Typescript und lässt sich z.B. mit „maschinengeschriebenes Schriftstück“ übersetzen. Genau das produzieren wir jetzt! Script möchte von uns dazu lediglich den Namen der Zieldatei haben, also:

# script recordfile
Script wurde gestartet, die Datei ist recordfile

oder alternativ:

# script -f recordfile
Script wurde gestartet, die Datei ist recordfile

Nun kann die wilde Bash-Show starten und wenn wirklich keine neuen Ideen mehr nachkommen lässt sich die Aufnahme mit [Strg] + [d] beenden, es erscheint folgende Ausgabe:

# exit
Script wurde beendet, die Datei ist recordfile

Die Wiedergabe der Datei recordfile kann nun beispielsweise mit dem altbekannten cat erfolgen. Da uns diese Methode vermutlich nicht allzu viele begeisterte Zuseher einbringen wird, erweitern wir die Aufnahme um einen sog. Timingaufruf, das könnte so aussehen:

# script -t 2> time.file record.file

Natürlich muss auch hier die „virtuelle Kamera“ am Ende wieder mit  [Strg] + [d] beendet werden. Bei der Wiedergabe unterstützt uns nun scriptreplay, das die Sequenzen deutlich massentauglicher darstellt:

# scriptreplay time.file record.file

Zugegeben – unsere Zuschauerzahlen werden sich wohl noch nicht (gleich) mit denen der großen Hollywood-Blockbuster vergleichen lassen, aber was nicht ist kann ja noch werden. In diesem Sinne: Klappe… und Action!

Markus Waldmüller
Markus Waldmüller
Head of Strategic Projects

Markus war bereits mehrere Jahre als Sysadmin in Neumarkt i.d.OPf. und Regensburg tätig. Nach Technikerschule und Selbständigkeit ist er nun Anfang 2013 bei NETWAYS als Senior Manager Services gelandet. Seit September 2023 kümmert er sich bei der NETWAYS Gruppe um strategische Projekte. Wenn er nicht gerade die Welt bereist, ist der sportbegeisterte Neumarkter mit an Sicherheit grenzender Wahrscheinlichkeit auf dem Mountainbike oder am Baggersee zu finden.