slackbuilds

My Slackbuilds
git clone git://git.server.ky/slackcoder/slackbuilds
Log | Files | Refs | README

postgresql.SlackBuild (7018B)


      1 #!/bin/bash
      2 
      3 # Slackware build script for PostgreSQL
      4 #
      5 # Copyright 2024 Slack Coder <slackcoder@server.ky>
      6 # Copyright 2007-2018 Adis Nezirovic <adis_at_linux.org.ba>
      7 # All rights reserved.
      8 #
      9 # Redistribution and use of this script, with or without modification, is
     10 # permitted provided that the following conditions are met:
     11 #
     12 # 1. Redistributions of this script must retain the above copyright
     13 #    notice, this list of conditions and the following disclaimer.
     14 #
     15 #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
     16 #  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     17 #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
     18 #  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     19 #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20 #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     21 #  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     22 #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     23 #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     24 #  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 
     26 # Modified by the SlackBuilds.org Project
     27 
     28 # 20220301 bkw: Modified by SlackBuilds.org, BUILD=2:
     29 # - strip pg_config binary (install-strip misses that one).
     30 
     31 cd $(dirname $0) ; CWD=$(pwd)
     32 
     33 PRGNAM=postgresql
     34 VERSION=${VERSION:-15.8}
     35 BUILD=${BUILD:-1}
     36 TAG=${TAG:-_slackcoder}
     37 PKGTYPE=${PKGTYPE:-tgz}
     38 
     39 PG_VERSION=${PG_VERSION:-15}
     40 PG_PORT=${PG_PORT:-5432}
     41 PG_UID=${PG_UID:-209}
     42 PG_GID=${PG_GID:-209}
     43 
     44 if [ -z "$ARCH" ]; then
     45   case "$( uname -m )" in
     46     i?86) ARCH=i586 ;;
     47     arm*) ARCH=arm ;;
     48        *) ARCH=$( uname -m ) ;;
     49   esac
     50 fi
     51 
     52 if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
     53   echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
     54   exit 0
     55 fi
     56 
     57 TMP=${TMP:-/tmp/SBo}
     58 PKG=$TMP/package-$PRGNAM
     59 OUTPUT=${OUTPUT:-/tmp}
     60 
     61 # Bail out if user or group isn't valid on your system
     62 # For slackbuilds.org, assigned postgres uid/gid are 209/209
     63 # See http://slackbuilds.org/uid_gid.txt
     64 # Other popular choice is 26/26
     65 if ! grep ^postgres: /etc/group > /dev/null 2>&1 ; then
     66   echo "  You must have a postgres group to run this script."
     67   echo "    # groupadd -g $PG_GID postgres"
     68   exit 1
     69 elif ! grep ^postgres: /etc/passwd > /dev/null 2>&1 ; then
     70   echo "  You must have a postgres user to run this script."
     71   echo "    # useradd -u $PG_UID -g $PG_GID -d /var/lib/pgsql postgres"
     72   exit 1
     73 fi
     74 
     75 # Enable NLS builds using 'ENABLE_NLS=1 ./postgresql.SlackBuild'
     76 if [ ! -z $ENABLE_NLS  ];then
     77   NLS=enable
     78 else
     79   NLS=disable
     80 fi
     81 
     82 if [ "$ARCH" = "i586" ]; then
     83   SLKCFLAGS="-O2 -march=i586 -mtune=i686"
     84   LIBDIRSUFFIX=""
     85 elif [ "$ARCH" = "i686" ]; then
     86   SLKCFLAGS="-O2 -march=i686 -mtune=i686"
     87   LIBDIRSUFFIX=""
     88 elif [ "$ARCH" = "x86_64" ]; then
     89   SLKCFLAGS="-O2 -fPIC"
     90   LIBDIRSUFFIX="64"
     91 else
     92   SLKCFLAGS="-O2"
     93   LIBDIRSUFFIX=""
     94 fi
     95 
     96 set -e
     97 
     98 rm -rf $TMP/$PRGNAM-$VERSION $PKG
     99 mkdir -p $TMP $PKG $OUTPUT
    100 cd $TMP
    101 tar xvf $CWD/$PRGNAM-$VERSION.tar.gz
    102 cd $PRGNAM-$VERSION
    103 chown -R root:root .
    104 find -L . \
    105  \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
    106   -o -perm 511 \) -exec chmod 755 {} \; -o \
    107  \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
    108  -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
    109 
    110 CFLAGS="$SLKCFLAGS" \
    111 PYTHON="/usr/bin/python3" \
    112 ./configure \
    113   --prefix=/usr/lib${LIBDIRSUFFIX}/$PRGNAM/$PG_VERSION \
    114   --sysconfdir=/etc/$PRGNAM/$PG_VERSION \
    115   --includedir=/usr/include \
    116   --datarootdir=/usr/share \
    117   --mandir=/usr/man \
    118   --docdir=/usr/doc/$PRGNAM-$VERSION \
    119   --datadir=/usr/share/$PRGNAM-$PG_VERSION \
    120   --with-openssl \
    121   --with-tcl \
    122   --with-perl \
    123   --with-python \
    124   --with-libxml \
    125   --with-libxslt \
    126   --enable-thread-safety \
    127   --with-system-tzdata=/usr/share/zoneinfo \
    128   --$NLS-nls \
    129   --build=$ARCH-slackware-linux
    130 
    131 make
    132 make install-strip DESTDIR=$PKG
    133 make install-docs DESTDIR=$PKG
    134 
    135 # 20220414 bkw: this one binary wasn't getting stripped...
    136 strip $PKG/usr/lib${LIBDIRSUFFIX}/$PRGNAM/$PG_VERSION/bin/pg_config
    137 
    138 # create symlinks to shared library for other programs to link against
    139 ( cd $PKG/usr/lib${LIBDIRSUFFIX}
    140   for i in $(ls $PRGNAM/$PG_VERSION/lib/lib*.so*) ; do ln -sf $i ; done
    141 )
    142 
    143 # create symlinks to pkg-config scripts
    144 ( mkdir -p $PKG/usr/lib${LIBDIRSUFFIX}/pkgconfig
    145   cd $PKG/usr/lib${LIBDIRSUFFIX}/pkgconfig
    146   for i in $(ls ../$PRGNAM/$PG_VERSION/lib/pkgconfig/*) ; do ln -sf $i ; done
    147 )
    148 
    149 # Some interesting additional modules:
    150 #   https://www.postgresql.org/docs/14/contrib.html
    151 #
    152 # adminpack - helper extension for pgAdmin
    153 # pgcrypto - extension for some business applications
    154 # ltree, xml2 - useful extensions for developers
    155 # postgres_fdw - foreign-data wrapper for access to external PostgreSQL servers
    156 # file_fdw - foreign-data wrapper for access to data files on filesystem
    157 
    158 PG_EXTENSIONS=${PG_EXTENSIONS:-"adminpack pgcrypto ltree xml2 postgres_fdw file_fdw hstore citext"}
    159 
    160 if [ "$PG_EXTENSIONS" = "ALL" ];then
    161   cd $TMP/$PRGNAM-$VERSION/contrib
    162   make all
    163   make install-strip DESTDIR=$PKG
    164 else
    165   for ext in $PG_EXTENSIONS; do
    166     cd $TMP/$PRGNAM-$VERSION/contrib/$ext
    167     make
    168     make install-strip DESTDIR=$PKG
    169   done
    170 fi
    171 
    172 cd $TMP/$PRGNAM-$VERSION
    173 
    174 find $PKG/usr/man -type f -exec gzip -9 {} \;
    175 for i in $( find $PKG/usr/man -type l ) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
    176 
    177 cp -a COPYRIGHT HISTORY README doc/KNOWN_BUGS doc/MISSING_FEATURES doc/TODO $PKG/usr/doc/$PRGNAM-$VERSION/
    178 rm -rf $PKG/usr/doc/$PRGNAM-$VERSION/{man.tar.gz,man1,manl,man7,postgres.tar.gz}
    179 cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
    180 cat $CWD/README_slackware.txt > $PKG/usr/doc/$PRGNAM-$VERSION/README_slackware.txt
    181 
    182 # base database directory
    183 # assumes you are using /var/lib/pgsql as a homedir for postgres user
    184 mkdir -p $PKG/var/lib/pgsql/$PG_VERSION/data
    185 chown -R postgres:postgres $PKG/var/lib/pgsql
    186 chmod 700 $PKG/var/lib/pgsql
    187 # permissions for DATADIR should be u=rwx (0700)
    188 chmod 700 $PKG/var/lib/pgsql/$PG_VERSION/data
    189 
    190 # Install init script
    191 mkdir -p $PKG/etc/rc.d
    192 sed -e "s%@PG_VERSION@%$PG_VERSION%" \
    193   -e "s%@PRGNAM@%$PRGNAM%" \
    194   -e "s%@PG_PORT@%$PG_PORT%" \
    195   -e "s%@LIBDIRSUFFIX@%$LIBDIRSUFFIX%" \
    196   $CWD/rc.$PRGNAM.new > $PKG/etc/rc.d/rc.$PRGNAM.new
    197 chmod 0755 $PKG/etc/rc.d/rc.$PRGNAM.new
    198 
    199 # Install logrotate script
    200 mkdir -p $PKG/etc/logrotate.d
    201 sed -e "s%@PG_VERSION@%$PG_VERSION%" \
    202   -e "s%@PRGNAM@%$PRGNAM%" \
    203   $CWD/$PRGNAM.logrotate > $PKG/etc/logrotate.d/$PRGNAM.new
    204 
    205 mkdir -p $PKG/var/log/setup
    206 sed -e "s%@UID@%$PG_UID%" \
    207   -e "s%@GID@%$PG_GID%" \
    208   -e "s%@PG_VERSION@%$PG_VERSION%" \
    209   $CWD/setup.$PRGNAM  > $PKG/var/log/setup/setup.$PRGNAM
    210 chmod 755 $PKG/var/log/setup/setup.$PRGNAM
    211 
    212 mkdir -p $PKG/install
    213 cat $CWD/slack-desc > $PKG/install/slack-desc
    214 sed -e "s%@PG_VERSION@%$PG_VERSION%" \
    215   -e "s%@PRGNAM@%$PRGNAM%" \
    216   -e "s%@LIBDIRSUFFIX@%$LIBDIRSUFFIX%" \
    217   $CWD/doinst.sh > $PKG/install/doinst.sh
    218 
    219 cd $PKG
    220 /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE