-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitclone.bits
More file actions
66 lines (54 loc) · 1.57 KB
/
gitclone.bits
File metadata and controls
66 lines (54 loc) · 1.57 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
#-----------
# VARIABLES
#-----------
NAME=${NAME-samplephp}
URL=${URL-https://github.com/capbash/samplephp}
INSTALL_DIR=${INSTALL_DIR-/var/local/apps}
USER_EMAIL=${USER_EMAIL-server@localhost}
USER_NAME=${USER_NAME-server}
GIT_REMOTE=${GIT_REMOTE-origin}
GIT_CHECKOUT_MODE=`if [ -z "$TAG" ]; then echo "branch"; else echo "tag"; fi`
BRANCH=${BRANCH-master}
TAG=${TAG-$BRANCH}
#-----------
# Install Script
#-----------
bits install-if git
bits install-if knownhosts
REPO_DIR=${INSTALL_DIR}/${NAME}
if [[ "`git config --global user.email`" == "" ]]; then
echo "Configuraitng default user $USER_EMAIL ($USER_NAME)"
git config --global user.email "$USER_EMAIL"
git config --global user.name "$USER_NAME"
fi
if [[ ! -e $INSTALL_DIR ]]; then
echo "Creating $INSTALL_DIR"
mkdir $INSTALL_DIR
fi
if [[ ! -e ${REPO_DIR} ]]; then
echo "Creating a new REPO ${REPO_DIR} (${BRANCH})..."
(cd ${INSTALL_DIR} && git clone ${URL} ${NAME})
[ $? -ne 0 ] && exit 1
(cd ${INSTALL_DIR}/${NAME} && git checkout ${TAG})
[ $? -ne 0 ] && exit 1
else
if [[ "$GIT_CHECKOUT_MODE" = "tag" ]]; then
echo "Forcing a checkout to ${REPO_DIR} (${BRANCH}, tag $TAG)"
(cd ${REPO_DIR} && \
git reset --hard HEAD && \
git fetch && \
git checkout $BRANCH && \
git merge origin $BRANCH && \
git checkout tags/$TAG 2>&1)
else
echo "Forcing a reset to ${REPO_DIR} (${BRANCH})"
(cd ${REPO_DIR} && \
git fetch && \
git checkout ${BRANCH} && \
git fetch && \
git reset --hard ${GIT_REMOTE}/${BRANCH} && \
git checkout ${TAG})
fi
fi
exit 0