Magellan Linux

Annotation of /smage/branches/alx07x-unstable/include/mtools.sminc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5218 - (hide annotations) (download)
Mon Dec 16 10:20:15 2013 UTC (10 years, 5 months ago) by niro
Original Path: smage/trunk/include/mtools.sminc
File size: 12410 byte(s)
-sync with upstream
1 niro 5117 # $Id$
2 niro 1665 # some special build tools
3    
4 niro 5218 # get the pname right with split-packages
5 niro 1665 mpname()
6     {
7     local pname="${PNAME}"
8     [[ ! -z ${SPLIT_PACKAGE_BASE} ]] && pname="${SPLIT_PACKAGE_BASE}"
9    
10     echo "${pname}"
11     }
12    
13 niro 5218 # installs given source to dest, but does not create any dest directories
14     # mcopy {[-r|-rf|-a]} /path/to/source /path/to/dest
15     mcopy()
16 niro 1665 {
17 niro 5218 local source="$1"
18     local dest="$2"
19     local opts
20 niro 1665
21 niro 5218 # recursive
22     if [[ $1 = -r ]] || [[ $1 = -R ]]
23     then
24     opts="-R"
25     source="$2"
26     dest="$3"
27     fi
28 niro 1665
29 niro 5218 # recursive
30     if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]]
31 niro 1665 then
32 niro 5218 opts="-R -f"
33     source="$2"
34     dest="$3"
35 niro 1665 fi
36    
37 niro 5218 if [[ $1 = -a ]]
38 niro 1665 then
39 niro 5218 opts="-a"
40     source="$2"
41     dest="$3"
42 niro 1665 fi
43    
44 niro 5218 [[ -z ${source} ]] && die "No source given."
45     [[ -z ${dest} ]] && die "No dest given."
46 niro 1665
47 niro 5218 cp -v ${opts} ${source} ${BINDIR}/${dest} || die
48 niro 1665 }
49    
50 niro 5218 # deletes given target
51     # mdelete {[-f|-r|-rf]} /path/to/target
52     mdelete()
53 niro 1665 {
54 niro 5218 local dest="$1"
55     local opts
56 niro 1665
57 niro 5218 # enforce
58     if [[ $1 = -f ]]
59     then
60     opts="-f"
61     dest="$2"
62     fi
63 niro 1665
64 niro 5218 # recursive
65     if [[ $1 = -r ]] || [[ $1 = -R ]]
66 niro 1665 then
67 niro 5218 opts="-r"
68     dest="$2"
69 niro 1665 fi
70    
71 niro 5218 # recursive
72     if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]]
73 niro 1665 then
74 niro 5218 opts="-r -f"
75     dest="$2"
76 niro 1665 fi
77    
78 niro 5218 [[ -z ${dest} ]] && die "No dest given."
79     [[ ! -e ${BINDIR}/${dest} ]] && die "${BINDIR}/${dest} does not exist."
80 niro 1665
81 niro 5218 rm -v ${opts} ${BINDIR}/${dest} || die
82 niro 1665 }
83    
84 niro 5218 # moves given source to dest, but does not create any dest directories
85     # mmove {-f} /path/to/source /path/to/dest
86     mmove()
87 niro 1665 {
88 niro 5218 local source="$1"
89     local dest="$2"
90     local opts
91 niro 1665
92 niro 5218 # force
93     if [[ $1 = -f ]]
94     then
95     opts="-f"
96     source="$2"
97     dest="$3"
98     fi
99 niro 1665
100 niro 5218 [[ -z ${source} ]] && die "No source given."
101     [[ -z ${dest} ]] && die "No dest given."
102    
103     mv -v ${opts} ${source} ${BINDIR}/${dest} || die
104     }
105    
106     # changes owner of destination
107     # mchown {-r} owner /path/to/dest
108     mchown()
109     {
110     local owner="$1"
111     local path="$2"
112     local recursive
113    
114     # recursive
115     if [[ $1 = -r ]] || [[ $1 = -R ]]
116 niro 1665 then
117 niro 5218 local recursive="-R"
118     local owner="$2"
119     local path="$3"
120 niro 1665 fi
121    
122 niro 5218 [[ -z ${owner} ]] && die "No owner given."
123     [[ -z ${path} ]] && die "No path given."
124    
125     chown -v ${recursive} ${owner} ${BINDIR}/${path} || die
126     }
127    
128     # changes permission of destination
129     # mchmod {-r} permision /path/to/dest
130     mchmod()
131     {
132     local posix="$1"
133     local path="$2"
134     local recursive
135    
136     # recursive
137     if [[ $1 = -r ]] || [[ $1 = -R ]]
138 niro 1665 then
139 niro 5218 local recursive="-R"
140     local posix="$2"
141     local path="$3"
142 niro 1665 fi
143    
144 niro 5218 [[ -z ${posix} ]] && die "No posix given."
145     [[ -z ${path} ]] && die "No path given."
146 niro 1665
147 niro 5218 chmod -v ${recursive} ${posix} ${BINDIR}/${path} || die
148 niro 1665 }
149    
150 niro 5218 # creates a symlink of source to destination
151     # mlink /path/to/source /path/to/symlink
152     mlink()
153 niro 1665 {
154 niro 5218 local symlink="$1"
155     local pathto="$2"
156     local verbose="-v"
157    
158     # check for busybox as it doesn't support 'ln -v'
159     need_busybox_support ln && verbose=""
160    
161     [[ -z ${symlink} ]] && die "No symlink given."
162     [[ -z ${pathto} ]] && die "No path given."
163    
164     ln ${verbose} -snf ${symlink} ${BINDIR}/${pathto} || die
165     }
166    
167     # installs given directories
168     # minstalldir /path/to/dest/dir {/path/to/dest/dirN}
169     minstalldir()
170     {
171     local argv="$@"
172     local dest
173    
174     [[ -z ${argv} ]] && die "No dest dir given"
175     for dest in ${argv}
176     do
177     [[ -d ${BINDIR}${dest} ]] && continue
178     install -v -d ${BINDIR}/${dest} || die
179     done
180     }
181    
182     # install files to given path (defaults to /usr/bin)
183     # minstallfile {-s} /path/to/file {/path/to/dest}
184     minstallfile()
185     {
186 niro 1665 local file
187 niro 5218 local dest
188 niro 1665
189 niro 5218 [[ -z $1 ]] && die "No etc file given"
190 niro 1665
191 niro 5218 if [[ $1 = -s ]]
192 niro 1665 then
193 niro 5218 file="${SOURCEDIR}/$(mpname)/$2"
194     dest="$3"
195     if [[ -z $3 ]]
196     then
197     dest=/usr/bin
198     fi
199 niro 1665 else
200     file="$1"
201 niro 5218 dest="$2"
202     if [[ -z $2 ]]
203     then
204     dest=/usr/bin
205     fi
206 niro 1665 fi
207    
208     # needed directory
209 niro 5218 minstalldir ${dest} || die
210 niro 1665
211     # install our configfile
212 niro 5218 install -v -m 0644 -o root -g root ${file} ${BINDIR}/${dest} || die
213 niro 1665 }
214    
215 niro 5218 # installs executables to given path
216     # minstallexec {-s} /path/to/exec {/path/to/dest}
217     minstallexec()
218 niro 1665 {
219     local file
220 niro 5218 local dest
221 niro 1665
222 niro 5218 [[ -z $1 ]] && die "No file given"
223 niro 1665
224 niro 5218 if [[ $1 = -s ]]
225 niro 1665 then
226 niro 5218 file="${SOURCEDIR}/$(mpname)/$2"
227     dest="$3"
228     if [[ -z $3 ]]
229     then
230     dest=/usr/bin
231     fi
232 niro 1665 else
233     file="$1"
234 niro 5218 dest="$2"
235     if [[ -z $2 ]]
236     then
237     dest=/usr/bin
238     fi
239 niro 1665 fi
240    
241     # needed directory
242 niro 5218 minstalldir ${dest} || die
243 niro 1665
244 niro 5218 # install our configfile
245     install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die
246 niro 1665 }
247    
248 niro 5218 # installs executables to given path
249     # minstalllib {-s} /path/to/exec {/path/to/dest}
250     minstalllib()
251 niro 1665 {
252     local file
253 niro 5218 local dest
254 niro 1665
255 niro 5218 [[ -z $1 ]] && die "No file given"
256 niro 1665
257 niro 5218 if [[ $1 = -s ]]
258 niro 1665 then
259 niro 5218 file="${SOURCEDIR}/$(mpname)/$2"
260     dest="$3"
261     if [[ -z $3 ]]
262     then
263     dest=/usr/$(mlibdir)
264     fi
265 niro 1665 else
266     file="$1"
267 niro 5218 dest="$2"
268     if [[ -z $2 ]]
269     then
270     dest=/usr/$(mlibdir)
271     fi
272 niro 1665 fi
273    
274 niro 5218 # needed directory
275     minstalldir ${dest} || die
276    
277     # install our library
278     minstallexec ${file} ${dest} || die
279    
280     # prefer scanelf
281     if [[ -x $(type -P scanelf) ]]
282 niro 1665 then
283 niro 5218 local soname="$(scanelf -qBF '%S#p' ${file})"
284     mlink $(basename ${file}) ${dest}/${soname} || die
285 niro 1665 else
286 niro 5218 echo -e "${COLYELLOW}minstalllib(): Warning: scanelf not found, using fallback symlink method${COLDEFAULT}"
287    
288     # create libtool symlinks
289     # 1. - library.so.1.0.0 -> library.so.1.0
290     if [ "${file%.*}" != *.so ]
291     then
292     mlink $(basename ${file}) ${dest}/$(basename ${file%.*}) || die
293     fi
294     # 2. - library.so.1.0.0 -> library.so.1
295     if [ "${file%.*.*}" != *.so ]
296     then
297     mlink $(basename ${file}) ${dest}/$(basename ${file%.*.*}) || die
298     fi
299     # 3. - library.so.1.0.0.0 -> library.so.1
300     if [ "${file%.*.*.*}" != *.so ]
301     then
302     mlink $(basename ${file}) ${dest}/$(basename ${file%.*.*.*}) || die
303     fi
304 niro 1665 fi
305     }
306    
307 niro 5218 # installs environment files
308     # minstallenv /path/to/envdfile {destfilename}
309     minstallenv()
310 niro 1665 {
311 niro 5218 local envdfile
312 niro 1665 local file
313    
314 niro 5218 [[ -z "$1" ]] && die "No envd file given"
315 niro 1665
316     # if no fullpath given use file from sourcedir
317     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
318     then
319     file="${SOURCEDIR}/$(mpname)/$1"
320     else
321     file="$1"
322     fi
323    
324     if [[ -n "$2" ]]
325     then
326 niro 5218 envdfile="$2"
327 niro 1665 else
328 niro 5218 envdfile="$(basename ${file})"
329 niro 1665 fi
330    
331     # needed directory
332 niro 5218 minstalldir /etc/env.d || die
333 niro 1665
334 niro 5218 # install our envfile
335     minstallfile ${file} /etc/env.d/${envdfile} || die
336 niro 1665 }
337    
338 niro 5218 # installs system configuration files
339     # minstallconf /path/to/confdfile {destfilename}
340     minstallconf()
341 niro 1665 {
342 niro 5218 local confdfile
343 niro 1665 local file
344    
345 niro 5218 [[ -z "$1" ]] && die "No confd file given"
346 niro 1665
347     # if no fullpath given use file from sourcedir
348     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
349     then
350     file="${SOURCEDIR}/$(mpname)/$1"
351     else
352     file="$1"
353     fi
354    
355     if [[ -n "$2" ]]
356     then
357 niro 5218 confdfile="$2"
358 niro 1665 else
359 niro 5218 confdfile="$(basename ${file})"
360 niro 1665 fi
361    
362     # needed directory
363 niro 5218 minstalldir /etc/conf.d || die
364 niro 1665
365 niro 5218 # install our configfile
366     minstallfile ${file} /etc/conf.d/${confdfile} || die
367 niro 1665 }
368    
369 niro 5218 # installs system configuration files to etc
370     # minstalletc /path/to/etcfile {destfilename} {destdir path}
371     minstalletc()
372 niro 1665 {
373 niro 5218 local etcfile
374 niro 1665 local file
375 niro 5218 local destdir
376 niro 1665
377 niro 5218 [[ -z "$1" ]] && die "No etc file given"
378 niro 1665
379     # if no fullpath given use file from sourcedir
380     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
381     then
382     file="${SOURCEDIR}/$(mpname)/$1"
383     else
384     file="$1"
385     fi
386    
387     if [[ -n "$2" ]]
388     then
389 niro 5218 etcfile="$2"
390 niro 1665 else
391 niro 5218 etcfile="$(basename ${file})"
392 niro 1665 fi
393    
394 niro 5218 if [[ -n "$3" ]]
395     then
396     destdir="$3"
397     else
398     destdir="/etc"
399     fi
400    
401 niro 1665 # needed directory
402 niro 5218 minstalldir ${destdir} || die
403 niro 1665
404 niro 5218 # install our configfile
405     minstallfile ${file} ${destdir}/${etcfile} || die
406 niro 1665 }
407    
408     # install man files to appropiate dirs
409     # minstallman /path/to/manfile.foo
410     minstallman()
411     {
412     local manfile
413     local mandir
414     local file
415    
416     [[ -z "$@" ]] && die "No man file given"
417    
418     for file in $@
419     do
420     manfile="$(basename ${file})"
421     mandir="man${manfile##*.}"
422    
423 niro 5218 minstalldir /usr/share/man/${mandir} || die
424     minstallfile ${file} /usr/share/man/${mandir}/${manfile} || die
425 niro 1665 done
426     }
427    
428     # install info files to appropiate dirs
429     # minstallinfo /path/to/infofile.foo
430     minstallinfo()
431     {
432     local file
433    
434     [[ -z "$@" ]] && die "No info file given"
435    
436     for file in $@
437     do
438 niro 5218 minstalldir /usr/share/info || die
439     minstallfile ${file} /usr/share/info/$(basename ${file}) || die
440 niro 1665 done
441     }
442    
443     # install html files to appropiate dirs
444     # minstallhtml /path/to/infofile.foo
445     minstallhtml()
446     {
447     local file
448     local subfile
449     local prefix
450     local subprefix
451    
452     # handle prefix
453     case "$1" in
454     --prefix|-p) shift; prefix="$1"; shift ;;
455     esac
456    
457     [[ -z "$@" ]] && die "No html file given"
458    
459     for file in $@
460     do
461 niro 5218 minstalldir /usr/share/doc/${PNAME}-${PVER}/html${prefix} || die
462 niro 1665
463     if [[ -d ${file} ]]
464     then
465     for subfile in ${file}/*
466     do
467     subprefix="$(dirname ${subfile/$(dirname ${file})/})"
468     subprefix="${prefix}${subprefix}/"
469    
470     minstallhtml --prefix ${subprefix} ${subfile} || die
471     done
472     else
473 niro 5218 minstallfile ${file} /usr/share/doc/${PNAME}-${PVER}/html/${prefix}$(basename ${file}) || die
474 niro 1665 fi
475     done
476     }
477    
478     # install pixmaps to appropiate dirs
479     # minstallpixmap srcname destname {/path/to}
480     minstallpixmap()
481     {
482     local file
483     local destdir
484     local destfile
485    
486     [[ -z "$1" ]] && die "No pixmap given"
487    
488     # if no fullpath given use file from sourcedir
489     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
490     then
491     file="${SOURCEDIR}/$(mpname)/$1"
492     else
493     file="$1"
494     fi
495    
496     if [[ -n "$2" ]]
497     then
498     destfile="$2"
499     else
500     destfile="$(basename ${file})"
501     fi
502    
503     if [[ -n "$3" ]]
504     then
505     destdir="$3"
506     else
507     destdir="/usr/share/pixmaps"
508     fi
509    
510     # needed directory
511 niro 5218 minstalldir ${destdir} || die
512 niro 1665
513     # install our pixmap
514 niro 5218 minstallfile ${file} ${destdir}/${destfile} || die
515 niro 1665 }
516    
517     # installs pam configuration files
518     # minstallpam /path/to/pamfile {destfilename}
519     minstallpam()
520     {
521     local pamfile
522     local file
523    
524     [[ -z "$1" ]] && die "No pam file given"
525    
526     # if no fullpath given use file from sourcedir
527     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
528     then
529     file="${SOURCEDIR}/$(mpname)/$1"
530     else
531     file="$1"
532     fi
533    
534     if [[ -n "$2" ]]
535     then
536     pamfile="$2"
537     else
538     pamfile="$(basename ${file})"
539     fi
540    
541     # needed directory
542 niro 5218 minstalldir /etc/pam.d || die
543 niro 1665
544     # install our configfile
545 niro 5218 minstallfile ${file} /etc/pam.d/${pamfile} || die
546 niro 1665 }
547    
548     # installs cronjobs
549     # minstallcron [hourly|daily|weekly|monthly] /path/to/cronfile {destfilename}
550     minstallcron()
551     {
552     local cronfile
553     local loop
554     local file
555    
556     [[ -z "$1" ]] && die "No loop rythem given [hourly|daily|weekly|monthly]"
557     [[ -z "$2" ]] && die "No cronfile given"
558    
559     loop="$1"
560    
561     # if no fullpath given use file from sourcedir
562     if [[ -z $(dirname $2) ]] || [[ $(dirname $2) = . ]]
563     then
564     file="${SOURCEDIR}/$(mpname)/$2"
565     else
566     file="$2"
567     fi
568    
569     if [[ -n "$3" ]]
570     then
571     cronfile="$3"
572     else
573     cronfile="$(basename ${file})"
574     fi
575    
576     # needed directory
577 niro 5218 minstalldir /etc/cron.${loop} || die
578     mchmod 0750 /etc/cron.${loop} || die
579 niro 1665
580     # install our cronfile
581 niro 5218 minstallexec ${file} /etc/cron.${loop}/${cronfile} || die
582     mchmod 0750 ${file} /etc/cron.${loop}/${cronfile} || die
583 niro 1665 }
584    
585     # installs logrotate configuration files
586 niro 3577 # minstalllog /path/to/logrotatefile {destfilename}
587 niro 1665 minstalllog()
588     {
589     local logfile
590     local file
591    
592     [[ -z "$1" ]] && die "No logrotate file given"
593    
594     # if no fullpath given use file from sourcedir
595     if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
596     then
597     file="${SOURCEDIR}/$(mpname)/$1"
598     else
599     file="$1"
600     fi
601    
602     if [[ -n "$2" ]]
603     then
604     logfile="$2"
605     else
606     logfile="$(basename ${file})"
607     fi
608    
609     # needed directory
610 niro 5218 minstalldir /etc/logrotate.d || die
611 niro 1665
612     # install our configfile
613 niro 5218 minstallfile ${file} /etc/logrotate.d/${logfile} || die
614 niro 1665 }
615    
616     # mark directories undeletable
617     mkeepdir()
618     {
619     local keepdir
620     [[ -z "$1" ]] && die "No directory given"
621    
622     keepdir="$1"
623 niro 5218 minstalldir ${keepdir} || die
624 niro 1665 touch ${BINDIR}/${keepdir}/.keep || die
625     }
626    
627     # creates empty files
628     memptyfile()
629     {
630     local file
631     local path
632    
633     [[ -z "$1" ]] && die "No file given"
634    
635     file="$1"
636     path="$(dirname ${file})"
637    
638 niro 5218 minstalldir ${path} || die
639 niro 1665 touch ${BINDIR}/${file} || die
640     }
641    
642 niro 3577 mclearconfig()
643     {
644     local confdir
645     local prefix="${BINDIR}"
646     [[ -z ${MCONFIG} ]] && die "No \$MCONFIG given!"
647    
648     # no bindir prefix if requested
649     case $1 in
650     -b|--no-bindir) prefix="";;
651     esac
652    
653     confdir="$(dirname ${MCONFIG})"
654     if [[ ! -d ${prefix}/${confdir} ]]
655     then
656     install -d ${prefix}/${confdir} || die
657     fi
658     : > ${prefix}/${MCONFIG}
659     }
660    
661     maddconfig()
662     {
663     local argv="$1"
664     local confdir
665     local prefix="${BINDIR}"
666    
667     [[ -z ${MCONFIG} ]] && die "No \$MCONFIG given!"
668    
669     # no bindir prefix if requested
670     case $1 in
671     -b|--no-bindir) prefix=""; argv="$2" ;;
672     esac
673    
674 niro 5117 #[[ -z ${argv} ]] && die "No argument given!"
675 niro 3577
676     confdir="$(dirname ${MCONFIG})"
677     if [[ ! -d ${prefix}/${confdir} ]]
678     then
679     install -d ${prefix}/${confdir} || die
680     fi
681     echo "${argv}" >> ${prefix}/${MCONFIG} || die
682     }