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

Contents of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Wed Mar 3 18:44:34 2004 UTC (10 years, 4 months ago) by stuart
Branch: MAIN
Changes since 1.3: +9 -7 lines
Removed BETA notice; fix for repoman scans when webapp-config not installed

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

  ViewVC Help
Powered by ViewVC 1.1.20