#!/bin/bash # checkout.sh - Git repository checkout/update script # Clones or updates the itenv_web2 repository set -euo pipefail # Exit on error, undefined vars, pipe failures # Jump to script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" # Check if there is a key loaded in ssh-agent echo "Checking SSH agent for loaded keys..." if ! ssh-add -l >/dev/null 2>&1; then echo "Error: No SSH keys are loaded in ssh-agent" echo "Please run 'ssh-add /path/to/your/private/key' first" exit 1 fi echo "SSH key found in agent" # Check if git user.name and user.email are configured echo "Checking Git configuration..." git_name=$(git config --global user.name 2>/dev/null || echo "") git_email=$(git config --global user.email 2>/dev/null || echo "") if [[ -z "$git_name" ]]; then echo "Git user.name is not configured." read -p "Please enter your name: " input_name if [[ -n "$input_name" ]]; then git config --global user.name "$input_name" echo "Set user.name to: $input_name" else echo "Error: Name cannot be empty" exit 1 fi fi if [[ -z "$git_email" ]]; then echo "Git user.email is not configured." read -p "Please enter your email: " input_email if [[ -n "$input_email" ]]; then git config --global user.email "$input_email" echo "Set user.email to: $input_email" else echo "Error: Email cannot be empty" exit 1 fi fi echo "Git configuration verified" # Create code directory if it doesn't exist mkdir -p /root/code/git.threefold.info/ourworld_web cd /root/code/git.threefold.info/ourworld_web # Check if itenv_web2 directory exists if [[ -d "itenv_web2" ]]; then echo "Directory itenv_web2 exists, pulling latest changes..." cd itenv_web2 git pull else echo "Directory itenv_web2 does not exist, cloning repository..." git clone git@git.threefold.info:ourworld_web/itenv_web2.git fi # Check if itenv_tools directory exists if [[ -d "itenv_tools" ]]; then echo "Directory itenv_tools exists, pulling latest changes..." cd itenv_tools git pull else echo "Directory itenv_tools does not exist, cloning repository..." git clone git@git.threefold.info:ourworld_web/itenv_tools.git fi echo "Checkout/update completed successfully!"