forked from MarkUsProject/markus-autotesting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·122 lines (109 loc) · 3.52 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
#!/usr/bin/env bash
install_packages() {
echo "[AUTOTEST] Installing system packages"
sudo apt-get install ruby redis-server
sudo gem install bundler
}
create_server_user() {
if id ${SERVERUSER} &> /dev/null; then
echo "[AUTOTEST] Reusing existing server user '${SERVERUSER}'"
else
echo "[AUTOTEST] Creating server user '${SERVERUSER}'"
sudo adduser --disabled-password ${SERVERUSER}
fi
sudo mkdir -p ${WORKINGDIR}
sudo chown ${SERVERUSER}:${SERVERUSER} ${WORKINGDIR}
}
create_test_user() {
local testuser=$1
local queue=$2
local testdir=${WORKINGDIR}/${testuser}
if id ${testuser} &> /dev/null; then
echo "[AUTOTEST] Reusing existing test user '${testuser}'"
else
echo "[AUTOTEST] Creating test user '${testuser}'"
sudo adduser --disabled-login --no-create-home ${testuser}
fi
sudo mkdir ${testdir}
sudo chown ${SERVERUSER}:${testuser} ${testdir}
sudo chmod ug=rwx,o=,+t ${testdir}
echo "${SERVERUSER} ALL=(${testuser}) NOPASSWD:ALL" | EDITOR="tee -a" sudo visudo
CONF="${CONF}{user: '${testuser}', dir: '${testdir}', queue: '${queue}'},"
}
create_test_users() {
if [[ -z ${NUMWORKERS} ]]; then
create_test_user ${TESTUSER} ${QUEUE}
else
for i in $(seq 0 $((NUMWORKERS - 1))); do
create_test_user ${TESTUSER}${i} ${QUEUE}${i}
done
fi
}
create_working_dirs() {
echo "[AUTOTEST] Creating working directories"
sudo mkdir -p ${SPECSDIR}
sudo mkdir -p ${VENVSDIR}
sudo mkdir -p ${RESULTSDIR}
sudo chown ${SERVERUSER}:${SERVERUSER} ${SPECSDIR} ${VENVSDIR} ${RESULTSDIR}
sudo chmod u=rwx,go= ${RESULTSDIR}
}
install_gems() {
echo "[AUTOTEST] Installing gems"
pushd ${SERVERDIR} > /dev/null
bundle install --deployment
popd > /dev/null
}
run_resque() {
sudo -u ${SERVERUSER} -- ${SERVERDIR}/start_resque.sh ${QUEUE} ${NUMWORKERS}
}
create_markus_conf() {
echo "[AUTOTEST] Creating Markus web server config snippet in 'markus_conf.rb'"
echo "
AUTOTEST_ON = true
AUTOTEST_STUDENT_TESTS_ON = false
AUTOTEST_STUDENT_TESTS_BUFFER_TIME = 1.hour
AUTOTEST_CLIENT_DIR = 'TODO_web_server_dir'
AUTOTEST_RUN_QUEUE = 'TODO_web_server_queue'
AUTOTEST_SERVER_HOST = '$(hostname).$(dnsdomainname)'
AUTOTEST_SERVER_FILES_USERNAME = '${SERVERUSER}'
AUTOTEST_SERVER_FILES_DIR = '${WORKINGDIR}'
AUTOTEST_SERVER_RESULTS_DIR = '${RESULTSDIR}'
AUTOTEST_SERVER_TESTS = [${CONF}]
" >| markus_conf.rb
}
suggest_next_steps() {
echo "[AUTOTEST] (You must add the Markus web server public key to ${SERVERUSER}'s '~/.ssh/authorized_keys')"
echo "[AUTOTEST] (You may want to add '${SERVERDIR}/start_resque.sh ${QUEUE} ${NUMWORKERS}' to ${SERVERUSER}'s crontab with a @reboot time)"
echo "[AUTOTEST] (You should install the individual testers you plan to use)"
}
# script starts here
if [[ $# -lt 3 || $# -gt 4 ]]; then
echo "Usage: $0 server_user test_user working_dir [num_workers]"
exit 1
fi
# vars
THISSCRIPT=$(readlink -f ${BASH_SOURCE})
THISSCRIPTDIR=$(dirname ${THISSCRIPT})
SERVERUSER=$1
TESTUSER=$2
WORKINGDIR=$(readlink -f $3)
if [[ $# -eq 4 ]]; then
NUMWORKERS=$4
else
NUMWORKERS=""
fi
SERVERDIR=${THISSCRIPTDIR}/server
SPECSDIR=${WORKINGDIR}/specs
VENVSDIR=${WORKINGDIR}/venvs
RESULTSDIR=${WORKINGDIR}/results
QUEUE=${TESTUSER}
CONF=""
# main
install_packages
create_server_user
create_test_users
create_working_dirs
install_gems
run_resque
create_markus_conf
suggest_next_steps