#!/bin/bash
#密码变量
password=""
#安装texlive
installTex(){
if [ "$1" = "1" ]; then
echo "==>texlive简单安装..."
sudo -K
echo $password| sudo -S apt-get -y install texlive
texlive-math-extra texlive-latex-base texlive-latex-extra
texlive-latex-recommended texlive-pictures texlive-science
texlive-bibtex-extra texlive-common latex-beamer
elif [ "$1" = "2" ]; then
echo "==>texlive完全安装..."
sudo -K
echo $password| sudo -S apt-get -y install texlive-full latex-beamer
else
echo "==>不安装texlive"
fi
}
#安装CJK
installCJK(){
if [ "$1" = "1" ]; then
echo "==>CJK中文支持..."
sudo -K
echo $password| sudo -S apt-get -y install latex-cjk-chinese ttf-arphic-* hbf-*
elif [ "$1" = "2" ]; then
echo "==>CJK完全支持..."
sudo -K
echo $password| sudo -S apt-get -y install latex-cjk-all
else
echo "==>不安装CJK"
fi
}
#安装fontforge
installFontforge(){
if [ "$1" = "1" ]; then
sudo -K
echo $password| sudo -S apt-get -y install fontforge
else
echo "==>不安装fontforge"
fi
}
#进度列表
stepEcho(){
case "$1" in
1) echo "安装Texlive和一些常用宏包配置";;
2) echo "安装CJK包配置";;
3) echo "安装fontforge配置";;
4) echo "确认subfonts.pe和Unicode.sfd文件路径";;
5) echo "设定CJK字体引用名";;
6) echo "正式安装texlive";;
7) echo "正式安装CJK";;
8) echo "正式安装fontforge";;
9) echo "正式检查subfonts.pe和Unicode.sfd存在性";;
*) echo "循环处理字体中...";;
esac
}
#生成map文件
makemap(){
for i in *.tfm
do
echo "${i%.tfm} ${i%.tfm} < ${i%.tfm}.pfb" >>$1
done
}
#检测返回值错误提示,和$?配合
perr(){
if [ "$1" != "0" ]; then
echo "[错误!]错误代码="$1
fi
}
################main################
proc="0" #进度参数
procFile="./texsetup.sh_procFile" #进度记录文件
maprec="./texsetup.sh_maprec" #记录生成的map列表
subfontsPath="/usr/share/latex-cjk-common/utils/subfonts/subfonts.pe" #subfonts.pe文件的默认位置
UnicodePath="/usr/share/texmf/fonts/sfd/Unicode.sfd" #Unicode.sfd文件的默认位置
findpath="/usr" #如果上面两个文件找不到,默认到这个目录下找
#CJK路径
mapPath="$HOME/.texmf-var/fonts/map/dvips/CJK/"
tfmPath="$HOME/.texmf-var/fonts/tfm/CJK/" #+"citename"
typePath="$HOME/.texmf-var/fonts/type1/CJK/" #+"citename"
encPath="$HOME/.texmf-var/tex/latex/CJK/" #+"encoding"
#开始欢迎信息
clear
echo "=============================================================="
echo "[[Texlive+Latex+CJK+字体配置]]"
echo "使用方法:"
echo "将需要添加的字体文件都放到一个可写的临时目录(比如~/tempfont)里,然后将脚本"
echo "文件也放到该目录下,运行即可,注意不要用root权限运行本脚本!!!"
echo "=============================================================="
usernow=`whoami`
if [ "$usernow" = "root" ]; then
echo "不能用root权限运行本脚本!"
exit 1
fi
echo "现在才需要输入sudo密码~"
echo -n "password:"
stty -echo
read password
stty echo
echo "输入完毕"
sudo -K
echo "检测当前权限..."
echo $password |sudo -S whoami
success=`echo $?`
if [ "$success" = "0" ];then
echo "密码输入正确"
else
echo "密码输入错误"
exit 1
fi
echo "=============================================================="
echo "完成后是否删掉临时目录(删掉不影响字体使用)?"`pwd`
RMYES="1"
OPTIONS="删掉 保留"
select opt in $OPTIONS;do
if [ "$opt" = "删掉" ]; then
RMYES="1"
break
elif [ "$opt" = "保留" ]; then
RMYES="0"
break
else
echo "错误选择!"
fi
done
echo "=========================================================="
#检测系统信息
echo "系统信息检测"
echo "----------------------------------"
echo "系统信息:"`cat /proc/version`
sysinfo=`cat /proc/version |egrep -i "ubuntu|debian"`
if [ -z "$sysinfo" ]; then
echo "你的系统不是ubuntu/debian,某些步骤可能不能正常工作:"
OPTIONS="继续 退出"
select opt in $OPTIONS;do
if [ "$opt" = "继续" ]; then
break
elif [ "$opt" = "退出" ]; then
exit 0
else
echo "错误选择!"
fi
done
fi
encoding=`env |grep -i '^lang'`
encoding=${encoding##*.}
echo "编码:"$encoding
if [ "${encoding:0:3}" != "UTF" ] && [ "${encoding:0:3}" != "utf" ]; then
echo "您当前系统默认编码不是UTF8,其他编码未测试可能支持不好,是否继续?"
OPTIONS="继续 退出"
select opt in $OPTIONS;do
if [ "$opt" = "继续" ]; then
break
elif [ "$opt" = "退出" ]; then
exit 0
else
echo "错误选择!"
fi
done
else
encoding="UTF8"
fi
echo "=========================================================="
#0:查看进度记录是否存在
echo "查看是否存在进度记录"
echo "<注意重启或注销可能会导致记录消失>"
echo "----------------------------------"
if [ -e "$procFile" ];then
proc=`cat $procFile`
echo -n "存在进度记录"$proc"=>"
stepEcho $proc
OPTIONS="从进度记录处开始 从头开始"
select opt in $OPTIONS;do
if [ "$opt" = "从进度记录处开始" ]; then
echo "正准备从进度记录处开始..."
break
elif [ "$opt" = "从头开始" ]; then
echo "正准备从头开始..."
proc="1"
break
else
echo "错误选择!"
fi
done
else
echo "无进度记录,从头开始..."
proc="1"
fi
echo "=========================================================="
#1:安装Texlive和一些常用宏包配置
if [ "$proc" = "1" ]; then
echo "安装Texlive和一些常用宏包"
echo "<具体配置请阅读脚本installTex函数>"
echo "----------------------------------"
OPTIONS="简单安装 完全安装 跳过本步"
select opt in $OPTIONS;do
if [ "$opt" = "简单安装" ]; then
s1="1"
break
elif [ "$opt" = "完全安装" ]; then
s1="2"
break
elif [ "$opt" = "跳过本步" ]; then
s1="0"
break
else
echo "错误选择!"
fi
done
proc="2"
echo $proc > $procFile
echo "=========================================================="
fi
#2:安装CJK包配置
if [ "$proc" = "2" ]; then
echo "安装CJK包"
echo "<简单安装=中文支持>"
echo "<完全安装=中日韩文等支持>"
echo "----------------------------------"
OPTIONS="简单安装 完全安装 跳过本步"
select opt in $OPTIONS;do
if [ "$opt" = "简单安装" ]; then
s2="1"
break
elif [ "$opt" = "完全安装" ]; then
s2="2"
break
elif [ "$opt" = "跳过本步" ]; then
s2="0"
break
else
echo "错误选择!"
fi
done
proc="3"
echo $proc > $procFile
echo "=========================================================="
fi
#3:安装fontforge配置
if [ "$proc" = "3" ]; then
echo "安装fontforge"
echo "<生成字体用,请务必安装>"
echo "----------------------------------"
OPTIONS="安装 跳过本步"
select opt in $OPTIONS;do
if [ "$opt" = "安装" ]; then
s3="1"
break
elif [ "$opt" = "跳过本步" ]; then
s3="0"
break
else
echo "错误选择!"
fi
done
proc="4"
echo $proc > $procFile
echo "=========================================================="
fi
#4:确认subfonts.pe和Unicode.sfd文件路径
if [ "$proc" = "4" ]; then
echo "确认subfonts.pe和Unicode.sfd文件位置"
echo ""
echo "-------------------------------------------------"
echo "subfonts.pe默认路径="$subfontsPath
echo "Unicode.sfd默认路径="$UnicodePath
OPTIONS="更改 不更改"
select opt in $OPTIONS;do
if [ "$opt" = "更改" ]; then
echo -n "subfonts.pe路径[直接回车采用默认]="
read filepath
if [ ! -z "$filepath" ];then
subfontsPath="$filepath"
fi
echo -n "Unicode.sfd路径[直接回车采用默认]="
read filepath
if [ ! -z "$filepath" ];then
UnicodePath="$filepath"
fi
echo "确认路径分别为:"
echo "subfonts.pe路径="$subfontsPath
echo "Unicode.sfd路径="$UnicodePath
break
elif [ "$opt" = "不更改" ]; then
break
else
echo "错误选择!"
fi
done
echo -n "若以上路径都不可用时,到$findpath搜索[直接回车采用默认]="
read tmpfindpath
if [ ! -z "$tmpfindpath" ];then
findpath="$tempfindpath"
fi
proc="5"
echo $proc > $procFile
echo "=========================================================="
fi
#5:设定CJK字体引用名
if [ "$proc" = "5" ]; then
echo "设定字体引用名"
echo "说明:比如设定simsun.ttc的引用名叫song,在tex文件中就是这么引用\begin{CJK*}{GBK}{song}"
echo "--------------------------------------"
echo "<目录中存在的文件列表>"
ls
echo "分别设定引用名(注意不要出现重名):"
fontcount="1"
for i in *.ttc *.ttf *.bdf *.dfont *.bin *.hqx *.otf *.sfd *.pfa *.pfb *.cid *.ps *.svg *.pk *.pcf
do
if [ "${i:0:1}" = "*" ]; then
continue;
fi
echo -n "字体文件"$i"="
read fname
mv $i $fontcount"-RENAMEDFONT-"$fname"."${i##*.}
let "fontcount=$fontcount+1"
done
proc="6"
echo $proc > $procFile
echo "=========================================================="
fi
#>=6:正式安装中!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo "配置完成,进行正式安装..."
echo "安装过程将持续很长时间,处理一个字体大约花费几十分钟,请确认以上步骤均没有错误,如果有错误请先结束脚本再次运行,确认继续?"
echo "选择后请耐心等待结束,没选项了= =|||......"
OPTIONS="继续 退出"
select opt in $OPTIONS;do
if [ "$opt" = "继续" ]; then
break
elif [ "$opt" = "退出" ]; then
exit 0
else
echo "错误选择!"
fi
done
#6:正式安装texlive
if [ "$proc" = "6" ]; then
echo "★正式安装texlive"
installTex $s1
perr $?
proc="7"
echo $proc > $procFile
fi
#7:正式安装CJK
if [ "$proc" = "7" ]; then
echo "★正式安装CJK"
installCJK $s2
perr $?
proc="8"
echo $proc > $procFile
fi
#8:正式安装fontforge(若有必要,要顺便配置PATH)
if [ "$proc" = "8" ]; then
echo "★正式安装fontforge"
installFontforge $s3
perr $?
proc="9"
echo $proc > $procFile
fi
#9:正式检查subfonts.pe和Unicode.sfd存在性
if [ "$proc" = "9" ]; then
echo "★检查subfonts.pe和Unicode.sfd存在性"
if [ -e "$subfontsPath" ]; then
echo "subfonts.pe在默认路径中找到"
else
echo "subfonts.pe没找到在"$findpath"中查找..."
subfontsPath=`find $findpath |grep -i "subfonts\.pe"`
if [ -z "$subfontsPath" ]; then
echo "[致命错误]没找到subfonts.pe"
exit 1
else
echo "找到文件:"$subfontsPath
fi
fi
if [ -e "$UnicodePath" ]; then
echo "Unicode.sfd在默认路径中找到"
else
echo "Unicode.sfd没找到在"$findpath"中查找..."
UnicodePath=`find $findpath |grep -i "unicode\.sfd"`
if [ -z "$subfontsPath" ]; then
echo "[致命错误]没找到Unicode.sfd"
exit 1
else
echo "找到文件:"$UnicodePath
fi
fi
proc="10"
echo $proc > $procFile
fi
#>=10:循环处理字体中
nowproc="9"
echo "★漫长的循环开始啦~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
#首先构造必要目录
mkdir -p $mapPath
mkdir -p $encPath"$encoding"
echo "生成路径:"$mapPath
echo "生成路径:${encPath}${encoding}"
for fontfile in *RENAMEDFONT*
do
fonttype=${fontfile##*.}
tmpname=${fontfile##*-}
citename=${tmpname%%.*}
count=${fontfile%%-*}
let "nowproc=${nowproc}+1"
echo "☆当前处理字体为${citename}......"
if [ "$proc" -gt "$nowproc" ]; then
echo "==>已处理"
continue;
fi
#如果提示找不到fontforge,看安装成功没,然后再检查PATH
mapfilename=${citename}".map"
if [ ! -e "$mapfilename" ]; then
fontforge -script "$subfontsPath" "$fontfile" "$citename" "$UnicodePath"
fi
makemap $mapfilename
mkdir -p $tfmPath"$citename"
mkdir -p $typePath"$citename"
echo "生成字体路径:"$tfmPath"$citename"
echo "生成字体路径:"$typePath"$citename"
cp $citename".map" $mapPath
mv *.tfm $tfmPath"$citename"
mv *.pfb $typePath"$citename"
#生成fd文件
echo "\ProvidesFile{c70${citename}.fd}" >>$encPath"$encoding/c70${citename}.fd"
echo "\DeclareFontFamily{C70}{${citename}}{\hyphenchar \font\m@ne}"
>>$encPath"$encoding/c70${citename}.fd"
echo "\DeclareFontShape{C70}{${citename}}{m}{n}{<-> CJK *
${citename}}{}" >>$encPath"$encoding/c70${citename}.fd"
echo "\DeclareFontShape{C70}{${citename}}{bx}{n}{<-> CJKb *
${citename}}{\CJKbold}" >>$encPath"$encoding/c70${citename}.fd"
echo "\endinput" >>$encPath"$encoding/c70${citename}.fd"
#记录生成的map文件名
echo $mapfilename >> $maprec
let "proc=$proc+1"
echo $proc > $procFile
done
#这个需要root权限
sudo -K
echo $password| sudo -S texhash
#更新
for i in `cat $maprec`
do
updmap --enable Map $i
done
#清理本临时目录
if [ "$RMYES" = "1" ]; then
rm -r `pwd`
fi
echo "任务终了= =|||久等了......"
阅读(4526) | 评论(0) | 转发(0) |