#!/bin/bash

ENABLED=yes
[ "$ENABLED" != "yes" ] && exit 0
DEBUGMODE=no
. usr/lib/ublinux/functions
. usr/lib/ublinux/os-config
debug_mode "$0" "$@"

. .$SYSCONF/config 2>/dev/null || . $SYSCONF/config 2>/dev/null 


if [ "$(cmdline_parameter ub.osinstall)" ]; then
    TTY_N=2
    sed -i "s/.*NAutoVTs=6.*/NAutoVTs=0/" etc/systemd/logind.conf
    sed -i "s/.*ReserveVT=6.*/ReserveVT=0/" etc/systemd/logind.conf
    mkdir -p etc/systemd/system/getty@tty${TTY_N}.service.d
    echo "[Service]" > etc/systemd/system/getty@tty${TTY_N}.service.d/override.conf
    echo "ExecStart=" >> etc/systemd/system/getty@tty${TTY_N}.service.d/override.conf
    FONT="$(grep "FONT" /etc/vconsole.conf | cut -d= -f2)"
    [[ -z ${FONT} ]] && FONT=cyr-sun16
    echo "ExecStart=-bash -c \". /etc/locale.conf; export LANG; setfont ${FONT}; /usr/bin/ubinstall.cli\"" >> etc/systemd/system/getty@tty${TTY_N}.service.d/override.conf
    echo "StandardInput=tty"  >> etc/systemd/system/getty@tty${TTY_N}.service.d/override.conf
    echo "StandardOutput=tty"  >> etc/systemd/system/getty@tty${TTY_N}.service.d/override.conf
    mkdir -p etc/systemd/system/getty.target.wants
    ln -sf /usr/lib/systemd/system/getty@.service etc/systemd/system/getty.target.wants/getty@tty${TTY_N}.service
    ln -sf /dev/null etc/systemd/system/getty.target.wants/getty@tty1.service
fi

