#! /bin/sh
# [ttf-monapo] TinyCore専用の拡張作成スクリプト
# 元はIPAが配布している日本語フォント。アスキーアート用に調整したもの
# 次のコマンドを実行してインストールして下さい
# sh ttf-monapo.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
}

distfile="fonts-monapo_20090423.orig.tar.gz"
url="http://ftp.jp.debian.org/debian/pool/main/f/fonts-monapo/fonts-monapo_20090423.orig.tar.gz"
target="ttf-monapo.tcz"
deplist=""

builddep="squashfs-tools-4.x"
workdir="ttf-monapo-20090423.orig"
ttfdir="/usr/local/share/fonts/ttf-monapo"

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}"

tar xf "${distfile}"
mkdir -p "squashfs-root/${ttfdir}"
mv ${workdir}/*.ttf "squashfs-root/${ttfdir}"

[ -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 "squashfs-root" ] && rm -rf "squashfs-root"
[ -d "${workdir}" ] && rm -rf "${workdir}"
echo "Done!"