Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2031 - (hide annotations) (download)
Fri Jun 12 10:56:41 2009 UTC (14 years, 11 months ago) by niro
Original Path: trunk/core/include/mtools.sminc
File size: 10852 byte(s)
-added minstalludev() to easy-install udev rules
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 niro 1113 install -v -m 0755 -o root -g root ${file} ${BINDIR}/etc/rc.d/init.d/${rcscript} || die
37 niro 2 }
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 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/env.d/${envdfile} || die
68 niro 2 }
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 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/conf.d/${confdfile} || die
99 niro 2 }
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 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${etcfile} || die
138 niro 2 }
139    
140 niro 2031 minstalludev()
141     {
142     local udevrule
143     local file
144    
145     [[ -z "$1" ]] && die "No udev rule given"
146    
147     # if no fullpath given use file from sourcedir
148     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
149     then
150     file="${SOURCEDIR}/${PNAME}/$1"
151     else
152     file="$1"
153     fi
154    
155     if [[ -n "$2" ]]
156     then
157     udevrule="$2"
158     else
159     udevrule="$(basename ${file})"
160     fi
161    
162     # needed directory
163     install -d ${BINDIR}/etc/udev/rules.d || die
164    
165     # install our initscript
166     install -v -m 0755 -o root -g root ${file} ${BINDIR}/etc/udev/rules.d/udevrule || die
167     }
168    
169 niro 2 # install man files to appropiate dirs
170     # minstallman /path/to/manfile.foo
171     minstallman()
172     {
173     local manfile
174     local mandir
175     local file
176    
177     [[ -z "$@" ]] && die "No man file given"
178    
179     for file in $@
180     do
181     manfile="$(basename ${file})"
182     mandir="man${manfile##*.}"
183    
184     install -d ${BINDIR}/usr/share/man/${mandir} || die
185 niro 1113 install -v -m0644 ${file} ${BINDIR}/usr/share/man/${mandir}/${manfile} || die
186 niro 2 done
187     }
188    
189     # install info files to appropiate dirs
190     # minstallinfo /path/to/infofile.foo
191     minstallinfo()
192     {
193     local file
194    
195     [[ -z "$@" ]] && die "No info file given"
196    
197     for file in $@
198     do
199     install -d ${BINDIR}/usr/share/info || die
200 niro 1113 install -v -m0644 ${file} ${BINDIR}/usr/share/info/$(basename ${file}) || die
201 niro 2 done
202     }
203    
204     # install html files to appropiate dirs
205     # minstallhtml /path/to/infofile.foo
206     minstallhtml()
207     {
208     local file
209     local subfile
210     local prefix
211     local subprefix
212    
213     # handle prefix
214     case "$1" in
215     --prefix|-p) shift; prefix="$1"; shift ;;
216     esac
217    
218     [[ -z "$@" ]] && die "No html file given"
219    
220     for file in $@
221     do
222     install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/html${prefix} || die
223    
224     if [[ -d ${file} ]]
225     then
226     for subfile in ${file}/*
227     do
228     subprefix="$(dirname ${subfile/$(dirname ${file})/})"
229     subprefix="${prefix}${subprefix}/"
230    
231     minstallhtml --prefix ${subprefix} ${subfile} || die
232     done
233     else
234 niro 1113 install -v -m0644 ${file} ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/html/${prefix}$(basename ${file}) || die
235 niro 2 fi
236     done
237     }
238    
239     # install pixmaps to appropiate dirs
240     # minstallpixmap srcname destname {/path/to}
241     minstallpixmap()
242     {
243     local file
244     local destdir
245     local destfile
246    
247     [[ -z "$1" ]] && die "No pixmap given"
248    
249     # if no fullpath given use file from sourcedir
250     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
251     then
252     file="${SOURCEDIR}/${PNAME}/$1"
253     else
254     file="$1"
255     fi
256    
257     if [[ -n "$2" ]]
258     then
259     destfile="$2"
260     else
261     destfile="$(basename ${file})"
262     fi
263    
264     if [[ -n "$3" ]]
265     then
266     destdir="$3"
267     else
268     destdir="/usr/share/pixmaps"
269     fi
270    
271     # needed directory
272     install -d ${BINDIR}/${destdir} || die
273    
274     # install our pixmap
275 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${destfile} || die
276 niro 2 }
277    
278     # installs pam configuration files
279     # minstallpam /path/to/pamfile {destfilename}
280     minstallpam()
281     {
282     local pamfile
283     local file
284    
285     [[ -z "$1" ]] && die "No pam file given"
286    
287     # if no fullpath given use file from sourcedir
288     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
289     then
290     file="${SOURCEDIR}/${PNAME}/$1"
291     else
292     file="$1"
293     fi
294    
295     if [[ -n "$2" ]]
296     then
297     pamfile="$2"
298     else
299     pamfile="$(basename ${file})"
300     fi
301    
302     # needed directory
303     install -d ${BINDIR}/etc/pam.d || die
304    
305     # install our configfile
306 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/pam.d/${pamfile} || die
307 niro 2 }
308    
309     # installs cronjobs
310     # minstallcron [hourly|daily|weekly|monthly] /path/to/cronfile {destfilename}
311     minstallcron()
312     {
313     local cronfile
314     local loop
315     local file
316    
317     [[ -z "$1" ]] && die "No loop rythem given [hourly|daily|weekly|monthly]"
318     [[ -z "$2" ]] && die "No cronfile given"
319    
320     loop="$1"
321    
322     # if no fullpath given use file from sourcedir
323     if [[ -z $(dirname $2) ]] || [[ $(dirname $2) = . ]]
324     then
325     file="${SOURCEDIR}/${PNAME}/$2"
326     else
327     file="$2"
328     fi
329    
330     if [[ -n "$3" ]]
331     then
332     cronfile="$3"
333     else
334     cronfile="$(basename ${file})"
335     fi
336    
337     # needed directory
338     install -m0750 -d ${BINDIR}/etc/cron.${loop} || die
339    
340     # install our cronfile
341 niro 1113 install -v -m 0750 -o root -g root ${file} ${BINDIR}/etc/cron.${loop}/${cronfile} || die
342 niro 2 }
343    
344    
345     # installs logrotate configuration files
346     # minstallpam /path/to/logrotatefile {destfilename}
347     minstalllog()
348     {
349     local logfile
350     local file
351    
352     [[ -z "$1" ]] && die "No logrotate file given"
353    
354     # if no fullpath given use file from sourcedir
355     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
356     then
357     file="${SOURCEDIR}/${PNAME}/$1"
358     else
359     file="$1"
360     fi
361    
362     if [[ -n "$2" ]]
363     then
364     logfile="$2"
365     else
366     logfile="$(basename ${file})"
367     fi
368    
369     # needed directory
370     install -d ${BINDIR}/etc/logrotate.d || die
371    
372     # install our configfile
373 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/logrotate.d/${logfile} || die
374 niro 2 }
375    
376    
377     # installs given directories
378     # minstalldir /path/to/dest/dir {/path/to/dest/dirN}
379     minstalldir()
380     {
381     local argv="$@"
382     local dest
383    
384     [[ -z ${argv} ]] && die "No dest dir given"
385     for dest in ${argv}
386     do
387     [[ -d ${BINDIR}${dest} ]] && continue
388 niro 1113 install -v -d ${BINDIR}/${dest} || die
389 niro 2 done
390     }
391    
392    
393     # install files to given path (defaults to /usr/bin)
394     # minstallfile {-s} /path/to/file {/path/to/dest}
395     minstallfile()
396     {
397     local file
398     local dest
399    
400     [[ -z $1 ]] && die "No etc file given"
401    
402     if [[ $1 = -s ]]
403     then
404     file="${SOURCEDIR}/${PNAME}/$2"
405     dest="$3"
406     if [[ -z $3 ]]
407     then
408     dest=/usr/bin
409     install -d ${BINDIR}/${dest} || die
410     fi
411     else
412     file="$1"
413     dest="$2"
414     if [[ -z $2 ]]
415     then
416     dest=/usr/bin
417     install -d ${BINDIR}/${dest} || die
418     fi
419     fi
420    
421     # install our configfile
422 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/${dest} || die
423 niro 2 }
424    
425     # installs executables to given path
426     # minstallexec {-s} /path/to/exec {/path/to/dest}
427     minstallexec()
428     {
429     local file
430     local dest
431    
432     [[ -z $1 ]] && die "No file given"
433    
434     if [[ $1 = -s ]]
435     then
436     file="${SOURCEDIR}/${PNAME}/$2"
437     dest="$3"
438     if [[ -z $3 ]]
439     then
440     dest=/usr/bin
441     install -d ${BINDIR}/${dest} || die
442     fi
443     else
444     file="$1"
445     dest="$2"
446     if [[ -z $2 ]]
447     then
448     dest=/usr/bin
449     install -d ${BINDIR}/${dest} || die
450     fi
451     fi
452    
453     # install our configfile
454 niro 1113 install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die
455 niro 2 }
456    
457     # installs executables to given path
458     # minstalllib {-s} /path/to/exec {/path/to/dest}
459     minstalllib()
460     {
461     local file
462     local dest
463    
464     [[ -z $1 ]] && die "No file given"
465    
466     if [[ $1 = -s ]]
467     then
468     file="${SOURCEDIR}/${PNAME}/$2"
469     dest="$3"
470     if [[ -z $3 ]]
471     then
472     dest=/usr/$(mlibdir)
473     install -d ${BINDIR}/${dest} || die
474     fi
475     else
476     file="$1"
477     dest="$2"
478     if [[ -z $2 ]]
479     then
480     dest=/usr/$(mlibdir)
481     install -d ${BINDIR}/${dest} || die
482     fi
483     fi
484    
485     # install our library
486 niro 1113 install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die
487 niro 2
488     # create libtool symlinks
489     # 1. - library.so.1.0.0 -> library.so.1.0
490     if [ "${file%.*}" != *.so ]
491     then
492 niro 1113 ln -v -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*})
493 niro 2 fi
494     # 2. - library.so.1.0.0 -> library.so.1
495     if [ "${file%.*.*}" != *.so ]
496     then
497 niro 1113 ln -v -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*})
498 niro 2 fi
499     }
500    
501     # mark directoris undeletable
502     mkeepdir()
503     {
504     local keepdir
505     [[ -z "$1" ]] && die "No directory given"
506    
507     keepdir="$1"
508 niro 1113 install -v -d ${BINDIR}/${keepdir} || die
509 niro 2 touch ${BINDIR}/${keepdir}/.keep || die
510     }
511    
512     # creates empty files
513     memptyfile()
514     {
515     local file
516     local path
517    
518     [[ -z "$1" ]] && die "No file given"
519    
520     file="$1"
521     path="$(dirname ${file})"
522    
523     install -d ${BINDIR}/${path} || die
524     touch ${BINDIR}/${file} || die
525     }
526    
527     mchown()
528     {
529     local owner="$1"
530     local path="$2"
531     local recursive
532    
533     # recursive
534     if [[ $1 = -r ]] || [[ $1 = -R ]]
535     then
536     local recursive="--recursive"
537     local owner="$2"
538     local path="$3"
539     fi
540    
541     [[ -z ${owner} ]] && die "No owner given."
542     [[ -z ${path} ]] && die "No path given."
543    
544 niro 1113 chown -v ${recursive} ${owner} ${BINDIR}/${path} || die
545 niro 2 }
546    
547     mchmod()
548     {
549     local posix="$1"
550     local path="$2"
551     local recursive
552    
553     # recursive
554     if [[ $1 = -r ]] || [[ $1 = -R ]]
555     then
556     local recursive="--recursive"
557     local posix="$2"
558     local path="$3"
559     fi
560    
561     [[ -z ${posix} ]] && die "No posix given."
562     [[ -z ${path} ]] && die "No path given."
563    
564 niro 1113 chmod -v ${recursive} ${posix} ${BINDIR}/${path} || die
565 niro 2 }
566    
567     mlink()
568     {
569     local symlink="$1"
570     local pathto="$2"
571    
572     [[ -z ${symlink} ]] && die "No symlink given."
573     [[ -z ${pathto} ]] && die "No path given."
574    
575 niro 1113 ln -v -snf ${symlink} ${BINDIR}/${pathto} || die
576 niro 2 }