Ing. Marcos Ortiz Valmaseda escribió:
> Jaime Casanova escribió:
> >2010/3/12 Ing. Marcos Ortiz Valmaseda <[email protected]>:
> >>Recuerdo Jaime, que cuando Álvaro y tú vinieron acá, él tenía en su laptop
> >>esto configurado. Él ejecutaba pgsql84env si mal no recuerdo y en el mismo
> >>prompt de comandos le salía una especie de environment usando esta versión
> >>de PostgreSQL, y creo que lo hizo con Debian, porque es lo que tiene
> >>instalado en su PC si mal no recuerdo.
> >>
> >
> >ah! pero sino me equivoco eso ha de ser solo un script que cambia el
> >directorio levanta la base apropiada y setea variables de ambiente...
> >
> >aunque si se veia bonito y es mejor que hacerlo manualmente ;)
> >
> Umm, ya entendí.
> OK, tendré que preguntarle entonces a él cómo lo hizo, lancé la
> pregunta aquí para si otro a lo mejor quiera hacer lo mismo
> compartirlo con todos.
Este es mi script. Se llama "runpg" y hace muchas cosas, dependiendo
del segundo parámetro (el primer parámetro lo describo más adelante).
"config" invoca configure con los parámetros estándar (que yo defino
dentro del mismo script, o bien los puedo sobreescribir con un archivo
CONFIGURE_ARGS dentro del árbol del código fuente); "build" construye
(make); "install" hace un make install; "init" hace un initdb en la
ubicación estándar que yo defino; "server" echa a andar el postmaster;
"client" abre un psql; "check" y "pcheck" son para ejecutar los tests de
regresión, serial y paralelo respectivamente (requiere tener el server
andando); tags actualiza el archivo de ctags y cscope; changelog genera
el archivo ChangeLog para esa rama usando cvs2cl; rmderived borra los
archivos derivados; update hace un cvs update; showdiff hace un cvs diff
y lo pasa por un pager (obviamente puedes redirigirlo si quieres guardar
el parche en un archivo); touchchanged hace un "touch" de todos los
archivos modificados (esto sirve para forzar a que se recompilen); edit
abre un "vi -g" en el directorio base del código fuente.
Si uno hace "runpg commands" da una lista de órdenes que conoce (esto es
útil para el "bash completion")
El primer parámetro debe ser el nombre de un "cvs checkout" de una rama,
y el nombre debe empezar con un número, el cual se suma a 55432 para
obtener el nombre de puerto base que se pasa a --with-pgport. (Yo uso
nombres como "84_rel" y así, de manera que cada nombre es fácil de
recordar y quedan en puertos distintos, así que puedo tener los servers
corriendo simultáneamente).
Si uno le da el nombre de la rama pero ninguna otra opción, emite una
serie de definiciones de variables de ambiente. Eso se puede agregar al
ambiente existente. Por ej. yo uso `runpg 84_rel` y define PGDATA,
PGPORT, y otras cosas útiles.
El código se debe poner en un directorio con esta estructura:
pgsql/
source/
84_rel
83_rel
etc
build/
84_rel
etc
install/
(Esto se ubica en /pgsql normalmente, pero uno puede definir la variable
de ambiente PGROOT para cambiar esto. Yo tengo "export
PGROOT=~/Code/pgsql" o algo por el estilo).
Cuando uno hace "config" de una rama del source, se crea el directorio
dentro de build y se ejecuta configure allí; los .o quedan en ese otro
directorio (esto se conoce como una construcción VPATH).
Además tengo un mecanismo rudimentario pero suficiente para hacer
completación automática de órdenes en bash. Finalmente, tengo un
pequeño script que define funciones para cambiar de un directorio a
otro, por ej. si estás en source/84_rel/src/backend y ejecutas "cdbld"
te deja parado en build/84_rel/src/backend. También existen cdinst y
cdsrc. Además cdpg que te posiciona en pgsql/ (si es que no le pasas
ningún parámetro) o bien puedes hacer cdpg 84_rel y te deja en
pgsql/84_rel. Como también tiene completación automática, puedes darle
cdpg 84<tab> y luego te va completando con los directorios que existen
dentro (o sea cdpg 84<tab>s<tab>bac<tab> te completa a
84_rel/src/backend, etc etc)
Hace unos años le pasé este script a Michael Glaesemann y él hizo unas
cuantas modificaciones para sus propósitos, que yo nunca llegué a
adoptar (por pereza, no porque no me gustaran). A Germán Poo también se
lo pasé años después, y él hizo un repositorio Mercurial en alguna
parte ... ahh, acá está: http://pgsql.calcifer.org/settings/ ... ah!
si me hubiera acordado de verlo antes me habría ahorrado tener que
escribir la explicación otra vez!!
--
Alvaro Herrera http://www.amazon.com/gp/registry/3BP7BYG9PUGI8
"I think my standards have lowered enough that now I think 'good design'
is when the page doesn't irritate the living f*ck out of me." (JWZ)
#!/bin/bash
# Default "configure" args. They will be overridden with the contents of a
# CONFIGURE_ARGS file in the source directory.
CONFIGURE_ARGS="--enable-debug --enable-depend --enable-cassert --enable-nls
--cache-file=/home/alvherre/tmp/pgconf...@[email protected] --enable-thread-safety
--with-python --with-perl --with-tcl --with-openssl --with-libxml"
# The root directory, where everything lies. Defaults to $HOME/CVS/pgsql,
# but can be changed by the PGROOT environment variable.
ROOT=${PGROOT-/pgsql}
# do we have a diff coloring utility?
for prog in cdiff colordiff; do
which $prog >/dev/null 2>/dev/null
if [ $? == 0 ]; then
# COLORDIFF=`which $prog`
break
fi
done
# If the first argument is "_commands", return the list of known commands
if [ ! -z "$1" -a "$1" == '_commands' ]; then
for i in config build install init server client check pcheck tags
changelog rmderived update showdiff touchchanged edit; do
echo $i
done
exit
fi
# If the argument is a file, its contents is the real target. Useful to have
# a "default" build, pointing to whatever is the current development tree.
if [ -f $ROOT/source/$1 ]; then
DIR=`cat $ROOT/source/$1`
else
DIR=$1
fi
SRCDIR=$ROOT/source/$DIR
INSTDIR=$ROOT/install/$DIR
BUILDDIR=$ROOT/build/$DIR
PGDATADIR=$INSTDIR/data
export LD_LIBRARY_PATH=$INSTDIR/lib
if [ -z "$DIR" ]; then
LIST=`cd "$SRCDIR" ; find . -maxdepth 1 -mindepth 1 -type d`
echo "I need an argument -- one from:"
for i in $LIST; do
echo -n " "`basename $i`
done | (fmt 2>&1 || true)
echo ""
exit
fi
PGPORT=$((55432+$(echo $BUILDDIR | sed -e 's/^[^0-9]*\([0-9]*\).*$/\1/' -e
's/^0*//' -e 's/^$/0/' )))
# Miscelaneous functions
check_srcdir() {
if [ ! -d $SRCDIR ]; then
echo "The first argument must be a source directory" >&2
ls $ROOT/source >&2
exit
fi
}
check_blddir() {
if [ ! -d $BUILDDIR ]; then
echo "The first argument must be a VPATH build directory" >&2
ls $ROOT/build >&2
exit
fi
}
check_backend() {
backend=$BUILDDIR/src/backend/postgres
if [ ! -f $backend ]; then
echo "The backend must exist at $backend" >&2
exit
fi
}
check_instdir() {
if [ ! -x $INSTDIR/bin/postmaster ]; then
echo "$DIR debe ser un directorio de instalación" >&2
exit
fi
}
runpg_config() {
check_srcdir
if [ -d $BUILDDIR ]; then
echo -n "Desea eliminar $BUILDDIR (y/n)? "
unset removed
read answer
if [ ! -z "$answer" ]; then
if [ "$answer" = 's' -o "$answer" = 'y' ]; then
rm -fr $BUILDDIR
removed=t
fi
fi
if [ -z "$removed" ]; then
exit
fi
fi
mkdir $BUILDDIR
if [ -f $SRCDIR/CONFIGURE_ARGS ]; then
CONFIGURE_ARGS=`cat $SRCDIR/CONFIGURE_ARGS`
fi
CONFIGURE_ARGS=${CONFIGURE_ARGS//@TREE@/$DIR}
cd $BUILDDIR
echo $SRCDIR/configure $CONFIGURE_ARGS --prefix=$INSTDIR
--with-pgport=$PGPORT
$SRCDIR/configure $CONFIGURE_ARGS --prefix=$INSTDIR
--with-pgport=$PGPORT
make -C src -s distprep
cd "$OLDPWD"
}
runpg_build() {
check_srcdir
check_blddir
cd $BUILDDIR
LC_ALL=C make -j3 2>&1 >> $BUILDDIR/build.out | tee -a
$BUILDDIR/build.err
LC_ALL=C make -j3 -C contrib 2>&1 >> $BUILDDIR/build.out | tee -a
$BUILDDIR/build.err
cd "$OLDPWD"
}
runpg_install() {
check_backend
cd $BUILDDIR
LC_ALL=C make -j3 install 2>&1 >> $BUILDDIR/build.out | tee -a
$BUILDDIR/build.err
LC_ALL=C make -j3 -C contrib install 2>&1 >> $BUILDDIR/build.out | tee
-a $BUILDDIR/build.err
cd "$OLDPWD"
}
# Select the action based on the parameters
case "$2" in
config)
runpg_config
exit $?
;;
build)
runpg_build
exit $?
;;
install)
runpg_install
exit $?
;;
init)
check_instdir
rm -fr $PGDATADIR
$INSTDIR/bin/initdb -D $PGDATADIR
exit $?
;;
server)
check_instdir
if [ ! -z $DISPLAY ]; then
echo -ne "\033]0;$1 server\007"
fi
ulimit -c unlimited
PGDATA=$PGDATADIR exec $INSTDIR/bin/postmaster
exit
;;
client)
check_instdir
export PATH=$INSTDIR/bin:$PATH
export PGDATA=$PGDATADIR
if [ ! -f $PGDATA/db_created ]; then
createdb &&
createlang plpgsql &&
createlang plperl &&
createlang pltcl &&
createlang plpythonu &&
touch $PGDATA/db_created
fi
PGCMD=psql
if [ ! -z "$DISPLAY" ]; then
echo -ne "\033]0;$1 client\007"
fi
psql
exit
;;
check)
check_instdir
make -C $BUILDDIR/src/test/regress installcheck
;;
contribcheck)
check_instdir
make -s -C $BUILDDIR/contrib installcheck
;;
pcheck)
check_instdir
cd $BUILDDIR/src/test/regress
make -C $BUILDDIR/src/test/regress installcheck-parallel
;;
tags)
check_srcdir
cd "$SRCDIR"
echo "getting file list for cscope ..."
find $SRCDIR $BUILDDIR \( -name "*.[chly]" -o -iname "*makefile*" -o
-name "*.mk" -o -name "*.in" -o -name "*.sgml" -o -name "*.sh" -o -name "*.sql"
\) -type f > $SRCDIR/cscope.files
echo "building cscope database ..."
cscope -b
echo "building tags file ..."
ctags -R
echo "done"
;;
changelog)
check_srcdir
cd "$SRCDIR"
if [ ! -d CVS ]; then
echo "operation is valid only on CVS trees" 1>&2
exit -1
fi
common_args="--revisions --no-indent --no-wrap --separate-header"
branch_arg=""
branch=$(cvs status configure.in | grep 'Sticky Tag' | awk '{print $3}')
if [ $branch != "(none)" ]; then
branch_arg="--follow $branch"
fi
if [ ! -f ChangeLog ]; then
cvs2cl $common_args $branch_arg
else
cvs2cl $common_args $branch_arg --accum
fi
;;
rmderived)
check_srcdir
cd "$SRCDIR"
find . -name .cvsignore | while read line
do
dir=$(dirname $line)
cd $dir
rm -fv `cat .cvsignore`
cd "$OLDPWD"
done
;;
update)
check_srcdir
cd "$SRCDIR"
if [ -d CVS ]; then
cvs update -Pd
elif [ -d .svn ]; then
svn update
elif [ -d .git ]; then
echo "not supported for git trees" >&2
exit -1
fi
;;
showdiff)
check_srcdir
cd "$SRCDIR"
if [ ! -z "$COLORDIFF" ]; then
pipe="$COLORDIFF"
else
pipe=cat
fi
if [ -d CVS ]; then
cvs -q diff | $pipe | less -r
elif [ -d .svn ]; then
svn diff | $pipe | less -r
elif [ -d .git ]; then
git diff
fi
;;
touchchanged)
check_srcdir
cd "$SRCDIR"
if [ -d CVS ]; then
cvs -q diff | grep ^Index | cut -d" " -f2 | xargs touch
elif [ -d .svn ]; then
svn diff | grep ^Index | cut -d" " -f2 | xargs touch
fi
;;
edit)
check_srcdir
cd "$SRCDIR"
vi -g &
;;
*)
check_instdir
echo "export PATH=$INSTDIR/bin:$PATH"
echo "export MANPATH=$INSTDIR/share/man"
echo "export PGDATA=`echo $PGDATADIR`"
echo "export PGPORT=$PGPORT"
echo "export PGLIBS=$INSTDIR/lib"
echo "export PGINCLUDE=$INSTDIR/include"
;;
esac
cdpg() {
cd /pgsql/source/$1
}
cdsrc() {
if ! echo $PWD | grep /pgsql/ >/dev/null 2>&1; then
echo $PWD no es correcto para esto
return
fi
NEWDIR=`echo $PWD | sed -e 's,^\(.*/pgsql/\)/,\1,' -e 's,build,source,'
-e 's,install,source,'`
cd $NEWDIR
}
cdbld() {
if ! echo $PWD | grep /pgsql/ >/dev/null 2>&1; then
echo $PWD no es correcto para esto
return
fi
NEWDIR=`echo $PWD | sed -e 's,^\(.*/pgsql/\)/,\1,' -e 's,source,build,'
-e 's,install,build,'`
cd $NEWDIR
}
cdinst() {
if ! echo $PWD | grep /pgsql/ >/dev/null 2>&1; then
echo $PWD no es correcto para esto
return
fi
NEWDIR=`echo $PWD | sed -e 's,^\(.*/pgsql/\)/,\1,' -e
's,source,install,' -e 's,build,install,'`
cd $NEWDIR
}
_runpg()
{
local cur prev;
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD -eq 1 ]; then
pushd ${PGROOT-/pgsql/}/source > /dev/null 2>&1
_filedir
popd > /dev/null 2>&1
return 0;
fi
if [ $COMP_CWORD -eq 2 ]; then
COMPREPLY=( $(compgen -W '$(runpg _commands)' -- $cur ));
return 0;
fi
_filedir
}
_cdpg()
{
local cur;
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
pushd ${PGROOT-/pgsql/}/source > /dev/null 2>&1
_filedir -d
popd > /dev/null 2>&1
}
_postgres()
{
local cur;
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ "$prev" == "-c" ]; then
COMPREPLY=($(compgen -S= -onospace -W '`LC_ALL=C command
postgres --describe-config | cut -d" " -f1`' -- $cur));
return 0
fi
COMPREPLY=($(compgen -W '-A -B -c -d -D -e -E -F -N -o -P -s -S -f -i
-O -t -W --describe-config --help --version' -- $cur))
return 0
}
complete -F _runpg runpg
complete -S/ -onospace -F _cdpg cdpg
complete -F _postgres postgres postmaster
--
TIP 1: para suscribirte y desuscribirte, visita
http://archives.postgresql.org/pgsql-es-ayuda