patch_profile() { if grep -q "/root/installer/firstrun.sh" /root/.profile; then echo "# first_run script already in root's .profile, doing nothing." else echo "# Patching root's .profile" echo "/root/installer/firstrun.sh" >> /root/.profile fi } drop_script() { mkdir -p "/root/installer" # So we know all the paths and the mysql password cat "${BASEDIR}/includes/00-dirs.inc" "${CONFIGDIR}/config" > "/root/installer/config" chmod 0600 /root/installer/config cp "${BASEDIR}/static_files/firstrun_script.sh" "${BASEDIR}/static_files/rclocal_script.sh" /root/installer/ chmod u+x /root/installer/firstrun.sh /root/installer/rclocal_script.sh } drop_keychanger_rclocal() { if grep -q "Deleting old ssh keys" /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 started: $(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 } drop_firstrun_script () { patch_profile drop_script drop_keychanger_rclocal }