Spotter-VM/basic.sh

80 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
set -e
cd $(realpath $(dirname "${0}"))/basic
# Configure APK repository
echo "@vm https://dl.dasm.cz/spotter-abuild" >>/etc/apk/repositories
cp etc/apk/keys/repokey.rsa.pub /etc/apk/keys/repokey.rsa.pub
# Install packages
apk --no-cache add ca-certificates curl bridge e2fsprogs-extra gettext iptables kbd-misc libcap libressl libseccomp postfix python3 py3-bcrypt py3-cffi py3-cryptography py3-dnspython py3-jinja2 py3-requests py3-six py3-werkzeug nginx util-linux acme-sh@vm lxc@vm
if [ ${DEBUG:-0} -eq 1 ]; then
# Install some utilities for DEBUG mode
apk --no-cache add git file htop less openssh-server openssh-sftp-server tar xz
fi
# Copy root profile files and settings for DEBUG mode
if [ ${DEBUG:-0} -eq 1 ]; then
mkdir -p /root/.config/htop /root/.ssh
cp root/.profile /root/.profile
cp root/.ssh/authorized_keys /root/.ssh/authorized_keys
cp root/.config/htop/htoprc /root/.config/htop/htoprc
fi
# Copy boot configuration
cp boot/extlinux.conf /boot/extlinux.conf
cp boot/vm.txt /boot/vm.txt
cp etc/inittab /etc/inittab
cp sbin/extend-disk /sbin/extend-disk
cp sbin/vmtty /sbin/vmtty
>/etc/motd
# Enable support for Czech characters
cp etc/rc.conf /etc/rc.conf
cp etc/conf.d/consolefont /etc/conf.d/consolefont
# Configure NTP client
cp etc/conf.d/ntpd /etc/conf.d/ntpd
# Configure networking
cp etc/conf.d/iptables /etc/conf.d/iptables
cp etc/iptables/rules-save /etc/iptables/rules-save
cp etc/network/interfaces /etc/network/interfaces
service networking restart
# Configure LXC
mkdir /var/log/lxc
echo -e "172.17.0.1 host" >>/etc/hosts
# Copy VMMgr resources
cp etc/init.d/vmmgr /etc/init.d/vmmgr
rc-update -u
cp -r srv/vm /srv/vm
ln -s /srv/vm/cli.py /usr/bin/vmmgr
# Create a self-signed certificate
vmmgr create-selfsigned
# Configure nginx
cp etc/nginx/nginx.conf /etc/nginx/nginx.conf
# Configure postfix
cp etc/postfix/main.cf /etc/postfix/main.cf
newaliases
# Configure services
for SERVICE in cgroups consolefont crond iptables nginx ntpd postfix swap vmmgr; do
rc-update add ${SERVICE} boot
service ${SERVICE} start
done
# Configure services for DEBUG mode
if [ ${DEBUG:-0} -eq 1 ]; then
rc-update add sshd boot
service sshd start
fi
# Generate nginx default.conf
vmmgr update-host spotter.vm 443