-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-deploy
More file actions
executable file
·49 lines (42 loc) · 947 Bytes
/
Copy pathgit-deploy
File metadata and controls
executable file
·49 lines (42 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
REMOTE=""
BRANCH="dev"
LIST=""
function usage() {
echo "Usage: $0 [-s] <remote> <branch>"
echo "Quick-and-dirty deployment:"
echo
echo "SSH to remote, and then within remote repo"
echo " fetch and rebase branch"
echo
echo "-s = simulate, dry-run"
exit 1
}
parseOpts() {
while getopts "shr:" opt; do
case $opt in
h) usage ;;
s) LIST=1 ;;
r) REMOTE="$OPTARG" ;;
*) usage ;;
esac
done
shift $(( $OPTIND - 1 ))
REMOTE="${REMOTE:-$1}"
REMOTE="${REMOTE:-origin}"
URL=$(git config "remote.$REMOTE.url")
HOST=$(echo -n $URL | sed -r 's@.+://([^/:]+).+@\1@')
RPATH=$(echo -n $URL | sed -r 's@.+://[^/:]+(.+)$@\1@;s/\.git$//')
}
main() {
[ -z "$LIST" ] && echo "SSH to $HOST"
[ -z "$LIST" ] && echo "And CD to $RPATH"
if [ -n "$LIST" ]; then
echo "ssh $HOST:$RPATH"
else
ssh -t "$HOST" "cd \"$RPATH\"; git rebase $BRANCH || bash";
echo "Deployed by rebase to $BRANCH"
fi
}
parseOpts "$@"
main