#!/bin/sh
# system one time tasks

# Exit on error:
set -e

PATH=/bin

echo -n '16. Mounting kernel-based file systems:'
echo -n ' /proc'
mount -n -o nosuid,noexec,nodev -t proc proc /proc
echo -n ' /sys'
mount -n -o nosuid,noexec,nodev -t sysfs sys /sys
echo ' /run'
mount -n -o mode=0755,nosuid,nodev -t tmpfs run /run

echo -n '15. Creating directories:'
echo -n ' /run/lock'
mkdir -m 1777 /run/lock
echo -n ' /dev/pts'
mkdir -p /dev/pts
echo ' /dev/shm'
mkdir -p /dev/shm

echo '14. Mounting root file system in read-write mode.'
mount -n -o remount,rw / >/dev/null

# Remove fsck-related system watermarks.
rm -f /fastboot /forcefsck

echo '13. Recording existing mounts in /etc/mtab.'
> /etc/mtab
mount -f /
mount -f /proc
mount -f /sys
mount -f /run
mount -f /dev

echo '12. Mounting remaining file systems.'
mount -a -r >/dev/null

echo '11. Cleaning file system /tmp.'
cd /tmp && find . -xdev -mindepth 1 ! -name lost+found -delete

echo '10. Creating /var/run/utmp.'
if grep -q '^utmp:' /etc/group; then
    chmod 664 /var/run/utmp
    chgrp utmp /var/run/utmp
fi

echo '9. Starting udevd...'
echo '' > /sys/kernel/uevent_helper

/lib/udev/udevd --daemon

echo '8. Performing Coldplugging...'
/sbin/udevadm trigger --action=add --type=subsystems
/sbin/udevadm trigger --action=add --type=devices

/sbin/udevadm settle

echo '7. Activating all swap files/partitions...'
swapon -a

echo '6. Setting Font...'
setfont LatArCyrHeb-16 -C /dev/tty2
setfont LatArCyrHeb-16 -C /dev/tty3

echo '5. Setting keymap to UTF-8...'
dumpkeys | loadkeys --unicode

echo '4. Enabling Multibyte input...'
kbd_mode -u

echo '3. Setting up FR Keymap...'
loadkeys -q fr

echo '2. Setting encoding to UTF-8...'
echo -ne $'\033%G' > /dev/tty2
echo -ne $'\033%G' > /dev/tty3

echo '1. Bringing up the loopback interface...'
ip addr add 127.0.0.1/8 label lo dev lo
ip link set lo up

echo '0. Setting hostname to gllfsc...'
hostname gllfsc

echo
echo To login, remember:
echo your login is root
echo with no password
echo
echo You can now login through tty2 by pressing simultaneously
echo Ctrl, Alt and F2 keys
echo
echo You can then come back to this screen \(tty1\) by pressing
echo simultaneously Ctrl, Alt and F1 keys
echo
echo Edit /etc/runit/1 if you want to remove this message
echo

touch /etc/runit/stopit
chmod 0 /etc/runit/stopit

exit 0
