#!/bin/sh

# kernel_cmdline <param> <default>
# Looks for a parameter on the kernel's boot-time command line.
#
# returns: 0 if param was found. Also prints its value if it was a K=V param.
#          1 if it was not. Also prints value passed as <default>
#
kernel_cmdline ()
{
    for param in $(/bin/cat /proc/cmdline); do
        case "${param}" in
            $1=*) echo "${param##*=}"; return 0 ;;
            $1) return 0 ;;
            *) continue ;;
        esac
    done
    [ -n "${2}" ] && echo "${2}"
    return 1
}

LOCALE="$(kernel_cmdline locale.LANG en_US.utf8)"
TIMEZONE="$(kernel_cmdline timezone UTC)"
KEYMAP="$(kernel_cmdline vconsole.keymap us)"
CONSOLEFONT="$(kernel_cmdline vconsole.font)"
CONSOLEMAP="$(kernel_cmdline vconsole.font.map)"
USENONFREE="$(kernel_cmdline nonfree no)"

#edit /etc/environment
#this settings overwrites the locale.conf settings
#do not enable it, is there as a placeolder
#echo "LANG=${LOCALE}" >> /etc/environment

# imports get_bootparam_value, get_country and set_locale
source /etc/locale_setup.sh

set_locale # sets locale settings and hwclock

#Hardware detection
/opt/chakra/bin/hwdetect

#Detecting drivers
#/opt/chakra/bin/xorg-detect

#Adjusting xorg config file
#/opt/chakra/bin/xorg-config

#do_configsforroot
cp -a /etc/skel/. /root/

# set correct permissions for live user
chown -R live:users /home/live
# fix sudoers file
chown root:root /etc/sudoers
chmod 0440 /etc/sudoers

# misc exports
export KDE_NO_IPV6="TRUE"
export OPERAPLUGINWRAPPER_PRIORITY=0

# in case proprietary drivers load takes longer
#systemctl restart kdm.service


