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

Contents of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log


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

1 stuart 1.1 # Copyright 1999-2003 Gentoo Technologies, Inc.
2     # Distributed under the terms of the GNU General Public License v2
3 stuart 1.8 # $Header: /home/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.2 2003/12/22 23:15:46 stuart Exp $
4 stuart 1.1 #
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 stuart 1.8 DEPEND="$DEPEND >=net-www/webapp-config-1.3"
24 stuart 1.1
25 stuart 1.5 EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install
26 stuart 1.1
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 stuart 1.3 # @param $2 - prefix directory to use
35 stuart 1.1 # @return 0 on success, never returns on an error
36     # ------------------------------------------------------------------------
37    
38     function webapp_checkfileexists ()
39     {
40 stuart 1.3 if [ ! -e $1 ]; then
41     msg="ebuild fault: file $1 not found"
42 stuart 1.1 eerror "$msg"
43     eerror "Please report this as a bug at http://bugs.gentoo.org/"
44     die "$msg"
45     fi
46     }
47    
48     # ------------------------------------------------------------------------
49 stuart 1.3 # 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 stuart 1.1 #
66     # ------------------------------------------------------------------------
67    
68 stuart 1.3 function webapp_strip_appdir ()
69     {
70 stuart 1.8 echo "$1" | sed -e "s|${D}${MY_APPDIR}/||g;"
71 stuart 1.3 }
72    
73     function webapp_strip_d ()
74     {
75     echo "$1" | sed -e "s|${D}||g;"
76     }
77    
78     function webapp_strip_cwd ()
79 stuart 1.1 {
80 stuart 1.3 echo "$1" | sed -e 's|/./|/|g;'
81 stuart 1.1 }
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 stuart 1.3 webapp_checkfileexists "$1" "$D"
94     local MY_FILE="`webapp_strip_appdir $1`"
95    
96     einfo "(config) $MY_FILE"
97 stuart 1.8 echo "$MY_FILE" >> ${D}${WA_CONFIGLIST}
98 stuart 1.1 }
99    
100     # ------------------------------------------------------------------------
101     # EXPORTED FUNCTION - FOR USE IN EBUILDS
102     #
103 stuart 1.5 # 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 stuart 1.8 cp "$2" "${D}${MY_APPDIR}/postinst-$1.txt"
115 stuart 1.5 }
116    
117     # ------------------------------------------------------------------------
118     # EXPORTED FUNCTION - FOR USE IN EBUILDS
119     #
120 stuart 1.1 # 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 stuart 1.3 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 stuart 1.8 echo "$1 $MY_FILE" >> ${D}${WA_RUNBYCGIBINLIST}
138 stuart 1.3 }
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 stuart 1.8 echo "$MY_FILE" >> ${D}${WA_SOLIST}
160 stuart 1.3 }
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 stuart 1.8 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 stuart 1.3 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 stuart 1.8 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${3}_to_${PVR}.sql
198 stuart 1.3 else
199     # no, we are not
200     einfo "($1) create script for ${PN}-${PVR}"
201 stuart 1.8 cp $2 ${D}${MY_SQLSCRIPTSDIR}/$1/${PVR}_create.sql
202 stuart 1.3 fi
203 stuart 1.1 }
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 stuart 1.5
220     keepdir ${MY_PERSISTDIR}
221     fowners root:root ${MY_PERSISTDIR}
222     fperms 755 ${MY_PERSISTDIR}
223 stuart 1.1 }
224    
225     # ------------------------------------------------------------------------
226 stuart 1.3 # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER
227 stuart 1.1 # 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 stuart 1.8 # pull in the shared configuration file
236    
237     . /etc/vhosts/webapp-config || die "Unable to open /etc/vhosts/webapp-config file"
238 stuart 1.6
239 stuart 1.3 # are we emerging something that is already installed?
240    
241 stuart 1.8 if [ -d "${D}${MY_APPROOT}/${MY_APPSUFFIX}" ]; then
242 stuart 1.3 # yes we are
243     ewarn "Removing existing copy of ${PN}-${PVR}"
244 stuart 1.8 rm -rf "${D}${MY_APPROOT}/${MY_APPSUFFIX}"
245 stuart 1.3 fi
246    
247     # create the directories that we need
248    
249 stuart 1.8 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 stuart 1.3 }
256    
257 stuart 1.5 function webapp_pkg_postinst ()
258 stuart 1.3 {
259 stuart 1.8 G_HOSTNAME="localhost"
260     . /etc/vhosts/webapp-config
261    
262 stuart 1.5 use vhosts || /usr/sbin/webapp-config -I -u root -d "${VHOST_ROOT}/htdocs/${PN}/" ${PN} ${PVR}
263 stuart 1.2 }

  ViewVC Help
Powered by ViewVC 1.1.20