62 lines
1.4 KiB
Bash
Executable File
62 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Get the directory where this script is located
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
if [[ -z "${AGENT_WORKSPACE:-}" ]]; then
|
|
echo "Error: AGENT_WORKSPACE environment variable is not set"
|
|
exit 1
|
|
fi
|
|
|
|
usage() {
|
|
echo "Usage: $0 <repo-name>"
|
|
echo ""
|
|
echo "Create a new git repository on git.hangman-lab.top"
|
|
echo ""
|
|
echo "Arguments:"
|
|
echo " repo-name Name of the repository to create"
|
|
exit 2
|
|
}
|
|
|
|
if [[ $# -eq 0 ]]; then
|
|
usage
|
|
fi
|
|
|
|
REPO_NAME="$1"
|
|
|
|
# Validate repo name (alphanumeric, hyphens, underscores only)
|
|
if ! [[ "$REPO_NAME" =~ ^[a-zA-Z0-9_-]+$ ]]; then
|
|
echo "Error: Invalid repository name '$REPO_NAME'"
|
|
echo "Only alphanumeric characters, hyphens, and underscores are allowed."
|
|
exit 1
|
|
fi
|
|
|
|
REPO_DIR="${AGENT_WORKSPACE}/${REPO_NAME}"
|
|
|
|
# Step 1: Create directory
|
|
echo "Creating directory: ${REPO_DIR}"
|
|
mkdir -p "${REPO_DIR}"
|
|
|
|
# Step 2: cd to directory
|
|
cd "${REPO_DIR}"
|
|
|
|
# Step 3: git init
|
|
echo "Initializing git repository..."
|
|
git init
|
|
|
|
# Step 4: git remote add origin
|
|
echo "Adding remote origin..."
|
|
USERNAME="$(secret-mgr get-username --key git)"
|
|
REMOTE_URL="https://git.hangman-lab.top/${USERNAME}/${REPO_NAME}.git"
|
|
git remote add origin "${REMOTE_URL}"
|
|
echo " Remote: ${REMOTE_URL}"
|
|
|
|
# Step 5: Run repo-config
|
|
echo "Configuring repository..."
|
|
"$SCRIPT_DIR/repo-config" --repo-path "${REPO_DIR}"
|
|
|
|
echo ""
|
|
echo "Done! Repository created at: ${REPO_DIR}"
|
|
echo "Remote: ${REMOTE_URL}"
|