Skip to content

Instantly share code, notes, and snippets.

@cubercsl
Created July 19, 2024 13:29
Show Gist options
  • Save cubercsl/03cb5ef52fd6c7cbf45efdca519e4414 to your computer and use it in GitHub Desktop.
Save cubercsl/03cb5ef52fd6c7cbf45efdca519e4414 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
VERSION=8.2.3
SRC_DIR=/domjudge-src
if [ $EUID -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
baseurl=${1:-http://localhost/domjudge}
depends=(
autoconf automake git pkg-config
gcc g++ make acl zip unzip
mariadb-server mariadb-client
apache2-utils nginx php-fpm
php-cli php-zip
php-gd php-curl php-mysql php-json php-intl
php-gmp php-xml php-mbstring
sudo bsdmainutils ntp libcgroup-dev procps
libcurl4-gnutls-dev libjsoncpp-dev libmagic-dev
ca-certificates python3-yaml python3-requests
curl composer
# for building the documentation
python3-sphinx python3-sphinx-rtd-theme rst2pdf fontconfig python3-yaml
latexmk texlive-latex-recommended texlive-latex-extra tex-gyre
)
export DEBIAN_FRONTEND=noninteractive
apt-get update && \
apt-get upgrade -y && \
apt-get install --no-install-recommends --no-install-suggests -y \
"${depends[@]}"
# Download DOMjudge source
channel="releases"
if [[ $VERSION == *snapshot* ]]; then
channel="snapshot"
fi
if [ -f $SRC_DIR/domjudge-$VERSION.tar.gz ]; then
echo "Using existing domjudge-$VERSION.tar.gz"
else
mkdir -p $SRC_DIR
curl -L https://www.domjudge.org/$channel/domjudge-$VERSION.tar.gz -o $SRC_DIR/domjudge-$VERSION.tar.gz
fi
tar -C $SRC_DIR -xzf $SRC_DIR/domjudge-$VERSION.tar.gz
# get name of uid 1000
domjudge_user=$(getent passwd 1000 | cut -d: -f1)
cd $SRC_DIR
pushd domjudge-$VERSION
chown -R "$domjudge_user": .
# Build DOMjudge
sudo -u "$domjudge_user" ./configure --with-baseurl="$baseurl"
sudo -u "$domjudge_user" make domserver
make install-domserver
# Build documentation
sudo -u "$domjudge_user" make docs
make install-docs
sudo -u "$domjudge_user" make judgehost
popd
echo "Make tarball of configured DOMjudge for installation of judgehosts on other machines"
tar -czf $SRC_DIR/domjudge-configured-$VERSION.tar.gz domjudge-$VERSION
echo "Configuring DOMjudge"
echo "Setting up database"
cat <<EOF >> /etc/mysql/conf.d/mysql.cnf
[mysqld]
max_connections=1000
max_allowed_packet=4096M
innodb_log_file_size=4096M
EOF
cd /opt/domjudge/domserver
./bin/dj_setup_database -s install
echo "Fix permissions for images"
chown -R www-data:www-data webapp/public/images/*
echo "Setting up php-fpm"
domjudge_fpm_conf=/opt/domjudge/domserver/etc/domjudge-fpm.conf
sed -i 's/php_admin_value\[memory_limit\] = .*/php_admin_value[memory_limit] = 4096M/' "$domjudge_fpm_conf"
sed -i 's/php_admin_value\[upload_max_filesize\] = .*/php_admin_value[upload_max_filesize] = 4096M/' "$domjudge_fpm_conf"
sed -i 's/php_admin_value\[post_max_size\] = .*/php_admin_value[post_max_size] = 4096M/' "$domjudge_fpm_conf"
sed -i 's/pm.max_children = .*/pm.max_children = 500/' "$domjudge_fpm_conf"
sed -i 's/;php_admin_value\[date.timezone\] = .*/php_admin_value[date.timezone] = Asia\/Shanghai/' "$domjudge_fpm_conf"
fpm_version=$(php -v | head -n 1 | cut -d ' ' -f 2 | cut -d '.' -f 1,2)
ln -s /opt/domjudge/domserver/etc/domjudge-fpm.conf /etc/php/"$fpm_version"/fpm/pool.d/domjudge.conf
systemctl restart php"$fpm_version"-fpm
echo "Setting up nginx"
ln -s /opt/domjudge/domserver/etc/nginx-conf /etc/nginx/sites-enabled/domjudge
cat <<EOF >> /opt/domjudge/domserver/etc/nginx-conf-inner
# enable caching for static files
location ~* \.(jpg|jpeg|png|css|js)\$ {
access_log off;
log_not_found off;
expires 6h; # adjust as needed
}
EOF
# remove default site
rm /etc/nginx/sites-enabled/default
systemctl reload nginx
echo "DOMjudge setup complete"
echo "You can now access DOMjudge at $baseurl"
echo "The default admin username is 'admin' and the password is '$(cat /opt/domjudge/domserver/etc/initial_admin_password.secret)'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment