2009-09-16

「perfect_stardict_dic」打包星際譯王8本漢英、英漢字典成deb檔

常安裝StarDict (星際譯王)的字典檔是蠻煩鎖鎖的一件事,要先到stardict dictionaries下載所需要的字典檔,在解壓縮移動到指定的目錄裡,並不是每個人都知道要存放在那,在Ubuntu正體中文站常常都有人尋問如何裝。

現在使用perfect_stardict_dic腳本,能夠直接下載8本英漢、漢英字典,並且解壓縮打包成deb檔,這樣不管是要直接安裝,還是下次要重新安裝都相當的方便。

8本字典不一定要全部都安裝,看你的喜歡裝幾個就裝幾個哦!
2010.04.27 由於星際譯王字典檔只能到論壇下載,目前此腳本無法使用了。


下載、打包、安裝字典檔

Setp1、建立perfect_stardict_dic檔後,複制貼上程式碼[1]內容。
gedit perfect_stardict_dic


程式碼[1]

#!/bin/bash
# by hepha
# http://playubuntu.blogspot.com/
# GPL or CC-BY-NA-SA
# 版號1 (16-09-09)
Tmp=/tmp
Dic_Dir=$Tmp/dic
Uri="http://kent.dl.sourceforge.net/project/stardict/stardict-dictionaries-zh_TW/2.4.2"
All_Dic=$Dic_Dir/all_dic
linktest=`ping -c 3 168.95.1.1 2>/dev/null| grep "time="`
if [ "$linktest" = "" ]; then
echo "現在網路是斷線的,無法使用本程式"
echo "ByeBye"
exit 1
fi
File_Test (){
echo "沒有下載成功任一辭典"
exit 0
}
getArg ()
{
echo "請決定「$1」"
path=$2
yn=n
while [ $yn != "y" ]
do
echo "目前設定為:「$path」"
read -p "您的確定要設為這樣嗎? (Y/N)" -n1 yn
echo ""
if [ $yn = "n" ];
then
read -p "那麼請您重新輸入「$1」:" path
fi
done
}
sourcePath=$HOME
getArg "存放路徑" $sourcePath
mkdir -p $Dic_Dir
echo > $All_Dic
echo 歡迎使用
echo welcome to perfect_stardict_dic ver 1
echo
echo 打包星際譯王8本漢英、英漢字典成deb檔
read -p "打包deb檔後要直接安裝嗎?(Y/N)" -n1 yn
if [[ $yn = "y" || $yn = "Y" ]]; then
Stardict=`aptitude search ^stardict$ | awk '{print $1}'`
if [ $Stardict != "ii" ]; then
echo
read -p "如要立即安裝需要主程式「stardict」你是否要一併安裝?(Y/N)" -n1 yn
if [[ $yn = "y" || $yn = "Y" ]]; then
Install_Stardict=1
else
Deb_Install=1
fi
fi
fi
echo
echo 你可以選要使用的即可,不用全部都選擇
Dic0=21世紀英漢漢英雙向詞典
echo
read -p "你要使用「$Dic0」嗎?(Y/N)" -n1 yn
if [[ $yn = "y" || $yn = Y ]]; then
dic0=1
echo $Dic0 >>$All_Dic
fi
Dic1=21世紀雙語科技詞典
echo
read -p "你要使用「$Dic1」嗎?(Y/N)" -n1 yn
if [[ $yn = "y" || $yn = Y ]]; then
dic1=1
echo $Dic1 >>$All_Dic
fi
Dic2=xdict英漢字典
echo
read -p "你要使用「$Dic2」嗎?(Y/N)" -n1 yn
if [[ $yn = "y" || $yn = Y ]]; then
dic2=1
echo $Dic2 >>$All_Dic
fi
Dic3=xdict漢英字典
echo
read -p "你要使用「$Dic3」嗎?(Y/N)" -n1 yn
if [[ $yn = "y" || $yn = Y ]]; then
dic3=1
echo $Dic3 >>$All_Dic
fi
Dic4=牛津現代英漢雙解詞典
echo
read -p "你要使用「$Dic4」嗎?(Y/N)" -n1 yn
if [[ $yn = "y" || $yn = Y ]]; then
dic4=1
echo $Dic4 >>$All_Dic
fi
Dic5=朗道英漢字典
echo
read -p "你要使用「$Dic5」嗎?(Y/N)" -n1 yn
if [[ $yn = "y" || $yn = Y ]]; then
dic5=1
echo $Dic5 >>$All_Dic
fi
Dic6=朗道漢英字典
echo
read -p "你要使用「$Dic6」嗎?(Y/N)" -n1 yn
if [[ $yn = "y" || $yn = Y ]]; then
dic6=1
echo $Dic6 >>$All_Dic
fi
Dic7=cdict-big5英漢字典
echo
read -p "你要使用「$Dic7」嗎?(Y/N)" -n1 yn
if [[ $yn = "y" || $yn = Y ]]; then
dic7=1
echo $Dic7 >>$All_Dic
fi
echo
echo
Deb_Dic=`cat $All_Dic | tr "\n" "," | sed 's/^,//g ; s/.$//g'`
echo 開始下載「$Deb_Dic」中請稍後
echo
echo
if [ $dic0 -eq 1 ]; then
wget -c "$Uri/stardict-21shijishuangxiangcidian-big5-2.4.2.tar.bz2" -P $Dic_Dir
fi
if [ $dic1 -eq 1 ]; then
wget -c "$Uri/stardict-21shijishuangyukejicidian-big5-2.4.2.tar.bz2" -P $Dic_Dir
fi
if [ $dic2 -eq 1 ]; then
wget -c "$Uri/stardict-xdict-ec-big5-2.4.2.tar.bz2" -P $Dic_Dir
fi
if [ $dic3 -eq 1 ]; then
wget -c "$Uri/stardict-xdict-ce-big5-2.4.2.tar.bz2" -P $Dic_Dir
fi
if [ $dic4 -eq 1 ]; then
wget -c "$Uri/stardict-oxford-big5-2.4.2.tar.bz2" -P $Dic_Dir
fi
if [ $dic5 -eq 1 ]; then
wget -c "$Uri/stardict-langdao-ec-big5-2.4.2.tar.bz2" -P $Dic_Dir
fi
if [ $dic6 -eq 1 ]; then
wget -c "$Uri/stardict-langdao-ce-big5-2.4.2.tar.bz2" -P $Dic_Dir
fi
if [ $dic7 -eq 1 ]; then
wget -c "$Uri/stardict-cdict-big5-2.4.2.tar.bz2" -P $Dic_Dir
fi
Stardict_Dir=$Tmp/stardict
Stardict_Dic_Dir=$Stardict_Dir/usr/share/stardict/dic
mkdir -p $Stardict_Dic_Dir
for var in $Dic_Dir/stardict-*.tar.bz2
do
test -e $var || File_Test
echo 解壓縮$var
tar jxf $var -C $Stardict_Dic_Dir
done
echo
echo 開始打包「$Deb_Dic」中請稍後
echo
Size=`du --max-depth=0 -k $Stardict_Dic_Dir | awk '{print $1}'`
mkdir -p $Stardict_Dir/DEBIAN
echo "Package: stardict-dic
Version: 1
Section: universe/utils
Priority: optional
Architecture: all
Depends: stardict
Installed-Size: $Size
Maintainer: $USER
Description: $Deb_Dic
">$Stardict_Dir/DEBIAN/control
dpkg -b $Stardict_Dir $sourcePath/stardict-dic_1.0.all.deb
echo
echo 檔案打包完成存放在「$sourcePath/stardict-dic_1.0.all.deb」
echo
if [ $Install_Stardict -eq 1 ]; then
sudo apt-get install stardict stardict-common --force-yes -y
echo 開始安裝「$sourcePath/stardict-dic_1.0.all.deb」請稍後
sudo dpkg -i $sourcePath/stardict-dic_1.0.all.deb
elif [ $Deb_Install -eq ]; then
echo 開始安裝「$sourcePath/stardict-dic_1.0.all.deb」請稍後
sudo dpkg -i $sourcePath/stardict-dic_1.0.all.deb
else
echo
fi
Setp2、給予執行權限並執行perfect_stardict_dic
chmod +x perfect_stardict_dic && ./perfect_stardict_dic

安裝畫面(略過下載字典檔)