3 Commits

Author SHA1 Message Date
Christian Tosta
495b33a6df Reorganizando estrutura do instalador 2025-06-04 03:29:34 -03:00
Christian Tosta
ddb1432fa7 Ajustes SigERP (db user) e SigPDV (CliSiTef) 2025-06-03 15:22:35 -03:00
Christian Tosta
2f74d906c3 Update tests 2025-06-02 18:07:18 -03:00
6 changed files with 115 additions and 110 deletions

148
sig-installer Normal file → Executable file
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=2505.6 version=2506.2
# == Funções Gerais ============================================================================== # # == Funções Gerais ============================================================================== #
@@ -564,10 +564,17 @@ function produto.install {
runuser -l ${PRODUTO} -- python -m pip install --upgrade --user pip runuser -l ${PRODUTO} -- python -m pip install --upgrade --user pip
runuser -l ${PRODUTO} -- python -m pip install --upgrade --user setuptools runuser -l ${PRODUTO} -- python -m pip install --upgrade --user setuptools
for _lib in ${_libs}; do for _lib in ${_libs}; do
[[ "${_lib}" == "stoqdrivers" ]] && continue
_lbpv=$(parsers.yaml ${CACHEDIR}/versoes.yml libs.python${_pdpy/.*}.${_lib}) _lbpv=$(parsers.yaml ${CACHEDIR}/versoes.yml libs.python${_pdpy/.*}.${_lib})
runuser -l ${PRODUTO} -- python -m pip install --user \ runuser -l ${PRODUTO} -- python -m pip install --user \
"${CACHEDIR}/${PRODUTO}/${_lib}-${_lbpv#*/}.tar.gz" "${CACHEDIR}/${PRODUTO}/${_lib}-${_lbpv#*/}.tar.gz"
if [[ "${_lib}" == "kiwi" ]]; then
_f=/srv/sig/${PRODUTO}/.local/lib/python2.7/site-packages/kiwi/__installed__.py
find $(dirname ${_f})/ -name *.pyc -delete
download "installer/config/${PRODUTO}/__installed__.py" "${_f}" \
&& chown -R ${PRODUTO}:${PRODUTO} "${_f}" \
&& chmod 644 ${_f} \
&& touch ${_f}
fi
done done
case "${PRODUTO}" in case "${PRODUTO}" in
@@ -626,21 +633,29 @@ function produto.install {
-x "${CACHEDIR}/${PRODUTO}/artwork-sigerp.zip" -x "${CACHEDIR}/${PRODUTO}/artwork-sigerp.zip"
# Runtime dependencies # Runtime dependencies
SIGERP_PACKAGES="libmysqlclient21" SIGERP_PACKAGES="\
atop \
libmysqlclient21 \
net-tools \
rclone \
tmate \
vim-nox \
"
system.install_pkgs ${SIGERP_PACKAGES} system.install_pkgs ${SIGERP_PACKAGES}
# Create/Alter PostgreSQL user # Create/Alter PostgreSQL user
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 \
"CREATE USER ${PRODUTO} WITH \ "CREATE USER ${_dbuser} WITH \
PASSWORD '${_password}' \ PASSWORD '${_password}' \
CREATEDB;" \ CREATEDB;" \
|| \ || \
sudo -iu postgres \ sudo -iu postgres \
psql -c \ psql -c \
"ALTER USER ${PRODUTO} WITH \ "ALTER USER ${_dbuser} WITH \
PASSWORD '${_password}' \ PASSWORD '${_password}' \
CREATEDB;" CREATEDB;"
@@ -656,57 +671,58 @@ function produto.install {
;; ;;
sigpdv) sigpdv)
_date=$(date +%Y%m%d%H%M%S) _date=$(date +%Y%m%d%H%M%S)
# -- Faz o backup da pasta anterior do SigPDV
[[ -d "/srv/sig/${PRODUTO}/sigpdv" ]] && \ [[ -d "/srv/sig/${PRODUTO}/sigpdv" ]] && \
mv \ mv \
/srv/sig/${PRODUTO}/sigpdv \ /srv/sig/${PRODUTO}/sigpdv \
/srv/sig/${PRODUTO}/sigpdv.${_date}.bak /srv/sig/${PRODUTO}/sigpdv.${_date}.bak
# TODO: Simplificar essa baderna
# -- Cria a árvore de diretórios do SigPDV
mkdir -p /srv/sig/${PRODUTO}/sigpdv
mkdir -p /usr/local/sigext
mkdir -p /recebe
# -- Instala pacotes necessários para rodar o programa
SIGPV_PACKAGES=" SIGPV_PACKAGES="
atop \ atop \
libmysqlclient21 \
mousepad \ mousepad \
net-tools \ net-tools \
qt5dxcb-plugin \ qt5dxcb-plugin \
system-config-printer \ system-config-printer \
terminator \ terminator \
rclone \
tmate \ tmate \
vim-nox \ vim-nox \
" "
system.install_pkgs ${SIGPV_PACKAGES} system.install_pkgs ${SIGPV_PACKAGES}
mkdir -p /srv/sig/${PRODUTO}/sigpdv # -- Download e instalação dos addons e aplicação de correções
mkdir -p /usr/local/sigext
mkdir -p /recebe
download "installer/config/${PRODUTO}/${PRODUTO}-single-instance-fix.patch" \
"${CACHEDIR}/sigpdv/${PRODUTO}-single-instance-fix.patch"
tar -C /srv/sig/${PRODUTO}/ \ tar -C /srv/sig/${PRODUTO}/ \
-xzf ${CACHEDIR}/${PRODUTO}/${PRODUTO}-${_pdpv#*/}.tar.gz -xzf ${CACHEDIR}/${PRODUTO}/${PRODUTO}-${_pdpv#*/}.tar.gz
patch -d /srv/sig/${PRODUTO}/sigpdv \
-p0 < "${CACHEDIR}/sigpdv/${PRODUTO}-single-instance-fix.patch"
ln -snf /srv/sig/${PRODUTO}/sigpdv /usr/local/
ln -snf \ ln -snf \
/srv/sig/${PRODUTO}/sigpdv \ /srv/sig/${PRODUTO}/sigpdv \
/srv/sig/sigpdv/.local/lib/python2.7/site-packages/ /srv/sig/sigpdv/.local/lib/python2.7/site-packages/
ln -snf \
/srv/sig/${PRODUTO}/sigpdv \
/usr/local/
# Correção para erro "Dois frentes em execução"
download "installer/config/${PRODUTO}/${PRODUTO}-single-instance-fix.patch" \
"${CACHEDIR}/sigpdv/${PRODUTO}-single-instance-fix.patch"
patch -d /srv/sig/${PRODUTO}/sigpdv \
-p0 < "${CACHEDIR}/sigpdv/${PRODUTO}-single-instance-fix.patch"
mkdir /srv/sig/sigpdv/.local/lib/python2.7/site-packages/share \ # -- Instalação dos módulos python de dependências
&& mv /srv/sig/${PRODUTO}/.local/share/kiwi \
/srv/sig/sigpdv/.local/lib/python2.7/site-packages/share/ \
&& ln -snf \
/srv/sig/sigpdv/.local/lib/python2.7/site-packages/share/kiwi \
/srv/sig/${PRODUTO}/.local/share/ \
tar --transform="s|stoqdrivers/||" \
-C /srv/sig/sigpdv/.local/lib/python2.7/site-packages/ \
-xzf ${CACHEDIR}/${PRODUTO}/stoqdrivers-0.9.11.tar.gz \
stoqdrivers/stoqdrivers
download "installer/config/${PRODUTO}/requirements.txt" \ download "installer/config/${PRODUTO}/requirements.txt" \
"/srv/sig/${PRODUTO}/sigpdv/requirements.txt" "/srv/sig/${PRODUTO}/sigpdv/requirements.txt"
[[ -f "/srv/sig/${PRODUTO}/sigpdv/requirements.txt" ]] && \
runuser -l ${PRODUTO} -- \
python -m pip install -qq -r /srv/sig/${PRODUTO}/sigpdv/requirements.txt --user \
&& rm -f /srv/sig/${PRODUTO}/sigpdv/requirements.txt
# -- Lançadores dos programas
download "installer/config/${PRODUTO}/${PRODUTO}-wrapper.sh" \ download "installer/config/${PRODUTO}/${PRODUTO}-wrapper.sh" \
"/srv/sig/${PRODUTO}/${PRODUTO}-wrapper.sh" \ "/srv/sig/${PRODUTO}/${PRODUTO}-wrapper.sh" \
&& chmod +x "/srv/sig/${PRODUTO}/${PRODUTO}-wrapper.sh" \ && chmod +x "/srv/sig/${PRODUTO}/${PRODUTO}-wrapper.sh" \
@@ -715,8 +731,8 @@ function produto.install {
&& ln -snf "/srv/sig/${PRODUTO}/${PRODUTO}-wrapper.sh" /usr/local/bin/start-pdvconfig \ && ln -snf "/srv/sig/${PRODUTO}/${PRODUTO}-wrapper.sh" /usr/local/bin/start-pdvconfig \
&& ln -snf "/srv/sig/${PRODUTO}/${PRODUTO}-wrapper.sh" /usr/local/bin/start-sigpdv \ && ln -snf "/srv/sig/${PRODUTO}/${PRODUTO}-wrapper.sh" /usr/local/bin/start-sigpdv \
&& ln -snf "/srv/sig/${PRODUTO}/${PRODUTO}-wrapper.sh" /usr/local/bin/start-sigpve && ln -snf "/srv/sig/${PRODUTO}/${PRODUTO}-wrapper.sh" /usr/local/bin/start-sigpve
ln -snf \
ln -snf /srv/sig/${PRODUTO}/${PRODUTO}/debian/icons/* \ /srv/sig/${PRODUTO}/${PRODUTO}/debian/icons/* \
/usr/share/pixmaps/ /usr/share/pixmaps/
mkdir /usr/local/share/applications/ \ mkdir /usr/local/share/applications/ \
&& ln -snf \ && ln -snf \
@@ -725,53 +741,59 @@ function produto.install {
&& sed -i 's|/usr/bin|/usr/local/bin|g' /usr/local/share/applications/*.desktop \ && sed -i 's|/usr/bin|/usr/local/bin|g' /usr/local/share/applications/*.desktop \
&& update-desktop-database || : && update-desktop-database || :
# -- Configuração padrão inicial
download "installer/config/${PRODUTO}/pdvconfig.cfg" \
"/usr/local/sigext/pdvconfig.cfg"
download "installer/config/${PRODUTO}/CliSiTef.ini" \
"/usr/local/sigext/CliSiTef.ini"
for amb in homologacao producao lib_ssl_antiga; do
ln -snf \
"/usr/local/sigext/CliSiTef.ini" \
/srv/sig/${PRODUTO}/${PRODUTO}/sigtef/lib_x86_64/${amb}/
done
# -- Configurações de segurança e dos usuários
local _app_user=${PRODUTO}
local _app_group=${_app_user}
# Acesso do usuário do desktop
local _desktop_user=$(getent passwd | sed '/x:1000/!d;s/:.*//g')
usermod -aG ${_app_group},pyenv ${_desktop_user}
# Configuração do sudo
download "installer/config/${PRODUTO}/${PRODUTO}.sudo" \ download "installer/config/${PRODUTO}/${PRODUTO}.sudo" \
"/etc/sudoers.d/${PRODUTO}" \ "/etc/sudoers.d/${PRODUTO}" \
&& chown root:root "/etc/sudoers.d/${PRODUTO}" \ && chown root:root "/etc/sudoers.d/${PRODUTO}" \
&& chmod 600 "/etc/sudoers.d/${PRODUTO}" && chmod 600 "/etc/sudoers.d/${PRODUTO}"
# Permissões de usuários e grupos
for dir in /srv/sig/${PRODUTO} /usr/local/sigext /recebe; do
chown -R ${_app_user}:${_app_group} ${dir}
chmod -R g+rw,o-rwx ${dir}
done
download "installer/config/${PRODUTO}/pdvconfig.cfg" \ # -- Configuração do banco de dados PostgreSQL
"/usr/local/sigext/pdvconfig.cfg" local _db_name=${PRODUTO}
local _db_user=${_db_name}
download "installer/config/${PRODUTO}/CliSiTef.ini" \ local _db_pass=$(openssl rand -base64 32 | sed 's/\//|/g')
"/usr/local/sigext/CliSiTef.ini" ${ui}.status info $"Configurando o banco de dados [%s]" ${_db_name}}
# PostgreSQL user and database
local _password=$(openssl rand -base64 32 | sed 's/\//|/g')
${ui}.status info $"Criando/Atualizando usuário e banco de dados [%s]" ${PRODUTO}
sudo -iu postgres \ sudo -iu postgres \
psql -c \ psql -c \
"CREATE USER ${PRODUTO} WITH \ "CREATE USER ${_db_user} WITH \
PASSWORD '${_password}' \ PASSWORD '${_db_pass}' \
CREATEDB;" \ CREATEDB;" \
|| \ || \
sudo -iu postgres \ sudo -iu postgres \
psql -c \ psql -c \
"ALTER USER ${PRODUTO} WITH \ "ALTER USER ${_db_user} WITH \
PASSWORD '${_password}' \ PASSWORD '${_db_pass}' \
CREATEDB;" CREATEDB;"
if [[ 0${?} -eq 0 ]]; then if [[ 0${?} -eq 0 ]]; then
sed -i "s/.*db_pdv_pass.*/db_pdv_pass = ${_password}/g" \ sed -i "s/.*db_pdv_pass.*/db_pdv_pass = ${_db_pass}/g" \
"/usr/local/sigext/pdvconfig.cfg" "/usr/local/sigext/pdvconfig.cfg"
sudo -i -u postgres createdb -O ${PRODUTO} ${PRODUTO} >/dev/null 2>&1 || : sudo -i -u postgres createdb -O ${_db_user} ${_db_name} >/dev/null 2>&1 || :
${ui}.status warn $"Senha de acesso ao banco de dados: %s" ${_password} ${ui}.status warn $"Senha de acesso ao banco de dados: %s" ${_db_pass}
sleep 5 sleep 5
fi fi
chown -R ${PRODUTO}: /usr/local/sigext /recebe
chmod -R g+rw /usr/local/sigext /recebe
# End TODO
[[ -f "/srv/sig/${PRODUTO}/sigpdv/requirements.txt" ]] && \
runuser -l ${PRODUTO} -- \
python -m pip install -qq -r /srv/sig/${PRODUTO}/sigpdv/requirements.txt --user \
&& rm -f /srv/sig/${PRODUTO}/sigpdv/requirements.txt
chown -R ${PRODUTO}: /srv/sig/${PRODUTO}/
local _user=$(getent passwd | sed '/x:1000/!d;s/:.*//g')
usermod -aG ${PRODUTO} ${_user}
;; ;;
sigvpn) sigvpn)
${ui}.status warn $"Não implementado." ${ui}.status warn $"Não implementado."
# rm -f /etc/apt/trusted.gpg.d/openvpn*.gpg # rm -f /etc/apt/trusted.gpg.d/openvpn*.gpg
@@ -799,7 +821,7 @@ function produto.install {
#system.remove_pkgs ${BUILD_PACKAGES} #system.remove_pkgs ${BUILD_PACKAGES}
${ui}.color none ${ui}.color none
${ui}.status info $"Instalação concluída. Reinicie o computador." ${ui}.status info $"Instalação concluída. REINICIE o computador."
${ui}.prompt $"Pressione ENTER para continuar ... " ${ui}.prompt $"Pressione ENTER para continuar ... "
} }

0
tests/00-create-container.sh Normal file → Executable file
View File

View File

@@ -1,17 +0,0 @@
#!/bin/bash
docker compose exec tests sh -c "
apt-get update \
&& apt-get -y install --no-install-suggests \
curl \
git-core \
iproute2 \
iputils-ping \
jq \
libarchive-tools \
locales \
python3-yaml \
ssh \
sudo \
tzdata \
"

0
tests/90-run-container-shell.sh Normal file → Executable file
View File

0
tests/90-run-sig-installer.sh Normal file → Executable file
View File

0
tests/99-destroy-container.sh Normal file → Executable file
View File