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

Commit 501a2ed

Browse files
committed
feat(install): make installer script download images
1 parent 101814c commit 501a2ed

File tree

8 files changed

+85
-144
lines changed

8 files changed

+85
-144
lines changed

.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

docker-compose.yml

Lines changed: 4 additions & 4 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:
2625
image: redis:5.0.9
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/_headers

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*
2+
content-disposition: attachment; filename="rctf-install.sh"

install/_redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* /install.sh 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 _headers _redirects build
5+
sed -e "s/{{git_commit}}/$(git rev-parse HEAD)/" install.sh > build/install.sh

install/config.sh

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

install/install.sh

Lines changed: 72 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -4,154 +4,112 @@
44

55
set -e
66

7-
# clear screen
8-
printf "\033c"
9-
10-
11-
# define functions
12-
13-
147
fg_cyan="\033[36m"
158
bold_fg_white="\033[1;37m"
169
bg_red="\033[41m"
1710
reset="\033[0m"
1811

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

2417
info() {
25-
# shellcheck disable=SC2059
26-
printf "${fg_cyan}%s %s${reset}\n" "[*]" "$*"
18+
# shellcheck disable=SC2059
19+
printf "${fg_cyan}%s %s${reset}\n" "[*]" "$*"
2720
}
2821

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

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..."
46-
47-
if [ ! "$(id -u)" = 0 ]; then
48-
error "You must run this script as root."
49-
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
70-
26+
do_install() {
27+
info "Installing rCTF..."
7128

72-
info "Configuring installation..."
29+
if [ ! "$(id -u)" = 0 ]; then
30+
error "You must run this script as root."
31+
exit 1
32+
fi
7333

74-
INSTALL_PATH="${INSTALL_PATH:-"/opt/rctf"}"
34+
RCTF_INSTALL_PATH="${RCTF_INSTALL_PATH:-"/opt/rctf"}"
7535

76-
if [ ! -d "$(dirname "$INSTALL_PATH")" ]; then
77-
error "The parent of \$INSTALL_PATH ($(dirname "$INSTALL_PATH")) does not exist."
36+
if [ ! -d "$(dirname "$RCTF_INSTALL_PATH")" ]; then
37+
error "The parent of \$RCTF_INSTALL_PATH ($(dirname "$RCTF_INSTALL_PATH")) does not exist."
7838
exit 1
79-
fi
39+
fi
8040

81-
if [ -d "$INSTALL_PATH" ]; then
82-
error "rCTF appears to already be installed in ${INSTALL_PATH}"
41+
if [ -d "$RCTF_INSTALL_PATH" ]; then
42+
error "rCTF appears to already be installed in ${RCTF_INSTALL_PATH}"
8343

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."
44+
info "... If you're trying to start rCTF, run 'docker-compose up -d'."
45+
info "... If you're trying to reinstall rCTF, 'rm -rf $RCTF_INSTALL_PATH' then re-run this script."
8646

8747
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-
48+
fi
9649

97-
info "Installing dependencies..."
50+
mkdir "$RCTF_INSTALL_PATH"
51+
cd "$RCTF_INSTALL_PATH"
9852

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."
53+
info "Installing dependencies..."
10454

105-
# pass Ctrl+C / SIGINT to inside script
106-
sh -c '
107-
trap break INT
108-
curl -fsSL https://get.docker.com/ | sh
109-
'
55+
if [ ! -x "$(command -v docker)" ]; then
56+
curl https://get.docker.com | sh
57+
fi
11058

111-
yum install git
112-
elif [ "$PACKAGE_MANAGER" = "pacman" ]; then
113-
pacman -Sy --noconfirm --needed docker docker-compose git
114-
fi
59+
if [ ! -x "$(command -v docker-compose)" ]; then
60+
curl -fsSLo /usr/local/bin/docker-compose "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)"
61+
chmod +x /usr/local/bin/docker-compose
62+
fi
11563

116-
info "Enabling docker..."
64+
info "Configuring rCTF..."
11765

118-
(systemctl enable docker || true) 2>/dev/null # XXX: Debian "masks" docker.service
119-
(systemctl start docker || true) 2>/dev/null
66+
RCTF_GIT_COMMIT="${RCTF_GIT_COMMIT:-"{{git_commit}}"}"
12067

68+
mkdir -p conf.d data/rctf-postgres data/rctf-redis
12169

122-
# clone repository
70+
printf "%s\n" \
71+
"RCTF_DATABASE_PASSWORD=$(get_key)" \
72+
"RCTF_REDIS_PASSWORD=$(get_key)" \
73+
"RCTF_GIT_COMMIT=$RCTF_GIT_COMMIT" \
74+
> .env
12375

76+
printf "%s\n" \
77+
"ctfName: rCTF" \
78+
"meta:" \
79+
" description: 'A description of your CTF'" \
80+
" imageUrl: 'https://example.com'" \
81+
"homeContent: 'A description of your CTF. Markdown supported.'" \
82+
> conf.d/01-ui.yaml
12483

125-
info "Cloning repository to ${INSTALL_PATH} from repository ${REPOSITORY_URL} branch ${REPOSITORY_BRANCH}..."
84+
printf "%s\n" \
85+
"origin: http://127.0.0.1:8080" \
86+
"divisions:" \
87+
" open: Open" \
88+
"tokenKey: '$(get_key)'" \
89+
"startTime: $(date +%s)000" \
90+
"endTime: $(date -d +1week +%s)000" \
91+
> conf.d/02-ctf.yaml
12692

127-
git clone "$REPOSITORY_URL" "$INSTALL_PATH"
128-
cd "$INSTALL_PATH"
129-
git checkout "$REPOSITORY_BRANCH"
93+
info "Downloading rCTF..."
13094

95+
curl -fsSO "https://raw.githubusercontent.com/redpwn/rctf/$RCTF_GIT_COMMIT/docker-compose.yml"
96+
docker-compose pull
13197

132-
# configure rctf
98+
info "Finished installation to ${RCTF_INSTALL_PATH}."
13399

100+
printf "Would you like to start rCTF now (y/N)? "
134101

135-
info "Configuring rCTF..."
102+
read -r result </dev/tty
136103

137-
./install/config.sh
138-
139-
140-
# start docker
141-
142-
143-
info "Finished installation to ${INSTALL_PATH}."
144-
145-
printf "Would you like to start rCTF now (y/N)? "
146-
147-
read -r result </dev/tty
104+
if [ "$result" = "y" ]; then
105+
info "Running 'docker-compose up -d'..."
106+
docker-compose up -d
107+
info "rCTF is now running at 127.0.0.1:8080."
108+
exit 0
109+
else
110+
info "If you would like to start rCTF, run 'docker-compose up -d' in $RCTF_INSTALL_PATH."
111+
exit 0
112+
fi
113+
}
148114

149-
if [ "$result" = "y" ]; then
150-
info "Running 'docker-compose up -d'..."
151-
docker-compose up -d
152-
info "rCTF is now running at 127.0.0.1:8080."
153-
exit 0
154-
else
155-
info "If you would like to start rCTF, run 'docker-compose up -d' in $INSTALL_PATH."
156-
exit 0
157-
fi
115+
do_install

0 commit comments

Comments
 (0)