Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 3a1c72c

Browse files
committed
Merge with origin/master
2 parents ae7a28f + f6da715 commit 3a1c72c

20 files changed

+296
-292
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,8 @@ jobs:
117117
# TODO: handle tagging releases correctly
118118
tags: ${{ github.sha }}
119119
# TODO: add cache_froms once we have full releases
120+
- name: Deploy installer
121+
uses: netlify/actions/build@master
122+
env:
123+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_INSTALL_SITE_ID }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ yarn-error.log*
1010
/conf.d/*
1111
!/conf.d/.keep
1212
/docs/site
13+
/install/build
1314

1415
# Upload provider dir
1516
/uploads

.readthedocs.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
[![Build Status](https://github.com/redpwn/rCTF/workflows/CI/badge.svg?branch=master)](https://github.com/redpwn/rCTF/actions?query=workflow%3ACI+branch%3Amaster)
44
[![Code Coverage](https://img.shields.io/codecov/c/github/redpwn/rctf.svg)](https://codecov.io/github/redpwn/rctf/)
5-
[![Docs](https://img.shields.io/readthedocs/rctf/latest)](https://rctf.redpwn.net/)
5+
[![Docs Status](https://img.shields.io/netlify/ae459ed6-1a84-43ff-b113-5561f3e4bd82.svg?label=docs)](https://rctf.redpwn.net)
6+
[![Install Status](https://img.shields.io/netlify/f528d484-6236-449c-8891-5ebfba3c178f.svg?label=install)](https://get.rctf.redpwn.net)
67

78
rCTF is redpwnCTF's CTF platform. It is developed and maintained by the [redpwn](https://redpwn.net) CTF team.
89

docker-compose.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '2.2'
22
services:
33
rctf:
4-
build: .
4+
image: redpwn/rctf:${RCTF_GIT_COMMIT}
55
restart: always
66
ports:
77
- '127.0.0.1:8080:80'
@@ -14,17 +14,17 @@ services:
1414
- RCTF_DATABASE_HOST=postgres
1515
- RCTF_DATABASE_DATABASE=rctf
1616
- RCTF_DATABASE_USERNAME=rctf
17-
- RCTF_DATABASE_PASSWORD=${RCTF_DATABASE_PASSWORD}
18-
- RCTF_REDIS_URL=redis://redis
17+
- RCTF_REDIS_HOST=redis
1918
- RCTF_DATABASE_MIGRATE=before
2019
volumes:
21-
- ./conf.d:/app/dist/conf.d
20+
- ./conf.d:/app/conf.d
2221
depends_on:
2322
- redis
2423
- postgres
2524
redis:
26-
image: redis:5.0.9
25+
image: redis:6.0.6
2726
restart: always
27+
command: ["redis-server", "--requirepass", "${RCTF_REDIS_PASSWORD}"]
2828
networks:
2929
- rctf
3030
volumes:

install/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

install/_redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* /install.txt 200!

install/build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
mkdir -p build
4+
cp _redirects build
5+
sed -e "s/{{git_commit}}/$(git rev-parse HEAD)/" install.sh > build/install.txt

install/config.sh

Lines changed: 0 additions & 25 deletions
This file was deleted.

install/install.sh

Lines changed: 70 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,119 @@
11
#!/bin/sh
22
# rCTF installation script
3-
# Supports Debian-like distros and Arch Linux
43

54
set -e
65

7-
# clear screen
8-
printf "\033c"
9-
10-
11-
# define functions
12-
13-
146
fg_cyan="\033[36m"
157
bold_fg_white="\033[1;37m"
168
bg_red="\033[41m"
179
reset="\033[0m"
1810

1911
error() {
20-
# shellcheck disable=SC2059
21-
printf "${bg_red}${bold_fg_white}%s %s${reset}\n" "[-]" "$*" 1>&2
12+
# shellcheck disable=SC2059
13+
printf "${bg_red}${bold_fg_white}%s %s${reset}\n" "[-]" "$*" 1>&2
2214
}
2315

2416
info() {
25-
# shellcheck disable=SC2059
26-
printf "${fg_cyan}%s %s${reset}\n" "[*]" "$*"
17+
# shellcheck disable=SC2059
18+
printf "${fg_cyan}%s %s${reset}\n" "[*]" "$*"
2719
}
2820

21+
get_key() {
22+
head -c 32 /dev/urandom | base64 -w 0
23+
}
2924

30-
# shellcheck disable=SC2059
31-
printf "\033[1;36m....########......######.....########....########...
32-
....##.....##....##....##.......##.......##.........
33-
....##.....##....##.............##.......##.........
34-
....########.....##.............##.......######.....
35-
....##...##......##.............##.......##.........
36-
....##....##.....##....##.......##.......##.........
37-
....##.....##.....######........##.......##.........
38-
39-
${reset}"
40-
41-
42-
# check environment
43-
44-
45-
info "Checking environment..."
25+
do_install() {
26+
info "Installing rCTF..."
4627

47-
if [ ! "$(id -u)" = 0 ]; then
28+
if [ ! "$(id -u)" = 0 ]; then
4829
error "You must run this script as root."
4930
exit 1
50-
fi
51-
52-
if [ -x "$(command -v apt-get)" ]; then
53-
PACKAGE_MANAGER="apt-get"
54-
elif [ -x "$(command -v yum)" ]; then
55-
error "Warning: Support for RHEL-like distros is experimental and things might break. Giving you 10 seconds to change your mind (by pressing Ctrl+C)..."
56-
sleep 10
57-
58-
PACKAGE_MANAGER="yum"
59-
elif [ -x "$(command -v pacman)" ]; then
60-
info "redpwn uses arch too btw"
61-
62-
PACKAGE_MANAGER="pacman"
63-
else
64-
# XXX: should we stop the script here?
65-
error "Unable to identify usable package manager, ignoring dependencies for now.";
66-
fi
67-
68-
69-
# setup variables
31+
fi
7032

71-
72-
info "Configuring installation..."
73-
74-
INSTALL_PATH="${INSTALL_PATH:-"/opt/rctf"}"
75-
76-
if [ ! -d "$(dirname "$INSTALL_PATH")" ]; then
77-
error "The parent of \$INSTALL_PATH ($(dirname "$INSTALL_PATH")) does not exist."
33+
if [ ! -x "$(command -v curl)" ]; then
34+
error "curl is not available. You must have curl to install rCTF."
7835
exit 1
79-
fi
80-
81-
if [ -d "$INSTALL_PATH" ]; then
82-
error "rCTF appears to already be installed in ${INSTALL_PATH}"
36+
fi
8337

84-
info "... If you're trying to start rCTF, run 'docker-compose up -d --project-directory $INSTALL_PATH'."
85-
info "... If you're trying to reinstall rCTF, 'rm -rf $INSTALL_PATH' then re-run this script."
38+
RCTF_INSTALL_PATH="${RCTF_INSTALL_PATH:-"/opt/rctf"}"
8639

40+
if [ ! -d "$(dirname "$RCTF_INSTALL_PATH")" ]; then
41+
error "The parent of \$RCTF_INSTALL_PATH ($(dirname "$RCTF_INSTALL_PATH")) does not exist."
8742
exit 1
88-
fi
89-
90-
REPOSITORY_URL="${REPOSITORY_URL:-"https://github.com/redpwn/rCTF.git"}"
91-
REPOSITORY_BRANCH="${REPOSITORY_BRANCH:-"master"}"
92-
93-
94-
# install dependencies
95-
43+
fi
9644

97-
info "Installing dependencies..."
45+
if [ -d "$RCTF_INSTALL_PATH" ]; then
46+
error "rCTF appears to already be installed in ${RCTF_INSTALL_PATH}"
9847

99-
if [ "$PACKAGE_MANAGER" = "apt-get" ]; then
100-
apt-get update
101-
apt-get install --yes docker.io docker-compose git
102-
elif [ "$PACKAGE_MANAGER" = "yum" ]; then
103-
info "We are about to install docker via https://get.docker.com/. Please follow along the steps to ensure it is configured properly."
104-
105-
# pass Ctrl+C / SIGINT to inside script
106-
sh -c '
107-
trap break INT
108-
curl -fsSL https://get.docker.com/ | sh
109-
'
110-
111-
yum install git
112-
elif [ "$PACKAGE_MANAGER" = "pacman" ]; then
113-
pacman -Sy --noconfirm --needed docker docker-compose git
114-
fi
115-
116-
info "Enabling docker..."
117-
118-
(systemctl enable docker || true) 2>/dev/null # XXX: Debian "masks" docker.service
119-
(systemctl start docker || true) 2>/dev/null
48+
info "... If you're trying to start rCTF, run 'docker-compose up -d'."
49+
info "... If you're trying to reinstall rCTF, 'rm -rf $RCTF_INSTALL_PATH' then re-run this script."
12050

51+
exit 1
52+
fi
12153

122-
# clone repository
54+
mkdir "$RCTF_INSTALL_PATH"
55+
cd "$RCTF_INSTALL_PATH"
12356

57+
info "Installing dependencies..."
12458

125-
info "Cloning repository to ${INSTALL_PATH} from repository ${REPOSITORY_URL} branch ${REPOSITORY_BRANCH}..."
59+
if [ ! -x "$(command -v docker)" ]; then
60+
curl -fsS https://get.docker.com | sh
61+
fi
12662

127-
git clone "$REPOSITORY_URL" "$INSTALL_PATH"
128-
cd "$INSTALL_PATH"
129-
git checkout "$REPOSITORY_BRANCH"
63+
if [ ! -x "$(command -v docker-compose)" ]; then
64+
curl -fsSLo /usr/local/bin/docker-compose "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)"
65+
chmod +x /usr/local/bin/docker-compose
66+
fi
13067

68+
info "Configuring rCTF..."
13169

132-
# configure rctf
70+
RCTF_GIT_COMMIT="${RCTF_GIT_COMMIT:-"{{git_commit}}"}"
13371

72+
mkdir -p conf.d data/rctf-postgres data/rctf-redis
13473

135-
info "Configuring rCTF..."
74+
printf "%s\n" \
75+
"RCTF_DATABASE_PASSWORD=$(get_key)" \
76+
"RCTF_REDIS_PASSWORD=$(get_key)" \
77+
"RCTF_GIT_COMMIT=$RCTF_GIT_COMMIT" \
78+
> .env
13679

137-
./install/config.sh
80+
printf "%s\n" \
81+
"ctfName: rCTF" \
82+
"meta:" \
83+
" description: 'A description of your CTF'" \
84+
" imageUrl: 'https://example.com'" \
85+
"homeContent: 'A description of your CTF. Markdown supported.'" \
86+
> conf.d/01-ui.yaml
13887

88+
printf "%s\n" \
89+
"origin: http://127.0.0.1:8080" \
90+
"divisions:" \
91+
" open: Open" \
92+
"tokenKey: '$(get_key)'" \
93+
"startTime: $(date +%s)000" \
94+
"endTime: $(date -d +1week +%s)000" \
95+
> conf.d/02-ctf.yaml
13996

140-
# start docker
97+
info "Downloading rCTF..."
14198

99+
curl -fsSO "https://raw.githubusercontent.com/redpwn/rctf/$RCTF_GIT_COMMIT/docker-compose.yml"
100+
docker-compose pull
142101

143-
info "Finished installation to ${INSTALL_PATH}."
102+
info "Finished installation to ${RCTF_INSTALL_PATH}."
144103

145-
printf "Would you like to start rCTF now (y/N)? "
104+
printf "Would you like to start rCTF now (y/N)? "
146105

147-
read -r result </dev/tty
106+
read -r result </dev/tty
148107

149-
if [ "$result" = "y" ]; then
108+
if [ "$result" = "y" ]; then
150109
info "Running 'docker-compose up -d'..."
151110
docker-compose up -d
152111
info "rCTF is now running at 127.0.0.1:8080."
153112
exit 0
154-
else
155-
info "If you would like to start rCTF, run 'docker-compose up -d' in $INSTALL_PATH."
113+
else
114+
info "If you would like to start rCTF, run 'docker-compose up -d' in $RCTF_INSTALL_PATH."
156115
exit 0
157-
fi
116+
fi
117+
}
118+
119+
do_install

0 commit comments

Comments
 (0)