Advertisement
Guest User

install_pg.sh

a guest
Jul 11th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.32 KB | None | 0 0
  1. usage() { echo "Usage: $0 [-i <install_dir>] [-d <data_dir>]" 1>&2; exit 1; }
  2.  
  3. while getopts i:d: flag
  4. do
  5.     case "${flag}" in
  6.         i)
  7.             INSTALL_DIR=${OPTARG}
  8.             ;;
  9.         d)
  10.             DATA_DIR=${OPTARG}
  11.             ;;
  12.         *)
  13.             usage
  14.             ;;
  15.     esac
  16. done
  17.  
  18. if [ -z "$INSTALL_DIR" ]
  19. then
  20.     INSTALL_DIR="$HOME"
  21. fi
  22.  
  23. if [ -z "$DATA_DIR" ]
  24. then
  25.     DATA_DIR="$INSTALL_DIR/postgresql-11.14/data"
  26. fi
  27.  
  28. echo "Installing Postgres at: $INSTALL_DIR";
  29. echo "Postgres DATA Directory: $DATA_DIR";
  30.  
  31. cd $INSTALL_DIR
  32. curl -LO https://ftp.postgresql.org/pub/source/v11.14/postgresql-11.14.tar.gz
  33. tar -xvzf postgresql-11.14.tar.gz
  34. cd postgresql-11.14/
  35.  
  36. ./configure --prefix=$INSTALL_DIR/postgresql-11.14 --enable-cassert --enable-debug CFLAGS="-ggdb -Og -gdwarf-2 -g3 -std=c99"
  37. error=$?
  38. if [ $error -eq 0 ]; then
  39.     make world
  40.     make install-world
  41.  
  42.     errorMakeInstall=$?
  43.     if [ $errorMakeInstall -eq 0 ]; then
  44.         echo "Installed Successfully"
  45.         echo "Creating DATA Directory at: $DATA_DIR";
  46.  
  47.         mkdir -p $DATA_DIR
  48.         chown -R $(whoami) $DATA_DIR
  49.         $INSTALL_DIR/postgresql-11.14/bin/initdb -D $DATA_DIR --no-locale
  50.     else
  51.         echo $errorMakeInstall
  52.         echo "Build Failed: Error while installing postgresql-11.14"
  53.         exit 1
  54.     fi
  55. else
  56.     echo $error
  57.     echo "Build Failed: Error while configuring postgresql-11.14"
  58.     exit 1
  59. fi
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement