summaryrefslogtreecommitdiffstats
path: root/satellit_installer/includes/90-patch_slxadmin.inc
blob: d6d6e88923dab48840a9fa447e4408f550f51a8f (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
copy_slxadmin_config () {
	# Install config
	cp -p "${BASEDIR}/static_files/slxadmin-config.php" "$WWWDIR/slx-admin/config.php" || perror "slxadmin config.php not found"
	chmod 640 "$WWWDIR/slx-admin/config.php"
	chown root:www-data "$WWWDIR/slx-admin/config.php"
}

# Prepare files and symlinks in slx-admin www dir
patch_slxadmin_dir () {
	# Create redirect for /
	cat > "$WWWDIR/index.php" <<-HIERDOCK
		<?php
		Header('Location: /slx-admin/?do=Main');
		Header('HTTP/1.1 301 Moved permanently');
	HIERDOCK

	# Create modules directory and link modules from modules-available according to slxadmin module list (SLXADMIN_MODULES):
	mkdir -p "$WWWDIR/slx-admin/modules"
	cd "$WWWDIR/slx-admin/modules" || perror "Cannot cd to slxadmin/modules"
	for MOD in ${SLXADMIN_MODULES}; do
		NAME="${MOD%%-*}"
		ln -s "../modules-available/$MOD" "$NAME" || perror "Could not activate module '$MOD' (alias '$NAME')"
	done
	cd - 1>/dev/null
	# Add system cronjob to execute slx-admin cronjob
	cp "$BASEDIR/static_files/slxadmin-crontab" "/etc/cron.d/slx-admin" || perror "could not install slxadmin crontab"
	cp "$BASEDIR/static_files/slxadmin-cronscript" "/opt/openslx/slxadmin-cronscript" || perror "could not install slxadmin cronscript"
	# Add script and service to trigger init hook
	cp "$BASEDIR/static_files/slxadmin-bootscript" "/opt/openslx/slxadmin-bootscript" || perror "could not install slxadmin bootscript"
	cp "$BASEDIR/static_files/slxadmin-boot.service" "/etc/systemd/system/slxadmin-boot.service" || perror "could not install slxadmin boot service"
	ln -nfs "../slxadmin-boot.service" "/etc/systemd/system/multi-user.target.wants/slxadmin-boot.service" || perror "Could not enable slxadmin boot service"
}

# This needs to be called after mysql users have been created
install_slxadmin_db () {
	# Prepare temporary config
	copy_slxadmin_config
	sed -i "s/%MYSQL_OPENSLX_PASS%/${MYSQL_OPENSLX_PASS}/" "$WWWDIR/slx-admin/config.php"
	# Install slx-admin DB
	cd "$WWWDIR/slx-admin" || perror "Cannot cd to $WWWDIR"
	echo "# Installing slx-admin database"
	sudo -n -u www-data ./install-all || perror "Could not install slx-admin database"
	cd - 1>/dev/null
	# Fill with data we need
	php "${BASEDIR}/static_files/slxadmin-init/slxadmin-init.php" || perror "Filling tables with required data failed"
	# Reset with original template for firstboot script
	copy_slxadmin_config
	# appending a variable with satellite server build date/time to slx-admin config:
	echo "define('CONFIG_FOOTER', 'Build time: $(date "+%Y-%m-%d %H:%m:%S"), $VERSION');" >> "$WWWDIR/slx-admin/config.php"
}