This repository was archived by the owner on Feb 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathinstall.sh
executable file
·130 lines (99 loc) · 3.05 KB
/
install.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/sh
# rCTF installation script
set -e
fg_cyan="\033[36m"
bold_fg_white="\033[1;37m"
bg_red="\033[41m"
reset="\033[0m"
error() {
# shellcheck disable=SC2059
printf "${bg_red}${bold_fg_white}%s %s${reset}\n" "[-]" "$*" 1>&2
}
info() {
# shellcheck disable=SC2059
printf "${fg_cyan}%s %s${reset}\n" "[*]" "$*"
}
get_key() {
head -c 32 /dev/urandom | base64 -w 0
}
do_install() {
info "Installing rCTF..."
if [ ! "$(id -u)" = 0 ]; then
error "You must run this script as root."
exit 1
fi
if [ ! -x "$(command -v curl)" ]; then
error "curl is not available. You must have curl to install rCTF."
exit 1
fi
RCTF_INSTALL_PATH="${RCTF_INSTALL_PATH:-"/opt/rctf"}"
if [ ! -d "$(dirname "$RCTF_INSTALL_PATH")" ]; then
error "The parent of \$RCTF_INSTALL_PATH ($(dirname "$RCTF_INSTALL_PATH")) does not exist."
exit 1
fi
if [ -d "$RCTF_INSTALL_PATH" ]; then
error "rCTF appears to already be installed in ${RCTF_INSTALL_PATH}"
info "... If you're trying to start rCTF, run 'docker-compose up -d'."
info "... If you're trying to reinstall rCTF, 'rm -rf $RCTF_INSTALL_PATH' then re-run this script."
exit 1
fi
mkdir "$RCTF_INSTALL_PATH"
cd "$RCTF_INSTALL_PATH"
info "Installing dependencies..."
if [ ! -x "$(command -v docker)" ]; then
curl -fsS https://get.docker.com | sh
fi
if [ ! -x "$(command -v docker-compose)" ]; then
curl -fsSLo /usr/local/bin/docker-compose "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)"
chmod +x /usr/local/bin/docker-compose
fi
info "Configuring rCTF..."
RCTF_GIT_REF="${RCTF_GIT_REF:-"master"}"
mkdir -p conf.d data/rctf-postgres data/rctf-redis data/rctf-uploads
printf "%s\n" \
"RCTF_DATABASE_PASSWORD=$(get_key)" \
"RCTF_REDIS_PASSWORD=$(get_key)" \
"RCTF_GIT_REF=$RCTF_GIT_REF" \
> .env
printf "%s\n" \
"ctfName: rCTF" \
"meta:" \
" description: 'A description of your CTF'" \
" imageUrl: 'https://example.com'" \
"homeContent: 'A description of your CTF. Markdown supported.'" \
> conf.d/01-ui.yaml
printf "%s\n" \
"origin: http://127.0.0.1:8080" \
"divisions:" \
" open: Open" \
"tokenKey: '$(get_key)'" \
"startTime: $(date +%s)000" \
"endTime: $(date -d +1week +%s)000" \
> conf.d/02-ctf.yaml
printf "%s\n" \
"database:" \
" sql:" \
" host: postgres" \
" user: rctf" \
" database: rctf" \
" redis:" \
" host: redis" \
" migrate: before" \
> conf.d/03-db.yaml
info "Downloading rCTF..."
curl -fsSO "https://raw.githubusercontent.com/redpwn/rctf/$RCTF_GIT_REF/docker-compose.yml"
docker-compose pull
info "Finished installation to ${RCTF_INSTALL_PATH}."
printf "Would you like to start rCTF now (y/N)? "
read -r result </dev/tty
if [ "$result" = "y" ]; then
info "Running 'docker-compose up -d'..."
docker-compose up -d
info "rCTF is now running at 127.0.0.1:8080."
exit 0
else
info "If you would like to start rCTF, run 'docker-compose up -d' in $RCTF_INSTALL_PATH."
exit 0
fi
}
do_install