Compare commits
7 Commits
dd5608e8e3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3116093ac8 | ||
|
|
56079c46be | ||
|
|
37a8a05951 | ||
|
|
17fbb3bc90 | ||
|
|
dd487b9fc1 | ||
|
|
4896c23a60 | ||
|
|
40c06db5ec |
146
builtin/cli.bash
146
builtin/cli.bash
@@ -21,20 +21,15 @@ export U_ITEM="\u21e2"
|
|||||||
export U_TICK="\u2713"
|
export U_TICK="\u2713"
|
||||||
export U_FAIL="\u2715"
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get the cursor current position and returns CURSOR_X, CURSOR_Y
|
# Get the cursor current position and returns CURSOR_X, CURSOR_Y
|
||||||
: "cli.get_cursor"
|
: "cli.get_cursor"
|
||||||
cli.get_cursor() {
|
cli.get_cursor() {
|
||||||
local _xy
|
local _xy
|
||||||
|
|
||||||
echo -ne $"\E[6n"
|
echo -ne $"\e[6n"
|
||||||
read -rsdR _xy
|
read -rsdR _xy
|
||||||
_xy="${_xy#*[}"
|
_xy="${_xy#*[}"
|
||||||
export CURSOR_X=${_xy/*;}
|
export CURSOR_X=${_xy/*;}
|
||||||
@@ -44,21 +39,45 @@ cli.get_cursor() {
|
|||||||
# Puts the cursor at x:y (defaults to 0:0)
|
# Puts the cursor at x:y (defaults to 0:0)
|
||||||
: "cli.set_cursor <x> <y>"
|
: "cli.set_cursor <x> <y>"
|
||||||
cli.set_cursor() {
|
cli.set_cursor() {
|
||||||
printf "\E[%sH" "${2:0};${1:0}"
|
printf "\e[%sH" "${2:0};${1:0}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Just prints N blank lines
|
# Puts cursor N lines up
|
||||||
: "cli.jump <number_lines>"
|
: "cli.lineup [<number_lines>]"
|
||||||
cli.jump() {
|
cli.lineup() {
|
||||||
for i in $(seq 1 ${1:-1}); do
|
printf "\e[%sA${EL}\e[0F" "${1:-1}"
|
||||||
printf "%s${EL}\n"
|
}
|
||||||
|
|
||||||
|
# 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
|
done
|
||||||
|
cli.set_cursor 0 ${CURSOR_Y}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Just prints a blank line
|
||||||
|
: "cli.writeln"
|
||||||
|
cli.writeln() {
|
||||||
|
cli.linedown
|
||||||
|
printf "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Just like printf
|
# Just like printf
|
||||||
: "cli.print [<printf_format>] <arg1> [<arg2> ...]"
|
: "cli.print [<printf_format>] <arg1> [<arg2> ...]"
|
||||||
cli.print() {
|
cli.print() {
|
||||||
printf $"${1}" ${@:2}
|
printf "${1:-}" ${@:2}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Folds text at 'size' column
|
# Folds text at 'size' column
|
||||||
@@ -69,8 +88,9 @@ cli.fold() {
|
|||||||
|
|
||||||
: "cli.status <status> [<printf_format>] <arg>"
|
: "cli.status <status> [<printf_format>] <arg>"
|
||||||
cli.status() {
|
cli.status() {
|
||||||
local fmt=${2//\\n}
|
local fmt="${2:-}"
|
||||||
cli.jump
|
fmt="${fmt//\\n}"
|
||||||
|
cli.writeln
|
||||||
case "${1:-info}" in
|
case "${1:-info}" in
|
||||||
debug) printf "\e[0F${S_DEBUG}${fmt:-%s}${@:3}${EL}\n" ;;
|
debug) printf "\e[0F${S_DEBUG}${fmt:-%s}${@:3}${EL}\n" ;;
|
||||||
crit*) printf "\e[0F${S_CRIT}${fmt:-%s}${@:3}${EL}\n" ;;
|
crit*) printf "\e[0F${S_CRIT}${fmt:-%s}${@:3}${EL}\n" ;;
|
||||||
@@ -130,7 +150,7 @@ cli.items() {
|
|||||||
printf "${U_ITEM} ${1:-%s}" "${@:2}"
|
printf "${U_ITEM} ${1:-%s}" "${@:2}"
|
||||||
}
|
}
|
||||||
|
|
||||||
: "cli.items <text>"
|
: "cli.item <text>"
|
||||||
cli.item() {
|
cli.item() {
|
||||||
cli.items "%s\n" "${@}" | head -1
|
cli.items "%s\n" "${@}" | head -1
|
||||||
}
|
}
|
||||||
@@ -139,45 +159,106 @@ cli.item() {
|
|||||||
cli.title() {
|
cli.title() {
|
||||||
cli.items "%s" "$(cli.emphasis blue "%s" "${@^^}")"
|
cli.items "%s" "$(cli.emphasis blue "%s" "${@^^}")"
|
||||||
cli.line
|
cli.line
|
||||||
|
cli.writeln
|
||||||
}
|
}
|
||||||
|
|
||||||
: "cli.subtitle <text>"
|
: "cli.subtitle <text> [noline]"
|
||||||
cli.subtitle() {
|
cli.subtitle() {
|
||||||
printf "%0.s\u2508%s"
|
printf "%0.s\u2508%s"
|
||||||
cli.bold " ${@^^} "
|
cli.bold " ${@^^} "
|
||||||
cli.get_cursor
|
cli.get_cursor
|
||||||
for i in $(seq 0 $((( ${COLS} - ${CURSOR_X} )))); do
|
for i in $(seq 0 $((( $(tput cols) - ${CURSOR_X} )))); do
|
||||||
printf "%0.s\u2508"
|
printf "%0.s\u2508"
|
||||||
done
|
done
|
||||||
cli.jump
|
cli.writeln
|
||||||
}
|
}
|
||||||
|
|
||||||
: "cli.prompt <tab_size> [<prompt_text>]"
|
: "cli.prompt <prompt_text> [<options>] [<var>]"
|
||||||
cli.prompt() {
|
cli.prompt() {
|
||||||
read -p "$(cli.print ${1:-})" k
|
local k=
|
||||||
echo ${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
|
# Draws a horizontal line
|
||||||
: "cli.line [nobreak]"
|
: "cli.line [nobreak]"
|
||||||
cli.line() {
|
cli.line() {
|
||||||
[[ -z "${1:-}" ]] && cli.jump
|
[[ -z "${1:-}" ]] && cli.writeln
|
||||||
for i in $(seq 1 ${COLS}); do
|
for i in $(seq 1 $(tput cols)); do
|
||||||
printf "%0.s\u2504"
|
printf "%0.s\u2504"
|
||||||
done
|
done
|
||||||
[[ -z "${1:-}" ]] && cli.jump
|
[[ -z "${1:-}" ]] && cli.writeln
|
||||||
}
|
}
|
||||||
|
|
||||||
# Draws a thin horizontal divisor line
|
# Draws a thin horizontal divisor line
|
||||||
: "cli.boldline"
|
: "cli.boldline"
|
||||||
cli.boldline() {
|
cli.boldline() {
|
||||||
for i in $(seq 1 ${COLS}); do
|
for i in $(seq 1 $(tput cols)); do
|
||||||
printf "%0.s\u2581"
|
printf "%0.s\u2581"
|
||||||
done
|
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 <printf_format> <title> <subtitle> <content>"
|
||||||
cli.section() {
|
cli.section() {
|
||||||
|
cli.set_cursor 0 0
|
||||||
__section.header() {
|
__section.header() {
|
||||||
__section.title() {
|
__section.title() {
|
||||||
printf $"${@:1:1}" \
|
printf $"${@:1:1}" \
|
||||||
@@ -186,13 +267,15 @@ cli.section() {
|
|||||||
}
|
}
|
||||||
__section.title.underline() {
|
__section.title.underline() {
|
||||||
cli.boldline
|
cli.boldline
|
||||||
|
cli.writeln
|
||||||
}
|
}
|
||||||
__section.title "${@}"
|
__section.title "${@}"
|
||||||
__section.title.underline
|
__section.title.underline
|
||||||
}
|
}
|
||||||
__section.content() {
|
__section.content() {
|
||||||
cli.jump 2
|
cli.linedown
|
||||||
cli.fold ${COLS} "${@}"
|
cli.fold $(tput cols) "${@}"
|
||||||
|
cli.writeln
|
||||||
}
|
}
|
||||||
__section.footer() {
|
__section.footer() {
|
||||||
__section.footer.line() {
|
__section.footer.line() {
|
||||||
@@ -200,9 +283,10 @@ cli.section() {
|
|||||||
}
|
}
|
||||||
__section.footer.line
|
__section.footer.line
|
||||||
}
|
}
|
||||||
|
cli.clear
|
||||||
__section.header "${@:1:3}"
|
__section.header "${@:1:3}"
|
||||||
__section.content "${@:4}"
|
! [[ -z "${@:4}" ]] && __section.content "${@:4}"
|
||||||
__section.footer
|
! [[ -z "${@:4}" ]] && __section.footer
|
||||||
}
|
}
|
||||||
|
|
||||||
cli.self_compress() {
|
cli.self_compress() {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
self=$(basename ${0})
|
self=$(basename ${0})
|
||||||
self=${self/.*bash}
|
self=${self/.*bash}
|
||||||
version=2506.3
|
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'
|
||||||
pg_conftool ${_pg_version} main set shared_preload_libraries ${_pg_shared_preload}
|
if [[ ! -z "${_pg_shared_preload}" ]]; then
|
||||||
|
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}
|
||||||
@@ -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"
|
||||||
system.install_postgres 17 citus-13.0
|
if [[ ${install_citus} -eq 1 ]]; then
|
||||||
|
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"
|
||||||
|
|||||||
1444
sig-installer-dev
1444
sig-installer-dev
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user