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

Contents of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Fri Apr 23 09:10:29 2004 UTC (10 years, 4 months ago) by stuart
Branch: MAIN
Changes since 1.6: +1 -1 lines
Added webapp-config as a dependency

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

  ViewVC Help
Powered by ViewVC 1.1.20