11 Commits

Author SHA1 Message Date
Christian Tosta
3116093ac8 Ajustes em funções e plugins 2025-08-01 15:34:26 -03:00
Christian Tosta
56079c46be Implementado downloads (parcial) e plugin PIP 2025-08-01 13:15:56 -03:00
Christian Tosta
37a8a05951 Suporte para Ubuntu 24.04 2025-07-07 20:58:16 -03:00
Christian Tosta
17fbb3bc90 Paginação de Produto 2025-06-11 18:29:00 -03:00
Christian Tosta
dd487b9fc1 Updated .gitignore 2025-06-11 15:28:24 -03:00
Christian Tosta
4896c23a60 Retira caracteres inválidos da senha 2025-06-11 15:26:35 -03:00
Christian Tosta
40c06db5ec Corrigido rebase incorreto 2025-06-11 15:25:22 -03:00
Christian Tosta
c60d49b42b Retira caracteres inválidos da senha 2025-06-09 15:30:16 -03:00
Christian Tosta
4a652637f0 Retira caracteres inválidos da senha 2025-06-09 11:55:15 -03:00
Christian Tosta
aa455e90bd Reescrevendo procedimentos 2025-06-08 19:59:27 -03:00
Christian Tosta
d49c0e6b76 Dev Updates 2025-06-06 22:36:05 -03:00
5 changed files with 1269 additions and 602 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*\.old
builtin/cli.bash.gz.b64
snippets/
tools/

View File

@@ -52,4 +52,3 @@ cli.section() {
__section.content "${@:4}" __section.content "${@:4}"
__section.footer __section.footer
} }
cli.section "${@}"

297
builtin/cli.bash Normal file
View File

@@ -0,0 +1,297 @@
export F_BOLD="\e[1m"
export F_NONE="\e[0m"
export C_NONE="\e[0m"
export C_RED="\e[38;5;9m"
export C_BLUE="\e[38;5;12m"
export C_GREEN="\e[38;5;2m"
export C_ORANGE="\e[38;5;208m"
export C_YELLOW="\e[38;5;220m"
export C_PURPLE="\e[38;5;5m"
export S_DEBUG="${C_PURPLE}\u2691 [debug]${F_NONE} "
export S_CRIT="${F_BOLD}${C_RED}\u2691 [critical]${F_NONE} "
export S_ERROR="${C_RED}\u2691 [error]${F_NONE} "
export S_WARN="${C_ORANGE}\u2691 [warning]${F_NONE} "
export S_INFO="${F_BOLD}${C_BLUE}\u2691 [info]${F_NONE} "
export S_NOTICE="${C_BLUE}\u2691 [notice]${F_NONE} "
export S_SUCCESS="${F_BOLD}${C_GREEN}\u2691 [success]${F_NONE} "
export U_ITEM="\u21e2"
export U_TICK="\u2713"
export U_FAIL="\u2715"
#export COLS="$(( $(tput cols) - 1 ))"
export EL=$(tput el)
# Get the cursor current position and returns CURSOR_X, CURSOR_Y
: "cli.get_cursor"
cli.get_cursor() {
local _xy
echo -ne $"\e[6n"
read -rsdR _xy
_xy="${_xy#*[}"
export CURSOR_X=${_xy/*;}
export CURSOR_Y=${_xy/;*}
}
# 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}"
}
# Puts cursor N lines up
: "cli.lineup [<number_lines>]"
cli.lineup() {
printf "\e[%sA${EL}\e[0F" "${1:-1}"
}
# Puts cursor N lines down
: "cli.linedown [<number_lines>]"
cli.linedown() {
printf "\e[%sB${EL}\e[0F" "${1:-1}"
}
# Clears the screen below cursor position
: "cli.clear"
cli.clear() {
cli.writeln
cli.lineup
cli.get_cursor
local _lines=$((( $(tput lines) - ${CURSOR_Y} - 1 )))
for i in $(seq 1 ${_lines}); do
cli.writeln
done
cli.set_cursor 0 ${CURSOR_Y}
}
# Just prints a blank line
: "cli.writeln"
cli.writeln() {
cli.linedown
printf "\n"
}
# 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() {
local fmt="${2:-}"
fmt="${fmt//\\n}"
cli.writeln
case "${1:-info}" in
debug) printf "\e[0F${S_DEBUG}${fmt:-%s}${@:3}${EL}\n" ;;
crit*) printf "\e[0F${S_CRIT}${fmt:-%s}${@:3}${EL}\n" ;;
error) printf "\e[0F${S_ERROR}${fmt:-%s}${@:3}${EL}\n" ;;
warn*) printf "\e[0F${S_WARN}${fmt:-%s}${@:3}${EL}\n" ;;
info*) printf "\e[0F${S_INFO}${fmt:-%s}${@:3}${EL}\n" ;;
noti*) printf "\e[0F${S_NOTICE}${fmt:-%s}${@:3}${EL}\n" ;;
succ*) printf "\e[0F${S_SUCCESS}${fmt:-%s}${@:3}${EL}\n" ;;
*) printf "\e[0F${S_INFO}${fmt:-%s}" "${@:3}" ;;
esac
}
: "cli.color <color> [<printf_format>] <arg1> [<arg2> ...]"
cli.color() {
local fmt="${2:-}"
fmt="${fmt//\\n}"
case "${1:-}" in
red) printf "${C_RED}${fmt:-%s}${C_NONE}" ${@:3} ;;
blue) printf "${C_BLUE}${fmt:-%s}${C_NONE}" ${@:3} ;;
green) printf "${C_GREEN}${fmt:-%s}${C_NONE}" ${@:3} ;;
orange) printf "${C_ORANGE}${fmt:-%s}${C_NONE}" ${@:3} ;;
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
}
: "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.emphasis bold "%s" "${@}"
}
: "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.item <text>"
cli.item() {
cli.items "%s\n" "${@}" | head -1
}
: "cli.title <text>"
cli.title() {
cli.items "%s" "$(cli.emphasis blue "%s" "${@^^}")"
cli.line
cli.writeln
}
: "cli.subtitle <text> [noline]"
cli.subtitle() {
printf "%0.s\u2508%s"
cli.bold " ${@^^} "
cli.get_cursor
for i in $(seq 0 $((( $(tput cols) - ${CURSOR_X} )))); do
printf "%0.s\u2508"
done
cli.writeln
}
: "cli.prompt <prompt_text> [<options>] [<var>]"
cli.prompt() {
local k=
_get_var() { : "${@:$#}"; echo "${_//-*/}"; }
_get_opts() { echo "${@//${_var}/}"; }
case ${#@} in
1)
_prompt="$(cli.print "${1:-}")"
_var=k
_opts=
;;
*)
_prompt="$(cli.print "${1:-}")"
_var=$(_get_var ${@:2})
_opts=$(_get_opts ${@:2})
;;
esac
read -p "$(cli.print "${1:-}")" ${_opts} ${_var:-k}
! [[ -z "${k}" ]] && echo "${k}" || :
}
# Draws a horizontal line
: "cli.line [nobreak]"
cli.line() {
[[ -z "${1:-}" ]] && cli.writeln
for i in $(seq 1 $(tput cols)); do
printf "%0.s\u2504"
done
[[ -z "${1:-}" ]] && cli.writeln
}
# Draws a thin horizontal divisor line
: "cli.boldline"
cli.boldline() {
for i in $(seq 1 $(tput cols)); do
printf "%0.s\u2581"
done
cli.writeln
}
cli.subprocess.output() {
while readarray -t -n ${1:-10} buffer && ((${#buffer[@]})); do
cli.set_cursor 0 ${CURSOR_Y}
local _max_len=$(( $(tput cols) - 18 ))
for line in "${buffer[@]}"; do
! [[ -z "${line}" ]] \
&& cli.color purple " %s" "${line:0:${_max_len}}${EL}" \
&& cli.writeln
done
done
cli.set_cursor 0 ${CURSOR_Y}
for _i in {1..${1}}; do
cli.writeln
done
cli.set_cursor 0 ${CURSOR_Y}
}
cli.subprocess.success() {
cli.set_cursor 0 ${CURSOR_Y}
printf " ${S_SUCCESS}%s\n" "${@:1:1}${EL}"
for p in ${@:2}; do
cli.tab 2; cli.print "$(
cli.color green "$(cli.item ${p}${EL})"
)\n"
done
}
cli.subprocess.failure() {
cli.set_cursor 0 ${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; cli.print "$(
cli.color red "${3:-Log}: ${line}${EL}"
)\n"
done
else
cli.lineup
cli.clear
fi
}
: "cli.section <printf_format> <title> <subtitle> <content>"
cli.section() {
cli.set_cursor 0 0
__section.header() {
__section.title() {
printf $"${@:1:1}" \
$(echo -ne ${F_BOLD}${C_BLUE}${@:2:1}${F_NONE}) \
$(echo -ne ${C_ORANGE}${@:3}${F_NONE})
}
__section.title.underline() {
cli.boldline
cli.writeln
}
__section.title "${@}"
__section.title.underline
}
__section.content() {
cli.linedown
cli.fold $(tput cols) "${@}"
cli.writeln
}
__section.footer() {
__section.footer.line() {
cli.line
}
__section.footer.line
}
cli.clear
__section.header "${@:1:3}"
! [[ -z "${@:4}" ]] && __section.content "${@:4}"
! [[ -z "${@:4}" ]] && __section.footer
}
cli.self_compress() {
cat cli.bash | \
gzip -c9 - | \
base64 -w77 | \
xargs printf ' %s \\\n'
}

View File

@@ -3,7 +3,7 @@
set -euo pipefail set -euo pipefail
self=$(basename ${0}) self=$(basename ${0})
self=${self/.*bash} self=${self/.*bash}
version=2506.2 version=2507.1
# == Funções Gerais ============================================================================== # # == Funções Gerais ============================================================================== #
@@ -21,7 +21,6 @@ function self.check_essential {
openssh-server:sshd \ openssh-server:sshd \
sudo:sudo \ sudo:sudo \
unzip:unzip \ unzip:unzip \
tzdata:tzconfig \
" "
local _not_found= local _not_found=
@@ -42,7 +41,7 @@ function self.check_essential {
read -p \ read -p \
$"Aperte ENTER para instalar os pacotes agora [CTRL+C para cancelar]: " $"Aperte ENTER para instalar os pacotes agora [CTRL+C para cancelar]: "
apt-get update apt-get update
apt-get install -yq ${_pkgs} apt-get install -yq ${_pkgs} tzdata
fi fi
} }
self.check_essential self.check_essential
@@ -254,7 +253,7 @@ function system.install_postgres {
local _pg_version=${1:-17} local _pg_version=${1:-17}
local _citus_version=${2} local _citus_version=${2}
local POSTRES_PACKAGES=" local POSTGRES_PACKAGES="
libjemalloc2 \ libjemalloc2 \
postgresql-${_pg_version} \ postgresql-${_pg_version} \
" "
@@ -276,7 +275,7 @@ function system.install_postgres {
${ui}.color none ${ui}.color none
local _pg_shared_preload= local _pg_shared_preload=
if [[ ! -z "${_citus_version}" ]]; then if [[ ! -z "${_citus_version:-}" ]]; then
${ui}.status info $"Habilitando repositório: PostgreSQL-Citus ..." ${ui}.status info $"Habilitando repositório: PostgreSQL-Citus ..."
if [[ ! -f "/etc/apt/sources.list.d/citusdata_community.list" ]]; then if [[ ! -f "/etc/apt/sources.list.d/citusdata_community.list" ]]; then
${ui}.color gold ${ui}.color gold
@@ -290,15 +289,17 @@ function system.install_postgres {
${ui}.status tab "The repository is set up! You can now install packages." ${ui}.status tab "The repository is set up! You can now install packages."
${ui}.color none ${ui}.color none
fi fi
POSTRES_PACKAGES+=" postgresql-${_pg_version}-citus-${_citus_version/*-}" POSTGRES_PACKAGES+=" postgresql-${_pg_version}-citus-${_citus_version/*-}"
_pg_shared_preload+="citus" _pg_shared_preload+="citus"
fi fi
system.install_pkgs ${POSTRES_PACKAGES} system.install_pkgs ${POSTGRES_PACKAGES}
pg_conftool ${_pg_version} main set listen_addresses '*' pg_conftool ${_pg_version} main set listen_addresses '*'
pg_conftool ${_pg_version} main set log_timezone 'America/Sao_Paulo' pg_conftool ${_pg_version} main set log_timezone 'America/Sao_Paulo'
if [[ ! -z "${_pg_shared_preload}" ]]; then
pg_conftool ${_pg_version} main set shared_preload_libraries ${_pg_shared_preload} pg_conftool ${_pg_version} main set shared_preload_libraries ${_pg_shared_preload}
fi
local _pg_hba_file="/etc/postgresql/${_pg_version}/main/pg_hba.conf" local _pg_hba_file="/etc/postgresql/${_pg_version}/main/pg_hba.conf"
sudo cat <<-EOF | sed 's/^\s*\(.*\)/\1/g' > ${_pg_hba_file} sudo cat <<-EOF | sed 's/^\s*\(.*\)/\1/g' > ${_pg_hba_file}
@@ -645,7 +646,7 @@ function produto.install {
# Create/Alter PostgreSQL user # Create/Alter PostgreSQL user
local _dbuser="openerp" local _dbuser="openerp"
local _password=$(openssl rand -base64 32 | sed 's/\//|/g') local _password=$(openssl rand -base64 32 | sed 's/[/+-_=]//g')
${ui}.status info $"Criando/Atualizando usuário do banco de dados [%s]" ${PRODUTO} ${ui}.status info $"Criando/Atualizando usuário do banco de dados [%s]" ${PRODUTO}
sudo -iu postgres \ sudo -iu postgres \
psql -c \ psql -c \
@@ -772,7 +773,7 @@ function produto.install {
# -- Configuração do banco de dados PostgreSQL # -- Configuração do banco de dados PostgreSQL
local _db_name=${PRODUTO} local _db_name=${PRODUTO}
local _db_user=${_db_name} local _db_user=${_db_name}
local _db_pass=$(openssl rand -base64 32 | sed 's/\//|/g') local _db_pass=$(openssl rand -base64 32 | sed 's/[/+-_=]//g')
${ui}.status info $"Configurando o banco de dados [%s]" ${_db_name}} ${ui}.status info $"Configurando o banco de dados [%s]" ${_db_name}}
sudo -iu postgres \ sudo -iu postgres \
psql -c \ psql -c \
@@ -858,8 +859,14 @@ system.setlocale
system.check_net system.check_net
system.setup_ntp system.setup_ntp
install_citus=0
${ui}.title $"Instalando e configurando serviços" ${ui}.title $"Instalando e configurando serviços"
if [[ ${install_citus} -eq 1 ]]; then
system.install_postgres 17 citus-13.0 system.install_postgres 17 citus-13.0
else
system.install_postgres 17
fi
system.install_pyenv /usr/local/share/pyenv 2.7.18 system.install_pyenv /usr/local/share/pyenv 2.7.18
${ui}.title $"Configurando contas de usuários" ${ui}.title $"Configurando contas de usuários"

File diff suppressed because it is too large Load Diff