|
1 | 1 | #!/bin/sh
|
2 | 2 | # rCTF installation script
|
3 |
| -# Supports Debian-like distros and Arch Linux |
4 | 3 |
|
5 | 4 | set -e
|
6 | 5 |
|
7 |
| -# clear screen |
8 |
| -printf "\033c" |
9 |
| - |
10 |
| - |
11 |
| -# define functions |
12 |
| - |
13 |
| - |
14 | 6 | fg_cyan="\033[36m"
|
15 | 7 | bold_fg_white="\033[1;37m"
|
16 | 8 | bg_red="\033[41m"
|
17 | 9 | reset="\033[0m"
|
18 | 10 |
|
19 | 11 | 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 |
22 | 14 | }
|
23 | 15 |
|
24 | 16 | 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" "[*]" "$*" |
27 | 19 | }
|
28 | 20 |
|
| 21 | +get_key() { |
| 22 | + head -c 32 /dev/urandom | base64 -w 0 |
| 23 | +} |
29 | 24 |
|
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..." |
46 | 27 |
|
47 |
| -if [ ! "$(id -u)" = 0 ]; then |
| 28 | + if [ ! "$(id -u)" = 0 ]; then |
48 | 29 | error "You must run this script as root."
|
49 | 30 | 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 |
70 | 32 |
|
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." |
78 | 35 | exit 1
|
79 |
| -fi |
80 |
| - |
81 |
| -if [ -d "$INSTALL_PATH" ]; then |
82 |
| - error "rCTF appears to already be installed in ${INSTALL_PATH}" |
| 36 | + fi |
83 | 37 |
|
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"}" |
86 | 39 |
|
| 40 | + if [ ! -d "$(dirname "$RCTF_INSTALL_PATH")" ]; then |
| 41 | + error "The parent of \$RCTF_INSTALL_PATH ($(dirname "$RCTF_INSTALL_PATH")) does not exist." |
87 | 42 | 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 |
96 | 44 |
|
97 |
| -info "Installing dependencies..." |
| 45 | + if [ -d "$RCTF_INSTALL_PATH" ]; then |
| 46 | + error "rCTF appears to already be installed in ${RCTF_INSTALL_PATH}" |
98 | 47 |
|
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." |
120 | 50 |
|
| 51 | + exit 1 |
| 52 | + fi |
121 | 53 |
|
122 |
| -# clone repository |
| 54 | + mkdir "$RCTF_INSTALL_PATH" |
| 55 | + cd "$RCTF_INSTALL_PATH" |
123 | 56 |
|
| 57 | + info "Installing dependencies..." |
124 | 58 |
|
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 |
126 | 62 |
|
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 |
130 | 67 |
|
| 68 | + info "Configuring rCTF..." |
131 | 69 |
|
132 |
| -# configure rctf |
| 70 | + RCTF_GIT_COMMIT="${RCTF_GIT_COMMIT:-"{{git_commit}}"}" |
133 | 71 |
|
| 72 | + mkdir -p conf.d data/rctf-postgres data/rctf-redis |
134 | 73 |
|
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 |
136 | 79 |
|
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 |
138 | 87 |
|
| 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 |
139 | 96 |
|
140 |
| -# start docker |
| 97 | + info "Downloading rCTF..." |
141 | 98 |
|
| 99 | + curl -fsSO "https://raw.githubusercontent.com/redpwn/rctf/$RCTF_GIT_COMMIT/docker-compose.yml" |
| 100 | + docker-compose pull |
142 | 101 |
|
143 |
| -info "Finished installation to ${INSTALL_PATH}." |
| 102 | + info "Finished installation to ${RCTF_INSTALL_PATH}." |
144 | 103 |
|
145 |
| -printf "Would you like to start rCTF now (y/N)? " |
| 104 | + printf "Would you like to start rCTF now (y/N)? " |
146 | 105 |
|
147 |
| -read -r result </dev/tty |
| 106 | + read -r result </dev/tty |
148 | 107 |
|
149 |
| -if [ "$result" = "y" ]; then |
| 108 | + if [ "$result" = "y" ]; then |
150 | 109 | info "Running 'docker-compose up -d'..."
|
151 | 110 | docker-compose up -d
|
152 | 111 | info "rCTF is now running at 127.0.0.1:8080."
|
153 | 112 | 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." |
156 | 115 | exit 0
|
157 |
| -fi |
| 116 | + fi |
| 117 | +} |
| 118 | + |
| 119 | +do_install |
0 commit comments