#!/bin/sh set -eu PRG=$(basename "$0") showhelp() { cat <&2 "${1:+ERROR: }${1:-Internal error!}" exit 1 } # parse cmdline options TEMP="`getopt -s sh -o h -l help -n "$PRG" -- "$@"`" || exit1 eval set -- "$TEMP" while true; do case "$1" in -h|--help) showhelp; exit;; --) shift; break;; *) exit1;; esac done PROJECT=${1-$(showhelp; exit1 "project name missing")} GIT_REPO=${2:-source.$(dnsdomainname --domain)} case "$GIT_REPO" in /*) BASEPATH=$GIT_REPO ;; *) GIT_HOST=$GIT_REPO BASEPATH=/srv/git/"$GIT_REPO" ;; esac SSH_CONN=${3:-$GIT_HOST} GIT_REMOTE=${4:-origin} [ origin != "$GIT_REMOTE" ] || ORIGIN_IS_DEFAULT=yes [ -z "$GIT_CONN" ] || ssh "$SSH_CONN" git init --bare --shared "$BASEPATH"/"$PROJECT".git git remote add "$GIT_REMOTE" "$SSH_CONN":"$BASEPATH"/"$PROJECT".git git push ${ORIGIN_IS_DEFAULT:+--set-upstream "$GIT_REMOTE"} master