Spotter-VM/01-basic.sh

153 lines
4.5 KiB
Bash
Raw Normal View History

2017-06-23 10:17:08 +02:00
#!/bin/bash
SOURCE_DIR=$(realpath $(dirname "${0}"))
export DEBIAN_FRONTEND="noninteractive"
2017-06-23 10:17:08 +02:00
# Uninstall unnecessary packages
apt-get -y purge bsdmainutils dictionaries-common emacsen-common iamerican ibritish ienglish-common installation-report ispell laptop-detect nano os-prober task-english tasksel tasksel-data wamerican
# Install useful packages
apt-get -y update
2017-09-24 20:12:30 +02:00
apt-get -y --no-install-recommends install bash-completion ca-certificates file git htop ntp openssl sudo tree unzip vim
######
# OpenSSH and user settings
#####
2017-06-23 10:17:08 +02:00
# Install OpenSSH server
apt-get -y --no-install-recommends install openssh-server
2017-09-11 10:36:04 +02:00
mkdir ~/.ssh
2017-09-17 23:05:00 +02:00
cp ${SOURCE_DIR}/basic/root/.ssh/authorized_keys /root/.ssh/authorized_keys
2017-09-17 23:05:00 +02:00
# Copy profile files and settings
mkdir -p /root/.config/htop
2017-06-29 11:38:48 +02:00
cp ${SOURCE_DIR}/basic/root/.bashrc /root/.bashrc
2017-09-17 23:05:00 +02:00
cp ${SOURCE_DIR}/basic/root/.config/htop/htoprc /root/.config/htop/htoprc
cp ${SOURCE_DIR}/basic/root/.vimrc /root/.vimrc
# Remove default user
deluser --remove-all-files user 2>/dev/null
2017-08-31 19:45:00 +02:00
#####
# System boot
#####
# Rename encrypted partition
sed -i 's/sda2_crypt/system/' /etc/crypttab
dmsetup rename sda2_crypt system
# Suppress warnings during boot
cp ${SOURCE_DIR}/basic/usr/share/initramfs-tools/scripts/local-top/lvm2 /usr/share/initramfs-tools/scripts/local-top/lvm2
cp ${SOURCE_DIR}/basic/usr/share/initramfs-tools/scripts/local-top/cryptroot /usr/share/initramfs-tools/scripts/local-top/cryptroot
# Set GRUB options
cp ${SOURCE_DIR}/basic/etc/default/grub /etc/default/grub
# Set legal banner with URL + latin2 character set
cp ${SOURCE_DIR}/basic/etc/default/console-setup /etc/default/console-setup
cp ${SOURCE_DIR}/basic/etc/issue /etc/issue
dpkg-reconfigure console-setup
2017-06-23 10:37:25 +02:00
# Forbid login on tty1, disable tty2-6
cp ${SOURCE_DIR}/basic/lib/systemd/system/getty@.service /lib/systemd/system/getty@.service
2017-06-23 10:37:25 +02:00
systemctl mask getty-static
# Update initramfs and GRUB
update-initramfs -u
update-grub
#####
# Postfix
#####
# Preconfigure
echo postfix postfix/main_mailer_type string "Satellite system" | debconf-set-selections
echo postfix postfix/mailname string "$(hostname -f)" | debconf-set-selections
echo postfix postfix/relayhost string "" | debconf-set-selections
# Install packages
apt-get -y --no-install-recommends install postfix
# Configure Postfix
cp ${SOURCE_DIR}/basic/etc/postfix/main.cf /etc/postfix/main.cf
# Restart services
systemctl restart postfix
2017-08-31 19:45:00 +02:00
#####
# LXC
#####
# Install packages
apt-get -y --no-install-recommends install lxc debootstrap rsync dnsmasq-base xz-utils
2017-08-31 19:45:00 +02:00
# Configure LXC
cp ${SOURCE_DIR}/basic/etc/default/lxc-net /etc/default/lxc-net
cp ${SOURCE_DIR}/basic/etc/lxc/default.conf /etc/lxc/default.conf
# Restart services
systemctl start lxc-net lxc
#####
# Nginx + uWSGI
#####
# Install packages
apt-get -y --no-install-recommends install nginx-light uwsgi uwsgi-plugin-python
# Create a self-signed certificate
openssl req -x509 -new -out /etc/ssl/certs/services.pem -keyout /etc/ssl/private/services.key -nodes -days 3654 -subj "/C=CZ/CN=$(hostname -f)"
chmod 640 /etc/ssl/private/services.key
# Configure nginx
mkdir /etc/nginx/apps-available /etc/nginx/apps-enabled
cp ${SOURCE_DIR}/basic/etc/nginx/nginx.conf /etc/nginx/nginx.conf
cp ${SOURCE_DIR}/basic/etc/nginx/sites-available/default /etc/nginx/sites-available/default
2017-09-20 14:15:57 +02:00
# Workaround for web2py shutdown problem, see https://github.com/web2py/web2py/issues/1769
sed -i 's|QUIT/30|QUIT/5|' /usr/share/uwsgi/init/specific_daemon
# Copy Portal resources
2017-09-14 21:49:57 +02:00
cp -r ${SOURCE_DIR}/basic/srv/portal /srv/portal
chown -R www-data:www-data /srv/portal
# Restart
systemctl restart nginx
#####
# PostgreSQL + PostGIS
#####
# Install packages
apt-get -y --no-install-recommends install postgresql-9.6 postgresql-9.6-postgis postgresql-contrib-9.6
# Configure
cp ${SOURCE_DIR}/basic/etc/postgresql/9.6/main/postgresql.conf /etc/postgresql/9.6/main/postgresql.conf
cp ${SOURCE_DIR}/basic/etc/postgresql/9.6/main/pg_hba.conf /etc/postgresql/9.6/main/pg_hba.conf
# Enable query logging. Only if the DEBUG environment variable is set
if [ ${DEBUG:-0} -eq 1 ]; then
sed -i 's/#log_destination/log_destination/' /etc/postgresql/9.6/main/postgresql.conf
sed -i 's/#logging_collector/logging_collector/' /etc/postgresql/9.6/main/postgresql.conf
sed -i 's/#log_directory/log_directory/' /etc/postgresql/9.6/main/postgresql.conf
sed -i 's/#log_statement/log_statement/' /etc/postgresql/9.6/main/postgresql.conf
fi
# Restart
systemctl restart postgresql
2017-10-26 22:47:44 +02:00
#####
# MariaDB
#####
# Install packages
apt-get -y --no-install-recommends install mariadb-server