#!/bin/sh
# Launch ALT Linux postinstall autoconfiguration (== hacks).

FLO=/var/log/first_boot_log
:>>$FLO
chmod go-rwx $FLO

WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

# On fail/exit erase the temporary file
trap 'rm -f /var/lock/TMP_1ST' EXIT HUP INT QUIT TERM

for f in /dev/cdrom*; do
	t="/dev/dvd${f#/dev/cdrom}"
	[ -e "$f" -a ! -e "$t" ] && ln -s "$f" "$t"
done

action "Building dynamic library cache:" /sbin/ldconfig

# Create new mbox files if they don't exist yet (for local users only).
for i in `awk -F: '{if ($3>=400) print $1}' </etc/passwd`; do
	[ -e "/var/mail/$i" ] ||
		action "Creating mailbox for $i:" install --owner="$i" --group=mail --mode=660 /dev/null "/var/mail/$i"
done

find / -mindepth 1 -maxdepth 1 \( -type d -o -type f \) -name '.??*' |
	fgrep -v /.automount |
	xargs -r rm -rf --

check_script()
{
	# Check if the script is there.
	[ -x "$1" ] || return 1

	# Don't run *.rpm* and *~ scripts.
	[ "${1%.rpm*}" = "$1" -a "${1%\~}" = "$1" ] || return 1

	return 0
}

# Run other first time scripts.
for f in /etc/firsttime.d/*; do
	check_script "$f" || continue

	if egrep -qs '(action|msg_) ' "$f"; then
		"$f"
	else
		action "Executing ${f##*/} first time script:" "$f"
	fi
done

ExecIfExecutable /etc/rc.d/scripts/distribution
