#!/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 # Database echo 'Initialize MariaDB...' systemctl stop mariadb if [ ! -d "/$LABEL/var/lib/mysql/mysql" ]; then mkdir -p /$LABEL/var/lib/mysql rm -rf /$LABEL/var/lib/mysql/* cp -a /var/lib/mysql/. /$LABEL/var/lib/mysql fi sed -i "s:^datadir.*:datadir = /$LABEL/var/lib/mysql:" /etc/mysql/mariadb.d/50-distro-server.cnf systemctl start mariadb echo 'Enable database...' systemctl enable mariadb rm /firstboot