drone/app/gitspace/orchestrator/container/template/clone_git.sh
Dhruv Dhruv 3acded8ed8 feat: [CDE-92]: Container orchestrator and IDE service
* feat: [CDE-92]: Removing Client method from infraprovider interface and using DockerClientFactory to generate docker clients. Using go templates to substitute values in gitspace scripts. Setting a default base path for gitspaces if not provided.
* Rebasing
* feat: [CDE-92]: Addressing review comments.
* Rebasing
* Rebasing
* feat: [CDE-92]: Addressing review comments
* Rebasing
* feat: [CDE-92]: Using port from config for code-server installation
* feat: [CDE-92]: Initial commit
* Rebasing
2024-07-05 05:28:31 +00:00

50 lines
1.3 KiB
Bash

#!/bin/bash
repo_url={{ .RepoURL }}
devcontainer_present={{ .DevcontainerPresent }}
image={{ .Image }}
# Extract the repository name from the URL
repo_name=$(basename -s .git "$repo_url")
# Check if Git is installed
if ! command -v git &>/dev/null; then
echo "Git is not installed. Installing Git..."
apt-get update
apt-get install -y git
fi
if ! command -v git &>/dev/null; then
echo "Git is not installed. Exiting..."
exit 1
fi
# Clone the repository only if it doesn't exist
if [ ! -d "$repo_name" ]; then
echo "Cloning the repository..."
git clone "$repo_url"
else
echo "Repository already exists. Skipping clone."
fi
# Check if devcontainer_present is set to false
if [ "$devcontainer_present" = "false" ]; then
# Ensure the repository is cloned
if [ -d "$repo_name" ]; then
echo "Creating .devcontainer directory and devcontainer.json..."
mkdir -p "$repo_name/.devcontainer"
cat <<EOL > "$repo_name/.devcontainer/devcontainer.json"
{
"image": "$image"
}
EOL
echo "devcontainer.json created."
else
echo "Repository directory not found. Cannot create .devcontainer."
fi
else
echo "devcontainer_present is set to true. Skipping .devcontainer creation."
fi
echo "Script completed."