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