Skip to content

Instantly share code, notes, and snippets.

@aljaxus
Last active August 11, 2019 09:58
Show Gist options
  • Save aljaxus/d5278fd840d20ffda557fac83f85a608 to your computer and use it in GitHub Desktop.
Save aljaxus/d5278fd840d20ffda557fac83f85a608 to your computer and use it in GitHub Desktop.
#!/bin/bash
function wait () {
echo ""
echo ""
if [ ! -z "$1" ]
then
echo "Finished: $1"
fi
if [ ! -z "$2" ]
then
echo "Up next: $2"
fi
echo "Waiting 5 seconds ..."
sleep 5
}
cd
apt-get update -y
apt-get upgrade -y
wait "Updating the system #1" "Installing required packages"
sudo apt-get install -y git build-essential python-pip openjdk-11-jdk-headless fp-compiler postgresql postgresql-client python3.6 cppreference-doc-en-html cgroup-lite libcap-dev zip
sudo apt-get install -y python3.6-dev libpq-dev libcups2-dev libyaml-dev libffi-dev python3-pip
sudo apt-get install -y nginx-full python2.7 php7.2-cli php7.2-fpm phppgadmin texlive-latex-base a2ps haskell-platform rustc mono-mcs
sudo apt-get install -y fp-units-base fp-units-fcl fp-units-misc fp-units-math fp-units-rtl
wait "Installed required packages" "Updating the system #2"
apt-get update -y
apt-get upgrade -y
wait "Updating the system #2" "Cloning the CMS repo"
git clone https://github.com/cms-dev/cms.git --recursive
cd cms
git fetch --all --tags --prune
git checkout v1.4.rc1
git submodule update --init
wait "Cloning the repo" "Installing the Python requirements and running the setup"
pip3 install -r requirements.txt
python3 prerequisites.py install
python3 setup.py install
wait "Installing Python requirements and setup.py" "PostgreSql setup"
cmsuserPwd=$(python3 -c 'from cmscommon import crypto; print(crypto.get_hex_random_key())')
sed -i "s|peer|trust|g" /etc/postgresql/10/main/pg_hba.conf
systemctl restart postgresql
echo "$cmsuserPwd"
sudo -u postgres createuser --username=postgres cmsuser
sudo -u postgres createdb --username=postgres --owner=cmsuser cmsdb
sudo -u postgres psql --username=postgres --dbname=cmsdb --command="ALTER USER cmsuser WITH PASSWORD '$cmsuserPwd'"
sudo -u postgres psql --username=postgres --dbname=cmsdb --command='ALTER SCHEMA public OWNER TO cmsuser'
sudo -u postgres psql --username=postgres --dbname=cmsdb --command='GRANT SELECT ON pg_largeobject TO cmsuser'
wait "PostgreSql setup" "CMS config setup"
cp config/cms.conf.sample /etc/cms.conf
cmsToken=$(python3 -c 'from cmscommon import crypto; print(crypto.get_hex_random_key())')
sed -i "s|postgresql+psycopg2://cmsuser:your_password_here@localhost:5432/cmsdb|postgresql+psycopg2://cmsuser:$cmsuserPwd@localhost:5432/cmsdb|g" /etc/cms.conf
sed -i "s|8e045a51e4b102ea803c06f92841a1fb|$cmsToken|g" /etc/cms.conf
wait "CMS config setup" "CMS database initialization"
cmsInitDB
wait "CMS database initialization" "Setting up the CMS service"
mkdir /var/local/log/
mkdir /var/local/cache/
servicesToRegister=( cmsAdminWebServer cmsContestWebServer cmsEvaluationService cmsLogService cmsPrintingService cmsProxyService cmsRankingWebServer cmsResourceService cmsScoringService )
for i in "${servicesToRegister[@]}"
do
touch "/etc/systemd/system/$i.service"
echo "
[Unit]
Description=CMS $i server
After=network.target
StartLimitInterval=0
[Service]
ExecStart=/usr/local/bin/$i
Restart=on-failure
RestartSec=20s
Type=idle
[Install]
WantedBy=multi-user.target
" > "/etc/systemd/system/$i.service"
systemctl enable "$i.service"
systemctl start "$i.service"
done
for i in "${servicesToRegister[@]}"
do
systemctl status "$i.service" --no-pager
done
wait "Setup CMS services" "Setup the admin account"
cmsAddAdminOut=$(cmsAddAdmin admin)
cmsAdminPass=$(echo $cmsAddAdminOut | awk '{ print $NF }')
wait "Setup the admin account" "Print system information"
echo ""
echo ""
echo "System info"
echo "|_ PostgreSql users"
echo " |_ cmsuser account => cmsuser : $cmsuserPwd"
echo "|_ CMS"
echo " |_ secret token => $cmsToken"
echo " |_ admin password => admin : $cmsAdminPass"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment