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

Contents of /eclass/webapp.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Wed Apr 14 16:02:37 2004 UTC (10 years, 5 months ago) by stuart
Branch: MAIN
Changes since 1.4: +29 -14 lines
Bump to eclass for webapp-config-1.1

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

  ViewVC Help
Powered by ViewVC 1.1.20