-
Notifications
You must be signed in to change notification settings - Fork 0
/
farsifont.sh
176 lines (160 loc) · 3.84 KB
/
farsifont.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
## By aref (Linuxlearn.org)
# Install some Persian fonts (XB Series) and Tahoma on Linux
#
# if you do anything cool with it, let me know so I can publish or host it for you
# contact me at fzerorubigd {ATSIGN} gmail {DOT} com
# You can use "axel" instead of default "wget", just install axel first and call this
# with axel parameter.
FONT_PATH="/home/$USER/.fonts/truetype/"
function detect(){
type -P $1 >/dev/null || { echo "Require $1 but not installed. Aborting." >&2; exit 1; }
}
# Address of toc file, I keep this file updated.
readonly URL="http://fzerorubigd.github.com/persian-fonts-linux/list"
readonly TOC="/tmp/list.txt"
if [ $# -eq 0 ]; then
DOWNLOADER=wget
PARAMETER="-c"
OUTPARAM="-O"
elif [ $1 == "wget" ]; then
DOWNLOADER=$1
PARAMETER="-c"
OUTPARAM="-O"
elif [ $1 == "axel" ]; then
DOWNLOADER=$1
PARAMETER="-n 10 -a"
OUTPARAM="-o"
else
echo "Usage : $0 [axel|wget]"
echo "defualt is wget"
exit
fi
detect $DOWNLOADER
detect unzip
detect sudo
echo "Using $DOWNLOADER as downloader"
cd ~
rm -f $TOC
echo "Downloading font list file..."
$DOWNLOADER $PARAMETER $URL $OUTPARAM $TOC 2>/dev/null
I=0
DL=0
declare -a downloaded
declare -a fonts
declare -a filename
declare -a urls
declare -a desc
OLD_IFS=$IFS
IFS=$'\n'
for nme in $(cat $TOC )
do
I=$(( $I + 1 ))
fonts[$I]=`echo $nme | cut -d'|' -f1`
filename[$I]=`echo $nme | cut -d'|' -f2`
urls[$I]=`echo $nme | cut -d'|' -f3`
desc[$I]=`echo $nme | cut -d'|' -f4`
done
IFS=$OLD_IFS
QUIT="Quit"
ALL="All.."
I=$(( $I + 1 ))
fonts[$I]=$ALL
I=$(( $I + 1 ))
fonts[$I]=$QUIT
function mainmenu(){
PS3="Your choice ($I for quit): "
echo "* All fonts are going to be install in '.fonts' directory in your home."
echo "Choose which fonts should be install or choose to quit"
select fnt in ${fonts[*]};
do
case $fnt in
"$QUIT")
return 0
break
;;
"$ALL")
echo "All fonts are going to be download..."
for i in `seq ${#filename[@]}`
do
echo "Downloading font ${filename[i]}..."
$DOWNLOADER $PARAMETER ${urls[i]} $OUTPARAM ${filename[i]} 2>/dev/null
DL=$(( $DL + 1 ))
downloaded[$DL]=${filename[i]}
mkdir -p $FONT_PATH${fonts[i]}
unzip -o -d $FONT_PATH${fonts[i]} ~/${filename[i]} 1>/dev/null
done
return 0
break
;;
*)
LAST_REPLY=$REPLY
echo ${desc[LAST_REPLY]}
echo "Download and install??"
PS3="Your choice : "
select ans in yes no;
do
case $ans in
"yes")
echo "Downloading font ${filename[LAST_REPLY]}..."
$DOWNLOADER $PARAMETER ${urls[LAST_REPLY]} $OUTPARAM ${filename[LAST_REPLY]} 2>/dev/null
DL=$(( $DL + 1 ))
downloaded[$DL]=${filename[LAST_REPLY]}
mkdir -p $FONT_PATH$fnt
unzip -o -d $FONT_PATH$fnt ~/${filename[LAST_REPLY]} 1>/dev/null
echo "Font ${filename[LAST_REPLY]} has been installed"
return 1
break
;;
"no")
return 1
break
esac
done
;;
esac
done
}
function postaction(){
clear
if [ $DL -gt 0 ]; then
echo "Do you want to detele all fonts' archive files?"
echo "If you choose yes, all downloaded files in your home folder will be deleted!!!"
PS3="Your answer: "
select ans in yes no;
do
case $ans in
"yes")
echo "Removing all font archive files..."
for i in `seq $DL`
do
rm -f ${downloaded[i]}
done
break
;;
"no")
break
;;
esac
done
echo "Updating font cache..."
fc-cache -f -v $FONT_PATH >/dev/null
echo "Done!"
fi
rm -f $TOC
}
while true
do
clear
mainmenu
return_val=$?
if [ $return_val -eq 0 ]; then
break
else
read -p "Press Enter to return to the menu..."
fi
done
postaction
export IFS=$OLD_IFS
## By aref (Linuxlearn.org)
## By aref (Linuxlearn.org)