| 1 |
# Copyright 1999-2004 Gentoo Technologies, Inc.
|
| 2 |
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
# $Header: /home/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.8 2004/04/23 14:19:35 stuart Exp $
|
| 4 |
#
|
| 5 |
# eclass/webapp.eclass
|
| 6 |
# Eclass for installing applications to run under a web server
|
| 7 |
#
|
| 8 |
# Part of the implementation of GLEP #11
|
| 9 |
#
|
| 10 |
# Author(s) Stuart Herbert <stuart@gentoo.org>
|
| 11 |
#
|
| 12 |
# ------------------------------------------------------------------------
|
| 13 |
#
|
| 14 |
# Please do not make modifications to this file without checking with a
|
| 15 |
# member of the web-apps herd first!
|
| 16 |
#
|
| 17 |
# ------------------------------------------------------------------------
|
| 18 |
|
| 19 |
ECLASS=webapp
|
| 20 |
INHERITED="$INHERITED $ECLASS"
|
| 21 |
SLOT="${PVR}"
|
| 22 |
IUSE="$IUSE vhosts"
|
| 23 |
DEPEND="$DEPEND >=net-www/webapp-config-1.6"
|
| 24 |
|
| 25 |
EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install
|
| 26 |
|
| 27 |
INSTALL_DIR="/$PN"
|
| 28 |
IS_UPGRADE=0
|
| 29 |
IS_REPLACE=0
|
| 30 |
|
| 31 |
# ------------------------------------------------------------------------
|
| 32 |
# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
|
| 33 |
#
|
| 34 |
# Check whether a specified file exists within the image/ directory
|
| 35 |
# or not.
|
| 36 |
#
|
| 37 |
# @param $1 - file to look for
|
| 38 |
# @param $2 - prefix directory to use
|
| 39 |
# @return 0 on success, never returns on an error
|
| 40 |
# ------------------------------------------------------------------------
|
| 41 |
|
| 42 |
function webapp_checkfileexists ()
|
| 43 |
{
|
| 44 |
local my_prefix
|
| 45 |
|
| 46 |
[ -n "$2" ] && my_prefix="$2/" || my_prefix=
|
| 47 |
|
| 48 |
if [ ! -e ${my_prefix}$1 ]; then
|
| 49 |
msg="ebuild fault: file $1 not found"
|
| 50 |
eerror "$msg"
|
| 51 |
eerror "Please report this as a bug at http://bugs.gentoo.org/"
|
| 52 |
die "$msg"
|
| 53 |
fi
|
| 54 |
}
|
| 55 |
|
| 56 |
# ------------------------------------------------------------------------
|
| 57 |
# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
|
| 58 |
# ------------------------------------------------------------------------
|
| 59 |
|
| 60 |
function webapp_check_installedat
|
| 61 |
{
|
| 62 |
local my_output
|
| 63 |
|
| 64 |
/usr/sbin/webapp-config --show-installed -h localhost -d $INSTALL_DIR 2> /dev/null
|
| 65 |
}
|
| 66 |
|
| 67 |
# ------------------------------------------------------------------------
|
| 68 |
# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
|
| 69 |
# ------------------------------------------------------------------------
|
| 70 |
|
| 71 |
function webapp_import_config ()
|
| 72 |
{
|
| 73 |
if [ -z "${MY_HTDOCSDIR}" ]; then
|
| 74 |
. /etc/conf.d/webapp-config
|
| 75 |
fi
|
| 76 |
|
| 77 |
if [ -z "${MY_HTDOCSDIR}" ]; then
|
| 78 |
libsh_edie "/etc/conf.d/webapp-config not imported"
|
| 79 |
fi
|
| 80 |
}
|
| 81 |
|
| 82 |
# ------------------------------------------------------------------------
|
| 83 |
# INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
|
| 84 |
#
|
| 85 |
# ------------------------------------------------------------------------
|
| 86 |
|
| 87 |
function webapp_strip_appdir ()
|
| 88 |
{
|
| 89 |
local my_stripped="$1"
|
| 90 |
echo "$1" | sed -e "s|${MY_APPDIR}/||g;"
|
| 91 |
}
|
| 92 |
|
| 93 |
function webapp_strip_d ()
|
| 94 |
{
|
| 95 |
echo "$1" | sed -e "s|${D}||g;"
|
| 96 |
}
|
| 97 |
|
| 98 |
function webapp_strip_cwd ()
|
| 99 |
{
|
| 100 |
local my_stripped="$1"
|
| 101 |
echo "$1" | sed -e 's|/./|/|g;'
|
| 102 |
}
|
| 103 |
|
| 104 |
# ------------------------------------------------------------------------
|
| 105 |
# EXPORTED FUNCTION - FOR USE IN EBUILDS
|
| 106 |
#
|
| 107 |
# Identify a config file for a web-based application.
|
| 108 |
#
|
| 109 |
# @param $1 - config file
|
| 110 |
# ------------------------------------------------------------------------
|
| 111 |
|
| 112 |
function webapp_configfile ()
|
| 113 |
{
|
| 114 |
webapp_checkfileexists "$1" "$D"
|
| 115 |
echo $1
|
| 116 |
local MY_FILE="`webapp_strip_appdir $1`"
|
| 117 |
echo $MY_FILE
|
| 118 |
|
| 119 |
einfo "(config) $MY_FILE"
|
| 120 |
echo "$MY_FILE" >> ${D}${WA_CONFIGLIST}
|
| 121 |
}
|
| 122 |
|
| 123 |
# ------------------------------------------------------------------------
|
| 124 |
# EXPORTED FUNCTION - FOR USE IN EBUILDS
|
| 125 |
#
|
| 126 |
# Install a text file containing post-installation instructions.
|
| 127 |
#
|
| 128 |
# @param $1 - language code (use 'en' for now)
|
| 129 |
# @param $2 - the file to install
|
| 130 |
# ------------------------------------------------------------------------
|
| 131 |
|
| 132 |
function webapp_postinst_txt
|
| 133 |
{
|
| 134 |
webapp_checkfileexists "$2"
|
| 135 |
|
| 136 |
einfo "(rtfm) $2 (lang: $1)"
|
| 137 |
cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt"
|
| 138 |
}
|
| 139 |
|
| 140 |
# ------------------------------------------------------------------------
|
| 141 |
# EXPORTED FUNCTION - FOR USE IN EBUILDS
|
| 142 |
#
|
| 143 |
# Identify a script file (usually, but not always PHP or Perl) which is
|
| 144 |
#
|
| 145 |
# Files in this list may be modified to #! the required CGI engine when
|
| 146 |
# installed by webapp-config tool in the future.
|
| 147 |
#
|
| 148 |
# @param $1 - the cgi engine to use
|
| 149 |
# @param $2 - the script file that could run under a cgi-bin
|
| 150 |
#
|
| 151 |
# ------------------------------------------------------------------------
|
| 152 |
|
| 153 |
function webapp_runbycgibin ()
|
| 154 |
{
|
| 155 |
webapp_checkfileexists "$2" "$D"
|
| 156 |
local MY_FILE="`webapp_strip_appdir $2`"
|
| 157 |
MY_FILE="`webapp_strip_cwd $MY_FILE`"
|
| 158 |
|
| 159 |
einfo "(cgi-bin) $1 - $MY_FILE"
|
| 160 |
echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST}
|
| 161 |
}
|
| 162 |
|
| 163 |
# ------------------------------------------------------------------------
|
| 164 |
# EXPORTED FUNCTION - FOR USE IN EBUILDS
|
| 165 |
#
|
| 166 |
# Identify a file which must be owned by the webserver's user:group
|
| 167 |
# settings.
|
| 168 |
#
|
| 169 |
# The ownership of the file is NOT set until the application is installed
|
| 170 |
# using the webapp-config tool.
|
| 171 |
#
|
| 172 |
# @param $1 - file to be owned by the webserver user:group combo
|
| 173 |
#
|
| 174 |
# ------------------------------------------------------------------------
|
| 175 |
|
| 176 |
function webapp_serverowned ()
|
| 177 |
{
|
| 178 |
webapp_checkfileexists "$1" "$D"
|
| 179 |
local MY_FILE="`webapp_strip_appdir $1`"
|
| 180 |
|
| 181 |
einfo "(server owned) $MY_FILE"
|
| 182 |
echo "$MY_FILE" >> ${D}${WA_SOLIST}
|
| 183 |
}
|
| 184 |
|
| 185 |
# ------------------------------------------------------------------------
|
| 186 |
# EXPORTED FUNCTION - FOR USE IN EBUILDS
|
| 187 |
#
|
| 188 |
#
|
| 189 |
# @param $1 - the db engine that the script is for
|
| 190 |
# (one of: mysql|postgres)
|
| 191 |
# @param $2 - the sql script to be installed
|
| 192 |
# @param $3 - the older version of the app that this db script
|
| 193 |
# will upgrade from
|
| 194 |
# (do not pass this option if your SQL script only creates
|
| 195 |
# a new db from scratch)
|
| 196 |
# ------------------------------------------------------------------------
|
| 197 |
|
| 198 |
function webapp_sqlscript ()
|
| 199 |
{
|
| 200 |
webapp_checkfileexists "$2"
|
| 201 |
|
| 202 |
# create the directory where this script will go
|
| 203 |
#
|
| 204 |
# scripts for specific database engines go into their own subdirectory
|
| 205 |
# just to keep things readable on the filesystem
|
| 206 |
|
| 207 |
if [ ! -d "${D}${MY_SQLSCRIPTSDIR}/$1" ]; then
|
| 208 |
mkdir -p "${D}${MY_SQLSCRIPTSDIR}/$1" || libsh_die "unable to create directory ${D}${MY_SQLSCRIPTSDIR}/$1"
|
| 209 |
fi
|
| 210 |
|
| 211 |
# warning:
|
| 212 |
#
|
| 213 |
# do NOT change the naming convention used here without changing all
|
| 214 |
# the other scripts that also rely upon these names
|
| 215 |
|
| 216 |
# are we dealing with an 'upgrade'-type script?
|
| 217 |
if [ -n "$3" ]; then
|
| 218 |
# yes we are
|
| 219 |
einfo "($1) upgrade script from ${PN}-${PVR} to $3"
|
| 220 |
cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql
|
| 221 |
else
|
| 222 |
# no, we are not
|
| 223 |
einfo "($1) create script for ${PN}-${PVR}"
|
| 224 |
cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql
|
| 225 |
fi
|
| 226 |
}
|
| 227 |
|
| 228 |
# ------------------------------------------------------------------------
|
| 229 |
# EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
|
| 230 |
# everything else has run
|
| 231 |
#
|
| 232 |
# For now, we just make sure that root owns everything, and that there
|
| 233 |
# are no setuid files. I'm sure this will change significantly before
|
| 234 |
# the final version!
|
| 235 |
# ------------------------------------------------------------------------
|
| 236 |
|
| 237 |
function webapp_src_install ()
|
| 238 |
{
|
| 239 |
chown -R root:root ${D}/
|
| 240 |
chmod -R u-s ${D}/
|
| 241 |
chmod -R g-s ${D}/
|
| 242 |
|
| 243 |
keepdir ${MY_PERSISTDIR}
|
| 244 |
fowners root:root ${MY_PERSISTDIR}
|
| 245 |
fperms 755 ${MY_PERSISTDIR}
|
| 246 |
|
| 247 |
HAS_webapp_src_install=1
|
| 248 |
}
|
| 249 |
|
| 250 |
# ------------------------------------------------------------------------
|
| 251 |
# EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
|
| 252 |
# everything else has run
|
| 253 |
#
|
| 254 |
# If 'vhosts' USE flag is not set, auto-install this app
|
| 255 |
#
|
| 256 |
# ------------------------------------------------------------------------
|
| 257 |
|
| 258 |
function webapp_pkg_setup ()
|
| 259 |
{
|
| 260 |
# add sanity checks here
|
| 261 |
|
| 262 |
if [ "$SLOT+" != "${PVR}+" ]; then
|
| 263 |
die "ebuild sets SLOT, overrides webapp.eclass"
|
| 264 |
fi
|
| 265 |
|
| 266 |
# pull in the shared configuration file
|
| 267 |
|
| 268 |
. /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file"
|
| 269 |
}
|
| 270 |
|
| 271 |
function webapp_getinstalltype ()
|
| 272 |
{
|
| 273 |
# are we emerging something that is already installed?
|
| 274 |
|
| 275 |
if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then
|
| 276 |
# yes we are
|
| 277 |
ewarn "Removing existing copy of ${PN}-${PVR}"
|
| 278 |
rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}"
|
| 279 |
fi
|
| 280 |
|
| 281 |
# or are we upgrading?
|
| 282 |
|
| 283 |
if ! use vhosts ; then
|
| 284 |
# we only run webapp-config if vhosts USE flag is not set
|
| 285 |
|
| 286 |
local my_output
|
| 287 |
|
| 288 |
my_output="`webapp_check_installedat`"
|
| 289 |
|
| 290 |
if [ "$?" = "0" ] ; then
|
| 291 |
# something is already installed there
|
| 292 |
#
|
| 293 |
# make sure it isn't the same version
|
| 294 |
|
| 295 |
local my_pn="`echo $my_output | awk '{ print $1 }'`"
|
| 296 |
local my_pvr="`echo $my_output | awk '{ print $2 }'`"
|
| 297 |
|
| 298 |
REMOVE_PKG="${my_pn}-${my_pvr}"
|
| 299 |
|
| 300 |
if [ "$my_pn" == "$PN" ]; then
|
| 301 |
if [ "$my_pvr" != "$PVR" ]; then
|
| 302 |
einfo "This is an upgrade"
|
| 303 |
IS_UPGRADE=1
|
| 304 |
else
|
| 305 |
einfo "This is a re-installation"
|
| 306 |
IS_REPLACE=1
|
| 307 |
fi
|
| 308 |
fi
|
| 309 |
fi
|
| 310 |
fi
|
| 311 |
}
|
| 312 |
|
| 313 |
function webapp_src_preinst ()
|
| 314 |
{
|
| 315 |
# create the directories that we need
|
| 316 |
|
| 317 |
dodir ${MY_HTDOCSDIR}
|
| 318 |
dodir ${MY_HOSTROOTDIR}
|
| 319 |
dodir ${MY_CGIBINDIR}
|
| 320 |
dodir ${MY_ICONSDIR}
|
| 321 |
dodir ${MY_ERRORSDIR}
|
| 322 |
dodir ${MY_SQLSCRIPTSDIR}
|
| 323 |
}
|
| 324 |
|
| 325 |
function webapp_pkg_postinst ()
|
| 326 |
{
|
| 327 |
# sanity checks, to catch bugs in the ebuild
|
| 328 |
|
| 329 |
if [ "$HAS_webapp_src_install+" == "+" ]; then
|
| 330 |
eerror
|
| 331 |
eerror "This ebuild did not call webapp_src_install() at the end"
|
| 332 |
eerror "of the src_install() function"
|
| 333 |
eerror
|
| 334 |
eerror "Please log a bug on http://bugs.gentoo.org"
|
| 335 |
eerror
|
| 336 |
eerror "You should use emerge -C to remove this package, as the"
|
| 337 |
eerror "installation is incomplete"
|
| 338 |
eerror
|
| 339 |
die "Ebuild did not call webapp_src_install() - report to http://bugs.gentoo.org"
|
| 340 |
fi
|
| 341 |
|
| 342 |
# if 'vhosts' is not set in your USE flags, we install a copy of
|
| 343 |
# this application in /var/www/localhost/htdocs/${PN}/ for you
|
| 344 |
|
| 345 |
if ! use vhosts ; then
|
| 346 |
echo
|
| 347 |
einfo "vhosts USE flag not set - auto-installing using webapp-config"
|
| 348 |
|
| 349 |
webapp_getinstalltype
|
| 350 |
|
| 351 |
G_HOSTNAME="localhost"
|
| 352 |
. /etc/vhosts/webapp-config
|
| 353 |
|
| 354 |
local my_mode=-I
|
| 355 |
|
| 356 |
if [ "$IS_REPLACE" = "1" ]; then
|
| 357 |
einfo "${PN}-${PVR} is already installed - replacing"
|
| 358 |
/usr/sbin/webapp-config -C -d "$INSTALL_DIR"
|
| 359 |
elif [ "$IS_UPGRADE" = "1" ]; then
|
| 360 |
einfo "$REMOVE_PKG is already installed - upgrading"
|
| 361 |
my_mode=-U
|
| 362 |
else
|
| 363 |
einfo "${PN}-${PVR} is not installed - using install mode"
|
| 364 |
fi
|
| 365 |
|
| 366 |
my_cmd="/usr/sbin/webapp-config $my_mode -h localhost -u root -d $INSTALL_DIR ${PN} ${PVR}"
|
| 367 |
einfo "Running $my_cmd"
|
| 368 |
$my_cmd
|
| 369 |
|
| 370 |
# remove the old version
|
| 371 |
#
|
| 372 |
# why do we do this? well ...
|
| 373 |
#
|
| 374 |
# normally, emerge -u installs a new version and then removes the
|
| 375 |
# old version. however, if the new version goes into a different
|
| 376 |
# slot to the old version, then the old version gets left behind
|
| 377 |
#
|
| 378 |
# if USE=-vhosts, then we want to remove the old version, because
|
| 379 |
# the user is relying on portage to do the magical thing for it
|
| 380 |
|
| 381 |
if [ "$IS_UPGRADE" = "1" ] ; then
|
| 382 |
einfo "Removing old version $REMOVE_PKG"
|
| 383 |
|
| 384 |
echo emerge -C $CATEGORY/$REMOVE_PKG
|
| 385 |
fi
|
| 386 |
fi
|
| 387 |
|
| 388 |
return 0
|
| 389 |
}
|