summaryrefslogblamecommitdiffstats
path: root/satellit_installer/includes/10-script_dropper.inc
blob: 512b4cf119de9aac8ee17e2cb25950e9be78a4bc (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 -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
	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
}