blob: 5b313f666c6553c7a27ac1b6b1666893d62412eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/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@<host> set-description <name> <desc>
#
# 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 <name> <desc>"
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
|