#!/bin/bash
# Author: Steven Shiau <steven _at_ nchc org tw>
# License: GPL

# Load gparted live functions
. /usr/bin/gl-functions

echo -n "Updating /etc/gparted-live/gparted-live.conf based on kernel parameters if found... "
# Get options from kernel parameter if available.
# gl_kbd is like: en, es, uk (2 lowecase letters), which will be used by:
# install-keymap ${gl_kbd}
param_2_be_parsed="gl_kbd gl_lang gl_numlk gl_capslk"
parse_cmdline_option "$param_2_be_parsed"

# tune the param in /etc/gparted-live/gparted-live.conf
for ik in $param_2_be_parsed; do
  eval real_var=\$$ik
  if [ -n "$real_var" ]; then
    if [ -z "$(grep -E "^[[:space:]]*$ik=" /etc/gparted-live/gparted-live.conf 2>/dev/null)" ]; then
      # append it
      echo "$ik=\"$real_var\"" >> /etc/gparted-live/gparted-live.conf
    else
      # modify it
      perl -pi -e "s|^[[:space:]]*$ik=.*|$ik=\"$real_var\"|g" /etc/gparted-live/gparted-live.conf
    fi
  fi
done
echo "done!"

#
[ -e /etc/gparted-live/gparted-live.conf ] && . /etc/gparted-live/gparted-live.conf

# Process the number lock and capslock
case "$gl_numlk" in
  on|ON) setleds +num ;;
  off|OFF) setleds -num ;;
esac
	
case "$gl_capslk" in
  on|ON) setleds +caps;;
  off|OFF) setleds -caps ;;
esac
