Gerador de Pacotes de Instalação
Publicado por Pedro Robson Leão 30/06/2004
[ Hits: 7.712 ]
Download InstallGeraPack.pkg.sh.gz
Este script gera um arquivo tipo auto-extract com opções de inclusão de nota de instalação e script de pós instalação. Para quem não estiver afim de usar rpm pode ser uma boa solução.
Uma outra caracteristica importante deste instalador é criar um backup dos arquivos ja existentes na maquina para casos de arrependimento após a instalação de seus arquivos.
script : geraPack.sh e initPack.sh
Junto com o pacote de instalação, segue o manual de uso dos scripts.
::::::::::::::
geraPack.sh
::::::::::::::
#! /usr/bin/bash
# gerador de arquivo auto instalador.
# /*** Informacoes do cvs ***
# $Author: pleao $
# $Revision: 1.3 $
# $Date: 2004/06/30 16:45:52 $
# $State: Exp $
# $Id: geraPack.sh,v 1.3 2004/06/30 16:45:52 pleao Exp $
# $Source: /Development/Develop/Batches/Common/Scripts/geraPack/geraPack.sh,v $
# *** Change Log ***
# $Log: geraPack.sh,v $
# Revision 1.3 2004/06/30 16:45:52 pleao
# 1) Remove arquivos temporarios mesmo quando o gerador ou instalador eh interrompido por <CTRL+C>.
# 2) Seta o ${EDITOR} como "vi" quando não existir nenhum definido ou quando ${DISPLAY} nao esta definida.
#
# Seria interesante atualizar a versao de todos, inclusive maquinas remotas.
#
# Revision 1.2 2004/06/07 15:48:14 pleao
# Compatibilidade tar e gtar (GNU TAR)
#
# Revision 1.1 2004/06/03 13:43:59 pleao
# Mudanca de repositorio.
#
# Revision 1.5 2004/05/21 21:33:01 pleao
# Ajustes na impressao da versao
#
# Revision 1.4 2004/05/21 21:30:27 pleao
# Ajustes na impressao da versao
#
# Revision 1.3 2004/05/21 21:27:35 pleao
# Inclusao de novos recurso para maior controle dos pacotes.
#
# Revision 1.2 2003/12/10 16:11:36 pleao
# return 0; para funcionar com o makefile.
#
# Revision 1.1 2003/07/31 15:06:01 pleao
# Gerador de pacotes de instalacao.
# Versao inicial.
#
VERSION="\$Id: geraPack.sh,v 1.3 2004/06/30 16:45:52 pleao Exp $";
trap 'cleanTmp && exit 0' 1 2 3 6 9 13 14 15 16 17 23 24 26
function cleanTmp() {
[ ! -z "${debug}" ] && echo "#-- Apaga arquivos temporarios.";
rm -f /tmp/intDate.$$ ${tmpfile} /tmp/script.sh /tmp/note.txt /tmp/intDate.$$ ;
}
function isGnuTar() {
tar --version 2>/dev/null | grep GNU
return $?
}
function usage() {
printf "Usage: %s [-p (package name)] [-s (post install script)] [-n (note file)] [-l (list files)] [-v version] [-d debug] files ...\n" $0
cleanTmp;
exit 2;
}
[ $# == 0 ] && usage $0
[ isGnuTar ] && TARPARM="-P";
pflg=
nflg=
lflg=
sflg=
debug=
while getopts p:n:l:s:dv name ; do
case $name in
p) pflg=1
pkgname="$OPTARG";;
n) nflg=1
notefile="$OPTARG";;
l) lflg=1
listfile="$OPTARG";;
s) sflg=1
pInstScript="$OPTARG";;
v) echo ${VERSION};
echo "";
usage $0;;
d) debug=1;;
*) usage $0;;
esac
done
if [ ! -z "${lflg}" ] ; then
[ ! -z "${debug}" ] && echo "#-- Le do arquivo fornecido como lista de entrada.";
FILES=$( cat ${listfile} );
else
[ ! -z "${debug}" ] && echo "#-- Le lista da entrada padrao separada por :";
shift $(($OPTIND - 1));
FILES=$( echo "$*" );
FILES=$( echo ${FILES} | sed s/":"/" "/g );
if [ "${FILES}" == "" ] ; then
[ ! -z "${debug}" ] && echo "#-- Le da entrada padrao.";
while read linha; do
FILES="${FILES} ${linha}";
done
fi
fi
tmpfile=/tmp/tmpfile.$$.tar;
[ ! -z "${debug}" ] && echo "#-- Empacota os arquivos a serem intalados.";
outputfile=/tmp/install.`date +%Y%m%d`.$$.sh;
date >/tmp/intDate.$$;
tar ${TARPARM}cvf ${tmpfile} /tmp/intDate.$$ >/dev/null;
for file in ${FILES} ; do
if [ -a ${file} ] ; then
[ ! -z "${debug}" ] && echo "#-- Append file ${file}";
tar ${TARPARM}uvf ${tmpfile} ${file} ;
else
echo "can't open file ${file}";
fi
done
if [ ! -z ${nflg} ] ; then
[ ! -z "${debug}" ] && echo "#-- Copy note file ";
cp ${notefile} /tmp/note.txt
else
[ ! -z "${debug}" ] && echo "#-- Edit note file ";
echo "Descreva informacoes sobre a instalacao aqui :" >/tmp/note.txt;
[ -z "${EDITOR}" ] && EDITOR=vi;
[ -z "${DISPLAY}" ] && EDITOR=vi;
${EDITOR} /tmp/note.txt;
fi
if [ -a /tmp/note.txt ] ; then
[ ! -z "${debug}" ] && echo "#-- Acrescenta nota ao pacote";
echo "" >>/tmp/note.txt
finger ${USER} | head -3 >>/tmp/note.txt
uname -a >>/tmp/note.txt
date >>/tmp/note.txt
echo "" >>/tmp/note.txt
echo "" >>/tmp/note.txt
echo "" >>/tmp/note.txt
tar ${TARPARM}uvf ${tmpfile} /tmp/note.txt
fi
if [ ! -z ${sflg} ] ; then
[ ! -z "${debug}" ] && echo "#-- Copia o script para o tmp";
cp ${pInstScript} /tmp/script.sh;
fi
if [ -a /tmp/script.sh ] ; then
[ ! -z "${debug}" ] && echo "#-- Acrescenta o script de pos instalacao";
tar ${TARPARM}uvf ${tmpfile} /tmp/script.sh
fi
[ ! -z "${debug}" ] && echo "#-- Encapsula com o instalador e gera permissoes.";
cat `which initPack.sh` ${tmpfile} >>${outputfile}
chmod 755 ${outputfile}
#Limpa arquivos temporarios
cleanTmp;
if [ ! -z ${pflg} ] ; then
[ ! -z "${debug}" ] && echo "#-- Move tmp file to name info";
mv ${outputfile} `date +%Y%m%d`.${pkgname}.pkg.sh
else
[ ! -z "${debug}" ] && echo "#-- Informa o arquivo instalador gerado.";
echo "Use the file ${outputfile}";
fi
cleanTmp;
exit 0;
::::::::::::::
initPack.sh
::::::::::::::
#! /usr/bin/bash
# cabecalho para o arquivo auto instalador.
# /*** Informacoes do cvs ***
# $Author: pleao $
# $Revision: 1.5 $
# $Date: 2004/06/30 16:45:52 $
# $State: Exp $
# $Id: initPack.sh,v 1.5 2004/06/30 16:45:52 pleao Exp $
# $Source: /Development/Develop/Batches/Common/Scripts/geraPack/initPack.sh,v $
# *** Change Log ***
# Este arquivo nao pode apresentar o changeLog, devido uso da variavel SCRIPTLASTLINE
# que deve conter a ultima linha do arquivo para desatachar o arquivo tarado.
VERSION="\$Id: initPack.sh,v 1.5 2004/06/30 16:45:52 pleao Exp $";
trap 'cleanTmp && exit 0' 1 2 3 6 9 13 14 15 16 17 23 24 26
function cleanTmp() {
[ ! -z "${debug}" ] && echo "#-- Apaga os arquivos temporarios.";
rm -f /tmp/script.sh /tmp/note.txt /tmp/intDate.* /tmp/bkpDate.* ${outname} ${tmpfile};
}
function isGnuTar() {
tar --version 2>/dev/null | grep GNU
return $?
}
SCRIPTLASTLINE=143;
iam=$( basename ${0} .sh );
outname=/tmp/install.sfx.$$;
tmpfile=/tmp/tmpfile.$$.tar;
[ isGnuTar ] && TARPARM="-P";
lflg=
Lflg=
debug=
while getopts Lldv name ; do
case $name in
l) lflg=1;;
L) Lflg=1;;
d) debug=1;;
v) echo ${VERSION};
echo "";
cleanTmp;
exit 0;;
*) exit 0;
esac
done
[ ${iam} == "initPack" ] && exit 0;
[ ! -z "${debug}" ] && echo "#-- Separa o arquivo tar anexado.";
tail +${SCRIPTLASTLINE} $0 >${outname}
if [ -z "${Lflg}" ] ; then
[ ! -z "${debug}" ] && echo "#-- Mostra notas";
[ -a /tmp/note.txt ] && rm -f /tmp/note.txt;
tar ${TARPARM}xvf ${outname} /tmp/note.txt
[ -a /tmp/note.txt ] && more /tmp/note.txt
echo "Relacao de arquivos para instalacao";
else
[ ! -z "${debug}" ] && echo "#-- Não mostra o arquivo de notas";
lflg=1;
fi
[ ! -z "${debug}" ] && echo "#-- Mostra arquivos a serem instalados.";
tar ${TARPARM}tvf ${outname} | awk '{ print $NF; }' | grep -v "intDate\." | grep -v /tmp/note.txt | grep -v /tmp/script.sh;
[ ! -z "${lflg}" ] && cleanTmp && exit 0
echo -n "Confirma a instalacao dos arquivos (s/n) : "
read conf;
if [ ${conf} != 's' ] ; then
[ ! -z "${debug}" ] && echo "#-- Apaga os arquivos temporarios.";
cleanTmp;
exit 2;
fi
echo "Realizando backup dos arquivos ...";
date >/tmp/bkpDate.$$;
[ ! -z "${debug}" ] && echo "#-- Empacota o backup.";
tar ${TARPARM}cvf ${tmpfile} /tmp/bkpDate.$$ >/dev/null;
for file in $( tar ${TARPARM}tvf ${outname} | awk '{print $NF;}' | grep -v "intDate\." | grep -v /tmp/note.txt | grep -v /tmp/script.sh ); do
if [ -a ${file} ] ; then
tar ${TARPARM}uvf ${tmpfile} ${file}
else
echo "can't open file ${file}";
fi
done
[ ! -z "${debug}" ] && echo "#-- Verifica se o diretorio de backup existe";
if [ -d ./pkg_backup ] ; then
true;
else
mkdir ./pkg_backup;
fi
[ ! -z "${debug}" ] && echo "#-- Move e compacta o backup";
pkg_out=`date +%Y%m%d%H%M%S`;
mv ${tmpfile} ./pkg_backup/${pkg_out}.bkp.${iam}.tar
[ ! -z "${debug}" ] && echo "#-- Efetua a atualizacao dos arquivos.";
echo "Atualiza com os novos arquivos...";
tar ${TARPARM}xvf ${outname} | grep -v "intDate\." | grep -v /tmp/note.txt | grep -v /tmp/script.sh;
for file in $( tar ${TARPARM}tvf ${outname} | awk '{ print $NF; }' | grep -v "intDate\." | grep -v /tmp/note.txt | grep -v /tmp/script.sh ) ; do
[ ! -z "${debug}" ] && echo "#-- Atualiza a data de cada arquivo atualizado para a data do log.";
touch ${file}
logger -p user.alert "ATUALIZACAO DE SISTEMA ${file}";
echo "\"$( date +%d%m%Y )\",\"$( date +%H%M%S )\",\"${iam}\",\"${file}\",\"$( tail -8 /tmp/note.txt | head -1 )\",\"$( tail -5 /tmp/note.txt | head -1 )\",\"$( tail -4 /tmp/note.txt | head -1)\",\"${LOGNAME}\"" >> ./pkg_backup/installReport.$( date +%Y%m ).csv;
done
[ ! -z "${debug}" ] && echo "#-- Verifica script de pos instalacao";
if [ -a /tmp/script.sh ] ; then
echo -n "Deseja executar um script de pos instalacao ? (s/n) : "
read conf;
if [ ${conf} == 's' ] ; then
bash /tmp/script.sh
fi
fi
cleanTmp;
exit 0;
#------------------------------
SSH - Detecta ataque por brute force e bloqueia o IP do atacante.
Faz uma busca no Google e abre o primeiro hit (Estou com Sorte)
Xqemu! Uma interface gráfica simples para o qemu.
Nenhum comentário foi encontrado.
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
IA Turbina o Desktop Linux enquanto distros renovam forças
Como extrair chaves TOTP 2FA a partir de QRCODE (Google Authenticator)
Como realizar um ataque de força bruta para desobrir senhas?
Como usar Gpaste no ambiente Cinnamon
Atualizando o Fedora 42 para 43
SQLITE não quer funcionar no LINUX LMDE6 64 com Lazaruz 4.2 64bit (n... (0)
Secure boot, artigo interessante, nada técnico. (5)
VOL já não é mais como antes? (9)
É normal não gostar de KDE? (13)
E aí? O Warsaw já está funcionando no Debian 13? [RESOLVIDO] (15)









