/[gentoo-x86]/eclass/webapp.eclass
Gentoo

Contents of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download)
Fri Apr 23 14:19:35 2004 UTC (9 years, 11 months ago) by stuart
Branch: MAIN
Changes since 1.7: +25 -24 lines
sync with webapp-config 1.3

1 # Copyright 1999-2003 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.2 2003/12/22 23:15:46 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.3"
24
25 EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install
26
27 # ------------------------------------------------------------------------
28 # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
29 #
30 # Check whether a specified file exists within the image/ directory
31 # or not.
32 #
33 # @param $1 - file to look for
34 # @param $2 - prefix directory to use
35 # @return 0 on success, never returns on an error
36 # ------------------------------------------------------------------------
37
38 function webapp_checkfileexists ()
39 {
40 if [ ! -e $1 ]; then
41 msg="ebuild fault: file $1 not found"
42 eerror "$msg"
43 eerror "Please report this as a bug at http://bugs.gentoo.org/"
44 die "$msg"
45 fi
46 }
47
48 # ------------------------------------------------------------------------
49 # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
50 # ------------------------------------------------------------------------
51
52 function webapp_import_config ()
53 {
54 if [ -z "${MY_HTDOCSDIR}" ]; then
55 . /etc/conf.d/webapp-config
56 fi
57
58 if [ -z "${MY_HTDOCSDIR}" ]; then
59 libsh_edie "/etc/conf.d/webapp-config not imported"
60 fi
61 }
62
63 # ------------------------------------------------------------------------
64 # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY
65 #
66 # ------------------------------------------------------------------------
67
68 function webapp_strip_appdir ()
69 {
70 echo "$1" | sed -e "s|${D}${MY_APPDIR}/||g;"
71 }
72
73 function webapp_strip_d ()
74 {
75 echo "$1" | sed -e "s|${D}||g;"
76 }
77
78 function webapp_strip_cwd ()
79 {
80 echo "$1" | sed -e 's|/./|/|g;'
81 }
82
83 # ------------------------------------------------------------------------
84 # EXPORTED FUNCTION - FOR USE IN EBUILDS
85 #
86 # Identify a config file for a web-based application.
87 #
88 # @param $1 - config file
89 # ------------------------------------------------------------------------
90
91 function webapp_configfile ()
92 {
93 webapp_checkfileexists "$1" "$D"
94 local MY_FILE="`webapp_strip_appdir $1`"
95
96 einfo "(config) $MY_FILE"
97 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST}
98 }
99
100 # ------------------------------------------------------------------------
101 # EXPORTED FUNCTION - FOR USE IN EBUILDS
102 #
103 # Install a text file containing post-installation instructions.
104 #
105 # @param $1 - language code (use 'en' for now)
106 # @param $2 - the file to install
107 # ------------------------------------------------------------------------
108
109 function webapp_postinst_txt
110 {
111 webapp_checkfileexists "$2"
112
113 einfo "(rtfm) $2 (lang: $1)"
114 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt"
115 }
116
117 # ------------------------------------------------------------------------
118 # EXPORTED FUNCTION - FOR USE IN EBUILDS
119 #
120 # Identify a script file (usually, but not always PHP or Perl) which is
121 #
122 # Files in this list may be modified to #! the required CGI engine when
123 # installed by webapp-config tool in the future.
124 #
125 # @param $1 - the cgi engine to use
126 # @param $2 - the script file that could run under a cgi-bin
127 #
128 # ------------------------------------------------------------------------
129
130 function webapp_runbycgibin ()
131 {
132 webapp_checkfileexists "$2" "$D"
133 local MY_FILE="`webapp_strip_appdir $2`"
134 MY_FILE="`webapp_strip_cwd $MY_FILE`"
135
136 einfo "(cgi-bin) $1 - $MY_FILE"
137 echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST}
138 }
139
140 # ------------------------------------------------------------------------
141 # EXPORTED FUNCTION - FOR USE IN EBUILDS
142 #
143 # Identify a file which must be owned by the webserver's user:group
144 # settings.
145 #
146 # The ownership of the file is NOT set until the application is installed
147 # using the webapp-config tool.
148 #
149 # @param $1 - file to be owned by the webserver user:group combo
150 #
151 # ------------------------------------------------------------------------
152
153 function webapp_serverowned ()
154 {
155 webapp_checkfileexists "$1" "$D"
156 local MY_FILE="`webapp_strip_appdir $1`"
157
158 einfo "(server owned) $MY_FILE"
159 echo "$MY_FILE" >> ${D}${WA_SOLIST}
160 }
161
162 # ------------------------------------------------------------------------
163 # EXPORTED FUNCTION - FOR USE IN EBUILDS
164 #
165 #
166 # @param $1 - the db engine that the script is for
167 # (one of: mysql|postgres)
168 # @param $2 - the sql script to be installed
169 # @param $3 - the older version of the app that this db script
170 # will upgrade from
171 # (do not pass this option if your SQL script only creates
172 # a new db from scratch)
173 # ------------------------------------------------------------------------
174
175 function webapp_sqlscript ()
176 {
177 webapp_checkfileexists "$2"
178
179 # create the directory where this script will go
180 #
181 # scripts for specific database engines go into their own subdirectory
182 # just to keep things readable on the filesystem
183
184 if [ ! -d "${D}${MY_SQLSCRIPTSDIR}/$1" ]; then
185 mkdir -p "${D}${MY_SQLSCRIPTSDIR}/$1" || libsh_die "unable to create directory ${D}${MY_SQLSCRIPTSDIR}/$1"
186 fi
187
188 # warning:
189 #
190 # do NOT change the naming convention used here without changing all
191 # the other scripts that also rely upon these names
192
193 # are we dealing with an 'upgrade'-type script?
194 if [ -n "$3" ]; then
195 # yes we are
196 einfo "($1) upgrade script from ${PN}-${PVR} to $3"
197 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql
198 else
199 # no, we are not
200 einfo "($1) create script for ${PN}-${PVR}"
201 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql
202 fi
203 }
204
205 # ------------------------------------------------------------------------
206 # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER
207 # everything else has run
208 #
209 # For now, we just make sure that root owns everything, and that there
210 # are no setuid files. I'm sure this will change significantly before
211 # the final version!
212 # ------------------------------------------------------------------------
213
214 function webapp_src_install ()
215 {
216 chown -R root:root ${D}/
217 chmod -R u-s ${D}/
218 chmod -R g-s ${D}/
219
220 keepdir ${MY_PERSISTDIR}
221 fowners root:root ${MY_PERSISTDIR}
222 fperms 755 ${MY_PERSISTDIR}
223 }
224
225 # ------------------------------------------------------------------------
226 # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
227 # everything else has run
228 #
229 # If 'vhosts' USE flag is not set, auto-install this app
230 #
231 # ------------------------------------------------------------------------
232
233 function webapp_pkg_setup ()
234 {
235 # pull in the shared configuration file
236
237 . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file"
238
239 # are we emerging something that is already installed?
240
241 if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then
242 # yes we are
243 ewarn "Removing existing copy of ${PN}-${PVR}"
244 rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}"
245 fi
246
247 # create the directories that we need
248
249 mkdir -p ${D}${MY_HTDOCSDIR}
250 mkdir -p ${D}${MY_HOSTROOTDIR}
251 mkdir -p ${D}${MY_CGIBINDIR}
252 mkdir -p ${D}${MY_ICONSDIR}
253 mkdir -p ${D}${MY_ERRORSDIR}
254 mkdir -p ${D}${MY_SQLSCRIPTSDIR}
255 }
256
257 function webapp_pkg_postinst ()
258 {
259 G_HOSTNAME="localhost"
260 . /etc/vhosts/webapp-config
261
262 use vhosts || /usr/sbin/webapp-config -I -u root -d "${VHOST_ROOT}/htdocs/${PN}/" ${PN} ${PVR}
263 }

  ViewVC Help
Powered by ViewVC 1.1.20