blob: 1f5717a2152411f30be23d6548f3e74af9314ca7 (
plain)
- #!/bin/sh
- set -eu
- PRG=$(basename "$0")
- showhelp() {
- cat <<EOF
- Usage: $PRG PROJECT [GIT_HOST [SSH_CONN [GIT_REMOTE]]]
- Initialize remote git, push local git, and set as default remote.
- PROJECT basename or relative path for remote git project
- GIT_HOST hostname for public git access
- default: "source." + current domainname
- SSH_CONN hostname for ssh, optionally with user + "@" prepended
- default: GIT_HOST
- GIT_REMOTE name for local repository set
- default: "origin"
- Full remote path becomes SSH_USER@SSH_HOST:/srv/git/GIT_HOST/PROJECT.git
- When local repository set is "origin" it is marked as default remote.
- Examples:
- $PRG myproject
- $PRG some/subproject git.example.org me@shell.example.org
- EOF
- }
- exit1() {
- echo >&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_HOST=${2:-source.$(dnsdomainname --domain)}
- SSH_CONN=${3:-$GIT_HOST}
- GIT_REMOTE=${4:-origin}
- [ origin != "$GIT_ORIGIN" ] || ORIGIN_IS_DEFAULT=yes
- ssh "$SSH_CONN" git init --bare --shared /srv/git/"$GIT_HOST"/"$PROJECT".git
- git remote add "$GIT_REMOTE" "$SSH_CONN":/srv/git/"$GIT_HOST"/"$PROJECT".git
- git push ${ORIGIN_IS_DEFAULT:+--set-upstream "$GIT_REMOTE"} master
|