Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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