#!/bin/sh
set -e

# Called from Ports.mk
# 1: Current linux directory
# 2: Kernel version


if [ -d /usr/src/$2/init ]; then
  echo "- kernel source $2 is ok"
else
  echo "> moving kernel sources to the right place"
  mv -vf "$1" "/usr/src/$2"
fi

if [ -L /usr/src/linux ]; then
  echo "> removing old /usr/src/linux link"
  rm -f /usr/src/linux
else
  echo "> pruning old /usr/src/linux directory"
  rm -fR /usr/src/linux/
fi

echo "> symlinking to $2"
ln -sf "/usr/src/$2" "/usr/src/linux"

