summaryrefslogtreecommitdiff
path: root/localgit-remote-init-push
blob: 5d0ab93f9f4f6a2ee39945762b1511315d174a3e (plain)
  1. #!/bin/sh
  2. set -eu
  3. PRG=$(basename "$0")
  4. showhelp() {
  5. cat <<EOF
  6. Usage: $PRG PROJECT [GIT_HOST [SSH_CONN]]
  7. Initialize remote git, push local git, and set as default remote.
  8. PROJECT basename or relative path for remote git project
  9. GIT_HOST hostname for public git access
  10. default: "source." + current domainname
  11. SSH_CONN hostname for ssh, optionally with user prepended
  12. default: GIT_HOST
  13. Full remote path becomes SSH_USER@SSH_HOST:/srv/git/GIT_HOST/PROJECT.git
  14. Examples:
  15. $PRG myproject
  16. $PRG some/subproject git.example.org me@shell.example.org
  17. EOF
  18. }
  19. exit1() {
  20. echo >&2 "${1:+ERROR: }${1:-Internal error!}"
  21. exit 1
  22. }
  23. # parse cmdline options
  24. TEMP="`getopt -s h -l help -n "$PRG" -- "$@"`" || exit1
  25. eval set -- "$TEMP"
  26. while true; do
  27. case "$1" in
  28. -h|--help) showhelp; exit;;
  29. --) shift; break;;
  30. *) exit1;;
  31. esac
  32. done
  33. PROJECT=${1-$(showhelp; exit1 "project name missing")}
  34. GIT_HOST=${2:-source.$(dnsdomainname --domain)}
  35. SSH_CONN=${4:+$4@}${3:-$GIT_HOST}
  36. ssh "$SSH_CONN" git init --bare --shared /srv/git/"$GIT_HOST"/"$PROJECT".git
  37. git remote add origin "$SSH_CONN":/srv/git/"$GIT_HOST"/"$PROJECT".git
  38. git push --set-upstream origin master