-
Notifications
You must be signed in to change notification settings - Fork 11
/
font.sh
executable file
·150 lines (130 loc) · 4.07 KB
/
font.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
#!/bin/bash
#-------------------------------
#
# Created By Fahad Ahammed
#
# WEB: https://www.fahadahammed.com
# Date: 2019-02-04_23-43
# Get me by [email protected] or [email protected] if you want to ...
#------------------------------------------------------------------------------
echo "Welcome to Bangla Font Installer from http://fahadahammed.com !!!"
echo "------------------------------------"
wgetexists=`/usr/bin/which wget`
fontcacheexists=`/usr/bin/which fc-cache`
if [[ `/usr/bin/which sudo` != "/usr/bin/sudo" ]];
then
echo -e "\n";
echo -e "Sorry, you are not eligible to install these fonts.\n";\
exit;
fi
echo "Now starting to download and install all Bangla fonts..........."
echo -e "------------------------------------\n"
echo -e "\n"
if [ "$wgetexists" != "/usr/bin/wget" -o $fontcacheexists != "/usr/bin/fc-cache" ]
then
if [ -z "$1" ]
then
echo -e "No argument supplied.\n";
echo "This script needs specific tools to work perfectly.";
echo -e "The required tools need to be installed before continuing.\n";
echo "1. wget";
echo -e "2. fontconfig\n";
read -p "Continue (y/n)? " choice;
case "$choice" in
y|Y ) if [ "$wgetexists" != "/usr/bin/wget" -o $fontcacheexists != "/usr/bin/fc-cache" ]; then sudo apt update;sudo apt install fontconfig wget -y;fi;;
n|N ) echo -e "Bye Bye !\n";exit;;
* ) echo -e "Invalid !\n"; exit;;
esac
fi
fi
#--
if [ ! -z "$1" ]
then
echo "Argument supplied: $1";
if [[ "$1" == "install" ]];
then
if [ "$wgetexists" != "/usr/bin/wget" -o $fontcacheexists != "/usr/bin/fc-cache" ]
then
sudo apt update;sudo apt install fontconfig wget -y;
fi
else
echo -e "Invalid Argument Passed !\n";
exit;
fi
fi
# Variables and choosing the mirror.
echo -e "Choosing best mirror to download the files.\n"
downloadUrls=("http://www.fahadahammed.com/extras/fonts/archieve/lsaBanglaFonts.tar.gz" "https://raw.githubusercontent.com/fahadahammed/linux-bangla-fonts/master/archieve/lsaBanglaFonts.tar.gz")
finalurl="" # it will select lowest latency mirror
# Get arrays of latency and plain urls.
point=()
pointPlus=()
finalu=()
for i in ${downloadUrls[@]};do
a=$(echo $i | sed 's|http://||g' | sed 's|https://||g' | cut -d '/' -f -1)
aa=$(ping -c 1 "$a" | tail -1 | awk '{print $4}' | cut -d '/' -f 2)
aaa=${aa%.*}
point+=("$aaa")
pointPlus+=("$aaa,$a")
finalu+=("$aaa,$i")
done
# Calculate Minimum Latency
#---------------------------
max=${point[0]}
min=${point[0]}
echo "Latency: $min milliseconds";
# Loop through all elements in the array
for i in "${finalu[@]}"
do
a=$(echo $i | cut -d ',' -f 1)
# Update max if applicable
if [[ "$a" -gt "$max" ]]; then
max="$i"
fi
# Update min if applicable
if [[ "$a" -lt "$min" ]]; then
min="$i"
fi
done
finalurl=$(echo $min | cut -d ',' -f 2)
echo -e "Final Mirror: $finalurl \n"
# Directory
echo -e "Now creating the font directory for user: $USER.\n"
if [ $USER = "root" ]; then
fontsDir="/root/.fonts/lsaBanglaFonts"
fi
if [ $USER != "root" ]; then
fontsDir="/home/$USER/.fonts/lsaBanglaFonts"
fi
echo -e "\n"
if [ ! -d "$fontsDir" ]; then
mkdir -p $fontsDir;
else
echo -e "Upgrading bangla fonts provided by us....\n";
rm -r $fontsDir;
mkdir -p $fontsDir;
fi
echo -e "\n"
echo -e "Downloading compressed file from $finalurl....\n"
echo -e "\n"
/usr/bin/wget -v -P $fontsDir"/" $finalurl
# Check if file is there and extractable
cd $fontsDir"/"
if [ -f lsaBanglaFonts.tar.gz ];
then
echo -e "Downloaded file successfully to extract and install fonts !\n";
tar -zxvf lsaBanglaFonts.tar.gz;
rm lsaBanglaFonts.tar.gz;
else
echo -e "Fonts couldn't be retrieved. So exiting the installation.\n";
exit;
fi
cd
echo -e "\n"
echo -e "Initiating font refresh......\n"
/usr/bin/fc-cache -f -v
echo -e "\n"
echo "------------------------------------"
echo "Download and Installation Complete !!!"
echo -e "Script is Created by Fahad Ahammed\n"
echo -e "Website: http://fahadahammed.com\n"