-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathinstall.sh
executable file
·193 lines (155 loc) · 3.5 KB
/
install.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/sh
# About: Siji font installer
# Maintainer: stark <[email protected]>
# License: GPLv2 See LICENSE file for copyright details
# TODO: Add '-f' flag for specifying the font manually
# Smarter non-zero checking for font existence
# Specify the font directory
XDG_DATA_HOME=${XDG_DATA_HOME:-"$HOME/.local/share"}
font_dir="$XDG_DATA_HOME/fonts"
# Specify the font
font="siji"
bdf_font="bdf/${font}.bdf"
pcf_font="pcf/${font}.pcf"
# Bold Colors for formatting
g="\033[1;32m" # Green
r="\033[1;31m" # Red
y="\033[1;33m" # Yellow
w="\033[1;37m" # White
rs="\033[0m" # Reset
_init_()
{
check_font
}
usage()
{
cat << HELP
Usage:
./install.sh [option] directory
If invoked without any option then '$(basename $pcf_font)' will be installed in the '${font_dir}' directory
Options:
-d Specify the directory for installing the font
Default is '${font_dir}' it will be created if non-existent
-h Show this help message
Example usage:
./install -d ~/.fonts
HELP
}
success()
{
printf "[${g}OK${rs}] $1 ${w}$2${rs}\n"
}
warning()
{
printf "[${y}XX${rs}] ${y}warning:${rs} $1 ${w}$2${rs}\n"
}
failure()
{
printf "[${r}XX${rs}] ${r}failed:${rs} $1 ${w}$2${rs}\n"
}
die()
{
"$@"
printf "${r}\nExiting${rs}\n"
exit 1
}
check_dir()
{
# Check if the specified font directory exists
if [ -d $font_dir ]; then
success "Found directory:" "$font_dir"
else
warning "directory not found:" "$font_dir"
success "Creating directory:" "$font_dir"
# Create the font directory if non-existent
mkdir -p $font_dir
fi
}
check_font()
{
# Check if any font is specified or not ( TODO: Better non-zero checking )
test -z "$bdf_font" && test -z "$pcf_font" && die error 1
# Check if the program 'bdftopcf' is installed or not
if [ $(command -v bdftopcf) ]; then
check_dir
# If 'bdftopcf' is installed then proceed to compile '$bdf_font'
make_pcf
else
check_dir
warning "Application 'bdftopcf':" "Not Found"
success "Installing precompiled" "$(basename $pcf_font)"
# If 'bdftopcf' is not installed then copy the precompiled '$pcf_font'
copy_pcf
fi
}
make_pcf()
{
if [ -f "$bdf_font" ]; then
# If it exists then proceed to compile the '$bdf_font'
success "Compiling" "$(basename $bdf_font)"
bdftopcf $bdf_font -o "${font_dir}/$(basename $pcf_font)"
# Update the font cache
update_cache
else
die error 2
fi
}
copy_pcf()
{
if [ -f "$pcf_font" ]; then
success "Copying" "'$pcf_font' -> '$font_dir'"
# If $pcf_font exists then proceed to copying
cp $pcf_font $font_dir
# Update the font cache
update_cache
else
die error 2
fi
}
update_cache()
{
success "Updating font cache... Please Wait"
mkfontdir $font_dir
xset +fp $font_dir
xset fp rehash
fc-cache -f
success "Finished. Your font cache has been updated"
# Perform post install stuff
post_install
}
post_install()
{
if [ -f "$HOME/.xinitrc" ]; then
file="${w}$HOME/.xinitrc${rs}"
else
file="custom startup script that gets executed during xlogin"
fi
printf "
Successfully installed ${w}$(basename $pcf_font) -> ${font_dir}${rs}
Add the following snippet in your ${file}:
${w}xset +fp ${font_dir}${rs}
${w}xset fp rehash${rs}
If it already exists then you can skip this step.
"
}
error()
{
case $1 in
1) failure "No font specified"
;;
2) failure "Font not found"
;;
*) failure "Unknown option"
;;
esac
}
while getopts "hd:" opt; do
case $opt in
d) font_dir=${OPTARG};;
h) usage; exit 0;;
*) usage; exit 1;;
esac
done
_init_
exit 0
# vim: ft=sh ts=4 :et