#!/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" repo_url_path="$PROJ/$repo_name" else repo_path="{{ obsd_git_home }}/$VISIBILITY/$repo_name.git" repo_url_path="$repo_name" fi if [ ! -d "$repo_path" ]; then echo "Creating bare repository: $repo_name.git" git init --bare --initial-branch=main "$repo_path" if [ -n "$DESC" ]; then echo "$DESC" >>"$repo_path/description" fi cgit_config_extra_head_content_set_go_import "$repo_path" "$repo_url_path" chown -R git:git "$repo_path" 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 } # Ensure cgit advertises a go-import meta tag so the repo can be used as a Go # module at {{ obsd_git_domain }}/. # # Requires enable-git-config=1 in cgitrc. cgit_config_extra_head_content_set_go_import() { module="{{ obsd_git_domain }}/$2" git -C "$1" config cgit.extra-head-content \ "" } main "$@"