-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathrun.sh
executable file
·47 lines (41 loc) · 1.14 KB
/
run.sh
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
#!/usr/bin/env bash
REPO_URL="${REPO_URL}"
CLONE_PATH="${CLONE_PATH}"
BRANCH_NAME="${BRANCH_NAME}"
# Expand home if it's specified!
CLONE_PATH="$${CLONE_PATH/#\~/$${HOME}}"
# Check if the variable is empty...
if [ -z "$REPO_URL" ]; then
echo "No repository specified!"
exit 0
fi
# Check if the variable is empty...
if [ -z "$CLONE_PATH" ]; then
echo "No clone path specified!"
exit 1
fi
# Check if `git` is installed...
if ! command -v git > /dev/null; then
echo "Git is not installed!"
exit 1
fi
# Check if the directory for the cloning exists
# and if not, create it
if [ ! -d "$CLONE_PATH" ]; then
echo "Creating directory $CLONE_PATH..."
mkdir -p "$CLONE_PATH"
fi
# Check if the directory is empty
# and if it is, clone the repo, otherwise skip cloning
if [ -z "$(ls -A "$CLONE_PATH")" ]; then
if [ -z "$BRANCH_NAME" ]; then
echo "Cloning $REPO_URL to $CLONE_PATH..."
git clone "$REPO_URL" "$CLONE_PATH"
else
echo "Cloning $REPO_URL to $CLONE_PATH on branch $BRANCH_NAME..."
git clone "$REPO_URL" -b "$BRANCH_NAME" "$CLONE_PATH"
fi
else
echo "$CLONE_PATH already exists and isn't empty, skipping clone!"
exit 0
fi