summaryrefslogtreecommitdiffstats
path: root/satellit_installer/includes/10-script_dropper.inc
diff options
context:
space:
mode:
authorroot2014-06-30 15:21:04 +0200
committerroot2014-06-30 15:21:04 +0200
commit9aabe45d6e2865dcc95e4a6f5823c9310904b1e9 (patch)
tree2b53f43e95d3944b73864f4e5995a75ab42a61b0 /satellit_installer/includes/10-script_dropper.inc
downloadsetup-scripts-9aabe45d6e2865dcc95e4a6f5823c9310904b1e9.tar.gz
setup-scripts-9aabe45d6e2865dcc95e4a6f5823c9310904b1e9.tar.xz
setup-scripts-9aabe45d6e2865dcc95e4a6f5823c9310904b1e9.zip
[SSPS] Satellite server preparation script. Further heavy debugging needed -
this is just the first checkin after tidying to server as a starting point.
Diffstat (limited to 'satellit_installer/includes/10-script_dropper.inc')
-rw-r--r--satellit_installer/includes/10-script_dropper.inc105
1 files changed, 105 insertions, 0 deletions
diff --git a/satellit_installer/includes/10-script_dropper.inc b/satellit_installer/includes/10-script_dropper.inc
new file mode 100644
index 0000000..efe1a53
--- /dev/null
+++ b/satellit_installer/includes/10-script_dropper.inc
@@ -0,0 +1,105 @@
+patch_bashrc() {
+ if [ $(grep -c $(echo "^${INSTALLDIR}.*first_run") /root/.bashrc) -gt 0 ]; then
+ echo "# first_run script already in root's bashrc, doing nothing."
+ else
+ echo "# Patching root's bashrc...) "
+ echo "${INSTALLDIR}/first_run" >> /root/.bashrc
+ fi
+}
+
+copy_public_key() {
+ cp -p "${BASEDIR}/static_files/finish_setup_public_key.pem" ${INSTALLDIR} \
+ || echo "Warning: Could not copy public key to ${INSTALLDIR}!"
+}
+
+drop_script() {
+ cat >"${INSTALLDIR}/first_run"<<-EOF
+ #!/bin/bash
+
+ generate_password() {
+ local password="\$(< /dev/urandom tr -dc _A-Za-z0-9 | head -c${1:-16};)"
+ echo "\$password"
+ }
+
+ LANG=en_US.UTF-8
+ echo
+ echo "Satellite server install post-install script"
+ echo
+ echo "This script will set safe password for root, the mysql root user"
+ echo 'and two mysql user accounts (openslx and bwLehrpool).'
+ echo
+ echo "We recommend you choose a secure password for root. The other"
+ echo "passwords will be auto generated."
+ echo ""
+ echo "Please set a secure password for root:"
+ echo ""
+ passwd
+ echo
+ echo "Thank you."
+ echo
+ echo "Now we will auto-generate new passwords for the mentioned mysql users:"
+ echo
+ MYSQL_ROOT_PASS="\$(grep MYSQL_ROOT_PASS "$LOGDIR/config"|cut -f 2 -d "=")"
+ umask 0066
+
+ MYSQL_ROOT_NEW=\$(generate_password)
+ mysqladmin -u root -p\${MYSQL_ROOT_PASS} password \${MYSQL_ROOT_NEW}
+ echo "MYSQL_ROOT_PASS=\$MYSQL_ROOT_NEW" > /root/new_passwords
+ echo "Mysql root password,"
+
+ MYSQL_BWLEHRPOOL_NEW=\$(generate_password)
+ echo "SET PASSWORD FOR 'bwLehrpool'@'localhost' = PASSWORD('\$MYSQL_BWLEHRPOOL_NEW');" | mysql -u root -p\${MYSQL_ROOT_NEW}
+ echo "MYSQL_BWLEHRPOOL_PASS=\$MYSQL_BWLEHRPOOL_NEW" >> /root/new_passwords
+ echo "Mysql bwLehrpool password,"
+
+ MYSQL_OPENSLX_NEW=\$(generate_password)
+ echo "SET PASSWORD FOR 'openslx'@'localhost' = PASSWORD('\$MYSQL_OPENSLX_NEW');" | mysql -u root -p\${MYSQL_ROOT_NEW}
+ echo "MYSQL_OPENSLX_PASS=\$MYSQL_OPENSLX_NEW" >> /root/new_passwords
+ echo "and mysql openslx password."
+
+ echo "... done."
+ echo
+ echo "Now we will save the newly set passwords in an encrypted file..."
+
+ cat /root/new_passwords | openssl rsautl -encrypt -pubin -inkey ${BASEDIR}/static_files/finish_setup_public_key.pem > \
+ ${BASEDIR}/static_files/new_passwords.encrypted
+ rm -f /root/new_passwords 2>/dev/null
+ echo "...ok."
+
+ # Patching openslx-mysql-userpass into bwSuite Server config:
+ sed -i "s/pass=%MYSQL_BWLEHRPOOL_PASS%/pass=\$MYSQL_BWLEHRPOOL_NEW/g" "$INSTALLDIR/Server_Config.ini"
+
+ # Patching openslx-mysql-userpass into bwSuite Server config:
+ sed -i "s/%MYSQL_OPENSLX_PASS%/\$MYSQL_OPENSLX_NEW/g" "/srv/openslx/www/slxadmin/config.php"
+
+ # inittab-entry dmsd:
+ if [ \$(grep -c "dmsd.*respawn" /etc/inittab) -gt 0 ]; then
+ echo "bwLehrpool Suite inittab entry detected, doing nothing. "
+ else
+ echo -n "bwLehrpool Suite: patching inittab..."
+ echo "dmsd:2345:respawn:$INSTALLDIR/dmsd.sh" >> /etc/inittab
+ echo "ok."
+ fi
+
+ # inittab-entry taskmanager:
+ if [ \$(grep -c "taskmanager.*respawn" /etc/inittab) -gt 0 ]; then
+ echo "Taskmanager inittab entry detected, doing nothing."
+ else
+ echo -n "bwLehrpool Suite: patching inittab..."
+ echo "taskmanager:2345:respawn:$TASKMANDIR/taskmanager.sh" >> /etc/inittab
+ echo "ok."
+ fi
+
+ echo "Last thing to is to delete the script starter from root's .bashrc..."
+ sed -i "/first_run/d" /root/.bashrc
+ echo "...done."
+
+ EOF
+ chmod u+x ${INSTALLDIR}/first_run
+}
+
+script_dropper () {
+ copy_public_key
+ patch_bashrc
+ drop_script
+}