Spotter-VM/basic.sh

65 lines
2.1 KiB
Bash
Executable File

#!/bin/sh
SOURCE_DIR=$(realpath $(dirname "${0}"))/basic
# Install packages
apk --no-cache add --virtual .useful curl git file htop libressl openssh-server openssh-sftp-server
apk --no-cache add docker gettext kbd-misc python2 nginx
# Copy profile files and settings
mkdir -p /root/.config/htop /root/.ssh
cp ${SOURCE_DIR}/root/.profile /root/.profile
cp ${SOURCE_DIR}/root/.ssh/authorized_keys /root/.ssh/authorized_keys
cp ${SOURCE_DIR}/root/.config/htop/htoprc /root/.config/htop/htoprc
# Copy boot configuration
cp ${SOURCE_DIR}/boot/extlinux.conf /boot/extlinux.conf
cp ${SOURCE_DIR}/boot/spotter.txt /boot/spotter.txt
cp ${SOURCE_DIR}/etc/inittab /etc/inittab
>/etc/motd
# Enable support for Czech characters
cp ${SOURCE_DIR}/etc/rc.conf /etc/rc.conf
cp ${SOURCE_DIR}/etc/conf.d/consolefont /etc/conf.d/consolefont
# Configure NTP client
cp ${SOURCE_DIR}/etc/conf.d/ntpd /etc/conf.d/ntpd
# Create a self-signed certificate
mkdir /etc/ssl/private
openssl req -x509 -new -out /etc/ssl/certs/services.pem -keyout /etc/ssl/private/services.key -nodes -days 7305 -subj "/CN=$(hostname)"
chmod 640 /etc/ssl/private/services.key
# Configure nginx
cp ${SOURCE_DIR}/etc/nginx/nginx.conf /etc/nginx/nginx.conf
# Download and configure acme.sh
mkdir /etc/acme.sh.d
wget https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh -O /usr/bin/acme.sh
sed -i 's|$HOME/.$PROJECT_NAME|/etc/acme.sh.d|' /usr/bin/acme.sh
cp ${SOURCE_DIR}/etc/periodic/daily/acme-sh /etc/periodic/daily/acme-sh
chmod +x /usr/bin/acme.sh
# Copy Spotter resources
mkdir /etc/spotter
cp ${SOURCE_DIR}/srv/config.json /srv/config.json
cp ${SOURCE_DIR}/usr/bin/spotter-appmgr /usr/bin/spotter-appmgr
cp -r ${SOURCE_DIR}/srv/portal /srv/portal
# Configure services
for SERVICE in consolefont crond nginx ntpd sshd; do
rc-update add ${SERVICE} boot
service ${SERVICE} start
done
# Configure Docker service
cp ${SOURCE_DIR}/etc/init.d/docker /etc/init.d/docker
rc-update add docker
service docker start
# Create basic images
docker build -t alpine ${SOURCE_DIR}
# Set dummy domain and generate related files
spotter-appmgr update-domain spotter.vm 443