| 1 | # Copyright 1999-2003 Gentoo Technologies, Inc. |
1 | # Copyright 1999-2003 Gentoo Technologies, Inc. |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/webapp.eclass,v 1.1 2003/10/07 21:54:46 stuart Exp $ |
|
|
| 4 | # |
3 | # |
| 5 | # eclass/webapp.eclass |
4 | # eclass/webapp.eclass |
| 6 | # Eclass for installing applications to run under a web server |
5 | # Eclass for installing applications to run under a web server |
| 7 | # |
6 | # |
| 8 | # Part of the implementation of GLEP #11 |
7 | # Part of the implementation of GLEP #11 |
| … | |
… | |
| 13 | # |
12 | # |
| 14 | # Please do not make modifications to this file without checking with a |
13 | # Please do not make modifications to this file without checking with a |
| 15 | # member of the web-apps herd first! |
14 | # member of the web-apps herd first! |
| 16 | # |
15 | # |
| 17 | # ------------------------------------------------------------------------ |
16 | # ------------------------------------------------------------------------ |
| 18 | # |
|
|
| 19 | # THIS IS A BETA RELEASE ONLY. ALL DETAILS ARE SUBJECT TO CHANGE BEFORE |
|
|
| 20 | # WE ARE READY TO START PORTING EVERYTHING TO THIS ECLASS |
|
|
| 21 | # |
|
|
| 22 | # ------------------------------------------------------------------------ |
|
|
| 23 | |
17 | |
| 24 | ECLASS=webapp |
18 | ECLASS=webapp |
| 25 | INHERITED="$INHERITED $ECLASS" |
19 | INHERITED="$INHERITED $ECLASS" |
| 26 | #DEPEND="${DEPEND} net-www/apache" |
|
|
| 27 | SLOT="${PVR}" |
20 | SLOT="${PVR}" |
| 28 | IUSE="$IUSE vhosts" |
21 | IUSE="$IUSE vhosts" |
|
|
22 | DEPEND="$DEPEND net-www/webapp-config" |
| 29 | |
23 | |
| 30 | if [ -f /usr/share/webapp-config/settings.sh ] ; then |
|
|
| 31 | . /usr/share/webapp-config/settings.sh |
|
|
| 32 | fi |
|
|
| 33 | |
|
|
| 34 | EXPORT_FUNCTIONS pkg_setup src_install |
24 | EXPORT_FUNCTIONS pkg_postinst pkg_setup src_install |
| 35 | |
25 | |
| 36 | # ------------------------------------------------------------------------ |
26 | # ------------------------------------------------------------------------ |
| 37 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
27 | # INTERNAL FUNCTION - USED BY THIS ECLASS ONLY |
| 38 | # |
28 | # |
| 39 | # Check whether a specified file exists within the image/ directory |
29 | # Check whether a specified file exists within the image/ directory |
| 40 | # or not. |
30 | # or not. |
| 41 | # |
31 | # |
| 42 | # @param $1 - file to look for |
32 | # @param $1 - file to look for |
|
|
33 | # @param $2 - prefix directory to use |
| 43 | # @return 0 on success, never returns on an error |
34 | # @return 0 on success, never returns on an error |
| 44 | # ------------------------------------------------------------------------ |
35 | # ------------------------------------------------------------------------ |
| 45 | |
36 | |
| 46 | function webapp_checkfileexists () |
37 | function webapp_checkfileexists () |
| 47 | { |
38 | { |
| 48 | if [ ! -e ${D}/$1 ]; then |
39 | if [ ! -e $1 ]; then |
| 49 | msg="ebuild fault: file $1 not found in ${D}" |
40 | msg="ebuild fault: file $1 not found" |
| 50 | eerror "$msg" |
41 | eerror "$msg" |
| 51 | eerror "Please report this as a bug at http://bugs.gentoo.org/" |
42 | eerror "Please report this as a bug at http://bugs.gentoo.org/" |
| 52 | die "$msg" |
43 | die "$msg" |
| 53 | fi |
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 |
| 54 | } |
137 | } |
| 55 | |
138 | |
| 56 | # ------------------------------------------------------------------------ |
139 | # ------------------------------------------------------------------------ |
| 57 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
140 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 58 | # |
141 | # |
| … | |
… | |
| 66 | # |
149 | # |
| 67 | # ------------------------------------------------------------------------ |
150 | # ------------------------------------------------------------------------ |
| 68 | |
151 | |
| 69 | function webapp_serverowned () |
152 | function webapp_serverowned () |
| 70 | { |
153 | { |
| 71 | webapp_checkfileexists $1 |
154 | webapp_checkfileexists "$1" "$D" |
|
|
155 | local MY_FILE="`webapp_strip_appdir $1`" |
|
|
156 | |
|
|
157 | einfo "(server owned) $MY_FILE" |
| 72 | echo "$1" >> $WA_SOLIST |
158 | echo "$MY_FILE" >> $WA_SOLIST |
| 73 | } |
159 | } |
| 74 | |
160 | |
| 75 | # ------------------------------------------------------------------------ |
161 | # ------------------------------------------------------------------------ |
| 76 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
162 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
| 77 | # |
163 | # |
| 78 | # Identify a config file for a web-based application. |
|
|
| 79 | # |
164 | # |
| 80 | # @param $1 - config file |
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) |
| 81 | # ------------------------------------------------------------------------ |
172 | # ------------------------------------------------------------------------ |
| 82 | |
173 | |
| 83 | function webapp_configfile () |
174 | function webapp_sqlscript () |
| 84 | { |
175 | { |
| 85 | webapp_checkfileexists $1 |
|
|
| 86 | echo "$1" >> $WA_CONFIGLIST |
|
|
| 87 | } |
|
|
| 88 | |
|
|
| 89 | # ------------------------------------------------------------------------ |
|
|
| 90 | # EXPORTED FUNCTION - FOR USE IN EBUILDS |
|
|
| 91 | # |
|
|
| 92 | # Identify a script file (usually, but not always PHP or Perl) which is |
|
|
| 93 | # |
|
|
| 94 | # Files in this list may be modified to #! the required CGI engine when |
|
|
| 95 | # installed by webapp-config tool in the future. |
|
|
| 96 | # |
|
|
| 97 | # @param $1 - the cgi engine to use |
|
|
| 98 | # @param $2 - the script file that could run under a cgi-bin |
|
|
| 99 | # |
|
|
| 100 | # ------------------------------------------------------------------------ |
|
|
| 101 | |
|
|
| 102 | function webapp_runbycgibin () |
|
|
| 103 | { |
|
|
| 104 | webapp_checkfileexists $2 |
176 | webapp_checkfileexists "$2" |
| 105 | echo "$1 $2" >> $WA_RUNBYCGIBINLIST |
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 |
| 106 | } |
202 | } |
| 107 | |
203 | |
| 108 | # ------------------------------------------------------------------------ |
204 | # ------------------------------------------------------------------------ |
| 109 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
205 | # EXPORTED FUNCTION - call from inside your ebuild's src_install AFTER |
| 110 | # everything else has run |
206 | # everything else has run |
| … | |
… | |
| 117 | function webapp_src_install () |
213 | function webapp_src_install () |
| 118 | { |
214 | { |
| 119 | chown -R root:root ${D}/ |
215 | chown -R root:root ${D}/ |
| 120 | chmod -R u-s ${D}/ |
216 | chmod -R u-s ${D}/ |
| 121 | chmod -R g-s ${D}/ |
217 | chmod -R g-s ${D}/ |
| 122 | } |
|
|
| 123 | |
218 | |
|
|
219 | keepdir ${MY_PERSISTDIR} |
|
|
220 | fowners root:root ${MY_PERSISTDIR} |
|
|
221 | fperms 755 ${MY_PERSISTDIR} |
|
|
222 | } |
|
|
223 | |
| 124 | # ------------------------------------------------------------------------ |
224 | # ------------------------------------------------------------------------ |
| 125 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_setup AFTER |
225 | # EXPORTED FUNCTION - call from inside your ebuild's pkg_config AFTER |
| 126 | # everything else has run |
226 | # everything else has run |
| 127 | # |
227 | # |
| 128 | # If 'vhosts' USE flag is not set, auto-install this app |
228 | # If 'vhosts' USE flag is not set, auto-install this app |
| 129 | # |
229 | # |
| 130 | # ------------------------------------------------------------------------ |
230 | # ------------------------------------------------------------------------ |
| 131 | |
231 | |
| 132 | function webapp_pkg_setup () |
232 | function webapp_pkg_setup () |
| 133 | { |
233 | { |
| 134 | use vhosts || webapp-config -u root -d /var/www/localhost/htdocs/${PN}/ ${PN} |
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 | } |