#!/bin/bash

set -x -e

emacsdir=~/.emacs.d
compatfile=$emacsdir/.emacs-ver
mylispdir_old=$emacsdir/my
mylispdir_new=$emacsdir/mylisp

if ! [[ -f $compatfile ]]; then
    echo 'Cannot detect compatibility.'
    exit 1
fi
read ver <$compatfile
if [[ $ver != 1 ]]; then
  echo 'Script is designed only for upgrade: v1 => v2.'
  exit 1
fi

rm $mylispdir_old/init.el || :
mv $mylispdir_old $mylispdir_new || :
rm $emacsdir/.emacs-my.elc || :

echo 2 >$compatfile
