82 lines
2.9 KiB
Bash
Executable File
82 lines
2.9 KiB
Bash
Executable File
#!/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/<disk> (use GPT label, create linux partition)"
|
|
echo "# mkfs.ext4 -L $LABEL /dev/<partition>"
|
|
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/guacamole_db" ]; 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/mariadb.d/50-distro-server.cnf
|
|
systemctl start mariadb
|
|
|
|
echo 'Create Guacamole database...'
|
|
mysql -u root -e "CREATE DATABASE guacamole_db;"
|
|
mysql -u root -e "CREATE USER 'guacamole_user'@'localhost' IDENTIFIED BY '$DATABASE_PASS';"
|
|
mysql -u root -e "GRANT SELECT,INSERT,UPDATE,DELETE ON guacamole_db.* TO 'guacamole_user'@'localhost';"
|
|
mysql -u root -e "FLUSH PRIVILEGES;"
|
|
sed -i "s/#mysql-hostname: localhost/mysql-hostname: localhost/" /etc/guacamole/guacamole.properties
|
|
sed -i "s/#mysql-port: 3306/mysql-port: 3306/" /etc/guacamole/guacamole.properties
|
|
sed -i "s/#mysql-database: guacamole/mysql-database: guacamole_db/" /etc/guacamole/guacamole.properties
|
|
sed -i "s/#mysql-username: guacamole/mysql-username: guacamole_user/" /etc/guacamole/guacamole.properties
|
|
sed -i "s/#mysql-password: some_password/mysql-password: $DATABASE_PASS/" /etc/guacamole/guacamole.properties
|
|
|
|
echo 'Initialize Guacamole database...'
|
|
cat /usr/share/guacamole-client/schema/mysql/001-create-schema.sql | mysql -u root guacamole_db
|
|
cat /usr/share/guacamole-client/schema/mysql/002-create-admin-user.sql | mysql -u root guacamole_db
|
|
|
|
else
|
|
echo 'Start MariaDB...'
|
|
sed -i "s:^datadir.*:datadir = /$LABEL/var/lib/mysql:" /etc/mysql/mariadb.d/50-distro-server.cnf
|
|
systemctl start mariadb
|
|
fi
|
|
echo 'Enable database...'
|
|
systemctl enable mariadb
|
|
|
|
echo 'Start and enable Guacamole proxy daemon...'
|
|
systemctl start guacd
|
|
systemctl enable guacd
|
|
|
|
echo 'Start and enable Guacamole Tomcat instance...'
|
|
systemctl start tomcat-8.5
|
|
systemctl enable tomcat-8.5
|
|
|
|
echo 'Start and enable Nginx...'
|
|
systemctl start nginx
|
|
systemctl enable nginx
|
|
|
|
rm /firstboot
|