#!/bin/bash set -euo pipefail # this script sets the description of an existing bare git repository # if public.conf exists the description is also set on the remote repository # # USAGE: # ssh git@ set-description # # EXAMPLES: # ssh git@treybastian.com set-description myrepo "my cool repo" # ssh git@treybastian.com set-description myrepo.git "my cool repo" usage() { echo "Usage: set-description " echo "" echo "Examples:" echo " set-description myrepo \"my cool repo\"" echo " set-description myrepo.git \"my cool repo\"" exit 1 } if [ "$#" -ne 2 ]; then echo "Error: expected 2 arguments, got $#" usage fi PROJECT_NAME="$1" DESCRIPTION="$2" if [[ "$PROJECT_NAME" != *.git ]]; then PROJECT_NAME="${PROJECT_NAME}.git" fi if [ ! -d "$PROJECT_NAME" ]; then echo "Error: '$PROJECT_NAME' does not exist" exit 1 fi echo "$DESCRIPTION" > "${PROJECT_NAME}/description" echo "description updated: $PROJECT_NAME" PUBLIC_FILE="${PROJECT_NAME}/public.conf" if [ -f "$PUBLIC_FILE" ]; then REPO_URL=$(cat "$PUBLIC_FILE" | tr -d '\n' | xargs) REMOTE_HOST="${REPO_URL%%:*}" REMOTE_PATH="${REPO_URL##*:}" ssh "$REMOTE_HOST" set-description "$REMOTE_PATH" "$(printf '%q' "$DESCRIPTION")" echo "description updated on remote: $REPO_URL" fi # vim: filetype=bash