#! /bin/sh
# [seamonkey-ja] TinyCore専用の拡張作成スクリプト
# anthy用の辞書編集ユーティリティ
# 次のコマンドを実行してインストールして下さい
# sh seamonkey-ja.install.sh

test ! -t 0 && exit
cd `dirname $0`
RUN_DIR=`pwd`

. /etc/init.d/tc-functions
LIST=`busybox --list`
for i in $LIST; do
	alias $i="busybox $i"
done

myinstall(){
	if [ ! -f "/usr/local/tce.installed/$1" ]; then
		if [ ! -f "/etc/sysconfig/tcedir/optional/$1.tcz" ]; then
			tce-load -w $1
		fi
		tce-load -i $1
	fi
}

mozver="2.9.1"
distfile="seamonkey-${mozver}.tar.bz2"
url="ftp://ftp.jaist.ac.jp/pub/mozilla.org/seamonkey/releases/${mozver}/linux-i686/ja/${distfile}"
appname="seamonkey-ja"
target="${appname}.tcz"
deplist="gtk2 libasound dbus-glib"

builddep="squashfs-tools-4.x"
workdir="seamonkey"

for i in ${builddep}; do
	myinstall $i
done

if [ ! -f "${distfile}" ]; then
	wget "${url}"
fi
[ ! -f "${distfile}" ] && exit

[ -d "squashfs-root" ] && rm -rf "squashfs-root"
[ -d "${workdir}" ] && rm -rf "${workdir}"
mkdir -p "squashfs-root/usr/local/share/applications"

tar xf ${distfile}
mv "${workdir}" "squashfs-root/usr/local"

cat << EOS > "squashfs-root/usr/local/share/applications/${appname}.desktop"
[Desktop Entry]
Name=Seamonkey
Exec=/usr/local/seamonkey/seamonkey
Comment=Seamonkey Web Browser
Terminal=False
StartupNotify=True
Type=Application
Categories=Application;Network;
Icon=/usr/local/seamonkey/chrome/icons/default/default48.png
X-FullPathIcon=/usr/local/seamonkey/chrome/icons/default/default48.png
EOS

[ -f "${target}" ] && rm -f "${target}"
mksquashfs "squashfs-root" "${target}" -all-root -b 4096
find "squashfs-root" ! -type d | sort | sed -e s#squashfs-root/## > "${target}.list"
md5sum "${target}" > "${target}.md5.txt"
if [ ! -z "${deplist}" ]; then
	> "${target}.dep"
	for i in ${deplist}; do
		echo "$i.tcz" >> "${target}.dep"
		myinstall $i
	done
fi

for i in ${target} ${target}.dep ${target}.md5.txt; do
	[ -f "$i" ] && cp -f "$i" "/etc/sysconfig/tcedir/optional"
done

[ -d "${workdir}" ] && rm -rf "${workdir}"
[ -d "squashfs-root" ] && rm -rf "squashfs-root"
echo "Done!"