-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsetup.sh
executable file
·103 lines (80 loc) · 2.34 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
SRC_DIR=$(dirname $0)
BUILD_DIR="$SRC_DIR/build"
PREFIX=${PREFIX:-/usr/local}
clean() {
rm -rf $BUILD_DIR
}
build() {
set -e
mkdir -p $BUILD_DIR
checkmodule -M -m -o $BUILD_DIR/gitlab-ssh.mod $SRC_DIR/gitlab-ssh.te
semodule_package -o $BUILD_DIR/gitlab-ssh.pp -m $BUILD_DIR/gitlab-ssh.mod
test -n "$SUDO_UID" && chown -R $SUDO_UID:$SUDO_GID $BUILD_DIR
set +e
}
install_pkg() {
set -e
install $SRC_DIR/gitlab-keys-check $PREFIX/bin
install $SRC_DIR/gitlab-shell-proxy $PREFIX/bin
if [[ $SE_LINUX != "no" ]]; then
test ! -e $BUILD_DIR/gitlab-ssh.pp && build
semodule -i $BUILD_DIR/gitlab-ssh.pp
fi
sed -E "s#/usr/local#${PREFIX}#" $SRC_DIR/99-gitlab-proxy.conf > $BUILD_DIR/99-gitlab-proxy.conf
if [[ -d /etc/ssh/sshd_config.d ]]; then
cp $BUILD_DIR/99-gitlab-proxy.conf /etc/ssh/sshd_config.d/99-gitlab-proxy.conf
else
echo "Warning: /etc/ssh/sshd_config.d directory is missing"
echo "Please manually add the contents of $BUILD_DIR/99-gitlab-proxy.conf to your /etc/ssh/sshd_config configuration"
fi
set +e
}
remove() {
test -e $PREFIX/bin/gitlab-keys-check && rm $PREFIX/bin/gitlab-keys-check
test -e $PREFIX/bin/gitlab-shell-proxy && rm $PREFIX/bin/gitlab-shell-proxy
test -e /etc/ssh/sshd_config.d/99-gitlab-proxy.conf && rm /etc/ssh/sshd_config.d/99-gitlab-proxy.conf
( semodule -l | grep gitlab-ssh > /dev/null ) && semodule -r gitlab-ssh
}
show_help() {
cat <<EOD
GitLab SSH Proxy
Usage:
./setup.sh [commands]...
Available Commands:
build Build SELinux policy module package in ./build
clean Remove ./build directory
install Copy scripts to /usr/local/bin and install SE Linux module package
remove Remove scripts and SE Linux module package
help Show available commands
EOD
}
if [[ $# -lt 1 ]]; then
show_help
exit 0
fi
for cmd in "$@"
do
case "$cmd" in
build)
build
;;
clean)
clean
;;
install)
install_pkg
;;
remove)
remove
;;
help)
show_help
;;
*)
echo "Error: unsupported command '${cmd}'" >&2
echo "Use '$0 help' for supported commands" >&2
exit 1
;;
esac
done