diff --git a/.vagrantenv/.bashrc b/.vagrantenv/.bashrc index a26630509d1da085cddcf1b274af5daa704a711f..a018e2336df6fe36ab62f1204873bc2b34f0371c 100644 --- a/.vagrantenv/.bashrc +++ b/.vagrantenv/.bashrc @@ -120,3 +120,13 @@ if ! shopt -oq posix; then . /etc/bash_completion fi fi + +## Display banner and print some usefull statistics to anyone that connects via SSH: +if [ ! -z "$SSH_CONNECTION" ]; then + echo "" + echo "" + if [ -x /vagrant/.vagrantenv/system-banner.sh ]; then + /vagrant/.vagrantenv/system-banner.sh + fi + echo "" +fi diff --git a/.vagrantenv/finalize.sh b/.vagrantenv/finalize.sh index ebbf3b4dca096c310ab2a125ab3db14e2de9038b..2cfdc56db912b118ec651b17c7e146a9db012dbd 100644 --- a/.vagrantenv/finalize.sh +++ b/.vagrantenv/finalize.sh @@ -1,25 +1,47 @@ #!/bin/bash #------------------------------------------------------------------------------- -# Installing environment suitable for Mentat development +# Final provisioning of Vagrant environment suitable for Mentat development. # # Copyright (C) since 2011 CESNET, z.s.p.o # Use of this source is governed by the MIT license, see LICENSE file. #------------------------------------------------------------------------------- -echo "==========> <BEGIN> finalize.sh" - -sudo -u mentat /var/mentat/venv/bin/python /vagrant/bin/mentat-dbmngr.py --command init -sudo -u mentat bash -c "source /var/mentat/venv/bin/activate ; hawat-cli db stamp head" -sudo -u mentat bash -c "source /var/mentat/venv/bin/activate ; /etc/mentat/scripts/sqldb-migrate.sh stamp head" +. /etc/default/mentat +. /etc/mentat/scripts/lib.sh -sudo -u mentat /var/mentat/venv/bin/python /vagrant/bin/mentat-precache.py --allow-empty +echo "==========> <BEGIN> finalize.sh" +echo "==========> Bootstraping database schema and configuration" +sudo -u mentat ${MENTAT_VENV}/python /vagrant/bin/mentat-dbmngr.py --command init +sudo -u mentat bash -c "source ${MENTAT_VENV}/activate ; hawat-cli db stamp head" +sudo -u mentat bash -c "source ${MENTAT_VENV}/activate ; /etc/mentat/scripts/sqldb-migrate.sh stamp head" /etc/mentat/scripts/sqldb-optimize.sh +echo "==========> Pregenerating application data" +sudo -u mentat ${MENTAT_VENV}/python /vagrant/bin/mentat-precache.py --allow-empty + +echo "==========> Tweaking database users" sudo -u postgres psql -c "SELECT usename FROM pg_catalog.pg_user;" | grep root > /dev/null if [ $? -ne 0 ]; then echo "Creating default PostgreSQL user 'root'" sudo -u postgres psql -c "CREATE USER root SUPERUSER WITH PASSWORD 'root';" fi +echo "==========> Configuring Apache to serve development server" +if [ ! -L /etc/apache2/sites-enabled/site_mentat_vagrant.conf ] ; then + ensure_linked_file /vagrant/conf/apache/site_mentat_vagrant.conf /etc/apache2/sites-available/site_mentat_vagrant.conf + sed -i.bak s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=mentat/g /etc/apache2/envvars + sed -i.bak s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=mentat/g /etc/apache2/envvars + rm -f /etc/apache2/envvars.bak + + a2enmod rewrite + a2enmod ssl + a2enmod wsgi + a2dissite 000-default.conf + a2dissite default-ssl.conf + a2ensite site_mentat_vagrant.conf + + systemctl restart apache2.service +fi + echo "==========> <DONE> finalize.sh" diff --git a/.vagrantenv/provision.sh b/.vagrantenv/provision.sh index 36982c3619d3191e719e1d5afadd1977c022e7ef..6543742865ffbebc96dc21fd83ceb45e3851309c 100644 --- a/.vagrantenv/provision.sh +++ b/.vagrantenv/provision.sh @@ -1,6 +1,6 @@ #!/bin/bash #------------------------------------------------------------------------------- -# Installing environment suitable for Mentat development +# Initial provisioning of Vagrant environment suitable for Mentat development. # # Copyright (C) since 2011 CESNET, z.s.p.o # Use of this source is governed by the MIT license, see LICENSE file. @@ -8,6 +8,15 @@ echo "==========> <BEGIN> provision.sh" +echo "==========> Configuring timezone and locales" +echo "Europe/Prague" > /etc/timezone +dpkg-reconfigure -f noninteractive tzdata && \ + sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ + sed -i -e 's/# cs_CZ.UTF-8 UTF-8/cs_CZ.UTF-8 UTF-8/' /etc/locale.gen && \ + echo 'LANG="en_US.UTF-8"'>/etc/default/locale && \ + dpkg-reconfigure --frontend=noninteractive locales && \ + update-locale LANG=en_US.UTF-8 + echo "==========> Linking default configurations" if [ ! -L /etc/default/mentat ] ; then ln -s /vagrant/etc/default/mentat /etc/default/mentat @@ -18,28 +27,19 @@ fi . /etc/default/mentat . /etc/mentat/scripts/lib.sh -echo "==========> Configuring timezone and locales" -echo "Europe/Prague" > /etc/timezone -dpkg-reconfigure -f noninteractive tzdata && \ - sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ - sed -i -e 's/# cs_CZ.UTF-8 UTF-8/cs_CZ.UTF-8 UTF-8/' /etc/locale.gen && \ - echo 'LANG="en_US.UTF-8"'>/etc/default/locale && \ - dpkg-reconfigure --frontend=noninteractive locales && \ - update-locale LANG=en_US.UTF-8 - -echo "==========> Creating Mentat user" -if ! getent passwd mentat > /dev/null 2>&1; then - useradd -m -s /bin/bash -U mentat --groups sudo - cp -pr /home/vagrant/.ssh /home/mentat/ - chown -R mentat:mentat /home/mentat - echo "%mentat ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/mentat +echo "==========> Creating Mentat user for development" +if ! getent passwd ${MENTAT_USER} > /dev/null 2>&1; then + useradd -m -s /bin/bash -U ${MENTAT_USER} --groups sudo + cp -pr /home/vagrant/.ssh /home/${MENTAT_USER}/ + chown -R ${MENTAT_USER}:${MENTAT_USER} /home/${MENTAT_USER} + echo "%${MENTAT_USER} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/mentat fi echo "==========> Linking additional configuration files" ensure_linked_file /vagrant/.vagrantenv/.bashrc /home/vagrant/.bashrc ensure_linked_file /vagrant/.vagrantenv/.bashrc /home/mentat/.bashrc -echo "==========> Installing common dependencies" +echo "==========> Installing essential dependencies" apt-get update -qq \ && DEBIAN_FRONTEND=noninteractive apt-get -yq dist-upgrade \ && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ @@ -50,8 +50,6 @@ apt-get update -qq \ less \ git \ vim \ - bash-completion \ - sudo \ openssl \ ssl-cert \ && apt-get clean \ @@ -77,6 +75,8 @@ fi echo "==========> Installing application dependencies" apt-get update -qq \ && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ + sudo \ + bash-completion \ python3 \ python3-dev \ python3-setuptools \ @@ -117,23 +117,6 @@ if [ ! -f /etc/mentat/install.pip ] ; then echo '--editable "/vagrant/"' > /etc/mentat/install.pip fi -echo "==========> Configuring Apache to serve development server" -if [ ! -L /etc/apache2/sites-enabled/site_mentat_vagrant.conf ] ; then - ensure_linked_file /vagrant/conf/apache/site_mentat_vagrant.conf /etc/apache2/sites-available/site_mentat_vagrant.conf - sed -i.bak s/APACHE_RUN_USER=www-data/APACHE_RUN_USER=mentat/g /etc/apache2/envvars - sed -i.bak s/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=mentat/g /etc/apache2/envvars - rm -f /etc/apache2/envvars.bak - - a2enmod rewrite - a2enmod ssl - a2enmod wsgi - a2dissite 000-default.conf - a2dissite default-ssl.conf - a2ensite site_mentat_vagrant.conf - - systemctl restart apache2.service -fi - echo "==========> Preparing Python development environment" if ! [ -d "${MENTAT_VENV}" ]; then python3 -m venv "${MENTAT_VENV}" diff --git a/.vagrantenv/system-banner.sh b/.vagrantenv/system-banner.sh new file mode 100755 index 0000000000000000000000000000000000000000..a72136a7a67f967c3d56c65eedea87b21fb89a17 --- /dev/null +++ b/.vagrantenv/system-banner.sh @@ -0,0 +1,12 @@ +echo "" +echo " â–â–â–â•— â–â–â–â•—â–â–â–â–â–â–â–â•—â–â–â–â•— â–â–â•—â–â–â–â–â–â–â–â–â•— â–â–â–â–â–â•— â–â–â–â–â–â–â–â–â•—" +echo " â–â–â–â–â•— â–â–â–â–â•‘â–â–â•”â•â•â•â•â•ťâ–â–â–â–â•— â–â–â•‘â•šâ•â•â–â–â•”â•â•â•ťâ–â–â•”â•â•â–â–â•—â•šâ•â•â–â–â•”â•â•â•ť" +echo " â–â–â•”â–â–â–â–â•”â–â–â•‘â–â–â–â–â–â•— â–â–â•”â–â–â•— â–â–â•‘ â–â–â•‘ â–â–â–â–â–â–â–â•‘ â–â–â•‘" +echo " â–â–â•‘â•šâ–â–╔╝â–â–â•‘â–â–â•”â•â•â•ť â–â–â•‘â•šâ–â–â•—â–â–â•‘ â–â–â•‘ â–â–â•”â•â•â–â–â•‘ â–â–â•‘" +echo " â–â–â•‘ â•šâ•â•ť â–â–â•‘â–â–â–â–â–â–â–â•—â–â–â•‘ â•šâ–â–â–â–â•‘ â–â–â•‘ â–â–â•‘ â–â–â•‘ â–â–â•‘" +echo " â•šâ•â•ť â•šâ•â•ťâ•šâ•â•â•â•â•â•â•ťâ•šâ•â•ť â•šâ•â•â•â•ť â•šâ•â•ť â•šâ•â•ť â•šâ•â•ť â•šâ•â•ť" +echo " Copyright (C) since 2011 CESNET, z.s.p.o" +echo "" +echo " Welcome to Mentat development environment" +echo " https://alchemist.cesnet.cz/mentat/doc/development/html/_doclib/development.html" +echo "" diff --git a/Vagrantfile b/Vagrantfile index 953ee016fa8c9ec8584b8ec749de2f9243bb348e..9f238e2cd2790fc3cd03727449d7070b27cee350 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,11 +5,11 @@ Vagrant.configure('2') do |config| config.vm.hostname = 'mentat-devel.local' config.vm.box = 'debian/contrib-buster64' - # Flask development server + # Host port 5000: Flask development server config.vm.network 'forwarded_port', guest: 5000, host: 5000 - # Apache web server + # Host port 4443: Apache web server config.vm.network 'forwarded_port', guest: 443, host: 4443 - # Sendria + # Host port 1080: Sendria mailtrap service for development config.vm.network 'forwarded_port', guest: 1080, host: 1080 # Create a private network, which allows host-only access to the machine @@ -45,10 +45,8 @@ Vagrant.configure('2') do |config| bash /vagrant/packaging/debian/postinst bash /vagrant/.vagrantenv/finalize.sh SHELL - #config.vm.provision :ansible do |ansible| - # ansible.playbook = '.vagrantenv/provision.yml' - #end + # Automatically connect as 'mentat' user with ssh command. VAGRANT_COMMAND = ARGV[0] config.ssh.username = 'mentat' if VAGRANT_COMMAND == 'ssh' end diff --git a/packaging/debian/postinst b/packaging/debian/postinst index 7c46aabd7b0db2b6a7ff92fd2fc4807c32f8f1eb..ca240e72c06c0c4efce0c0bfa32c0e74dc51749e 100755 --- a/packaging/debian/postinst +++ b/packaging/debian/postinst @@ -13,8 +13,8 @@ set -e . /etc/default/mentat # Add restricted mentat user -if ! getent passwd mentat > /dev/null 2>&1; then - adduser --quiet --system --home /var/mentat/spool --no-create-home --disabled-login --group mentat +if ! getent passwd ${MENTAT_USER} > /dev/null 2>&1; then + adduser --quiet --system --home /var/mentat/spool --no-create-home --disabled-login --group ${MENTAT_USER} fi if ! [ -d "${MENTAT_VENV}" ]; then