summaryrefslogblamecommitdiffstats
path: root/satellit_installer/includes/10-script_dropper.inc
blob: e9802ead1baea05c5b12b58c56d3400a6aaf7749 (plain) (tree)
1
2
3
4
5
6
7
8
9


                                                                                    
            
                                                 
                                                                           


          
               


                                                                                              

                                                                                                                    
                                                                                      
 

 







                                                                            

                                                                                                         


                                                                                                         


                                      
                               
















                                                                     


                                                                                           

 

                         
                   
                               
 
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_script.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_script.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
	if [ "$SYSTEMD" ]; then
		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 reenable rc-local >/dev/null
		[ $? -ne 0 ] && echo "Warning - could not enable systemd service rc-local!"
	fi
}

drop_firstrun_script () {
	patch_profile
	drop_script
	drop_keychanger_rclocal
}