3 #=======================================================================
5 # File ID: 86126f82-2e60-11e5-bf33-fefdb24f8e10
7 # Compile and install the Postgres version stored in $srcdir .
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
13 progname
=build-postgres
27 " -n "$progname" -- "$@
")"
28 test "$?" = "0" ||
exit 1
37 -h|
--help) opt_help
=1; shift ;;
38 -q|
--quiet) opt_quiet
=$
(($opt_quiet + 1)); shift ;;
39 -u|
--update) opt_update
=1; shift ;;
40 -v|
--verbose) opt_verbose
=$
(($opt_verbose + 1)); shift ;;
41 --version) echo $progname $VERSION; exit 0 ;;
43 *) echo $progname: Internal error
>&2; exit 1 ;;
46 opt_verbose
=$
(($opt_verbose - $opt_quiet))
48 if test "$opt_help" = "1"; then
49 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
52 Usage: $progname [options]
59 Be more quiet. Can be repeated to increase silence.
61 Fetch new commits and update the source code.
63 Increase level of verbosity. Can be repeated.
65 Print version information.
73 if test "$1" = "-n"; then
74 # If -n is first argument, don't terminate with \n
78 if test "$1" = "-s"; then
79 # If -s is specified, skip initial \n
84 echo $no_lf "$progname: $*" >&2
88 srcdir
="$HOME/src/other/postgres"
89 cd "$srcdir" ||
exit 1
91 if test "$opt_update" = "1"; then
99 pgdesc
="$(git desc --long --tags)"
100 pgdir
="postgres-$pgdesc"
103 destdir
="$prefix/varprg/$pgdir"
104 dbroot
="/var/lib/postgresql"
105 dumpfile
="$dbroot/$(date -u +"%Y
%m
%dT
%H
%M
%SZ
").all.pgdump.gz"
107 test -e "$destdir" && {
108 sudo
rmdir "$destdir" ||
{
109 echo $progname: $destdir already exists
>&2
114 test -e "$dbroot/$pgdesc/main" && {
115 echo $progname: $dbroot/$pgdesc/main already exists
>&2
120 msg Remove ignored files from $
(pwd)/
122 msg
\"git wait-until-clean
\" or
\"git clean
\" failed
127 $prgdir/postgres/bin/postgres --version 2>/dev/null | fmt -1 | tail -1
130 if [ -n "$old_version" ]; then
131 msg git status
in $
(pwd)
132 GIT_PAGER
=cat git status
134 until [ "$choice" = "y" ]; do
138 git log
--format=oneline
$old_version..
$pgdesc |
wc -l
139 ) new commits available
in range
$old_version..
$pgdesc
140 echo Going to compile Postgres
$pgdesc
142 echo If that looks okay to you
, press
\'y
\' to start the build
, or
:
144 echo \'ds
\' to
diff --stat
145 echo \'dw
\' to word-diff
146 echo \'l
\' to list log
147 echo \'ld
\' to list current databases
148 echo \'lp\' to list log with
patch
149 echo \'lt
\' to list log with commit tree
150 echo \'lw
\' to list log with
patch using word
diff
152 echo \'p
\' to push new commits
153 echo \'t
\' to show commit tree
155 [ "$choice" = "d" ] && git
diff $old_version $pgdesc
156 [ "$choice" = "ds" ] && git
diff --stat $old_version $pgdesc
157 [ "$choice" = "dw" ] && git
diff --word-diff $old_version $pgdesc
158 [ "$choice" = "l" ] && git log
--stat $old_version..
$pgdesc
159 [ "$choice" = "ld" ] && psql
-X -c '\l+'
160 [ "$choice" = "lp" ] && git log
--patch $old_version..
$pgdesc
161 [ "$choice" = "lt" ] && git log
--graph --stat $old_version..
$pgdesc
162 [ "$choice" = "lw" ] && git log
--patch --word-diff $old_version..
$pgdesc
163 [ "$choice" = "n" ] && exit 0
164 [ "$choice" = "p" ] && git pa
165 [ "$choice" = "t" ] && {
166 git log
--abbrev-commit --date-order --decorate=short
--graph \
167 --pretty=format
:'%Cred%h %Cblue%p%Creset -%Creset %s %Cgreen(%cd %Cblue%an%Cgreen)%Creset%C(yellow)%d%Creset' \
168 $old_version..
$pgdesc
174 until [ "$choice" = "y" ]; do
175 echo -n Press
\'y
\' to start the build
, or
\'n
\' to abort...
177 [ "$choice" = "n" ] && exit 0
181 msg mkdir
$destdir &&
182 sudo mkdir
-p "$destdir" &&
184 msg chown
$user.
$user $destdir &&
185 sudo chown
$user.
$user "$destdir" &&
187 msg Run .
/configure
&&
188 .
/configure
--prefix="$destdir" --with-extra-version="+$pgdesc" \
189 --enable-debug --with-libxml --with-openssl --with-perl --with-uuid=ossp
&&
197 msg
make install-world
&&
198 make install-world
&&
200 until sudo
-u postgres
echo postgres
pwd OK |
grep -q "postgres pwd OK"; do
204 msg Dump all databases to
$dumpfile &&
205 sudo
-u postgres bash
-c "pg_dumpall | gzip >\"$dumpfile\"" &&
208 sudo
-u postgres pg_ctl
-D "$dbroot/current/main" stop
&&
210 msg Update the
$prgdir/postgres symlink
&&
212 sudo
ln -fnsv "../varprg/$pgdir" postgres
&&
214 msg Create
\'current
\' symlink to
$pgdesc &&
215 sudo
-u postgres
ln -fnsv "$pgdesc" "$dbroot/current" &&
218 sudo
-u postgres initdb
--lc-collate=C
-E UTF-8
"$dbroot/$pgdesc/main" &&
221 sudo
-u postgres pg_ctl
-D "$dbroot/$pgdesc/main" \
222 -l "$dbroot/$pgdesc/logfile" start
&&
224 sudo
-u postgres bash
-c "until pg_isready -q; do sleep 1; done" &&
229 msg Restore databases from
$dumpfile &&
230 sudo
-u postgres bash
-c "zcat \"$dumpfile\" | psql postgres" &&
232 msg Create manpage symlinks
&&
234 cd "$prefix/share/man/man$f" &&
235 sudo
ln -nfsv ..
/..
/..
/prg
/postgres
/share
/man
/man
$f/* . || true
239 echo $progname: Old version
: $old_version >&2 &&
240 echo $progname: New version
: $
(
241 $prgdir/postgres
/bin
/postgres
--version |
fmt -1 |
tail -1
244 if test -d "$prefix/.git/."; then
245 msg Commit the symlink
&&
247 echo $progname installed
$pgdir on $
(hostname
)
249 suuid
-t commit
,$progname
252 sudo git add postgres
&&
253 echo Commit message
: &&
255 sudo git commit
-m "$commitmsg" &&
256 msg
\"git pa
\" in $
(pwd) &&
261 echo $progname finished successfully
>&2 &&
263 msg Something went wrong
, aborted
264 sudo
rmdir "$destdir"