forked from fzerorubigd/persian-fonts-linux
-
Notifications
You must be signed in to change notification settings - Fork 2
/
farsifonts.sh
executable file
·171 lines (158 loc) · 3.91 KB
/
farsifonts.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
#!/bin/bash
# By fzerorubigd (http://cyberrabbits.net)
# 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.
function detect(){
type -P $1 || { 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
$DOWNLOADER $PARAMETER $URL $OUTPARAM $TOC
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 "Choose font to install or choose Quit"
select fnt in ${fonts[*]};
do
case $fnt in
"$QUIT")
return 0
break
;;
"$ALL")
echo "All fonts are going to be downloaded..."
for i in `seq ${#filename[@]}`
do
$DOWNLOADER $PARAMETER ${urls[i]} $OUTPARAM ${filename[i]}
DL=$(( $DL + 1 ))
downloaded[$DL]=${filename[i]}
if [ ${filename[i]: -4} == ".zip" ]; then
sudo mkdir -p /usr/share/fonts/truetype/${fonts[i]}
sudo unzip -o -d /usr/share/fonts/truetype/${fonts[i]} ~/${filename[i]}
elif [ ${filename[i]: -4} == ".ttf" ]; then
sudo cp ~/${filename[i]} /usr/share/fonts/truetype/
fi
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")
$DOWNLOADER $PARAMETER ${urls[LAST_REPLY]} $OUTPARAM ${filename[LAST_REPLY]}
DL=$(( $DL + 1 ))
downloaded[$DL]=${filename[LAST_REPLY]}
if [ ${filename[LAST_REPLY]: -4} == ".zip" ]; then
sudo mkdir -p /usr/share/fonts/truetype/$fnt
sudo unzip -o -d /usr/share/fonts/truetype/$fnt ~/${filename[LAST_REPLY]}
elif [ ${filename[LAST_REPLY]: -4} == ".ttf" ]; then
sudo cp ~/${filename[LAST_REPLY]} /usr/share/fonts/truetype/
fi
return 1
break
;;
"no")
return 1
break
esac
done
;;
esac
done
}
function postaction(){
clear
if [ $DL -gt 0 ]; then
echo "Delete downloaded 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")
for i in `seq $DL`
do
rm -f ${downloaded[i]}
done
break
;;
"no")
break
;;
esac
done
echo "Refresh font cache"
sudo fc-cache -f -v >/dev/null
echo "All 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