diff options
Diffstat (limited to 'satellit_installer')
11 files changed, 92 insertions, 144 deletions
diff --git a/satellit_installer/includes/10-script_dropper.inc b/satellit_installer/includes/10-script_dropper.inc index efae442..62d1b58 100644 --- a/satellit_installer/includes/10-script_dropper.inc +++ b/satellit_installer/includes/10-script_dropper.inc @@ -1,9 +1,11 @@ patch_profile() { - if grep -q "/root/installer/firstrun.sh" /root/.profile; then + local script="/root/installer/firstrun_script.sh" + [ -x "$script" ] || perror "Firstrun script not found ($script)" + if grep -qF "$script" /root/.profile; then echo "# first_run script already in root's .profile, doing nothing." else echo "# Patching root's .profile" - echo "/root/installer/firstrun_script.sh" >> /root/.profile + echo "$script" >> /root/.profile fi } @@ -14,46 +16,9 @@ drop_script() { chmod 0600 /root/installer/config } -drop_keychanger_rclocal() { - if grep -q -F "/root/installer/rclocal_script.sh" /etc/rc.local; then - echo "# ssh key changer already in rc.local; doing nothing." - else - echo - echo "# Patching rc.local..." - cp -p /etc/rc.local /etc/rc.local.sik - cat > /etc/rc.local <<-HIERDOK - #!/bin/bash - echo "rc.local created: $(date "+%Y-%m-%d %H:%m:%S")" >> /root/init.log - echo "Starting /root/installer/rclocal_script.sh..." >> /root/init.log - /root/installer/rclocal_script.sh - exit 0 - HIERDOK - chmod +x /etc/rc.local - fi - # WTF? Why forking? - cat > /etc/systemd/system/rc-local.service <<-DORTDOK - [Unit] - Description=/etc/rc.local Compatibility - ConditionFileIsExecutable=/etc/rc.local - After=network.target mysql.service - - [Service] - Type=forking - ExecStart=/etc/rc.local start - TimeoutSec=0 - RemainAfterExit=yes - SysVStartPriority=99 - - [Install] - WantedBy=multi-user.target - DORTDOK - - systemctl daemon-reload - systemctl reenable rc-local || perror "Could not enable systemd service rc-local!" -} - drop_firstrun_script () { patch_profile drop_script - drop_keychanger_rclocal + systemctl daemon-reload + systemctl enable firstboot.service || perror "Could not enable firstboot service" } diff --git a/satellit_installer/includes/50-install_bwSuite_server.inc b/satellit_installer/includes/50-install_bwSuite_server.inc index 85a8904..2b89126 100644 --- a/satellit_installer/includes/50-install_bwSuite_server.inc +++ b/satellit_installer/includes/50-install_bwSuite_server.inc @@ -1,71 +1,14 @@ -config_bwSuite_server() { - # $1: Path to server directory - cat > "$1/config.properties" <<-EOF - vmstore.path = /srv/openslx/nfs - db.uri = jdbc:mysql://localhost/sat?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=utf8&connectionCollation=utf8mb4_unicode_ci - db.username = sat - db.password = %MYSQL_SAT_PASS% - db.location-table = openslx.location - master.address = bwlp-masterserver.ruf.uni-freiburg.de - EOF - - chown root:images "$1/config.properties" - chmod 0640 "$1/config.properties" -} - -install_bwSuite_service() { - # $1: Path to server directory - cat > "/etc/systemd/system/dmsd.service" <<-EOF - [Unit] - Description=DMSD is the Dozentenmodul server daemon - Wants=mysql.service - After=mysql.service - - [Service] - User=dmsd - Group=images - WorkingDirectory=$1 - ExecStart=$1/dmsd.sh - Restart=always - RestartSec=5 - SyslogIdentifier=dmsd - StandardOutput=syslog - StandardError=syslog - - [Install] - WantedBy=multi-user.target - EOF - cat > "$1/dmsd.sh" <<-EOF - #!/bin/sh - - KB=\$($(which grep) ^MemTotal /proc/meminfo | $(which awk) '{print \$2}') - [ -z "\$KB" ] && KB=600000 - if [ "\$KB" -gt 4096000 ]; then - MB=\$(( \$KB / ( 1024 * 3 ) + 667 )) - else - MB=\$(( \$KB / ( 1024 * 2 ) )) - fi - if [ "\$MB" -gt 2000 ] && ! $(which java) -version 2>&1 | $(which grep) -q '64-Bit'; then - MB=2000 - fi - [ "\$MB" -lt 190 ] && MB=190 - [ "\$MB" -gt 4500 ] && MB=4500 - - exec $(which java) -Xmx\${MB}M -jar dmsd.jar - EOF - chmod +x "$1/dmsd.sh" -} - install_bwSuite_server() { # $1: directory to install server to echo "# Installing server part of bwSuite... " - mkdir -p "$1" 2>/dev/null + mkdir -p "$1" || perror "Cannot create $1" install -m 0644 -p -o root -g root "$BASEDIR/static_files/dmsd.jar" "$1/dmsd.jar" \ || perror "Could not install dmsd.jar" chown -R root:root "$1" chmod -R go-w "$1" - config_bwSuite_server "$1" - install_bwSuite_service "$1" + install_files "dmsd" + chown root:images "$1/config.properties" + chmod 0640 "$1/config.properties" } diff --git a/satellit_installer/includes/70-write_tmate_config.inc b/satellit_installer/includes/70-write_tmate_config.inc deleted file mode 100644 index bd68ef4..0000000 --- a/satellit_installer/includes/70-write_tmate_config.inc +++ /dev/null @@ -1,12 +0,0 @@ -write_tmate_config() { - echo -n "# Writing tmate config... " - [ -d /root/.tmate.conf ] && mv /root/.tmate.conf.old # Unnecessary here, but... - cat > /root/.tmate.conf <<-JUSTANOTHERDOC - set -g tmate-server-host "tmate.ruf.uni-freiburg.de" - set -g tmate-server-port 2222 - set -g tmate-server-rsa-fingerprint "d7:d7:06:d0:b6:0d:75:a1:ad:ec:69:18:b3:a3:c0:4a" - set -g tmate-server-ecdsa-fingerprint "4f:c9:81:f1:1a:20:7d:6f:97:12:f2:a9:0f:f4:c5:6c" - set -g tmate-identity "" - JUSTANOTHERDOC - echo "done." -} diff --git a/satellit_installer/satellit_installer b/satellit_installer/satellit_installer index 33aaefc..fd4bbd6 100755 --- a/satellit_installer/satellit_installer +++ b/satellit_installer/satellit_installer @@ -116,8 +116,6 @@ write_tftpd_config patch_lighttpd_config patch_php_config # This takes a lot of time, so any background stuff before this. -write_tmate_config # here or elsewhere... - patch_ldapsearch patch_java @@ -146,9 +144,6 @@ patch_bashrc # vim config patch_vim -# This part drops a script and anchors it's execution within root's .profile: -drop_firstrun_script - install_timesync # cheap HTTP based timesync on boot # Remove translation from menu etc., enable required modules @@ -175,6 +170,10 @@ write_versionstring clean_install end_message +# This part drops a script and anchors it's execution within root's .profile +# Do this at the end so it's not there if something failed +drop_firstrun_script + finalize # Cleaning script; finalize script will delete itself. [ "$NODELETE_SOURCE" != "true" ] && { echo "#"; echo "# Deleting source directory..."; rm -rf "$BASEDIR"; echo "# done."; } \ diff --git a/satellit_installer/static_files/dmsd/etc/systemd/system/dmsd.service b/satellit_installer/static_files/dmsd/etc/systemd/system/dmsd.service new file mode 100644 index 0000000..fdb665c --- /dev/null +++ b/satellit_installer/static_files/dmsd/etc/systemd/system/dmsd.service @@ -0,0 +1,18 @@ +[Unit] +Description=DMSD is the Dozentenmodul server daemon +Wants=mysql.service +After=mysql.service + +[Service] +User=dmsd +Group=images +WorkingDirectory=/opt/dmsd +ExecStart=/opt/dmsd/dmsd.sh +Restart=always +RestartSec=5 +SyslogIdentifier=dmsd +StandardOutput=syslog +StandardError=syslog + +[Install] +WantedBy=multi-user.target diff --git a/satellit_installer/static_files/dmsd/opt/dmsd/config.properties b/satellit_installer/static_files/dmsd/opt/dmsd/config.properties new file mode 100644 index 0000000..9f7b03a --- /dev/null +++ b/satellit_installer/static_files/dmsd/opt/dmsd/config.properties @@ -0,0 +1,6 @@ +vmstore.path = /srv/openslx/nfs +db.uri = jdbc:mysql://localhost/sat?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&characterSetResults=utf8&connectionCollation=utf8mb4_unicode_ci +db.username = sat +db.password = %MYSQL_SAT_PASS% +db.location-table = openslx.location +master.address = bwlp-masterserver.ruf.uni-freiburg.de diff --git a/satellit_installer/static_files/dmsd/opt/dmsd/dmsd.sh b/satellit_installer/static_files/dmsd/opt/dmsd/dmsd.sh new file mode 100755 index 0000000..04994d3 --- /dev/null +++ b/satellit_installer/static_files/dmsd/opt/dmsd/dmsd.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +KB=$( grep ^MemTotal /proc/meminfo | awk '{print $2}' ) +[ -z "$KB" ] && KB=600000 +if [ "$KB" -gt 4096000 ]; then + MB=$(( KB / ( 1024 * 3 ) + 667 )) +else + MB=$(( KB / ( 1024 * 2 ) )) +fi +if [ "$MB" -gt 2000 ] && ! java -version 2>&1 | grep -q '64-Bit'; then + MB=2000 +fi +[ "$MB" -lt 190 ] && MB=190 +[ "$MB" -gt 4500 ] && MB=4500 + +exec java -Xmx${MB}M -jar dmsd.jar diff --git a/satellit_installer/static_files/system/etc/systemd/system/firstboot.service b/satellit_installer/static_files/system/etc/systemd/system/firstboot.service new file mode 100644 index 0000000..a21ad61 --- /dev/null +++ b/satellit_installer/static_files/system/etc/systemd/system/firstboot.service @@ -0,0 +1,13 @@ +[Unit] +Description=Initialization of bwLehrpool on first boot +ConditionFileIsExecutable=/root/installer/rclocal_script.sh +After=network.target mysql.service + +[Service] +Type=oneshot +ExecStart=/root/installer/rclocal_script.sh +RemainAfterExit=yes +RefuseManualStart=yes + +[Install] +WantedBy=multi-user.target diff --git a/satellit_installer/static_files/system/root/.tmate.conf b/satellit_installer/static_files/system/root/.tmate.conf new file mode 100644 index 0000000..6059b8d --- /dev/null +++ b/satellit_installer/static_files/system/root/.tmate.conf @@ -0,0 +1,5 @@ +set -g tmate-server-host "tmate.ruf.uni-freiburg.de" +set -g tmate-server-port 2222 +set -g tmate-server-rsa-fingerprint "d7:d7:06:d0:b6:0d:75:a1:ad:ec:69:18:b3:a3:c0:4a" +set -g tmate-server-ecdsa-fingerprint "4f:c9:81:f1:1a:20:7d:6f:97:12:f2:a9:0f:f4:c5:6c" +set -g tmate-identity "" diff --git a/satellit_installer/static_files/system/root/installer/rclocal_script.sh b/satellit_installer/static_files/system/root/installer/rclocal_script.sh index 07da0ee..78bf23c 100755 --- a/satellit_installer/static_files/system/root/installer/rclocal_script.sh +++ b/satellit_installer/static_files/system/root/installer/rclocal_script.sh @@ -2,7 +2,7 @@ MY_PID=$$ perror() { - echo "$@" >> /root/init.log + echo "[ERROR] $*" [ "$MY_PID" != "$$" ] && kill "$MY_PID" if ! grep -q "rclocal_script.sh has thrown an error" /etc/motd; then @@ -19,11 +19,14 @@ perror() { exit 5 } -echo "$(basename $0) gestartet: $(date "+%Y-%m-%d %H:%m:%S")" >> /root/init.log +# Logfile +exec &> /root/init.log -[ -r "/root/installer/config" ] || perror "Installationsfehler: Keine firstrun-config gefunden!" +echo "+++ $(basename "$0") gestartet: $(date "+%Y-%m-%d %H:%m:%S")" -source "/root/installer/config" || { echo "Fehler beim Sourcen der firstrun-config." >> /root/init.log; exit 1; } +[ -r "/root/installer/config" ] || perror "Installationsfehler: Keine firstrun-config gefunden!" + +source "/root/installer/config" || perror "Fehler beim Sourcen der firstrun-config." generate_password() { tr -dc _A-Za-z0-9 < /dev/urandom | head -c 16 @@ -41,20 +44,18 @@ patchfiles() { 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 "+++ Lösche alte ssh-Schlüssel ..." +rm -f -- /etc/ssh/ssh_host_*key* 2>/dev/null -echo -n "Generating new ssh keys..." >> /root/init.log +echo "+++ Generating new ssh 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 -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 +echo "+++ Generiere intern genutzte Passwörter (z.B. MySQL-Zugänge) neu ..." umask 0077 MYSQL_SAT_NEW=$(generate_password) @@ -63,7 +64,7 @@ echo "SET PASSWORD FOR 'sat'@'localhost' = PASSWORD('$MYSQL_SAT_NEW');" | mysql 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 -n "Konfigurationsdateien werden aktualisiert..." >> /root/init.log +echo "+++ Konfigurationsdateien werden aktualisiert..." # sat mysql pass # Patch dmsd @@ -77,15 +78,12 @@ patchfiles "%MYSQL_OPENSLX_PASS%" "$MYSQL_OPENSLX_NEW" "$WWWDIR/slx-admin/co TASKMANAGER_PASS=$(generate_password) patchfile "%TM_OPENSLX_PASS%" "$TASKMANAGER_PASS" "$WWWDIR/slx-admin/config.php" "$TASKMANDIR/config/config" -echo " ok." >> /root/init.log - -echo "Dienste werden aktiviert..." >> /root/init.log +echo "+++ Dienste werden aktiviert..." # Enable bwLehrpool related services for i in dmsd.service taskmanager.service; do - systemctl enable $i - [ $? -ne 0 ] && echo "Warnung - konnte systemd-Service $i nicht aktivieren!" >> /root/init.log - systemctl start $i + systemctl enable "$i" || echo "Warnung - konnte systemd-Service $i nicht aktivieren!" + systemctl --no-block start "$i" done # Write MOTD @@ -102,12 +100,10 @@ Andere Modifikationen am System sind in der Regel nicht notwendig. THEREDOC -# Write version to /etc/sat_version -echo "$VERSION" > /etc/sat_version +echo "+++ Daten des Firstrun-Scripts werden aufgeräumt..." +unlink "/root/installer/config" +unlink "/root/installer/rclocal_script.sh" +unlink "/etc/systemd/system/firstboot.service" +unlink "/etc/systemd/system/multi-user.target.wants/firstboot.service" -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 - diff --git a/satellit_installer/static_files/taskmanager/etc/systemd/system/multi-user.target.wants/taskmanager.service b/satellit_installer/static_files/taskmanager/etc/systemd/system/multi-user.target.wants/taskmanager.service deleted file mode 120000 index 141a3f2..0000000 --- a/satellit_installer/static_files/taskmanager/etc/systemd/system/multi-user.target.wants/taskmanager.service +++ /dev/null @@ -1 +0,0 @@ -../taskmanager.service
\ No newline at end of file |