Reescrevendo procedimentos
This commit is contained in:
181
builtin/cli.bash
181
builtin/cli.bash
@@ -10,12 +10,12 @@ export C_YELLOW="\e[38;5;220m"
|
|||||||
export C_PURPLE="\e[38;5;5m"
|
export C_PURPLE="\e[38;5;5m"
|
||||||
|
|
||||||
export S_DEBUG="${C_PURPLE}\u2691 [debug]${F_NONE} "
|
export S_DEBUG="${C_PURPLE}\u2691 [debug]${F_NONE} "
|
||||||
export S_CRIT="${C_RED}\u2691 [critical]${F_NONE} "
|
export S_CRIT="${F_BOLD}${C_RED}\u2691 [critical]${F_NONE} "
|
||||||
export S_ERROR="${C_RED}\u2691 [error]${F_NONE} "
|
export S_ERROR="${C_RED}\u2691 [error]${F_NONE} "
|
||||||
export S_WARN="${C_ORANGE}\u2691 [warning]${F_NONE} "
|
export S_WARN="${C_ORANGE}\u2691 [warning]${F_NONE} "
|
||||||
export S_INFO="${C_BLUE}\u2691 [info]${F_NONE} "
|
export S_INFO="${F_BOLD}${C_BLUE}\u2691 [info]${F_NONE} "
|
||||||
export S_NOTICE="${C_BLUE}\u2691 [notice]${F_NONE} "
|
export S_NOTICE="${C_BLUE}\u2691 [notice]${F_NONE} "
|
||||||
export S_SUCCESS="${C_GREEN}\u2691 [success]${F_NONE} "
|
export S_SUCCESS="${F_BOLD}${C_GREEN}\u2691 [success]${F_NONE} "
|
||||||
|
|
||||||
export U_ITEM="\u21e2"
|
export U_ITEM="\u21e2"
|
||||||
export U_TICK="\u2713"
|
export U_TICK="\u2713"
|
||||||
@@ -24,8 +24,14 @@ export U_FAIL="\u2715"
|
|||||||
export COLS="$(( $(tput cols) - 1 ))"
|
export COLS="$(( $(tput cols) - 1 ))"
|
||||||
export EL=$(tput el)
|
export EL=$(tput el)
|
||||||
|
|
||||||
|
: "cli.clear"
|
||||||
|
function cli.clear {
|
||||||
|
clear
|
||||||
|
}
|
||||||
|
|
||||||
cli.cursor_pos() {
|
# Get the cursor current position and returns CURSOR_X, CURSOR_Y
|
||||||
|
: "cli.get_cursor"
|
||||||
|
cli.get_cursor() {
|
||||||
local _xy
|
local _xy
|
||||||
|
|
||||||
echo -ne $"\E[6n"
|
echo -ne $"\E[6n"
|
||||||
@@ -33,42 +39,144 @@ cli.cursor_pos() {
|
|||||||
_xy="${_xy#*[}"
|
_xy="${_xy#*[}"
|
||||||
export CURSOR_X=${_xy/*;}
|
export CURSOR_X=${_xy/*;}
|
||||||
export CURSOR_Y=${_xy/;*}
|
export CURSOR_Y=${_xy/;*}
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Puts the cursor at x:y (defaults to 0:0)
|
||||||
|
: "cli.set_cursor <x> <y>"
|
||||||
|
cli.set_cursor() {
|
||||||
|
printf "\E[%sH" "${2:0};${1:0}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Just prints N blank lines
|
||||||
|
: "cli.jump <number_lines>"
|
||||||
|
cli.jump() {
|
||||||
|
for i in $(seq 1 ${1:-1}); do
|
||||||
|
printf "%s${EL}\n"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Just like printf
|
||||||
|
: "cli.print [<printf_format>] <arg1> [<arg2> ...]"
|
||||||
|
cli.print() {
|
||||||
|
printf $"${1}" ${@:2}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Folds text at 'size' column
|
||||||
|
: "cli.fold <size> <text>"
|
||||||
|
cli.fold() {
|
||||||
|
printf "%s" "${@:2}" | fold -sw ${1}
|
||||||
|
}
|
||||||
|
|
||||||
|
: "cli.status <status> [<printf_format>] <arg>"
|
||||||
cli.status() {
|
cli.status() {
|
||||||
printf "%0.s\n"
|
local fmt=${2//\\n}
|
||||||
|
cli.jump
|
||||||
case "${1:-info}" in
|
case "${1:-info}" in
|
||||||
debug) printf "\e[0F${S_DEBUG}${2:-%s}" "${@:3}${EL}" ;;
|
debug) printf "\e[0F${S_DEBUG}${fmt:-%s}${@:3}${EL}\n" ;;
|
||||||
crit*) printf "\e[0F${S_CRIT}${2:-%s}" "${@:3}${EL}" ;;
|
crit*) printf "\e[0F${S_CRIT}${fmt:-%s}${@:3}${EL}\n" ;;
|
||||||
error) printf "\e[0F${S_ERROR}${2:-%s}" "${@:3}${EL}" ;;
|
error) printf "\e[0F${S_ERROR}${fmt:-%s}${@:3}${EL}\n" ;;
|
||||||
warn*) printf "\e[0F${S_WARN}${2:-%s}" "${@:3}${EL}" ;;
|
warn*) printf "\e[0F${S_WARN}${fmt:-%s}${@:3}${EL}\n" ;;
|
||||||
info*) printf "\e[0F${S_INFO}${2:-%s}" "${@:3}${EL}" ;;
|
info*) printf "\e[0F${S_INFO}${fmt:-%s}${@:3}${EL}\n" ;;
|
||||||
noti*) printf "\e[0F${S_NOTICE}${2:-%s}" "${@:3}${EL}" ;;
|
noti*) printf "\e[0F${S_NOTICE}${fmt:-%s}${@:3}${EL}\n" ;;
|
||||||
succ*) printf "\e[0F${S_SUCCESS}${2:-%s}" "${@:3}${EL}" ;;
|
succ*) printf "\e[0F${S_SUCCESS}${fmt:-%s}${@:3}${EL}\n" ;;
|
||||||
*) printf "\e[0F${S_INFO}${2:-%s}" "${@:3}${EL}" ;;
|
*) printf "\e[0F${S_INFO}${fmt:-%s}" "${@:3}" ;;
|
||||||
esac
|
esac
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
: "cli.color <color> [<printf_format>] <arg1> [<arg2> ...]"
|
||||||
cli.color() {
|
cli.color() {
|
||||||
case "${1:-info}" in
|
local fmt="${2:-}"
|
||||||
red) printf "${C_RED}${2:-%s}${C_NONE}" "${@:3}${EL}" ;;
|
fmt="${fmt//\\n}"
|
||||||
blue) printf "${C_BLUE}${2:-%s}${C_NONE}" "${@:3}${EL}" ;;
|
case "${1:-}" in
|
||||||
green) printf "${C_GREEN}${2:-%s}${C_NONE}" "${@:3}${EL}" ;;
|
red) printf "${C_RED}${fmt:-%s}${C_NONE}" ${@:3} ;;
|
||||||
orange) printf "${C_ORANGE}${2:-%s}${C_NONE}" "${@:3}${EL}" ;;
|
blue) printf "${C_BLUE}${fmt:-%s}${C_NONE}" ${@:3} ;;
|
||||||
yellow) printf "${C_YELLOW}${2:-%s}${C_NONE}" "${@:3}${EL}" ;;
|
green) printf "${C_GREEN}${fmt:-%s}${C_NONE}" ${@:3} ;;
|
||||||
purple) printf "${C_PURPLE}${2:-%s}${C_NONE}" "${@:3}${EL}" ;;
|
orange) printf "${C_ORANGE}${fmt:-%s}${C_NONE}" ${@:3} ;;
|
||||||
*) printf "${C_NONE}${2:-%s}${C_NONE}" "${@:3}${EL}" ;;
|
yellow) printf "${C_YELLOW}${fmt:-%s}${C_NONE}" ${@:3} ;;
|
||||||
|
purple) printf "${C_PURPLE}${fmt:-%s}${C_NONE}" ${@:3} ;;
|
||||||
|
*) printf "${C_NONE}${fmt:-%s}${C_NONE}" ${@:3} ;;
|
||||||
esac
|
esac
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
: "cli.emphasis <color|bold> [<printf_format>] <arg1> [<arg2> ...]"
|
||||||
|
cli.emphasis() {
|
||||||
|
local fmt="${2:-}"
|
||||||
|
fmt="${fmt//\\n}"
|
||||||
|
case "${1:-bold}" in
|
||||||
|
red) printf "${C_RED}${F_BOLD}${fmt:-%s}${F_NONE}" "${@:3}" ;;
|
||||||
|
blue) printf "${C_BLUE}${F_BOLD}${fmt:-%s}${F_NONE}" "${@:3}" ;;
|
||||||
|
green) printf "${C_GREEN}${F_BOLD}${fmt:-%s}${F_NONE}" "${@:3}" ;;
|
||||||
|
orange) printf "${C_ORANGE}${F_BOLD}${fmt:-%s}${F_NONE}" "${@:3}" ;;
|
||||||
|
yellow) printf "${C_YELLOW}${F_BOLD}${fmt:-%s}${F_NONE}" "${@:3}" ;;
|
||||||
|
purple) printf "${C_PURPLE}${F_BOLD}${fmt:-%s}${F_NONE}" "${@:3}" ;;
|
||||||
|
bold|*) printf "${F_BOLD}${fmt:-%s}${F_NONE}" "${@:3}" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
: "cli.bold <arg>"
|
||||||
cli.bold() {
|
cli.bold() {
|
||||||
printf "${F_BOLD}${1:-%s}${F_NONE}" "${@:2}${EL}"
|
cli.emphasis bold "%s" "${@}"
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
: "cli.tab <size>"
|
||||||
|
cli.tab() {
|
||||||
|
s=${1:-2}
|
||||||
|
! [[ -z "${s//[0-9]}" ]] && s=2
|
||||||
|
printf "%${s:-2}s" " "
|
||||||
|
}
|
||||||
|
|
||||||
|
: "cli.items [<printf_format>] <text> [<text> ...]"
|
||||||
|
cli.items() {
|
||||||
|
printf "${U_ITEM} ${1:-%s}" "${@:2}"
|
||||||
|
}
|
||||||
|
|
||||||
|
: "cli.items <text>"
|
||||||
|
cli.item() {
|
||||||
|
cli.items "%s\n" "${@}" | head -1
|
||||||
|
}
|
||||||
|
|
||||||
|
: "cli.title <text>"
|
||||||
|
cli.title() {
|
||||||
|
cli.items "%s" "$(cli.emphasis blue "%s" "${@^^}")"
|
||||||
|
cli.line
|
||||||
|
}
|
||||||
|
|
||||||
|
: "cli.subtitle <text>"
|
||||||
|
cli.subtitle() {
|
||||||
|
printf "%0.s\u2508%s"
|
||||||
|
cli.bold " ${@^^} "
|
||||||
|
cli.get_cursor
|
||||||
|
for i in $(seq 0 $((( ${COLS} - ${CURSOR_X} )))); do
|
||||||
|
printf "%0.s\u2508"
|
||||||
|
done
|
||||||
|
cli.jump
|
||||||
|
}
|
||||||
|
|
||||||
|
: "cli.prompt <tab_size> [<prompt_text>]"
|
||||||
|
cli.prompt() {
|
||||||
|
read -p "$(cli.print ${1:-})" k
|
||||||
|
echo ${k}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Draws a horizontal line
|
||||||
|
: "cli.line [nobreak]"
|
||||||
|
cli.line() {
|
||||||
|
[[ -z "${1:-}" ]] && cli.jump
|
||||||
|
for i in $(seq 1 ${COLS}); do
|
||||||
|
printf "%0.s\u2504"
|
||||||
|
done
|
||||||
|
[[ -z "${1:-}" ]] && cli.jump
|
||||||
|
}
|
||||||
|
|
||||||
|
# Draws a thin horizontal divisor line
|
||||||
|
: "cli.boldline"
|
||||||
|
cli.boldline() {
|
||||||
|
for i in $(seq 1 ${COLS}); do
|
||||||
|
printf "%0.s\u2581"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
: "cli.section <printf_format> <title> <subtitle> <content>"
|
||||||
cli.section() {
|
cli.section() {
|
||||||
__section.header() {
|
__section.header() {
|
||||||
__section.title() {
|
__section.title() {
|
||||||
@@ -77,24 +185,18 @@ cli.section() {
|
|||||||
$(echo -ne ${C_ORANGE}${@:3}${F_NONE})
|
$(echo -ne ${C_ORANGE}${@:3}${F_NONE})
|
||||||
}
|
}
|
||||||
__section.title.underline() {
|
__section.title.underline() {
|
||||||
for i in $(seq 1 ${COLS}); do \
|
cli.boldline
|
||||||
printf "%s" $(echo -ne "\u2581"); \
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
__section.title "${@}"
|
__section.title "${@}"
|
||||||
__section.title.underline
|
__section.title.underline
|
||||||
}
|
}
|
||||||
__section.content() {
|
__section.content() {
|
||||||
printf "%2s\n"
|
cli.jump 2
|
||||||
printf "%s" "${@}" | fold -sw ${COLS}
|
cli.fold ${COLS} "${@}"
|
||||||
}
|
}
|
||||||
__section.footer() {
|
__section.footer() {
|
||||||
__section.footer.line() {
|
__section.footer.line() {
|
||||||
[ -z "${1:-}" ] && printf "%s\n"
|
cli.line
|
||||||
for i in $(seq 1 ${COLS}); do \
|
|
||||||
printf "%s" $(echo -ne "\u2504${F_NONE}"); \
|
|
||||||
done && \
|
|
||||||
[ -z "${1:-}" ] && printf "%2s\n"
|
|
||||||
}
|
}
|
||||||
__section.footer.line
|
__section.footer.line
|
||||||
}
|
}
|
||||||
@@ -102,3 +204,10 @@ cli.section() {
|
|||||||
__section.content "${@:4}"
|
__section.content "${@:4}"
|
||||||
__section.footer
|
__section.footer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cli.self_compress() {
|
||||||
|
cat cli.bash | \
|
||||||
|
gzip -c9 - | \
|
||||||
|
base64 -w77 | \
|
||||||
|
xargs printf ' %s \\\n'
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,56 +1,66 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
self=$(basename ${0})
|
|
||||||
self=${self/.*bash}
|
self=$(: "${0/*\/}"; echo ${_%%.*sh})
|
||||||
version=2506.4
|
version=2506.90
|
||||||
|
|
||||||
|
: ${LANG:=C.UTF-8}
|
||||||
|
|
||||||
|
# Read the configuration from all config files found
|
||||||
|
CONFPATH="/etc/${self}:/usr/local/etc/${self}:.config:./config:."
|
||||||
|
for _p in ${CONFPATH//:/\ }; do
|
||||||
|
test -f ${_p}/${self}.conf && \
|
||||||
|
. ${_p}/${self}.conf
|
||||||
|
done
|
||||||
|
|
||||||
|
function cli { # Compressed built-in CLI
|
||||||
|
cli.__init__() {
|
||||||
|
local blob="\
|
||||||
|
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 \
|
||||||
|
0MMmahd1/gelgdo3VRQAAA== \
|
||||||
|
"
|
||||||
|
envfile=$(mktemp /tmp/sig-installer.env.XXXXXX)
|
||||||
|
echo $blob | base64 -di | gunzip -dc > ${envfile}
|
||||||
|
test -r ${envfile} && source ${envfile}
|
||||||
|
rm -f ${envfile}
|
||||||
|
}
|
||||||
|
cli.__init__
|
||||||
|
cli.clear
|
||||||
|
}
|
||||||
|
|
||||||
# == Funções Gerais ============================================================================== #
|
# == Funções Gerais ============================================================================== #
|
||||||
|
|
||||||
function self.check_essential {
|
|
||||||
# We need at least some programs installed
|
|
||||||
local _essential=" \
|
|
||||||
libarchive-tools:bsdtar \
|
|
||||||
curl:curl \
|
|
||||||
git-core:git \
|
|
||||||
iproute2:ip \
|
|
||||||
iputils-ping:ping \
|
|
||||||
jq:jq \
|
|
||||||
python3-yaml:jq \
|
|
||||||
locales:locale-gen \
|
|
||||||
openssh-server:sshd \
|
|
||||||
sudo:sudo \
|
|
||||||
unzip:unzip \
|
|
||||||
tzdata:tzconfig \
|
|
||||||
"
|
|
||||||
|
|
||||||
local _not_found=
|
|
||||||
for _prog in ${_essential}; do
|
|
||||||
if [[ -z "$(which ${_prog/*:})" ]]; then
|
|
||||||
_not_found+=" ${_prog}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ ! -z "$_not_found" ]]; then
|
|
||||||
clear
|
|
||||||
echo -e "Os seguintes pacotes/programas são necessários para o instalador:\n"
|
|
||||||
_pkgs=
|
|
||||||
for _prog in ${_not_found}; do
|
|
||||||
echo " - ${_prog/:*}: ${_prog/*:}"
|
|
||||||
_pkgs+="${_prog/:*} "
|
|
||||||
done
|
|
||||||
read -p \
|
|
||||||
$"Aperte ENTER para instalar os pacotes agora [CTRL+C para cancelar]: "
|
|
||||||
apt-get update
|
|
||||||
apt-get install -yq ${_pkgs}
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
self.check_essential
|
|
||||||
|
|
||||||
# -- Import functions from local or remote scripts
|
|
||||||
function import {
|
function import {
|
||||||
case ${1} in
|
case ${1} in
|
||||||
http?://*|ftp?://*)
|
http?://*|ftp?://*)
|
||||||
|
[[ -z "$(which curl 2>/dev/null)" ]] && return 1
|
||||||
_tmpfile=$(mktemp /tmp/${self}.import.XXXXX)
|
_tmpfile=$(mktemp /tmp/${self}.import.XXXXX)
|
||||||
curl -ks ${1} -o ${_tmpfile} \
|
curl -ks ${1} -o ${_tmpfile} \
|
||||||
&& source ${_tmpfile} \
|
&& source ${_tmpfile} \
|
||||||
@@ -63,6 +73,105 @@ function import {
|
|||||||
return ${?}
|
return ${?}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function self.check_sudo {
|
||||||
|
# Check if user has sudo access
|
||||||
|
if ! [[ (0$(id -u) -eq 0 || "$(groups)" =~ "sudo") ]]; then
|
||||||
|
cli.status info $"Este programa deve ser executado com 'sudo'"
|
||||||
|
cli.tab 9; cli.item $"Tente usar: $(cli.emphasis red 'sudo') ${0}"
|
||||||
|
echo -ne "\E[0G\n"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function self.check_os {
|
||||||
|
local _os_id="${ID}"
|
||||||
|
local _os_name=$(cli.emphasis bold "%s" "${NAME// /-}")
|
||||||
|
local _os_version=" $(cli.bold "${VERSION/\(*}")"${VERSION/*\(/(}""
|
||||||
|
|
||||||
|
cli.status info $"Sistema operacional detectado: "
|
||||||
|
cli.tab 9
|
||||||
|
case "${_os_id}" in
|
||||||
|
ubuntu) cli.color orange "%s" "${_os_name}"; cli.print "${_os_version}" ;;
|
||||||
|
debian) cli.color purple "%s" "${_os_name}"; cli.print "${_os_version}" ;;
|
||||||
|
fedora) cli.color blue "%s" "${_os_name}"; cli.print "${_os_version}" ;;
|
||||||
|
*) (printf "%s %s\n" "${_os_name}" "${_os_version}") ;;
|
||||||
|
esac
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function self.check_essential {
|
||||||
|
# We need at least some programs installed
|
||||||
|
local _essential_ubuntu=" \
|
||||||
|
libarchive-tools:/usr/bin/bsdtar \
|
||||||
|
curl:/usr/bin/curl \
|
||||||
|
git-core:/usr/bin/git \
|
||||||
|
iproute2:/usr/bin/ip \
|
||||||
|
iputils-ping:/usr/bin/ping \
|
||||||
|
jq:/usr/bin/jq \
|
||||||
|
python3-yaml:/usr/lib/python3/dist-packages/yaml \
|
||||||
|
locales:/usr/sbin/locale-gen \
|
||||||
|
openssh-server:/usr/sbin/sshd \
|
||||||
|
sudo:/usr/bin/sudo \
|
||||||
|
tzdata:/usr/sbin/tzconfig \
|
||||||
|
"
|
||||||
|
local _essential_fedora=" \
|
||||||
|
bsdtar:/usr/bin/bsdtar \
|
||||||
|
curl:/usr/bin/curl \
|
||||||
|
git-core:/usr/bin/git \
|
||||||
|
iproute:/usr/bin/ip \
|
||||||
|
iputils:/usr/bin/ping \
|
||||||
|
jq:/usr/bin/jq \
|
||||||
|
python3-pyyaml:/usr/lib64/python$( \
|
||||||
|
python3 -V 2>/dev/null | grep -iPo 'Python \K.[\d]*\.[\d]*' \
|
||||||
|
)/site-packages/yaml \
|
||||||
|
glibc-common:/usr/lib/locale/C.utf8 \
|
||||||
|
glibc-langpack-en:/usr/lib/locale/en_US.utf8 \
|
||||||
|
glibc-langpack-pt:/usr/lib/locale/pt_BR.utf8 \
|
||||||
|
openssh-server:/usr/bin/sshd \
|
||||||
|
sudo:/usr/bin/sudo \
|
||||||
|
tzdata:/usr/share/zoneinfo \
|
||||||
|
"
|
||||||
|
|
||||||
|
not_found=
|
||||||
|
_essential=$(eval "echo \${_essential_${DISTRO}}")
|
||||||
|
for _prog in ${_essential}; do
|
||||||
|
if ! [[ -e "${_prog/*:}" ]] && [[ -z "$(which ${_prog/*:} 2>/dev/null)" ]]; then
|
||||||
|
not_found+=" ${_prog}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ! -z "$not_found" ]] || [[ 0${#not_found} -gt 0 ]]; then
|
||||||
|
cli.status info "%s\n" $"As seguintes dependências são necessárias:"
|
||||||
|
|
||||||
|
local _pkgs=
|
||||||
|
for _prog in ${not_found}; do
|
||||||
|
local _arrow=$(cli.color green "${U_ITEM}")
|
||||||
|
printf " %s %s [%s]\n" ${_arrow} ${_prog/*:} $(cli.color green "${_prog/:*}")
|
||||||
|
_pkgs+="${_prog/:*} "
|
||||||
|
done;
|
||||||
|
system.install_pkgs "${_pkgs}"
|
||||||
|
return ${#_pkgs}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function self.get_token() {
|
||||||
|
local _passphrase="Sig%$ºluc03s"
|
||||||
|
|
||||||
|
tail -n +$(( \
|
||||||
|
${LINENO} + \
|
||||||
|
$(\
|
||||||
|
: "$( \
|
||||||
|
grep -anP "^exit 0" ${0})"; \
|
||||||
|
echo $(( ${_%%:*} - ${LINENO} + 2)) \
|
||||||
|
) \
|
||||||
|
)) ${0} | base64 -d \
|
||||||
|
| bsdtar \
|
||||||
|
--passphrase ${_passphrase} \
|
||||||
|
-xOf -
|
||||||
|
|
||||||
|
return ${?}
|
||||||
|
}
|
||||||
|
|
||||||
# -- YAML Parser
|
# -- YAML Parser
|
||||||
: parsers.yaml file.yml key
|
: parsers.yaml file.yml key
|
||||||
function parsers.yaml {
|
function parsers.yaml {
|
||||||
@@ -85,39 +194,6 @@ function parsers.yaml {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# == UI =======================================================================+================= #
|
|
||||||
# -- Import UI from dbtool
|
|
||||||
ui=${ui:-cli}
|
|
||||||
dbtool=https://raw.githubusercontent.com/infra7ti/dbtool/refs/heads/main
|
|
||||||
import ${dbtool}/lib/ui/${ui}.bash
|
|
||||||
|
|
||||||
function cli.clear {
|
|
||||||
clear
|
|
||||||
}
|
|
||||||
|
|
||||||
function cli.status {
|
|
||||||
${ui}.${@:1:1} && ${ui}.print "${@:2}"
|
|
||||||
echo; return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function cli.title {
|
|
||||||
${ui}.color blue
|
|
||||||
${ui}.emphasis "$(${ui}.subitem "${@^^}")"
|
|
||||||
${ui}.color none
|
|
||||||
${ui}.line
|
|
||||||
}
|
|
||||||
|
|
||||||
function cli.subtitle {
|
|
||||||
${ui}.subitem "${@^^} \n"
|
|
||||||
printf "%0.s$(echo -ne "\u2508${NO_FMT}")" {1..80}
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
function cli.prompt {
|
|
||||||
read -p "$(${ui}.status tab "${1}")" ${2:-} k
|
|
||||||
echo ${k}
|
|
||||||
}
|
|
||||||
|
|
||||||
# == Configuração do Sistema====================================================================== #
|
# == Configuração do Sistema====================================================================== #
|
||||||
|
|
||||||
function system.check_os {
|
function system.check_os {
|
||||||
@@ -215,7 +291,7 @@ function system.setup_openssh {
|
|||||||
|
|
||||||
# == Instalação de Pacotes e Aplicativos ======================================================== #
|
# == Instalação de Pacotes e Aplicativos ======================================================== #
|
||||||
|
|
||||||
function system.install_pkgs {
|
function system.install_pkgs_old {
|
||||||
import /etc/os-release
|
import /etc/os-release
|
||||||
local _os_id=${ID}
|
local _os_id=${ID}
|
||||||
case ${_os_id} in
|
case ${_os_id} in
|
||||||
@@ -241,6 +317,75 @@ function system.install_pkgs {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function system.install_pkgs {
|
||||||
|
__buffer_output() {
|
||||||
|
while mapfile -t -n ${1:-10} buffer && ((${#buffer[@]})); do
|
||||||
|
cli.set_cursor 1 ${CURSOR_Y}
|
||||||
|
printf "${C_PURPLE}"
|
||||||
|
for line in "${buffer[@]}"; do
|
||||||
|
! [[ -z "${line}" ]] && printf " %s\n" "${line}${EL}"
|
||||||
|
done;
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
__apt_success() {
|
||||||
|
cli.set_cursor 1 ${CURSOR_Y}
|
||||||
|
printf "${S_SUCCESS}%s\n" \
|
||||||
|
"${@:1:1}:${EL}"
|
||||||
|
for p in ${@:2}; do
|
||||||
|
cli.tab 2; cli.item "${p}${EL}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
__apt_failure() {
|
||||||
|
cli.set_cursor 1 ${CURSOR_Y}
|
||||||
|
printf "${S_ERROR}%s\n" \
|
||||||
|
"${@:1:1}:${EL}"
|
||||||
|
if [[ -f "${2:-}" ]]; then
|
||||||
|
tail -${4:-50} ${@:2:1} 2>/dev/null | while read line; do
|
||||||
|
cli.tab 2; printf "${C_RED}${3:-Log}: %s\n" "${line}${EL}"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
cli.set_cursor 1 ${CURSOR_Y}
|
||||||
|
cli.jump
|
||||||
|
fi
|
||||||
|
printf "\\E[0G${C_NONE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
local _log=$(mktemp /tmp/${self}.install.XXXXX)
|
||||||
|
case "${DISTRO}" in
|
||||||
|
debian|ubuntu)
|
||||||
|
printf "%0.s\n"
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
cli.status info "%s\n" $"Instalando os pacotes. Por favor aguarde ..."
|
||||||
|
cli.get_cursor
|
||||||
|
apt-get -q update | tee ${_log} | \
|
||||||
|
__buffer_output 5 && \
|
||||||
|
apt-get -qy install ${@} 2>&1 | tee ${_log} | \
|
||||||
|
__buffer_output 10 \
|
||||||
|
&& __apt_success $"Pacotes instalados com sucesso" ${@} \
|
||||||
|
|| __apt_failure $"A instalação de pacotes falhou" ${_log} APT 50
|
||||||
|
printf "${C_NONE}%0.s\n"
|
||||||
|
;;
|
||||||
|
fedora)
|
||||||
|
cli.jump
|
||||||
|
cli.status info "%s\n" $"Instalando os pacotes. Por favor aguarde ..."
|
||||||
|
cli.get_cursor
|
||||||
|
dnf -y install --refresh ${@} 2>&1 | tee ${_log} | \
|
||||||
|
__buffer_output 10 \
|
||||||
|
&& __apt_success $"Pacotes instalados com sucesso" ${@} \
|
||||||
|
|| __apt_failure $"A instalação de pacotes falhou" ${_log} DNF 50
|
||||||
|
printf "${C_NONE}%0.s\n"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
cli.jump
|
||||||
|
cli.status crit "%s" $"${DISTRO^}: Sistema operacional não suportado!"
|
||||||
|
cli.jump
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
cli.get_cursor
|
||||||
|
}
|
||||||
|
|
||||||
function system.remove_pkgs {
|
function system.remove_pkgs {
|
||||||
import /etc/os-release
|
import /etc/os-release
|
||||||
local _os_id=${ID}
|
local _os_id=${ID}
|
||||||
@@ -421,15 +566,13 @@ function system.install_pyenv {
|
|||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# == Installer =================================================================================== #
|
# == Installer =================================================================================== #
|
||||||
|
|
||||||
function installer.configure {
|
function installer.configure {
|
||||||
local _passphrase
|
local \
|
||||||
|
_passphrase=$(${ui}.prompt $"Frase secreta para acesso aos downloads: ")
|
||||||
|
|
||||||
${ui}.prompt $"Frase secreta para acesso aos downloads: " _passphrase
|
|
||||||
PRIVKEY_PASSPHRASE="${_passphrase}"
|
PRIVKEY_PASSPHRASE="${_passphrase}"
|
||||||
|
|
||||||
! [[ "X" == "${PRIVKEY_PASSPHRASE}X" ]] && \
|
! [[ "X" == "${PRIVKEY_PASSPHRASE}X" ]] && \
|
||||||
${ui}.status info $"Frase secreta armazenada com sucesso." ${_passphrase}
|
${ui}.status info $"Frase secreta armazenada com sucesso." ${_passphrase}
|
||||||
}
|
}
|
||||||
@@ -444,12 +587,13 @@ function installer.download {
|
|||||||
|
|
||||||
local _token=$(mktemp /tmp/${self}.dl.XXXXXX)
|
local _token=$(mktemp /tmp/${self}.dl.XXXXXX)
|
||||||
local _token_pass=${PRIVKEY_PASSPHRASE}
|
local _token_pass=${PRIVKEY_PASSPHRASE}
|
||||||
local _seek=$(($(grep -anE "^exit 0" ${0} | cut -d: -f1) - ${LINENO} + 1))
|
#local _seek=$(($(grep -anE "^exit 0" ${0} | cut -d: -f1) - ${LINENO} + 1))
|
||||||
local _message="$(tail -n +$(( ${LINENO} + ${_seek} )) ${0})"
|
#local _message="$(tail -n +$(( ${LINENO} + ${_seek} )) ${0})"
|
||||||
|
|
||||||
[[ -z "${_quiet}" ]] && ${ui}.status info $"Fazendo download [${_src}]"
|
[[ -z "${_quiet}" ]] && ${ui}.status info $"Fazendo download [${_src}]"
|
||||||
(echo ${_message} | base64 -d \
|
#(echo ${_message} | base64 -d \
|
||||||
| bsdtar --passphrase ${_token_pass} -C $(dirname ${_token}) -xOf - > ${_token} \
|
# | bsdtar --passphrase ${_token_pass} -C $(dirname ${_token}) -xOf - > ${_token} \
|
||||||
|
(self.get_token > ${_token} \
|
||||||
&& chmod 0400 ${_token} \
|
&& chmod 0400 ${_token} \
|
||||||
&& scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
|
&& scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
|
||||||
-qi ${_token} "${_repo_user}@${_repo_home}/${_src}" "${_dst}" \
|
-qi ${_token} "${_repo_user}@${_repo_home}/${_src}" "${_dst}" \
|
||||||
@@ -498,15 +642,25 @@ function installer.product.menu {
|
|||||||
_products _prod_variant _prod_name _prod_color \
|
_products _prod_variant _prod_name _prod_color \
|
||||||
_prod_version _id _prod
|
_prod_version _id _prod
|
||||||
|
|
||||||
${ui}.clear
|
cli.set_cursor 0 0
|
||||||
${ui}.init "%s [VERSÃO: %s] - CONFIGURAÇÃO DE PRODUTOS\n" ${self^^} ${version}
|
cli.section "%s [VERSÃO: %s] - CONFIGURAÇÃO DE PRODUTOS${EL}\n" \
|
||||||
|
${self^^} \
|
||||||
|
${version} \
|
||||||
|
"$(
|
||||||
|
${ui}.status info $"Atualizando metadados de produtos... "
|
||||||
|
installer.download_metadata products
|
||||||
|
installer.download_metadata versions
|
||||||
|
installer.download_metadata repos
|
||||||
|
_products="$(installer.load_products)"
|
||||||
|
)"
|
||||||
|
|
||||||
PRIVKEY_PASSPHRASE=Sig%$ºluc03s
|
#PRIVKEY_PASSPHRASE=Sig%$ºluc03s
|
||||||
while [[ -z "${PRIVKEY_PASSPHRASE}" ]]; do
|
while [[ -z "${PRIVKEY_PASSPHRASE}" ]]; do
|
||||||
installer.configure
|
installer.configure
|
||||||
done
|
done
|
||||||
|
|
||||||
${ui}.status info $"Atualizando metadados de produtos... \n"
|
exit 1
|
||||||
|
${ui}.status info $"Atualizando metadados de produtos... "
|
||||||
installer.download_metadata products
|
installer.download_metadata products
|
||||||
installer.download_metadata versions
|
installer.download_metadata versions
|
||||||
installer.download_metadata repos
|
installer.download_metadata repos
|
||||||
@@ -1113,16 +1267,25 @@ function product.sigpdv.setup_sigtef {
|
|||||||
|
|
||||||
# == Loop Principal =======================================================================+===== #
|
# == Loop Principal =======================================================================+===== #
|
||||||
|
|
||||||
#clear
|
# MAIN
|
||||||
export LANG=${LANG:-'C.UTF-8'}
|
import /etc/os-release
|
||||||
#${ui}.init $"%s [VERSÃO: %s] - CONFIGURAÇÃO INICIAL\n" ${self^^} ${version}
|
export DISTRO="${ID}"
|
||||||
|
|
||||||
#self.check_essential
|
eval cli
|
||||||
|
ui=${ui:-cli}
|
||||||
|
|
||||||
|
${ui}.section "%s [VERSÃO: %s] - CONFIGURAÇÃO DO INSTALADOR\n" \
|
||||||
|
${self^^} \
|
||||||
|
${version} \
|
||||||
|
"$(
|
||||||
|
self.check_sudo || exit ${?}; \
|
||||||
|
self.check_os || exit ${?}; \
|
||||||
|
)"
|
||||||
|
|
||||||
|
self.check_essential
|
||||||
|
|
||||||
# -- Configuração do sistema
|
# -- Configuração do sistema
|
||||||
#${ui}.title $"Reconfigurando o sistema operacional"
|
#${ui}.title $"Reconfigurando o sistema operacional"
|
||||||
#system.check_os
|
|
||||||
#system.check_sudo
|
|
||||||
#system.setlocale
|
#system.setlocale
|
||||||
#system.check_net
|
#system.check_net
|
||||||
#system.setup_ntp
|
#system.setup_ntp
|
||||||
|
|||||||
Reference in New Issue
Block a user