-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvoid-setfont
executable file
·158 lines (142 loc) · 4.64 KB
/
void-setfont
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
#!/usr/bin/env bash
#shellcheck disable=SC2145,SC2001,SC2188,SC2015,SC2155,SC2317,SC2320,SC2291,SC2034,SC2120,SC2086,SC2319
#shellcheck disable=SC2016,SC2154,SC2207,SC2166,SC2128,SC2059,SC2140,SC2031,SC2030,SC2036,SC2119,SC2027
# void-setfont - utilitario para exibibir e setar fontes do console
# Created: 2022/12/24
# Altered: 2024/04/12
#
# Copyright (c) 2022-2024, Vilmar Catafesta <vcatafesta@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
##############################################################################
#export LANGUAGE=pt_BR
export TEXTDOMAINDIR=/usr/share/locale
export TEXTDOMAIN=void-setfont
#debug
export PS4='${red}${0##*/}${green}[$FUNCNAME]${pink}[$LINENO]${reset} '
#set -x
#set -e
shopt -s extglob
#system
readonly APP="${0##*/}"
readonly _VERSION_='3.01.20240412'
readonly distro=$(uname -n)
readonly DEPENDENCIES=(dialog setfont tput)
function sh_setfont() {
local arrdir=('/usr/share/consolefonts' '/usr/share/kbd/consolefonts')
local array
local fonts
local font
local xglob="$*"
local x
local i
[[ $# -lt 1 ]] && xglob="*.gz"
for i in "${arrdir[@]}"; do
if test -d "$i"; then
pushd "$i" &>/dev/null || die "ERRO: no access $i"
mapfile -t fonts <<< "$(printf "%s\n" $xglob)"
popd &>/dev/null || return 1
fi
done
if [[ ${#fonts[*]} -eq 0 ]] ; then
die "no fonts found in:" "\n${arrdir[0]}\n${arrdir[1]}"
fi
for i in "${fonts[@]}"; do
x="$i"; x="${i%%.gz*}"; x="${x%%.psf*}"; x="${x%%.psfu*}"
array+=("$x")
array+=("$i")
done
while :; do
font=$(dialog \
--backtitle "Chili Linux setfont v$_VERSION_" \
--title "Chili Linux setfont v$_VERSION_" \
--menu "Escolha uma fonte:" \
0 0 14 \
"${array[@]}" 2>&1 >/dev/tty)
if [[ $? -eq 1 ]]; then
exit
fi
echo -e "Fonte escolhida: $font"
setfont "$font"
done
}
function sh_setvarcolors() {
if tput setaf 1 &> /dev/null; then
#tput setaf 127 | cat -v #capturar saida
tput sgr0 # reset colors
bold=$(tput bold)
reset=$(tput sgr0)
white="${bold}$(tput setaf 7)"
black="${bold}$(tput setaf 0)"
red=$(tput bold)$(tput setaf 196)
green=$(tput setaf 2)
yellow=$(tput bold)$(tput setaf 3)
blue=$(tput setaf 4)
pink=$(tput setaf 5)
cyan=$(tput setaf 6)
orange=$(tput setaf 3)
purple=$(tput setaf 125);
violet=$(tput setaf 61);
else
bold=''
reset="\e[0m"
green="\e[1;32m"
red="\e[1;31m"
yellow="\e[1;33m"
orange="\e[1;33m"
fi
}
function die() {
local msg=$1; shift
printf "${pink}=> ${red}$msg${reset} ${*}"
exit 1
}
function msg() {
local msg=$1; shift
printf '%s\n' "${black}$msg${reset}"
return 0
}
function erro() {
local msg=$1; shift
printf '%s\n' "${yellow}=> ${bold}${yellow}$msg${reset}"
return 1
}
function check_deps() {
local errorFound=0
declare -a missing
for d in "${DEPENDENCIES[@]}" ; {
[[ -z $(command -v "$d") ]] && missing+=("$d") && errorFound=1 && printf '%s\n' "${red}ERRO${reset}: não encontrei o comando ${orange}'$d'${reset}"
}
if (( errorFound )); then
erro "============ IMPOSSÍVEL CONTINUAR ============"
msg "Esse script precisa dos comandos listados acima"
msg "Instale-os e/ou verifique se estão no seu \$PATH"
erro "============ IMPOSSÍVEL CONTINUAR ============"
die "Abortado..."
fi
}
sh_setvarcolors
# debug
#export PS4=$'${red}${0##*/}${green}[$FUNCNAME]${pink}[$LINENO]${reset} '
#set -x
check_deps
sh_setfont "$@"