· 5 years ago · Mar 15, 2020, 08:18 AM
1#!/bin/sh -e
2# Slackware build script for pgadmin4
3
4# Copyright 2019 Jeremy Hansen jebrhansen+SBo -at- gmail.com
5# All rights reserved.
6#
7# Redistribution and use of this script, with or without modification, is
8# permitted provided that the following conditions are met:
9#
10# 1. Redistributions of this script must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12#
13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
14# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
18# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
19# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
21# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
24# This script is for building pgAdimin4 for slackware current as of 3/12/2020
25# Full installation of slackware current is assumed, additionally slackware
26# package tools use is also assumed.
27# pgAdmin4 requires QT 4.6 or above and python 2.7 or 3.4+, all provided with
28# full slackware installation. We do NOT check for those packages, however we
29# do check for postgresql package installation.
30# Note that default slackware installation use python2.7. Whole world moving
31# to python3.
32# We utilise python3 by creating Python Virtual Environment under /usr/local
33# directory. We use python3 pip command to install required python modules for
34# pgAmin4 in the Virtual Environment directory.
35
36CWD=$(pwd)
37PRGNAM=pgadmin4
38VERSION=${VERSION:-4.19}
39BUILD=${BUILD:-3}
40TAG=${TAG:-_wh}
41TMP=${TMP:-/tmp}
42PKG=$TMP/package-$PRGNAM
43OUTPUT=${OUTPUT:-/tmp}
44SRC=$TMP/$PRGNAM-$VERSION
45
46if [ -z "$ARCH" ]; then
47 case "$( uname -m )" in
48 i?86) ARCH=i586 ;;
49 arm*) ARCH=arm ;;
50 *) ARCH=$( uname -m ) ;;
51 esac
52fi
53
54if [ "$ARCH" = "i586" ]; then
55 SLKCFLAGS="-O2 -march=i586 -mtune=i686"
56 LIBDIRSUFFIX=""
57elif [ "$ARCH" = "i686" ]; then
58 SLKCFLAGS="-O2 -march=i686 -mtune=i686"
59 LIBDIRSUFFIX=""
60elif [ "$ARCH" = "x86_64" ]; then
61 SLKCFLAGS="-O2 -fPIC"
62 LIBDIRSUFFIX="64"
63else
64 SLKCFLAGS="-O2"
65 LIBDIRSUFFIX=""
66fi
67
68# Step one: check for postgresql package installation - bailout if not found.
69# Assume slackpkg use. Is postgresql package installed?
70PG_PKG=$(ls /var/lib/pkgtools/packages/postgresql*)
71
72# empty string from ls command above indecates missing PostgreSQL package
73if [ -z "$PG_PKG" ]; then
74 echo "PostgreSQL package not found. Please install PostgreSQL with"
75 echo "slackpkg. Exiting!"
76 exit 1;
77fi
78
79# pg_config file is usually installed in postgresql bin directory
80PG_BIN_PART1=$(cat $PG_PKG | egrep "*/bin/pg_config")
81
82# empty string means missed up installation!
83if [ -z "$PG_BIN_PART1" ]; then
84 echo "ERROR: Could not get path for PostgreSQL bin directory."
85 echo "Exiting!"
86 exit 1;
87fi
88
89# prepend leading slash to directory
90SLASH=/
91
92# with leading slash this is pg_config file which MUST exist in file system
93if [ ! -f "$SLASH$PG_BIN_PART1" ]; then
94 echo "ERROR: Could not find postgresql pg_config configuration file."
95 echo "Ensure that postgresql package is propely installed with slackware"
96 echo "package tools. Exiting."
97 exit 1
98fi
99# seems good postgresql package installation.
100
101# Step 2: run the build in python virtual environment
102
103#PY_VENV_ROOT=~/py-venv
104PY_VENV_ROOT=/usr/local/py-venv
105APP_PVE=pgAdmin4-py-venv
106
107source $PY_VENV_ROOT/$APP_PVE/bin/activate
108
109# check return value from above!
110SUCCESS=0
111RET_VALUE=$?
112if [ $RET_VALUE -ne $SUCCESS ]; then
113 echo "ERROR: Could not activate Python Virtual Environment!"
114 echo "Make sure to run mk-PyVenv-4-pgAdmin.sh script to set it up."
115 echo "Exiting"
116 exit 1
117fi
118
119
120rm -rf $PKG
121mkdir -p $TMP $PKG $OUTPUT
122cd $TMP
123rm -rf $PRGNAM-$VERSION
124tar xvzf $CWD/$PRGNAM-$VERSION.tar.gz
125
126cd $SRC
127
128chown -R root:root .
129find -L . \
130 \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
131 -o -perm 511 \) -exec chmod 755 {} \; -o \
132 \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
133 -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
134
135convert +set date:create +set date:modify runtime/pgAdmin4.{ico,png}
136
137# both patch files are from arch linux build package for version 4.18
138patch -Np1 < $CWD/python-3.8.patch
139patch -Np1 < $CWD/pgadmin4-python-de-vendor-venv-paths.patch
140
141make docs
142
143cd $SRC/runtime
144
145# set PYTHON_CONFIG to force python3 version
146PYTHON_CONFIG=/usr/bin/python3.8-config qmake-qt5
147make
148
149# move to source root
150cd ..
151
152# make javascripts Web Assets "bundle" requires yarn package
153# TODO : make this optional / check for yarn installation!!!
154make install-node
155make bundle
156
157# start-pve+pgAdmin4.sh :: simple script to start pgAdmin4 in PyVENV
158start_script=start-pve+pgAdmin4.sh
159
160# Install binary
161install -Dm 755 runtime/pgAdmin4 "$PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/runtime/pgAdmin4"
162install -Dm 755 $CWD/$start_script "$PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/runtime/$start_script"
163
164# Install icons
165install -Dm 644 runtime/pgAdmin4-0.png "$PKG/usr/share/icons/hicolor/256x256/apps/pgAdmin4.png"
166install -Dm 644 runtime/pgAdmin4-1.png "$PKG/usr/share/icons/hicolor/48x48/apps/pgAdmin4.png"
167install -Dm 644 runtime/pgAdmin4-2.png "$PKG/usr/share/icons/hicolor/32x32/apps/pgAdmin4.png"
168install -Dm 644 runtime/pgAdmin4-3.png "$PKG/usr/share/icons/hicolor/16x16/apps/pgAdmin4.png"
169
170# Install docs/ and web/ folders
171cp -a docs web "$PKG/usr/lib$LIBDIRSUFFIX/pgadmin4"
172
173# Add possibly needed config files
174touch $PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/web/config_local.py
175install -Dm 644 /dev/stdin "$PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/web/config_distro.py" <<END
176SERVER_MODE = False
177HELP_PATH = "/usr/lib$LIBDIRSUFFIX/pgadmin4/docs/en_US/_build/html/"
178END
179
180# Install .desktop file
181# Note we use out start_script to start the application
182install -Dm 755 /dev/stdin "$PKG/usr/share/applications/pgAdmin4.desktop" <<END
183[Desktop Entry]
184Encoding=UTF-8
185Name=pgAdmin 4
186Exec=/usr/lib$LIBDIRSUFFIX/pgadmin4/runtime/$start_script
187Icon=pgAdmin4
188Type=Application
189Categories=Application;Development;Database;
190MimeType=text/html
191DocPath=/usr/lib$LIBDIRSUFFIX/pgadmin4/docs/en_US/_build/html/index.html
192Comment=PostgreSQL Tools
193Keywords=database;db;sql;query;administration;development;
194END
195
196# Install scripts to /usr/bin
197# I am not sure about those scripts and their use; W.H
198install -Dm 755 /dev/stdin "$PKG/usr/bin/pgadmin4" <<END
199#!/bin/sh
200cd /usr/lib$LIBDIRSUFFIX/pgadmin4
201source $PY_VENV_ROOT/$APP_PVE/bin/activate
202exec runtime/pgAdmin4 "\$@"
203END
204
205install -Dm 755 /dev/stdin "$PKG/usr/bin/pgadmin4-server" <<END
206#!/bin/sh
207cd /usr/lib$LIBDIRSUFFIX/pgadmin4
208source $PY_VENV_ROOT/$APP_PVE/bin/activate
209python3 web/pgAdmin4.py "\$@"
210END
211
212mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
213cp -a LICENSE README $PKG/usr/doc/$PRGNAM-$VERSION
214cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
215
216mkdir -p $PKG/install
217cat $CWD/slack-desc > $PKG/install/slack-desc
218
219cd $PKG
220/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}
221
222# be nice
223deactivate
224cd $CWD
225
226exit $SUCCESS