# Bail if we're not running a core with kernel functions

if [ ! -e $FUNCTIONS/kernel.lunar ] ; then
  message "${PROBLEM_COLOR}Bailing out, ${DEFAULT_COLOR}Lunar (or theedge) code version too old"
  message "${PROBLEM_COLOR}Update core ${MODULE_COLOR}(lin lunar or lin theedge)${DEFAULT_COLOR} to install this kernel"
  exit 1
fi

mk_source_dir $SOURCE_DIRECTORY
rm -f /usr/src/linux
ln -sf $SOURCE_DIRECTORY /usr/src/linux
cd $SOURCE_DIRECTORY

# Check wether we're running an up-to-date tar
if [ `installed_version tar | cut -d. -f2` -ge 15 ]; then
  tar xf $SOURCE_CACHE/$SOURCE --no-same-owner \
  --no-same-permissions --strip-components=1
else
  message "${PROBLEM_COLOR}Error:${DEFAULT_COLOR} Please update your tar module"
  exit 1
fi

# if we have an EXTRA patch, apply it
if [ -n "${SOURCE2}" ]; then
    patch_it ${SOURCE2} 1
fi

if  [ -f $CONFIG_CACHE/.config.previous ]; then
    cp $CONFIG_CACHE/.config.previous $SOURCE_DIRECTORY/.config;
elif [ -f $CONFIG_CACHE/.config.2.6.stable ]; then
    cp $CONFIG_CACHE/.config.2.6.stable $SOURCE_DIRECTORY/.config;
fi

while
  if [ "$CONFIG_KERNEL" == "y" ]; then
      if [ "$PREFER_XCONFIG" == "y" -a -n "$DISPLAY" ]; then
          make xconfig || make menuconfig || make config
      elif [ "$PREFER_MENUCONFIG" == "y" ]; then
          make menuconfig || make config
      else
          make config
      fi
      if ! query "Repeat configuration?" n; then
          CONFIG_KERNEL=n
      fi
  else
      false
  fi
do
  true
done

