-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·64 lines (58 loc) · 1.46 KB
/
setup.sh
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
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
usage()
{
cat <<- _EOF_
Usage: ./setup.sh [OPTIONS] COMMAND...
Set up infrastructure for tracking PKGBUILDs.
OPTIONS
-h, --help Show this usage message
COMMANDS
ssh [/path/to/key] Add/replace ssh-config rules.
Key defaults to '~/.ssh/keys/aur'
hooks Link hooks from repo root to githooks directory.
Must be run from repo root.
_EOF_
}
ssh() {
echo "Adding ssh-config rules (this will clear previous rules for 'aur')..."
sed -ri '/^Host aur(( aur)?.*\.archlinux\.org)?$/,+3d' ~/.ssh/config
cat <<- _EOF_ >> ~/.ssh/config
Host aur aur.archlinux.org
User aur
Hostname aur.archlinux.org
IdentityFile ${keypath}
_EOF_
}
hooks() {
echo "Adding commit hooks..."
shopt -s nullglob
for hook in *.hook; do
ln -sf "$(pwd)/${hook}" ".git/hooks/${hook%.hook}"
done
}
if [[ $# -eq 0 ]]; then
echo "error: No arguments passed."
echo "Try '${0} --help' for more information."
exit 1
fi
while [[ "${1}" != "" ]]; do
case ${1} in
-h|--help)
usage
exit
;;
ssh)
shift
keypath="${1:-~/.ssh/keys/aur}"
ssh
;;
hooks)
hooks
;;
*)
echo "${0}: unrecognized option '${1}'"
echo "Try '${0} --help' for more information."
exit 1
esac
shift
done