#!/bin/bash set -euo pipefail # this script allows the creation of projects over ssh on git server # public repos will get a public.conf containing the remote # private repos will just exist on the server # # USAGE: # ssh git@ new-project [--public] # # EXAMPLES: # ssh git@treybastian.com new-project myrepo # ssh git@treybastian.com new-project myrepo --public REMOTE_BASE_URL="git@treybastian.com:repos" usage() { echo "Usage: new-project [--public]" echo "" echo "Examples:" echo " new-project myrepo" echo " new-project myrepo --public" exit 1 } if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then echo "Error: expected 1 or 2 arguments, got $#" usage fi PROJECT_NAME="$1" PUBLIC=false if [ "$#" -eq 2 ]; then if [ "$2" != "--public" ]; then echo "Error: unknown flag '$2'" usage fi PUBLIC=true fi if [[ "$PROJECT_NAME" != *.git ]]; then PROJECT_NAME="${PROJECT_NAME}.git" fi if [ -d "$PROJECT_NAME" ]; then echo "Error: '$PROJECT_NAME' already exists" exit 1 fi git --bare init "${PROJECT_NAME}" if [ "$PUBLIC" = true ]; then echo "${REMOTE_BASE_URL}/${PROJECT_NAME}" > "${PROJECT_NAME}/public.conf" ssh git@treybastian.com new-repo "repos/${PROJECT_NAME}" echo "public repo: ${REMOTE_BASE_URL}/${PROJECT_NAME}" fi echo "git url: ${USER}@${HOSTNAME}:${PROJECT_NAME}" # vim: filetype=bash