Magellan Linux

Annotation of /branches/R11-unstable/include/mtools.sminc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations) (download)
Fri Oct 10 13:29:42 2008 UTC (15 years, 7 months ago) by niro
Original Path: trunk/core/include/mtools.sminc
File size: 10267 byte(s)
import repo
1 niro 2 # $Header: /magellan-cvs/smage/include/mtools.sminc,v 1.39 2008/04/20 08:28:23 niro Exp $
2     # some special build tools
3    
4     # automatical inherit mtools.minc
5     # this will provide the service management functions
6     INHERITS="${INHERITS} mtools"
7    
8     # installs initscripts
9     # minstallrc /path/to/rc-script {destfilename}
10     minstallrc()
11     {
12     local rcscript
13     local file
14    
15     [[ -z "$1" ]] && die "No initscript given"
16    
17     # if no fullpath given use file from sourcedir
18     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
19     then
20     file="${SOURCEDIR}/${PNAME}/$1"
21     else
22     file="$1"
23     fi
24    
25     if [[ -n "$2" ]]
26     then
27     rcscript="$2"
28     else
29     rcscript="$(basename ${file})"
30     fi
31    
32     # needed directory
33     install -d ${BINDIR}/etc/rc.d/init.d || die
34    
35     # install our initscript
36     install -m 0755 -o root -g root ${file} ${BINDIR}/etc/rc.d/init.d/${rcscript} || die
37     }
38    
39     # installs environment files
40     # minstallenv /path/to/envdfile {destfilename}
41     minstallenv()
42     {
43     local envdfile
44     local file
45    
46     [[ -z "$1" ]] && die "No envd file given"
47    
48     # if no fullpath given use file from sourcedir
49     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
50     then
51     file="${SOURCEDIR}/${PNAME}/$1"
52     else
53     file="$1"
54     fi
55    
56     if [[ -n "$2" ]]
57     then
58     envdfile="$2"
59     else
60     envdfile="$(basename ${file})"
61     fi
62    
63     # needed directory
64     install -d ${BINDIR}/etc/env.d || die
65    
66     # install our envfile
67     install -m 0644 -o root -g root ${file} ${BINDIR}/etc/env.d/${envdfile} || die
68     }
69    
70     # installs system configuration files
71     # minstallconf /path/to/confdfile {destfilename}
72     minstallconf()
73     {
74     local confdfile
75     local file
76    
77     [[ -z "$1" ]] && die "No confd file given"
78    
79     # if no fullpath given use file from sourcedir
80     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
81     then
82     file="${SOURCEDIR}/${PNAME}/$1"
83     else
84     file="$1"
85     fi
86    
87     if [[ -n "$2" ]]
88     then
89     confdfile="$2"
90     else
91     confdfile="$(basename ${file})"
92     fi
93    
94     # needed directory
95     install -d ${BINDIR}/etc/conf.d || die
96    
97     # install our configfile
98     install -m 0644 -o root -g root ${file} ${BINDIR}/etc/conf.d/${confdfile} || die
99     }
100    
101     # installs system configuration files to etc
102     # minstalletc /path/to/etcfile {destfilename} {destdir path}
103     minstalletc()
104     {
105     local etcfile
106     local file
107     local destdir
108    
109     [[ -z "$1" ]] && die "No etc file given"
110    
111     # if no fullpath given use file from sourcedir
112     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
113     then
114     file="${SOURCEDIR}/${PNAME}/$1"
115     else
116     file="$1"
117     fi
118    
119     if [[ -n "$2" ]]
120     then
121     etcfile="$2"
122     else
123     etcfile="$(basename ${file})"
124     fi
125    
126     if [[ -n "$3" ]]
127     then
128     destdir="$3"
129     else
130     destdir="/etc"
131     fi
132    
133     # needed directory
134     install -d ${BINDIR}/${destdir} || die
135    
136     # install our configfile
137     install -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${etcfile} || die
138     }
139    
140     # install man files to appropiate dirs
141     # minstallman /path/to/manfile.foo
142     minstallman()
143     {
144     local manfile
145     local mandir
146     local file
147    
148     [[ -z "$@" ]] && die "No man file given"
149    
150     for file in $@
151     do
152     manfile="$(basename ${file})"
153     mandir="man${manfile##*.}"
154    
155     install -d ${BINDIR}/usr/share/man/${mandir} || die
156     install -m0644 ${file} ${BINDIR}/usr/share/man/${mandir}/${manfile} || die
157     done
158     }
159    
160     # install info files to appropiate dirs
161     # minstallinfo /path/to/infofile.foo
162     minstallinfo()
163     {
164     local file
165    
166     [[ -z "$@" ]] && die "No info file given"
167    
168     for file in $@
169     do
170     install -d ${BINDIR}/usr/share/info || die
171     install -m0644 ${file} ${BINDIR}/usr/share/info/$(basename ${file}) || die
172     done
173     }
174    
175     # install html files to appropiate dirs
176     # minstallhtml /path/to/infofile.foo
177     minstallhtml()
178     {
179     local file
180     local subfile
181     local prefix
182     local subprefix
183    
184     # handle prefix
185     case "$1" in
186     --prefix|-p) shift; prefix="$1"; shift ;;
187     esac
188    
189     [[ -z "$@" ]] && die "No html file given"
190    
191     for file in $@
192     do
193     install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/html${prefix} || die
194    
195     if [[ -d ${file} ]]
196     then
197     for subfile in ${file}/*
198     do
199     subprefix="$(dirname ${subfile/$(dirname ${file})/})"
200     subprefix="${prefix}${subprefix}/"
201    
202     minstallhtml --prefix ${subprefix} ${subfile} || die
203     done
204     else
205     install -m0644 ${file} ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/html/${prefix}$(basename ${file}) || die
206     fi
207     done
208     }
209    
210     # install pixmaps to appropiate dirs
211     # minstallpixmap srcname destname {/path/to}
212     minstallpixmap()
213     {
214     local file
215     local destdir
216     local destfile
217    
218     [[ -z "$1" ]] && die "No pixmap given"
219    
220     # if no fullpath given use file from sourcedir
221     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
222     then
223     file="${SOURCEDIR}/${PNAME}/$1"
224     else
225     file="$1"
226     fi
227    
228     if [[ -n "$2" ]]
229     then
230     destfile="$2"
231     else
232     destfile="$(basename ${file})"
233     fi
234    
235     if [[ -n "$3" ]]
236     then
237     destdir="$3"
238     else
239     destdir="/usr/share/pixmaps"
240     fi
241    
242     # needed directory
243     install -d ${BINDIR}/${destdir} || die
244    
245     # install our pixmap
246     install -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${destfile} || die
247     }
248    
249     # installs pam configuration files
250     # minstallpam /path/to/pamfile {destfilename}
251     minstallpam()
252     {
253     local pamfile
254     local file
255    
256     [[ -z "$1" ]] && die "No pam file given"
257    
258     # if no fullpath given use file from sourcedir
259     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
260     then
261     file="${SOURCEDIR}/${PNAME}/$1"
262     else
263     file="$1"
264     fi
265    
266     if [[ -n "$2" ]]
267     then
268     pamfile="$2"
269     else
270     pamfile="$(basename ${file})"
271     fi
272    
273     # needed directory
274     install -d ${BINDIR}/etc/pam.d || die
275    
276     # install our configfile
277     install -m 0644 -o root -g root ${file} ${BINDIR}/etc/pam.d/${pamfile} || die
278     }
279    
280     # installs cronjobs
281     # minstallcron [hourly|daily|weekly|monthly] /path/to/cronfile {destfilename}
282     minstallcron()
283     {
284     local cronfile
285     local loop
286     local file
287    
288     [[ -z "$1" ]] && die "No loop rythem given [hourly|daily|weekly|monthly]"
289     [[ -z "$2" ]] && die "No cronfile given"
290    
291     loop="$1"
292    
293     # if no fullpath given use file from sourcedir
294     if [[ -z $(dirname $2) ]] || [[ $(dirname $2) = . ]]
295     then
296     file="${SOURCEDIR}/${PNAME}/$2"
297     else
298     file="$2"
299     fi
300    
301     if [[ -n "$3" ]]
302     then
303     cronfile="$3"
304     else
305     cronfile="$(basename ${file})"
306     fi
307    
308     # needed directory
309     install -m0750 -d ${BINDIR}/etc/cron.${loop} || die
310    
311     # install our cronfile
312     install -m 0750 -o root -g root ${file} ${BINDIR}/etc/cron.${loop}/${cronfile} || die
313     }
314    
315    
316     # installs logrotate configuration files
317     # minstallpam /path/to/logrotatefile {destfilename}
318     minstalllog()
319     {
320     local logfile
321     local file
322    
323     [[ -z "$1" ]] && die "No logrotate file given"
324    
325     # if no fullpath given use file from sourcedir
326     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
327     then
328     file="${SOURCEDIR}/${PNAME}/$1"
329     else
330     file="$1"
331     fi
332    
333     if [[ -n "$2" ]]
334     then
335     logfile="$2"
336     else
337     logfile="$(basename ${file})"
338     fi
339    
340     # needed directory
341     install -d ${BINDIR}/etc/logrotate.d || die
342    
343     # install our configfile
344     install -m 0644 -o root -g root ${file} ${BINDIR}/etc/logrotate.d/${logfile} || die
345     }
346    
347    
348     # installs given directories
349     # minstalldir /path/to/dest/dir {/path/to/dest/dirN}
350     minstalldir()
351     {
352     local argv="$@"
353     local dest
354    
355     [[ -z ${argv} ]] && die "No dest dir given"
356     for dest in ${argv}
357     do
358     [[ -d ${BINDIR}${dest} ]] && continue
359     install -d ${BINDIR}/${dest} || die
360     done
361     }
362    
363    
364     # install files to given path (defaults to /usr/bin)
365     # minstallfile {-s} /path/to/file {/path/to/dest}
366     minstallfile()
367     {
368     local file
369     local dest
370    
371     [[ -z $1 ]] && die "No etc file given"
372    
373     if [[ $1 = -s ]]
374     then
375     file="${SOURCEDIR}/${PNAME}/$2"
376     dest="$3"
377     if [[ -z $3 ]]
378     then
379     dest=/usr/bin
380     install -d ${BINDIR}/${dest} || die
381     fi
382     else
383     file="$1"
384     dest="$2"
385     if [[ -z $2 ]]
386     then
387     dest=/usr/bin
388     install -d ${BINDIR}/${dest} || die
389     fi
390     fi
391    
392     # install our configfile
393     install -m 0644 -o root -g root ${file} ${BINDIR}/${dest} || die
394     }
395    
396     # installs executables to given path
397     # minstallexec {-s} /path/to/exec {/path/to/dest}
398     minstallexec()
399     {
400     local file
401     local dest
402    
403     [[ -z $1 ]] && die "No file given"
404    
405     if [[ $1 = -s ]]
406     then
407     file="${SOURCEDIR}/${PNAME}/$2"
408     dest="$3"
409     if [[ -z $3 ]]
410     then
411     dest=/usr/bin
412     install -d ${BINDIR}/${dest} || die
413     fi
414     else
415     file="$1"
416     dest="$2"
417     if [[ -z $2 ]]
418     then
419     dest=/usr/bin
420     install -d ${BINDIR}/${dest} || die
421     fi
422     fi
423    
424     # install our configfile
425     install -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die
426     }
427    
428     # installs executables to given path
429     # minstalllib {-s} /path/to/exec {/path/to/dest}
430     minstalllib()
431     {
432     local file
433     local dest
434    
435     [[ -z $1 ]] && die "No file given"
436    
437     if [[ $1 = -s ]]
438     then
439     file="${SOURCEDIR}/${PNAME}/$2"
440     dest="$3"
441     if [[ -z $3 ]]
442     then
443     dest=/usr/$(mlibdir)
444     install -d ${BINDIR}/${dest} || die
445     fi
446     else
447     file="$1"
448     dest="$2"
449     if [[ -z $2 ]]
450     then
451     dest=/usr/$(mlibdir)
452     install -d ${BINDIR}/${dest} || die
453     fi
454     fi
455    
456     # install our library
457     install -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die
458    
459     # create libtool symlinks
460     # 1. - library.so.1.0.0 -> library.so.1.0
461     if [ "${file%.*}" != *.so ]
462     then
463     ln -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*})
464     fi
465     # 2. - library.so.1.0.0 -> library.so.1
466     if [ "${file%.*.*}" != *.so ]
467     then
468     ln -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*})
469     fi
470     }
471    
472     # mark directoris undeletable
473     mkeepdir()
474     {
475     local keepdir
476     [[ -z "$1" ]] && die "No directory given"
477    
478     keepdir="$1"
479     install -d ${BINDIR}/${keepdir} || die
480     touch ${BINDIR}/${keepdir}/.keep || die
481     }
482    
483     # creates empty files
484     memptyfile()
485     {
486     local file
487     local path
488    
489     [[ -z "$1" ]] && die "No file given"
490    
491     file="$1"
492     path="$(dirname ${file})"
493    
494     install -d ${BINDIR}/${path} || die
495     touch ${BINDIR}/${file} || die
496     }
497    
498     mchown()
499     {
500     local owner="$1"
501     local path="$2"
502     local recursive
503    
504     # recursive
505     if [[ $1 = -r ]] || [[ $1 = -R ]]
506     then
507     local recursive="--recursive"
508     local owner="$2"
509     local path="$3"
510     fi
511    
512     [[ -z ${owner} ]] && die "No owner given."
513     [[ -z ${path} ]] && die "No path given."
514    
515     chown ${recursive} ${owner} ${BINDIR}/${path} || die
516     }
517    
518     mchmod()
519     {
520     local posix="$1"
521     local path="$2"
522     local recursive
523    
524     # recursive
525     if [[ $1 = -r ]] || [[ $1 = -R ]]
526     then
527     local recursive="--recursive"
528     local posix="$2"
529     local path="$3"
530     fi
531    
532     [[ -z ${posix} ]] && die "No posix given."
533     [[ -z ${path} ]] && die "No path given."
534    
535     chmod ${recursive} ${posix} ${BINDIR}/${path} || die
536     }
537    
538     mlink()
539     {
540     local symlink="$1"
541     local pathto="$2"
542    
543     [[ -z ${symlink} ]] && die "No symlink given."
544     [[ -z ${pathto} ]] && die "No path given."
545    
546     ln -snf ${symlink} ${BINDIR}/${pathto} || die
547     }