diff options
Diffstat (limited to 'satellit_installer/static_files/system/opt')
3 files changed, 185 insertions, 0 deletions
diff --git a/satellit_installer/static_files/system/opt/openslx/bashrc.inc b/satellit_installer/static_files/system/opt/openslx/bashrc.inc new file mode 100644 index 0000000..98711d4 --- /dev/null +++ b/satellit_installer/static_files/system/opt/openslx/bashrc.inc @@ -0,0 +1,13 @@ +ifname="$( ifconfig | grep -oEm1 '^e\w+' )" +slxip="$( ip -4 a show "$ifname" 2>/dev/null | grep -m1 '^\s*inet ' | awk '{print $2}' )" +[ -z "$slxip" ] && slxip="$( ip -4 a | grep '^\s*inet '| grep -vFm1 ' 127.' | awk '{print $2}' )" +slxip=${slxip%/*} +[ -z "$slxip" ] && read -r _ _ slxip _ <<<"$SSH_CONNECTION" +[ -z "$slxip" ] && slxip="noip???" +slxcol=32 +(( UID == 0 )) && slxcol=31 +PS1="\[\033[01;${slxcol}m\]\u\[\033[00m\]@\[\033[01;32m\]\h \[\033[00m\]($slxip) +\[\033[01;34m\]\w\[\033[00m\] # " +unset ifname slxip slxcol +# We always want to run this as root; sudo is a noop in case we already are. +alias tmate='sudo tmate' diff --git a/satellit_installer/static_files/system/opt/openslx/firstboot.sh b/satellit_installer/static_files/system/opt/openslx/firstboot.sh new file mode 100755 index 0000000..7ef2bfc --- /dev/null +++ b/satellit_installer/static_files/system/opt/openslx/firstboot.sh @@ -0,0 +1,120 @@ +#!/bin/bash + +MY_PID=$$ +perror() { + echo "[ERROR] $*" + [ "$MY_PID" != "$$" ] && kill "$MY_PID" + + if ! grep -q "firstboot.sh has thrown an error" /etc/motd; then + cat <<-EOF >> /etc/motd + + WARNING! + + firstboot.sh has thrown an error! + Please read /opt/openslx/firstrun.log and take appropriate measures! + This server may not work correctly! + + EOF + fi + exit 5 +} + +# Logfile +exec &> /opt/openslx/firstrun.log + +echo "+++ $(basename "$0") gestartet: $(date "+%Y-%m-%d %H:%m:%S")" + +conf="/opt/openslx/config.install" +[ -s "$conf" ] || perror "Config file $conf missing" +bash -n "$conf" || perror "Config file $conf has errors" +. "$conf" + +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 "+++ Lösche alte ssh-Schlüssel ..." +rm -f -- /etc/ssh/ssh_host_*key* 2>/dev/null + +echo "+++ Generating new sshd keys..." +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 +ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N "" -t ed25519 -q + +export LANG=de_DE.UTF-8 + +echo "+++ Generiere intern genutzte Passwörter (z.B. MySQL-Zugänge) neu ..." +umask 0077 + +MYSQL_SAT_NEW=$(generate_password) +echo "SET PASSWORD FOR 'sat'@'localhost' = PASSWORD('$MYSQL_SAT_NEW');" | mysql -u root || perror "Neusetzen des sat-MySQL-Passworts fehlgeschlagen." + +MYSQL_OPENSLX_NEW=$(generate_password) +echo "SET PASSWORD FOR 'openslx'@'localhost' = PASSWORD('$MYSQL_OPENSLX_NEW');" | mysql -u root || perror "Neusetzen des openslx-MySQL-Passworts fehlgeschlagen." + +echo "+++ Konfigurationsdateien werden aktualisiert..." + +# sat mysql pass +# Patch dmsd +patchfiles "%MYSQL_SAT_PASS%" "$MYSQL_SAT_NEW" "$DMSDDIR/config.properties" + +# openslx mysql pass +# Patching openslx-mysql-userpass into slx-admin config: +patchfiles "%MYSQL_OPENSLX_PASS%" "$MYSQL_OPENSLX_NEW" "$WWWDIR/slx-admin/config.php" + +# taskmanager password +TASKMANAGER_PASS=$(generate_password) +patchfiles "%TM_OPENSLX_PASS%" "$TASKMANAGER_PASS" "$WWWDIR/slx-admin/config.php" "$TASKMANDIR/config/config" + +echo "+++ Dienste werden aktiviert..." + +# Enable bwLehrpool related services +for i in dmsd.service taskmanager.service; do + systemctl enable "$i" || perror "Konnte systemd-Service $i nicht aktivieren!" + systemctl --no-block start "$i" +done + +# root ssh key +echo "" +echo "Erzeuge SSH Schlüsselpaar für root" +echo "" + +KEY=~/.ssh/id_rsa +rm -f -- "$KEY" "${KEY}.pub" +ssh-keygen -q -N "" -f "$KEY" \ + || echo "Achtung: Erzeugung Schlüsselpaar $KEY fehlgeschlagen." + +# Write MOTD +cat > /etc/motd <<THEREDOC +> *** bwLehrpool Satelliten-Server, Version $VERSION *** +> Eingerichtet am $(date) +> +> Wenn Sie sich als 'openslx' eingeloggt haben, haben Sie nun folgende Optionen: +> netsetup - Konfiguriert das Netzwerk-Interface neu (DHCP oder statisch) +> sudo reboot - System neustarten +> sudo poweroff - System herunterfahren +> +> Andere Modifikationen am System sind in der Regel nicht notwendig. +> +THEREDOC + +echo "+++ Daten des Firstrun-Scripts werden aufgeräumt..." +unlink "/opt/openslx/firstboot.sh" +unlink "$conf" +unlink "/etc/systemd/system/firstboot.service" +unlink "/etc/systemd/system/multi-user.target.wants/firstboot.service" + +exit 0 diff --git a/satellit_installer/static_files/system/opt/openslx/firstrun.sh b/satellit_installer/static_files/system/opt/openslx/firstrun.sh new file mode 100755 index 0000000..fc22959 --- /dev/null +++ b/satellit_installer/static_files/system/opt/openslx/firstrun.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +cat <<-HEREDOC +> +> Willkommen zur Grundkonfiguration des bwLehrpool-Satellitenservers. +> +> Diese einmalige Konfiguration dient dazu, das Passwort des System-Users +> "openslx" zu ändern (für Terminal, SSH), sowie ggf. die +> Netzwerkkonfiguration des Servers anzupassen. +> +HEREDOC + +while ! passwd; do + echo "> Das hat nicht geklappt. Bitte noch einmal versuchen:" +done + +cat <<-SUPPE +> +> Erzeuge SSH Schlüsselpaar +> +SUPPE + +KEY=~/.ssh/id_rsa + +rm -f -- "$KEY" "${KEY}.pub" +ssh-keygen -q -N "" -f "$KEY" \ + || echo "> Achtung: Erzeugung Schlüsselpaar $KEY fehlgeschlagen." + +cat <<-HERRR +> +> Abschließend können Sie festlegen, ob der Server seine IP-Konfiguration +> per DHCP erhält, oder eine statische Konfiguration verwendet wird. +> +HERRR + +netsetup + +cat <<YONDERDOC +> +> Damit ist die Einrichtung abgeschlossen. Die weitere Konfiguration des +> bwLehrpool-Systems erfolgt über die Webschnittstelle, die über die +> IP-Addresse oder den Hostnamen des Servers erreichbar ist. +> +> Bitte geben Sie zum Abschluss noch einmal das oben neu festgelegte +> Passwort ein. Der Server wird sich daraufhin neustarten und ist +> dann betriebsbereit. +> +YONDERDOC + +unlink /opt/openslx/firstrun.sh + +sudo reboot |