#!/bin/sh

kill -INT `ps -acx -o pid,command | grep uim-helper-server | grep -v grep | awk '{ print $1 }'` || true
sleep 1
kill -TERM `ps -acx -o pid,command | grep uim-helper-server | grep -v grep | awk '{ print $1 }'` || true
sleep 1
kill -KILL `ps -acx -o pid,command | grep uim-helper-server | grep -v grep | awk '{ print $1 }'` || true

#kill `ps -acx -o pid,command | grep SystemUIServer | grep -v grep | awk '{ print $1 }'` || true

if [ -f "~/.anthy/private_words_default" -a ! -f "~/.anthy_ghal/private_words_default" ]; then
        if [ ! -d "~/.anthy_ghal" ]; then
                mkdir -p ~/.anthy_ghal
                cp -pf "~/.anthy/private_words_default" "~/.anthy_ghal/"
        else
                cp -pf "~/.anthy/private_words_default" "~/.anthy_ghal/"
        fi
fi

rm -f ~/.anthy_ghal/last-record1_*.bin
/Library/Anthy/bin/anthy-agent --update-base-record
rm -f ~/.anthy_ghal/last-record1_*.bin
/Library/Anthy/bin/anthy-agent --update-base-record
mkdir -p ~/.anthy_ghal
touch ~/.anthy_ghal/last-record1_default.utf8
chown -R $USER ~/.anthy_ghal
chmod 700 ~/.anthy_ghal

kill -KILL `ps -acx -o pid,command | grep MozcConverter | grep -v grep | awk '{ print $1 }'` || true
