-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitClone.sh
More file actions
executable file
·35 lines (31 loc) · 1.3 KB
/
gitClone.sh
File metadata and controls
executable file
·35 lines (31 loc) · 1.3 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
#!/bin/bash
# Set the repository URL and destination path
repository_url="https://github.com/CAELESTIS-Project-EU/Workflows.git"
dest_path="/home/ubuntu/installDir/"
requested_branch="${1:-main}" # Default to 'main' if no argument is provided
# Create a folder with the name of the branch inside the destination path
branch_folder="${dest_path}${requested_branch}"
if [ ! -d "$branch_folder" ]; then
echo "Creating directory for branch: $requested_branch"
mkdir -p "$branch_folder"
fi
# Navigate to the branch folder
cd "$branch_folder" || { echo "Failed to navigate to directory: $branch_folder"; exit 1; }
# Check if the repository is already cloned
if [ -d ".git" ]; then
echo "Checking for updates in the existing repository..."
git fetch origin "$requested_branch"
local_commit=$(git rev-parse HEAD)
remote_commit=$(git rev-parse FETCH_HEAD)
if [ "$local_commit" != "$remote_commit" ]; then
echo "Changes detected. Pulling latest changes..."
git pull origin "$requested_branch"
else
echo "No changes detected. Repository is up to date."
fi
else
echo "Repository not found. Cloning repository..."
git clone -b "$requested_branch" "$repository_url" .
fi
# Navigate to the final directory
cd /var/www/API_REST || { echo "Failed to navigate to final directory: /var/www/API_REST"; exit 1; }