summaryrefslogtreecommitdiff
path: root/localgit-remote-init-push
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2017-02-22 16:21:42 +0100
committerJonas Smedegaard <dr@jones.dk>2017-02-22 16:21:42 +0100
commit640cb6fc116be1568cad6d2338b8bd7781cbf2b7 (patch)
tree8e15368ab84889aab2808b9dff6dd78e6cb77c76 /localgit-remote-init-push
parent7e31f6447915acf4412fb1488b66f435ef16a5b3 (diff)
Add localgit-remote-init-push.
Diffstat (limited to 'localgit-remote-init-push')
-rwxr-xr-xlocalgit-remote-init-push52
1 files changed, 52 insertions, 0 deletions
diff --git a/localgit-remote-init-push b/localgit-remote-init-push
new file mode 100755
index 0000000..5d0ab93
--- /dev/null
+++ b/localgit-remote-init-push
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+set -eu
+
+PRG=$(basename "$0")
+
+showhelp() {
+ cat <<EOF
+Usage: $PRG PROJECT [GIT_HOST [SSH_CONN]]
+
+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
+
+Full remote path becomes SSH_USER@SSH_HOST:/srv/git/GIT_HOST/PROJECT.git
+
+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 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=${4:+$4@}${3:-$GIT_HOST}
+
+ssh "$SSH_CONN" git init --bare --shared /srv/git/"$GIT_HOST"/"$PROJECT".git
+git remote add origin "$SSH_CONN":/srv/git/"$GIT_HOST"/"$PROJECT".git
+git push --set-upstream origin master