#!/bin/bash # base settings set -e [ -e /firstboot ] || exit 0 echo 'Setting defaults...' localectl --no-convert set-keymap de-latin1-nodeadkeys echo 'Activate services...' timedatectl set-ntp true # variables LABEL="DATA" DATABASE_PASS="Di1sgMySQLPwd." # Data partition echo 'Mount data partition...' mkdir -p /$LABEL if [ ! -L "/dev/disk/by-label/$LABEL" ]; then echo 'ERROR: Data partition not found!' echo "Please create a data partition with ext4 filesystem and label \"$LABEL\":" echo "# cfdisk /dev/ (use GPT label, create linux partition)" echo "# mkfs.ext4 -L $LABEL /dev/" exit 1 fi if ! grep -Fq "LABEL=$LABEL" /etc/fstab; then echo "LABEL=$LABEL /$LABEL ext4 noatime 0 1" >> /etc/fstab fi mount -a if ! mount | grep /$LABEL > /dev/null; then echo "ERROR: Could not mount data partition!" exit 1 fi if [ ! -d "/$LABEL/var/lib/mysql/assp" ]; then echo 'Initialize MariaDB...' systemctl stop mariadb mkdir -p /$LABEL/var/lib/mysql rm -rf /$LABEL/var/lib/mysql/* cp -a /var/lib/mysql/. /$LABEL/var/lib/mysql sed -i "s:^datadir.*:datadir = /$LABEL/var/lib/mysql:" /etc/mysql/my.cnf systemctl start mariadb echo 'Create ASSP database...' mysql -u root -e "CREATE USER 'assp'@'localhost' IDENTIFIED BY '$DATABASE_PASS'" mysql -u root -e "CREATE DATABASE assp;" mysql -u root -e "GRANT ALL PRIVILEGES ON assp.* TO 'assp'@'localhost' IDENTIFIED by '$DATABASE_PASS';" mysql -u root -e "FLUSH PRIVILEGES;" else echo 'Start MariaDB...' sed -i "s:^datadir.*:datadir = /$LABEL/var/lib/mysql:" /etc/mysql/my.cnf systemctl start mariadb fi echo 'Enable database...' systemctl enable mariadb # Perl (und damit ASSP) darf auch Ports unter 1024 öffnen setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/perl rm /firstboot