generated from digitalservicebund/java-application-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·76 lines (64 loc) · 1.69 KB
/
run.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
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
set -eu
readonly DEBUG="${DEBUG:-unset}"
if [ "${DEBUG}" != unset ]; then
set -x
fi
_fail() {
printf "\033[0;31m==> %s\033[0m\n\n" "$1"
}
_success() {
printf "\033[0;32m==> %s\033[0m\n\n" "$1"
}
_info() {
printf "\033[1;33m==> %s\033[0m\n\n" "$1"
}
_user() {
printf "\033[0;33m%s\033[0m" "$1"
}
_find_placeholder_strings() {
grep -rlZ 'java-application-template' --exclude-dir=.git --exclude-dir=.gradle --exclude-dir=.idea --exclude-dir=build --exclude=run.sh .
}
_setup_repo() {
if _find_placeholder_strings > /dev/null; then
defaultname="$(basename "$(git rev-parse --show-toplevel)")"
_user "Name of the repository? ($defaultname) "
read -r name
newname=$name
if [ -z "$newname" ]; then
newname=$defaultname
fi
_find_placeholder_strings | xargs sed -i '' 's/java-application-template/'"$newname"'/g'
_info "Renamed, please commit the changes! You might have to adapt the package structure as well.."
fi
}
_setup_git_hooks() {
_user "Do you want to install the Git hooks? (y/n) "
read -r answer
if [ "$answer" = "y" ]; then
if ! command -v lefthook > /dev/null 2>&1; then
_fail "Setup requires Lefthook, please install first: \`brew install lefthook\`"
exit 1
fi
if ! command -v talisman > /dev/null 2>&1; then
_fail "Setup requires Talisman, please install first: \`brew install talisman\`"
exit 1
fi
lefthook install
_info "Git hooks installed.."
fi
}
_init() {
_setup_repo
_setup_git_hooks
}
_help() {
echo "Usage: ./run.sh [command]"
echo ""
echo "Available commands:"
echo "init Set up repository for development"
}
case "$@" in
"init") _init ;;
*) _help ;;
esac