· 5 years ago · Jun 20, 2020, 06:50 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 06/18/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# We utilise python3 by creating Python Virtual Environment under /usr/local
31# directory. We use python3 pip3 command to install required python modules for
32# pgAmin4 in the Virtual Environment directory.
33# PYTHONPATH = /usr/local/pve/pgAdmin4-pve/lib64/python3.8/site-packages
34
35CWD=$(pwd)
36PRGNAM=pgadmin4
37VERSION=${VERSION:-4.22}
38BUILD=${BUILD:-4}
39TAG=${TAG:-_wh}
40TMP=${TMP:-/tmp}
41PKG=$TMP/package-$PRGNAM
42OUTPUT=${OUTPUT:-/tmp}
43SRC=$TMP/$PRGNAM-$VERSION
44
45if [ -z "$ARCH" ]; then
46 case "$( uname -m )" in
47 i?86) ARCH=i586 ;;
48 arm*) ARCH=arm ;;
49 *) ARCH=$( uname -m ) ;;
50 esac
51fi
52
53if [ "$ARCH" = "i586" ]; then
54 SLKCFLAGS="-O2 -march=i586 -mtune=i686"
55 LIBDIRSUFFIX=""
56elif [ "$ARCH" = "i686" ]; then
57 SLKCFLAGS="-O2 -march=i686 -mtune=i686"
58 LIBDIRSUFFIX=""
59elif [ "$ARCH" = "x86_64" ]; then
60 SLKCFLAGS="-O2 -fPIC"
61 LIBDIRSUFFIX="64"
62else
63 SLKCFLAGS="-O2"
64 LIBDIRSUFFIX=""
65fi
66
67# Step one: check for postgresql package installation - bailout if not found.
68# Assume slackpkg use. Is postgresql package installed?
69PG_PKG=$(ls /var/lib/pkgtools/packages/postgresql*)
70
71# empty string from ls command above indecates missing PostgreSQL package
72if [ -z "$PG_PKG" ]; then
73 echo "PostgreSQL package not found. Please install PostgreSQL with"
74 echo "slackpkg. Exiting!"
75 exit 1;
76fi
77
78# pg_config file is usually installed in postgresql bin directory
79PG_BIN_PART1=$(cat $PG_PKG | egrep "*/bin/pg_config")
80
81# empty string means missed up installation!
82if [ -z "$PG_BIN_PART1" ]; then
83 echo "ERROR: Could not get path for PostgreSQL bin directory."
84 echo "Exiting!"
85 exit 1;
86fi
87
88# prepend leading slash to directory
89SLASH=/
90
91# with leading slash this is pg_config file which MUST exist in file system
92if [ ! -f "$SLASH$PG_BIN_PART1" ]; then
93 echo "ERROR: Could not find postgresql pg_config configuration file."
94 echo "Ensure that postgresql package is propely installed with slackware"
95 echo "package tools. Exiting."
96 exit 1
97fi
98# seems good postgresql package installation.
99
100# Step 2: run the build in python virtual environment
101PVE_ROOT=/usr/local/pve
102APP_PVE=$PVE_ROOT/pgAdmin4-pve
103
104# activate python virtual environment
105if [ ! -f $APP_PVE/bin/activate ]; then
106 echo ""
107 echo "Missing or wrong path to application Python Virtual Environment!"
108 echo "This slackware build script rquires Python Virtual Environment to be"
109 echo "initialed by \"mk-pve.sh\" found with package source."
110 echo "Please run the script \"mk-pve.sh\" before this one."
111 echo ""
112 exit 1;
113fi
114
115source $APP_PVE/bin/activate
116
117# Save and check return value from above!
118RET_VALUE=$?
119SUCCESS=0
120
121if [ $RET_VALUE -ne $SUCCESS ]; then
122 echo "ERROR: Could not activate Python Virtual Environment!"
123 echo "Make sure to run mk-pve.sh script to set it up."
124 echo "Exiting"
125 exit 1
126fi
127
128rm -rf $PKG
129mkdir -p $TMP $PKG $OUTPUT
130cd $TMP
131rm -rf $PRGNAM-$VERSION
132tar xvzf $CWD/$PRGNAM-$VERSION.tar.gz
133
134# move to source root
135cd $SRC
136
137# set sane permissions
138chown -R root:root .
139find -L . \
140 \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
141 -o -perm 511 \) -exec chmod 755 {} \; -o \
142 \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
143 -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
144
145# use python virtual environment paths in runtime/Server.cpp
146# please note that developers claim that paths are NOT hard coded
147patch -u runtime/Server.cpp -i $CWD/pve-paths.patch
148
149# use python virtual environment paths in runtime/ConfigWindow.ui
150# You NEED to manually enter PYTHONPATH on first use!
151PYTHONVERSION="$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')"
152sed -E "s|/usr/pgadmin4/web|/usr/lib$LIBDIRSUFFIX/pgadmin4/web|g;
153 s|/usr/pgadmin4/lib/python2\.7|/usr/local/pve/pgAdmin4-pve/lib$LIBDIRSUFFIX/python$PYTHONVERSION|g" \
154 -i runtime/ConfigWindow.ui
155
156convert +set date:create +set date:modify runtime/pgAdmin4.{ico,png}
157
158export PGADMIN_PYTHON_DIR=/usr
159
160cd runtime
161
162qmake-qt5
163make
164
165# make documentation
166cd $SRC
167make docs
168
169# Make javascripts bundles? Requires yarn v1.22.4 and nodejs v14.4.0
170if [ "${BUNDLE:-no}" = "yes" ]; then
171 echo ""
172 echo "Building javascripts bundles ..."
173 make install-node
174 make bundle
175
176else
177 echo ""
178 echo "Skipping bundles making! Pass BUNDLE=yes to script to make them."
179 echo ""
180fi
181
182# done compiling ... copy files and directories to package
183
184# Install web and docs directories
185mkdir -p $PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/docs/en_US
186cp -a web "$PKG/usr/lib$LIBDIRSUFFIX/pgadmin4"
187cp -a docs/en_US/_build/html "$PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/docs/en_US"
188
189# file provided with this slackbuild "pgAdmin4-pve.sh" is a simple wrapper
190# script to start pgAdimin4 executable in python virtual environment
191start_script=pgAdmin4-pve.sh
192
193# Install binary and scripts
194install -Dm 755 runtime/pgAdmin4 "$PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/runtime/pgAdmin4"
195install -Dm 755 $CWD/$start_script "$PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/runtime/$start_script"
196install -Dm 755 /dev/stdin "$PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/runtime/pgadmin4-initial-server" <<END
197#!/bin/sh
198# run script once to initial server in desktop mode
199source $APP_PVE/bin/activate
200python3 /usr/lib$LIBDIRSUFFIX/pgadmin4/web/setup.py
201END
202
203# Install icons
204install -Dm 644 runtime/pgAdmin4-0.png "$PKG/usr/share/icons/hicolor/256x256/apps/pgAdmin4.png"
205install -Dm 644 runtime/pgAdmin4-1.png "$PKG/usr/share/icons/hicolor/48x48/apps/pgAdmin4.png"
206install -Dm 644 runtime/pgAdmin4-2.png "$PKG/usr/share/icons/hicolor/32x32/apps/pgAdmin4.png"
207install -Dm 644 runtime/pgAdmin4-3.png "$PKG/usr/share/icons/hicolor/16x16/apps/pgAdmin4.png"
208
209# needed config files
210install -Dm 644 /dev/stdin "$PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/web/config_distro.py" <<END
211SERVER_MODE = False
212HELP_PATH = "/usr/lib$LIBDIRSUFFIX/pgadmin4/docs/en_US/html"
213END
214cp $PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/web/config_distro.py \
215 $PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/web/config_local.py
216
217# remove not needed
218rm -rf $PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/web/regression
219rm -rf "$PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/docs/en_US/html/_sources"
220
221# remove __pycache__ and test(s) directories
222find $PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/web -name "__pycache__" -type d -print0 | xargs -0 rm -rf
223find $PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/web -name "test" -type d -print0 | xargs -0 rm -rf
224find $PKG/usr/lib$LIBDIRSUFFIX/pgadmin4/web -name "tests" -type d -print0 | xargs -0 rm -rf
225
226# Install desktop file
227# Note we use our start_script to start the application
228install -Dm 755 /dev/stdin "$PKG/usr/share/applications/pgAdmin4.desktop" <<END
229[Desktop Entry]
230Encoding=UTF-8
231Name=pgAdmin 4
232Exec=/usr/lib$LIBDIRSUFFIX/pgadmin4/runtime/$start_script
233Icon=pgAdmin4
234Type=Application
235Categories=Application;Development;Database;
236MimeType=text/html
237DocPath=/usr/lib$LIBDIRSUFFIX/pgadmin4/docs/en_US/html
238Comment=PostgreSQL Tools
239Keywords=database;db;sql;query;administration;development;
240END
241
242# I do copy ALL package-making files
243mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
244cp -a LICENSE README $PKG/usr/doc/$PRGNAM-$VERSION
245cp $CWD/$PRGNAM.SlackBuild $PKG/usr/doc/$PRGNAM-$VERSION/
246cp $CWD/pgAdmin4-pve.sh $PKG/usr/doc/$PRGNAM-$VERSION/
247cp $CWD/mk-pve.sh $PKG/usr/doc/$PRGNAM-$VERSION/
248cp $CWD/pve-paths.patch $PKG/usr/doc/$PRGNAM-$VERSION/
249cp $CWD/pgadmin4.conf $PKG/usr/doc/$PRGNAM-$VERSION
250
251mkdir -p $PKG/install
252cat $CWD/slack-desc > $PKG/install/slack-desc
253
254cd $PKG
255/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}
256
257# be nice
258deactivate
259cd $CWD
260
261exit $SUCCESS