blob: f8f778fa68d0379be1edc896a6c9e0bd06533034 (
plain) (
tree)
|
|
#!/bin/bash
MY_PID=$$
perror() {
echo "$@" >> /root/init.log
[ "$MY_PID" != "$$" ] && kill "$MY_PID"
exit 5
}
echo "$(basename $0) gestartet: $(date "+%Y-%m-%d %H:%m:%S")" >> /root/init.log
[ -r "/root/installer/config" ] || perror "Installationsfehler: Keine firstrun-config gefunden!"
source "/root/installer/config" || { echo "Fehler beim Sourcen der firstrun-config." >> /root/init.log; exit 1; }
[ -z "$MYSQL_ROOT_PASS" ] && perror "Installationsfehler: WARNUNG: Aktuelles MySQL-root-Passwort nicht bekannt!"
generate_password() {
tr -dc _A-Za-z0-9 < /dev/urandom | head -c 16
}
patchfiles() {
# <find> <replace> <file1> <file2> ... <fileN>
# Warning: does not escape!
FIND=$1
REPLACE=$2
shift 2
while [ $# -gt 0 ]; do
sed -i "s/${FIND}/${REPLACE}/g" "$1"
shift
done
}
echo -n "Lösche alte ssh-Schlüssel ..." >> /root/init.log
rm -f /etc/ssh/ssh_host_*key* 2>/dev/null
echo " done."
echo -n "Generating new ssh keys..." >> /root/init.log
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N "" -t rsa -q
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N "" -t dsa -q
ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N "" -t ecdsa -q
echo "... done." >> /root/init.log
export LANG=de_DE.UTF-8
echo "Generiere intern genutzte Passwörter (z.B. MySQL-Zugänge) neu ..." >> /root/init.log
umask 0077
MYSQL_ROOT_NEW=$(generate_password)
mysqladmin -u root -p"${MYSQL_ROOT_PASS}" password "${MYSQL_ROOT_NEW}" || perror "Neusetzen des root-MySQL-Passworts fehlgeschlagen"
# Just in case...
sed -i "s/^MYSQL_ROOT_PASS=.*\$/MYSQL_ROOT_PASS=${MYSQL_ROOT_NEW}/g" "/root/installer/config"
MYSQL_BWLEHRPOOL_NEW=$(generate_password)
echo "SET PASSWORD FOR 'bwLehrpool'@'localhost' = PASSWORD('$MYSQL_BWLEHRPOOL_NEW');" | mysql -u root -p"${MYSQL_ROOT_NEW}" || perror "Neusetzen des bwLehrpool-MySQL-Passworts fehlgeschlagen."
MYSQL_OPENSLX_NEW=$(generate_password)
echo "SET PASSWORD FOR 'openslx'@'localhost' = PASSWORD('$MYSQL_OPENSLX_NEW');" | mysql -u root -p"${MYSQL_ROOT_NEW}" || perror "Neusetzen des openslx-MySQL-Passworts fehlgeschlagen."
MYSQL_SYSMAINT_NEW=$(generate_password)
echo "SET PASSWORD FOR 'debian-sys-maint'@'localhost' = PASSWORD('$MYSQL_SYSMAINT_NEW');" | mysql -u root -p"${MYSQL_ROOT_NEW}" || perror "Neusetzen des debian-sys-maint-Passworts fehlgeschlagen."
# Store mysql root pass in root's home
echo "$MYSQL_ROOT_NEW" > /root/mysqlpass
chmod 600 /root/mysqlpass
echo -n "Konfigurationsdateien werden aktualisiert..." >> /root/init.log
# bwLehrpool mysql pass
# Patch dmsd, vmchooser-query-script
patchfiles "%MYSQL_BWLEHRPOOL_PASS%" "$MYSQL_BWLEHRPOOL_NEW" "$DMSDDIR/config.properties" "/srv/openslx/www/vmchooser/list.php"
# Pureftpd
patchfiles 'MYSQLPassword.*$' "MYSQLPassword $MYSQL_BWLEHRPOOL_NEW" "/etc/pure-ftpd/db/mysql.conf"
# openslx mysql pass
# Patching openslx-mysql-userpass into slx-admin config:
patchfiles "%MYSQL_OPENSLX_PASS%" "$MYSQL_OPENSLX_NEW" "$WWWDIR/slx-admin/config.php"
# Patching debian-sys-maint password into /etc/mysql/debian.cnf:
patchfiles 'password *=.*$' "password = $MYSQL_SYSMAINT_NEW" "/etc/mysql/debian.cnf"
echo " ok." >> /root/init.log
echo -n "Dienste werden aktiviert..." >> /root/init.log
if [ $(ps -p 1 -o comm=) = systemd ]; then
echo "Systemd erkannt (systemctl vorhanden)." >> /root/init.log
if [ ! -f /etc/systemd/system/dmsd.service ]; then
cat > /etc/systemd/system/dmsd.service <<-HEREDOC
[Unit]
Description=DMSD is the Dozentenmodul server daemon
[Service]
User=dmsd
Group=images
WorkingDirectory=$DMSDDIR
ExecStart=$(which java) -Xmx96M -jar bwLehrpoolSuite_Server.jar
Restart=always
RestartSec=5
SyslogIdentifier=dmsd
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
HEREDOC
echo "dmsd.service geschrieben." >> /root/init.log
fi
if [ ! -f /etc/systemd/system/taskmanager.service ]; then
cat > /etc/systemd/system/taskmanager.service <<-SOMEWHEREDOC
[Unit]
Description=Taskmanager is a bwLehrpool service daemon
[Service]
User=taskmanager
Group=taskmanager
WorkingDirectory=$TASKMANDIR
ExecStart=$(which java) -Xmx80M -jar taskmanager.jar
Restart=always
RestartSec=5
SyslogIdentifier=taskmanager
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
SOMEWHEREDOC
echo "taskmanager.service geschrieben." >> /root/init.log
fi
for i in dmsd.service taskmanager.service; do
systemctl enable $i
[ $? -ne 0 ] && echo "Warnung - konnte systemd-Service $i nicht aktivieren!" >> /root/init.log
done
else
# No systemctl -> no systemd, so: inittab-entry dmsd:
if ! grep -q "dmsd.*respawn" /etc/inittab; then
echo "dmsd:2:once:$DMSDDIR/dmsd.sh" >> /etc/inittab
fi
# inittab-entry taskmanager:
if ! grep -q "tman.*respawn" /etc/inittab; then
echo "tman:2345:respawn:$TASKMANDIR/taskmanager.sh" >> /etc/inittab
fi
fi
echo -n " ok." >> /root/init.log
# Write MOTD
cat > /etc/motd <<-THEREDOC
*** bwLehrpool Satelliten-Server, Version $VERSION ***
Eingerichtet am $(date)
Wenn Sie sich als root eingeloggt haben, haben Sie nun folgende Optionen:
netsetup - Konfiguriert das Netzwerk-Interface neu (DHCP oder statisch)
reboot - System neustarten
poweroff - System herunterfahren
Andere Modifikationen am System sind in der Regel nicht notwendig.
THEREDOC
# Write version to /etc/sat_version
echo "$VERSION" > /etc/sat_version
sed -i "/rclocal_script.sh/d" /etc/rc.local
unlink "/root/installer/config" 2>/dev/null
unlink "/root/installer/rclocal_script.sh" 2>/dev/null
mv /etc/rc.local.sik /etc/rc.local
exit 0
|