summaryrefslogtreecommitdiffstats
path: root/satellit_installer/includes/10-script_dropper.inc
blob: e9802ead1baea05c5b12b58c56d3400a6aaf7749 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
}