Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 680 lines (597 sloc) 19.607 kb
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
1 #!/bin/bash
2
3 #
4 # peg: Wrapper script for setting up a useful working area to
5 # hack on PostgreSQL code, covering everything from checking out
6 # code to starting and stopping the database server.
7 #
8 # The main UI to the code works using environment variables, similarly
9 # to how the PostgreSQL server and client code both assume default
10 # behavior; PGDATA for example. The environment variable names used
11 # by the standard RHEL RPM packaging are also used when appropriate,
12 # such as PGLOG.
13
14 #
307fc436 »
2011-05-08 Switch to git as the default repo. Update docs.
15 # Copyright (c) 2009-2011, Gregory Smith
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
16 # All rights reserved.
17 # See COPYRIGHT for license details.
18 #
19
20 # Turn this on to get line-by-line execution details for the script, to
21 # make debugging easier
22 #set -x
23
24 function usage {
25 echo peg takes subcommands followed by a project name. Available
26 echo subcommands are:
27 echo
28 echo status: Report on environment variables that would be in place if you were
29 echo to execute a command. Useful mainly for troubleshooting.
30 echo
31 echo init: Create a repo and a project based on it, if one is named
32 echo
33 echo update: Update your repo and a project based on it, if one is named
34 echo
35 echo build-only: Execute the build steps and create a database cluster, but
36 echo "don't start it. This is typically for if you know you need to modify the"
37 echo database configuration before you start it.
38 echo
307fc436 »
2011-05-08 Switch to git as the default repo. Update docs.
39 echo build: Build binaries, install them, create a cluster, start the database
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
40 echo initdb: Create a cluster
41 echo switch: Switch to an existing built binary set and cluster
42 echo start: Start a cluster
43 echo stop: Stop a cluster
46296765 » Greg Smith
2009-12-14 Fix typo in rm help message
44 echo "rm: Remove all data from a project (but not the repo)"
189f9fb0 »
2011-01-15 Add "clean" command.
45 echo "clean: Clean up the source code tree ('make maintainer-clean')"
512e4a62 » Greg Smith
2011-06-21 Add rebuild command
46 echo rebuild: Just build the main server files in the server backend
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
47 }
48
49 # Set $1 to $2 only if it's empty
50 function set_if_empty {
51 # See "Shell Parameter Expansion" in the Bash manual for how this ! works
52 if [ -z "${!1}" ] ; then
53 eval "$1=\"$2\""
54 fi
55 }
56
57 COMMAND="$1"
58 set_if_empty PGPROJECT "$2"
0e0d0cc1 » Greg Smith
2010-01-04 Tweak Solaris changes, update docs to reflect them
59 set_if_empty PGMAKE "make"
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
60 # Typically if you're overriding this, you'll want to set PGDEBUG to
61 # something harmless but not empty; a space would do.
62 set_if_empty PGDEBUG "--enable-cassert --enable-debug"
63
64 ERROR=
65
66 # Default directory names. Not really worth making these user
67 # configurable; typically if you want something custom, you'll
68 # be overriding the final result rather than this component
69 # (i.e. customizing PGDATA rather than just DATADIR)
70
71 REPODIR="repo"
72 DATADIR="data"
73 SRCDIR="src"
74 INSTDIR="inst"
75 LOGFILE="pg.log"
76
77 # Defaults for what the various types of VCS directories you might
78 # have or want would be named. These directory names are also used
79 # as the name of the repo type internally, so be careful if changing
80 # them
81
82 GITDIR="git"
83 CVSDIR="cvs"
84 TGZDIR="tgz"
85
86 # Names of the top-level directory tree for the various repository types
87 GITPGROOTDIR="postgresql"
88 CVSPGROOTDIR="pgsql"
89
c9375d7e » Greg Smith
2012-01-14 Be explicit about the PostgreSQL git repo branch
90 # Remote branch of interest for the PostgreSQL git repo
91 # TODO An easy UI for checking out back branches would be nice
92 GITMASTERREPO="origin"
93 GITMASTERBRANCH="$GITMASTERREPO/master"
94
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
95 function error {
96 # Report an error and save its value for exit and wrap's command filtering
97 ERROR=$1
98 echo ERROR: $2
99 }
100
101 function wrap {
102 # Only executed passed function if we haven't gotten an error yet
103 # This whole scheme is necessary because we can't just call bash's exit if
104 # this script is sourced--that will exit from the shell rather than just
105 # this script. Since sourcing it is the main we expect to be called,
106 # that's clearly not acceptable
107 if [ -z "$ERROR" ] ; then
108 $1
109 fi
110 }
111
112 function project_save {
113 # Remember and restore the project name we're given, to provide a useful
114 # guess for cases when it's not provided
115 if [ -n "$PGPROJECT" ] ; then
116 echo $PGPROJECT > $PGWORK/lastproject
117 else
118 if [ -f "$PGWORK/lastproject" ] ; then
119 PGPROJECT=`cat $PGWORK/lastproject`
120 if [ -n "$PGPROJECT" ] ; then
121 echo "Using discovered last project $PGPROJECT"
122 fi
123 fi
124 fi
125 }
126
127 #
128 # Handlers for the individual steps we might need executed
129 #
130
131 # Create all the directories we expect
132 function setup {
133 mkdir -p $PGWORK $PGREPO $PGSRC $PGINST $PGREPO/$PGVCS
134 if [ -n "$PGPROJECT" ] ; then
a959ebe7 » Greg Smith
2009-12-01 Switch to using PGENGINE, like RPM install does.
135 mkdir -p $PGSRC/$PGPROJECT $PGDATA $PGENGINE
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
136 fi
137 }
138
139 function pull_cvs {
140 export CVSROOT=$PGREPO/$PGVCS
141 mkdir -p $CVSROOT
142 rsync --progress -avzCH --delete anoncvs.postgresql.org::pgsql-cvs $CVSROOT
143 }
144
145 function link_project_git
146 {
147 if [ -h "$PGSRC/$PGPROJECT" ] ; then
148 # This message is way too verbose
149 #echo "Project source $PGSRC/$PGPROJECT is already linked to git repo"
150 return
151 fi
152
153 # Remove this directory without any flags. This will wipe it out only if
154 # it's empty, which is what we want. That should be the case if this
155 # is a new project. Cowardly refuse to do anything if the rmdir doesn't
156 # make the directory go away
157 rmdir $PGSRC/$PGPROJECT
158 if [ -d "$PGSRC/$PGPROJECT" ] ; then
159 error 14 "Failed to link project $PGSRC/$PGPROJECT to git, was expecting that to be an empty directory"
160 else
161 ln -s $GITROOT/$GITPGROOTDIR $PGSRC/$PGPROJECT
162 fi
163 }
164
165 function pull_git {
166 cd $GITROOT
167 if [ -d "$GITPGROOTDIR/.git" ] ; then
168 # Apparently we already have a repo around
169 echo "Updating existing git repository at $GITPGROOTDIR"
170 cd $GITPGROOTDIR
c9375d7e » Greg Smith
2012-01-14 Be explicit about the PostgreSQL git repo branch
171 git fetch $GITMASTERREPO
172 git merge $GITMASTERBRANCH
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
173 else
174 echo "Creating new git repository from master repo"
175 git clone git://git.postgresql.org/git/postgresql.git
176 fi
177
178 if [ ! -d $GITROOT/$GITPGROOTDIR ] ; then
179 error 10 "$PGVCS repo at $GITROOT does not have expected directory $GITPGROOTDIR"
180 else
181 link_project_git
182 fi
183 }
184
185 function extract_project_tgz
186 # Actual extraction that we can only do if there's a project directory
187 {
188 cd $PGSRC/$PGPROJECT
189 # Try not to overwrite something; presumably at this point we should only
190 # have a blank source directory for this project.
191 if [ -f "configure" ] ; then
192 error 12 "Extraction from $TARFILE aborted because $PGSRC/$PGPROJECT isn't empty"
193 else
194 echo "Extracting repo to $PGSRC/$PGPROJECT"
195 # Since the "z" option to tar only exists in GNU tar, try to improve
196 # compatibility by doing it the log way
197 gzip -d -c $PGREPO/$PGVCS/$TARFILE | tar xf -
198
199 # The tar file we just extracted is likely to have a base directory name.
200 # Figure out what that is and move the files to the correct destination
201 cd $PGSRC/$PGPROJECT
202 TGZPGROOTDIR=
203 for f in * ; do
204 if [ -d "$f" ] ; then
205 if [ -z "$TGZPGROOTDIR" ] ; then
206 TGZPGROOTDIR="$f"
207 echo "Extracted $PGVCS root directory is named $TGZPGROOTDIR"
208 else
209 echo "Warning: unexpectedly found a second directory $f inside extracted tar file"
210 fi
211 else
212 echo "Ignoring non-directory $f extracted from tar file"
213 fi
214 done
215 if [ -f "$TGZPGROOTDIR/configure" ] ; then
216 mv $TGZPGROOTDIR/* $PGSRC/$PGPROJECT
217 rmdir $TGZPGROOTDIR
218 else
219 error 14 "Cannot determine subdirectory root for extracted tar file, needs a manual fix"
220 fi
221 fi
222 }
223
224 function extract_tgz {
225 # This will let you confirm that there's an acceptable tar file even
226 # you don't pass a project directory, which makes this call more like
227 # its git/cvs siblings. Those let you nail down the repo details
228 # during "init" even without a project defined yet.
229 TARFILE=
230 cd $PGREPO/$PGVCS
231
232 for file in *.tar.gz ; do
233 if [ -z "$TARFILE" ] ; then
234 TARFILE="$file"
235 fi
236 done
237
238 for file in *.tgz ; do
239 if [ -z "$TARFILE" ] ; then
240 TARFILE="$file"
241 fi
242 done
243
244 if [ -n "$TARFILE" ] ; then
245 echo "Using $PGVCS repo source $PGREPO/$PGVCS/$TARFILE"
246 require_project
247 wrap extract_project_tgz
248 else
249 error 11 "For repo type $PGVCS cannot find a compatible .tar.gz or .tgz file"
250 fi
251 }
252
253 function setup_repo {
254 # Download/extract a repo in cases where that's what we want
255 if [ "$PGVCS" = "$CVSDIR" ]; then
256 pull_cvs
257 elif [ "$PGVCS" = "$GITDIR" ]; then
258 pull_git
259 elif [ "$PGVCS" = "$TGZDIR" ]; then
260 extract_tgz
261 else
262 error 3 "Setup cannot handle PGVCS=$PGVCS"
263 fi
264 }
265
266 function checkout_repo_git {
267 link_project_git
268 cd $PGSRC/$PGPROJECT
269 # TODO This will fail if this branch already exists.
c9375d7e » Greg Smith
2012-01-14 Be explicit about the PostgreSQL git repo branch
270 git checkout -b $PGPROJECT $GITMASTERBRANCH
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
271 }
272
273 function checkout_repo_cvs {
274 cd $PGSRC
275 cvs co -d $PGPROJECT $CVSPGROOTDIR
276 update_cvs
277 }
278
279 function checkout_repo_tgz {
280 echo "No checkout step needed for PGVCS=$PGVCS"
281 }
282
283 function create_project {
284 if [ "$PGVCS" = "$CVSDIR" ]; then
285 checkout_repo_cvs
286 elif [ "$PGVCS" = "$GITDIR" ]; then
287 checkout_repo_git
288 elif [ "$PGVCS" = "$TGZDIR" ]; then
289 checkout_repo_tgz
290 else
291 error 3 "Create project cannot handle PGVCS=$PGVCS"
292 fi
293 }
294
c74638ad »
2010-02-18 Implement "rm" command. Document issues with
295 function rm_if_exists {
296 if [ -d "$1" ] ; then
297 echo Erasing directory $1
298 rm -rf "$1"
299 else
300 echo Not removing directory $1 because it does not exist
301 fi
302 }
303
189f9fb0 »
2011-01-15 Add "clean" command.
304 function clean_project {
305 if [ -d "$PGSRC/$PGPROJECT" ] ; then
306 echo Cleaning out source code tree at $PGSRC/$PGPROJECT
307 pushd $PGSRC/$PGPROJECT
308 make maintainer-clean
309 popd
310 echo maintainer-clean of source directory $PGSRC/$PRPROJECT finished
311 else
312 echo Not cleaning up $PGSRC/$PGPROJECT because it does not exist
313 fi
314 }
315
97667826 » Greg Smith
2009-12-14 Add in stub for "peg rm"
316 function remove_project {
c74638ad »
2010-02-18 Implement "rm" command. Document issues with
317 # This might be more than the user wants, but if we just removed a project
318 # and this is a git repo, odds are decent the repo directory is filled with
319 # that project's build artifacts. Get rid of those to be safe.
320 if [ "$PGVCS" = "$GITDIR" ]; then
321 GITBASE="$GITROOT/$GITPGROOTDIR"
322 echo Cleaning out all build artifacts from the git repo at $GITBASE
323 pushd $GITBASE
c3ac8aaf »
2010-02-26 Switch to use maintainer-clean for clearing build info
324 make maintainer-clean
c74638ad »
2010-02-18 Implement "rm" command. Document issues with
325 popd
189f9fb0 »
2011-01-15 Add "clean" command.
326 echo maintainer-clean of repo directory $GITBASE finished
c74638ad »
2010-02-18 Implement "rm" command. Document issues with
327 fi
328
97667826 » Greg Smith
2009-12-14 Add in stub for "peg rm"
329 # The tricky part here is that we want to cleanup things like PGDATA only
330 # if that points to a PEG-managed directory tree, *not* if the user supplied
c74638ad »
2010-02-18 Implement "rm" command. Document issues with
331 # their own PGDATA. For now we just work around this by only deleting
332 # the standard PGDATA for a PEG-managed project, not whatever PGDATA
333 # is actually pointing to.
334 rm_if_exists "$PGWORK/$DATADIR/$PGPROJECT"
335 rm_if_exists "$PGINST/$PGPROJECT"
336 rm_if_exists "$PGSRC/$PGPROJECT"
97667826 » Greg Smith
2009-12-14 Add in stub for "peg rm"
337 }
338
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
339 function optional_project {
340 if [ -z "$PGPROJECT" ] ; then
341 error 6 "Command $COMMAND only partially completes without a PGPROJECT name"
342 fi
343 }
344
345 function require_project {
346 if [ -z "$PGPROJECT" ] ; then
347 error 7 "Command $COMMAND requires a PGPROJECT name"
348 usage
349 fi
350 }
351
352 function update_cvs {
353 cd $PGSRC/$PGPROJECT
354 cvs update -dP
355 }
356
357 function update_git {
c9375d7e » Greg Smith
2012-01-14 Be explicit about the PostgreSQL git repo branch
358 # TODO Should this consider not merging automatically based on whether
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
359 # a PGPROJECT name was passed or not?
360 cd $PGSRC/$PGPROJECT
c9375d7e » Greg Smith
2012-01-14 Be explicit about the PostgreSQL git repo branch
361 git fetch $GITMASTERREPO
362 git merge $GITMASTERBRANCH
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
363 }
364
365 function update_project {
366 if [ "$PGVCS" = "$CVSDIR" ]; then
367 update_cvs
368 elif [ "$PGVCS" = "$GITDIR" ]; then
369 update_git
370 elif [ "$PGVCS" = "$TGZDIR" ]; then
371 echo WARNING: PGVCS=$PGVCS does not support being updated
372 return
373 else
374 error 4 "Update cannot handle PGVCS=$PGVCS"
375 fi
376 }
377
378 function require_binary {
379 # Check if initdb binary exists
a959ebe7 » Greg Smith
2009-12-01 Switch to using PGENGINE, like RPM install does.
380 if [ ! -x $PGENGINE/initdb ]; then
381 error 7 "No PostgreSQL binaries found in $PGENGINE"
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
382 fi
383 }
384
385 function build {
386 cd $PGSRC/$PGPROJECT
387 if [ -f GNUmakefile ] ; then
388 echo WARNING: Build found an existing GNUmakefile, not running configure again
389 else
0e0d0cc1 » Greg Smith
2010-01-04 Tweak Solaris changes, update docs to reflect them
390 ./configure --prefix=$PGINST/$PGPROJECT --enable-depend --enable-thread-safety $PGDEBUG
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
391 fi
392 # TODO Detect CPUs and set jobs accordingly
6a3b05ae » Robert Treat
2010-01-12 bugfix: need to pgmake install to actually install
393 $PGMAKE -j 4 && $PGMAKE install
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
394 }
395
512e4a62 » Greg Smith
2011-06-21 Add rebuild command
396 function rebuild {
397 # Check if initdb binary exists
398 if [ ! -x $PGENGINE/initdb ]; then
399 echo WARNING: No existing binary found, executing full build instead of rebuild
400 build
401 elif [ ! -f $PGSRC/$PGPROJECT/GNUmakefile ] ; then
402 echo "WARNING: Didn't find an existing GNUmakefile, executing full build instead of rebuild"
403 build
404 else
405 # Looks good to rebuild with install-bin here
406 cd $PGSRC/$PGPROJECT/src/backend
407 $PGMAKE install-bin
408 fi
409 }
410
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
411 function initdb {
412 if [ ! -f "$PGDATA/PG_VERSION" ] ; then
a959ebe7 » Greg Smith
2009-12-01 Switch to using PGENGINE, like RPM install does.
413 $PGENGINE/initdb -D $PGDATA
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
414 if [ "$?" -ne "0" ]; then
415 error 9 "Error when running initdb, aborting"
416 fi
417 else
418 echo Database cluster already exists in $PGDATA
419 fi
420 }
421
422 function set_port_str {
423 # If PGPORT is set to something, presume that's what port we should start
424 # the server on
425 if [ -n "$PGPORT" ] ; then
426 echo "Using discovered port $PGPORT"
427 else
428 PGPORT=5432
429 fi
430 PORTSTR="-o '-p $PGPORT'"
431 }
432
433 function start {
434 if [ -f "$PGDATA/postmaster.pid" ] ; then
435 echo "Server appears started:"
436 ls -l $PGDATA/postmaster.pid
437 else
438 # Do a basic sanity check before letting pg_ctl loose, since it
439 # will take a while to timeout even if there's database
440 if [ ! -f "$PGDATA/postgresql.conf" ] ; then
441 error 8 "Database cluster at $PGDATA looks incomplete:"
442 else
443 # We have a postgresql.conf but not a posmaster.pid, server should
444 # be setup to start normally
a959ebe7 » Greg Smith
2009-12-01 Switch to using PGENGINE, like RPM install does.
445 $PGENGINE/pg_ctl start -D $PGDATA -l $PGLOG "$PORTSTR" -w
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
446 tail $PGLOG
447 fi
448 fi
449 }
450
451 function stop {
452 if [ -f "$PGDATA/postmaster.pid" ] ; then
453 # TODO Add a more gradual shutdown behavior
a959ebe7 » Greg Smith
2009-12-01 Switch to using PGENGINE, like RPM install does.
454 $PGENGINE/pg_ctl stop -D $PGDATA -m immediate
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
455 else
456 echo "Server doesn't appear started"
457 fi
458 }
459
460 function add_user_db {
461 # psql by default wants to connect to a database with the same user
462 # as is running the program. createdb will default to creating a user
463 # with the same name. Might as well take advantage of that synergy.
464
465 # TODO Only execute this if the database doesn't already exist
a959ebe7 » Greg Smith
2009-12-01 Switch to using PGENGINE, like RPM install does.
466 $PGENGINE/createdb
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
467 }
468
469 function report_env {
470 # Mainly for debugging setup issues and the script itself
471 echo "Base directories:"
472 echo PGWORK=$PGWORK
473 echo PGREPO=$PGREPO
474 echo PGSRC=$PGSRC
475 echo PGINST=$PGINST
476 echo
f81afd09 » Greg Smith
2010-01-04 Change status message, all project info after general
477 echo "Active Project:"
478 echo PGPROJECT=$PGPROJECT
479 echo
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
480 echo "Project specific directories (only if defined):"
a959ebe7 » Greg Smith
2009-12-01 Switch to using PGENGINE, like RPM install does.
481 echo PGENGINE=$PGENGINE
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
482 echo PGDATA=$PGDATA
483 echo PGLOG=$PGLOG
484 echo
485 # TODO Show whether we have a) binaries, b) a cluster, c) a running server
486 }
487
488 #
489 # Environment and directory setup
490 #
491
492 # Try the following possibilities to locate the base of the structure we're looking for:
493 # 1) The value passed for PGWORK
494 # 2) The current directory
495 # 3) $HOME/pgwork
496 # 4) $HOME
497
498 CWD=`pwd`
499 if [ -n "$PGWORK" -a -d "$PGWORK" ] ; then
500 echo Using specified PGWORK=$PGWORK
501 elif [ -d "$CWD/$REPODIR" ] ; then
502 PGWORK="$CWD"
503 echo Using discovered PGWORK=$PGWORK
504 elif [ -d "$HOME/pgwork" ] ; then
505 PGWORK="$HOME/pgwork"
506 echo Using discovered PGWORK=$PGWORK
507 elif [ -d "$HOME/$REPODIR" ] ; then
508 PGWORK="$HOME"
509 echo Using discovered PGWORK=$PGWORK
510 else
511 error 1 "Cannot find or guess a PGWORK base directory"
512 fi
513
514 # Now that we have a base directory, setup the rest of the
515 # environment varibles we use in terms of it only if they
516 # are not set already
517
518 # These variables point to the base of the work area, without a project
519 # name appended to them
520 set_if_empty PGREPO "$PGWORK/$REPODIR"
521 set_if_empty PGSRC "$PGWORK/$SRCDIR"
522 set_if_empty PGINST "$PGWORK/$INSTDIR"
523
524 # Save or restore project name
525 wrap project_save
526
527 # Thse variables are only set if there's a project name given
528 if [ -z "$PGPROJECT" ] ; then
529 echo "Cannot set binary location or provide a new PGDATA without a project name"
530 else
a959ebe7 » Greg Smith
2009-12-01 Switch to using PGENGINE, like RPM install does.
531 set_if_empty PGENGINE "$PGINST/$PGPROJECT/bin"
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
532 set_if_empty PGDATA "$PGWORK/$DATADIR/$PGPROJECT"
533 set_if_empty PGLOG "$PGDATA/$LOGFILE"
534 set_port_str
535 fi
536
537 # In cases where we're not passed a PGVCS, or it appears invalid,
538 # now that we know where the local repo is stored see if there's
539 # already something there. If so, determine PGVCS from it.
307fc436 »
2011-05-08 Switch to git as the default repo. Update docs.
540 # Default to grabbing from git if no source is specified and
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
541 # there's nothing useful in the directory tree.
542
543 if [ -n "$PGVCS" ] ; then
544 echo Using specified PGVCS=$PGVCS
545 elif [ -d "$PGREPO/$TGZDIR" ] ; then
546 PGVCS=$TGZDIR
547 echo Using discovered PGVCS=$PGVCS
548 elif [ -d "$PGREPO/$GITDIR" ] ; then
549 PGVCS=$GITDIR
550 echo Using discovered PGVCS=$PGVCS
551 elif [ -d "$PGREPO/$CVSDIR" ] ; then
552 PGVCS=$CVSDIR
553 echo Using discovered PGVCS=$PGVCS
554 else
307fc436 »
2011-05-08 Switch to git as the default repo. Update docs.
555 PGVCS=$GITDIR
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
556 echo Using default PGVCS=$PGVCS
557 fi
558
c74638ad »
2010-02-18 Implement "rm" command. Document issues with
559 GITROOT="$PGREPO/$PGVCS"
560
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
561 # Command interpreter
562
563 # "init" and "update" will work without a project name. The rest will not.
564 # Each individual command here should be split into a function, because
565 # some commands are just going to be composites of others.
566 # the building blocks are:
567 # -Grab/sync master repo (only one per structure here, shared)
568 # -Create a new PGPROJECT structure
569 # -Update the checked out code of a project. Here the workflow for CVS and git are very different.
570 # -Build the source code
571 # -Create a database cluster
572 # -Start the database
573
574 # The only thing that really needs to get split out is that
575 # regularly I'd expect the checkout and build steps will
576 # require applying a patch in the middle. A special command might
577 # make sense for the combination, with the normal workflow being
578 # an init, manual patch application, then "start"
579
580 if [ "$COMMAND" = "status" ] ; then
581 wrap report_env
582
583 elif [ "$COMMAND" = "init" ] ; then
584 # Init will create a project if you give it one, otherwise
585 # it just sets up the repo
586 wrap setup
587 wrap setup_repo
588 wrap optional_project
589 wrap create_project
590
591 elif [ "$COMMAND" = "update" ] ; then
592 # Update with no PGPROJECT name is OK, but not so useful for
593 # anything but CVS
594 wrap setup
595 wrap optional_project
596 wrap create_project
597 wrap update_project
598
599 elif [ "$COMMAND" = "build-only" ] ; then
600 wrap require_project
601 wrap build
602 wrap require_binary
603 wrap initdb
604
605 elif [ "$COMMAND" = "build" ] ; then
606 wrap require_project
607 wrap build
608 wrap require_binary
609 wrap initdb
610 wrap start
611 wrap add_user_db
612
512e4a62 » Greg Smith
2011-06-21 Add rebuild command
613 elif [ "$COMMAND" = "rebuild" ] ; then
614 wrap require_project
615 wrap rebuild
616 wrap require_binary
617 wrap initdb
618 wrap start
619 wrap add_user_db
620
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
621 elif [ "$COMMAND" = "initdb" ] ; then
622 # Explicitly calling initdb suggests the caller wants to adjust the
623 # postgresql.conf before starting
624 wrap require_project
625 wrap require_binary
626 wrap initdb
627
628 elif [ "$COMMAND" = "switch" ] ; then
629 wrap require_project
630 wrap require_binary
631 wrap start
632 wrap add_user_db
633
634 elif [ "$COMMAND" = "start" ] ; then
635 wrap require_project
636 wrap require_binary
637 wrap initdb
638 wrap start
639 wrap add_user_db
640
641 elif [ "$COMMAND" = "stop" ] ; then
642 wrap require_project
643 wrap require_binary
644 wrap stop
645
97667826 » Greg Smith
2009-12-14 Add in stub for "peg rm"
646 elif [ "$COMMAND" = "rm" ] ; then
647 wrap require_project
648 wrap remove_project
649
189f9fb0 »
2011-01-15 Add "clean" command.
650 elif [ "$COMMAND" = "clean" ] ; then
651 wrap require_project
652 wrap clean_project
653
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
654 else
655 error 5 "Command not recognized: $COMMAND"
656 usage
657 fi
658
659 # We only want to export settings if we're given a project name
660 wrap require_project
661
662 # Only export things if we didn't raise an error, as not
663 # to pollute the caller's environment with garbage.
664 if [ -z "$ERROR" ]; then
665 # Export the bits we expect the user to directly reference
666 export PGDATA PGLOG
a959ebe7 » Greg Smith
2009-12-01 Switch to using PGENGINE, like RPM install does.
667 # TODO Don't dupe PGENGINE if it's already in the PATH
668 export PATH="$PGENGINE:$PATH"
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
669
a959ebe7 » Greg Smith
2009-12-01 Switch to using PGENGINE, like RPM install does.
670 alias start="$PGENGINE/pg_ctl -D $PGDATA -l $PGLOG start"
671 alias stop="$PGENGINE/pg_ctl -D $PGDATA stop -m fast"
672 alias immediate="$PGENGINE/bin/pg_ctl -D $PGDATA stop -m immediate"
5f2dc637 » Greg Smith
2009-11-19 Convert local peg files for distribution
673
674 # Use bash black magic to pass an exit code back in a way that
675 # won't exit the calling shell script. See
676 # http://fvue.nl/wiki/Bash:_Return_or_exit%3F for background.
677 $(exit 0)
678 else
679 $(exit $ERROR)
680 fi
Something went wrong with that request. Please try again.