#!/bin/sh set -e REPO="" DESC="" PROJ="" VISIBILITY="public" main() { parse_args "$@" repo_name=$(basename "$REPO" .git) if [ -n "$PROJ" ]; then proj_dir="{{ obsd_git_home }}/$VISIBILITY/$PROJ" if [ ! -d "$proj_dir" ]; then mkdir "$proj_dir" fi repo_path="$proj_dir/$repo_name.git" else repo_path="{{ obsd_git_home }}/$VISIBILITY/$repo_name.git" fi if [ ! -d "$repo_path" ]; then echo "Creating bare repository: $repo_name.git" git init --bare --initial-branch=main "$repo_path" chown -R git:git "$repo_path" if [ -n "$DESC" ]; then echo "$DESC" >>"$repo_path/description" fi fi } parse_args() { while [ $# -gt 0 ]; do case "$1" in --visibility) VISIBILITY="$2" case "$VISIBILITY" in public | private) ;; *) usage ;; esac shift 2 ;; --description) DESC="$2" shift 2 ;; --project) PROJ="$2" shift 2 ;; -*) echo "Unknown option: $1" >&2 exit 1 ;; *) if [ -n "$REPO" ]; then echo "Unexpected argument: $1" >&2 usage fi REPO="$1" shift ;; esac done [ -n "$REPO" ] || usage } usage() { echo "Usage: $0 [--visibility public|private] [--description DESC] [--project PROJ] " >&2 exit 1 } main "$@"