Magellan Linux

Contents of /smage/trunk/include/mtools.sminc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5218 - (show annotations) (download)
Mon Dec 16 10:20:15 2013 UTC (10 years, 5 months ago) by niro
File size: 12410 byte(s)
-sync with upstream
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 source to dest, but does not create any dest directories
14 # mcopy {[-r|-rf|-a]} /path/to/source /path/to/dest
15 mcopy()
16 {
17 local source="$1"
18 local dest="$2"
19 local opts
20
21 # recursive
22 if [[ $1 = -r ]] || [[ $1 = -R ]]
23 then
24 opts="-R"
25 source="$2"
26 dest="$3"
27 fi
28
29 # recursive
30 if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]]
31 then
32 opts="-R -f"
33 source="$2"
34 dest="$3"
35 fi
36
37 if [[ $1 = -a ]]
38 then
39 opts="-a"
40 source="$2"
41 dest="$3"
42 fi
43
44 [[ -z ${source} ]] && die "No source given."
45 [[ -z ${dest} ]] && die "No dest given."
46
47 cp -v ${opts} ${source} ${BINDIR}/${dest} || die
48 }
49
50 # deletes given target
51 # mdelete {[-f|-r|-rf]} /path/to/target
52 mdelete()
53 {
54 local dest="$1"
55 local opts
56
57 # enforce
58 if [[ $1 = -f ]]
59 then
60 opts="-f"
61 dest="$2"
62 fi
63
64 # recursive
65 if [[ $1 = -r ]] || [[ $1 = -R ]]
66 then
67 opts="-r"
68 dest="$2"
69 fi
70
71 # recursive
72 if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]]
73 then
74 opts="-r -f"
75 dest="$2"
76 fi
77
78 [[ -z ${dest} ]] && die "No dest given."
79 [[ ! -e ${BINDIR}/${dest} ]] && die "${BINDIR}/${dest} does not exist."
80
81 rm -v ${opts} ${BINDIR}/${dest} || die
82 }
83
84 # moves given source to dest, but does not create any dest directories
85 # mmove {-f} /path/to/source /path/to/dest
86 mmove()
87 {
88 local source="$1"
89 local dest="$2"
90 local opts
91
92 # force
93 if [[ $1 = -f ]]
94 then
95 opts="-f"
96 source="$2"
97 dest="$3"
98 fi
99
100 [[ -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 then
117 local recursive="-R"
118 local owner="$2"
119 local path="$3"
120 fi
121
122 [[ -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 then
139 local recursive="-R"
140 local posix="$2"
141 local path="$3"
142 fi
143
144 [[ -z ${posix} ]] && die "No posix given."
145 [[ -z ${path} ]] && die "No path given."
146
147 chmod -v ${recursive} ${posix} ${BINDIR}/${path} || die
148 }
149
150 # creates a symlink of source to destination
151 # mlink /path/to/source /path/to/symlink
152 mlink()
153 {
154 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 local file
187 local dest
188
189 [[ -z $1 ]] && die "No etc file given"
190
191 if [[ $1 = -s ]]
192 then
193 file="${SOURCEDIR}/$(mpname)/$2"
194 dest="$3"
195 if [[ -z $3 ]]
196 then
197 dest=/usr/bin
198 fi
199 else
200 file="$1"
201 dest="$2"
202 if [[ -z $2 ]]
203 then
204 dest=/usr/bin
205 fi
206 fi
207
208 # needed directory
209 minstalldir ${dest} || die
210
211 # install our configfile
212 install -v -m 0644 -o root -g root ${file} ${BINDIR}/${dest} || die
213 }
214
215 # installs executables to given path
216 # minstallexec {-s} /path/to/exec {/path/to/dest}
217 minstallexec()
218 {
219 local file
220 local dest
221
222 [[ -z $1 ]] && die "No file given"
223
224 if [[ $1 = -s ]]
225 then
226 file="${SOURCEDIR}/$(mpname)/$2"
227 dest="$3"
228 if [[ -z $3 ]]
229 then
230 dest=/usr/bin
231 fi
232 else
233 file="$1"
234 dest="$2"
235 if [[ -z $2 ]]
236 then
237 dest=/usr/bin
238 fi
239 fi
240
241 # needed directory
242 minstalldir ${dest} || die
243
244 # install our configfile
245 install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die
246 }
247
248 # installs executables to given path
249 # minstalllib {-s} /path/to/exec {/path/to/dest}
250 minstalllib()
251 {
252 local file
253 local dest
254
255 [[ -z $1 ]] && die "No file given"
256
257 if [[ $1 = -s ]]
258 then
259 file="${SOURCEDIR}/$(mpname)/$2"
260 dest="$3"
261 if [[ -z $3 ]]
262 then
263 dest=/usr/$(mlibdir)
264 fi
265 else
266 file="$1"
267 dest="$2"
268 if [[ -z $2 ]]
269 then
270 dest=/usr/$(mlibdir)
271 fi
272 fi
273
274 # 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 then
283 local soname="$(scanelf -qBF '%S#p' ${file})"
284 mlink $(basename ${file}) ${dest}/${soname} || die
285 else
286 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 fi
305 }
306
307 # installs environment files
308 # minstallenv /path/to/envdfile {destfilename}
309 minstallenv()
310 {
311 local envdfile
312 local file
313
314 [[ -z "$1" ]] && die "No envd file given"
315
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 envdfile="$2"
327 else
328 envdfile="$(basename ${file})"
329 fi
330
331 # needed directory
332 minstalldir /etc/env.d || die
333
334 # install our envfile
335 minstallfile ${file} /etc/env.d/${envdfile} || die
336 }
337
338 # installs system configuration files
339 # minstallconf /path/to/confdfile {destfilename}
340 minstallconf()
341 {
342 local confdfile
343 local file
344
345 [[ -z "$1" ]] && die "No confd file given"
346
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 confdfile="$2"
358 else
359 confdfile="$(basename ${file})"
360 fi
361
362 # needed directory
363 minstalldir /etc/conf.d || die
364
365 # install our configfile
366 minstallfile ${file} /etc/conf.d/${confdfile} || die
367 }
368
369 # installs system configuration files to etc
370 # minstalletc /path/to/etcfile {destfilename} {destdir path}
371 minstalletc()
372 {
373 local etcfile
374 local file
375 local destdir
376
377 [[ -z "$1" ]] && die "No etc file given"
378
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 etcfile="$2"
390 else
391 etcfile="$(basename ${file})"
392 fi
393
394 if [[ -n "$3" ]]
395 then
396 destdir="$3"
397 else
398 destdir="/etc"
399 fi
400
401 # needed directory
402 minstalldir ${destdir} || die
403
404 # install our configfile
405 minstallfile ${file} ${destdir}/${etcfile} || die
406 }
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 minstalldir /usr/share/man/${mandir} || die
424 minstallfile ${file} /usr/share/man/${mandir}/${manfile} || die
425 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 minstalldir /usr/share/info || die
439 minstallfile ${file} /usr/share/info/$(basename ${file}) || die
440 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 minstalldir /usr/share/doc/${PNAME}-${PVER}/html${prefix} || die
462
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 minstallfile ${file} /usr/share/doc/${PNAME}-${PVER}/html/${prefix}$(basename ${file}) || die
474 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 minstalldir ${destdir} || die
512
513 # install our pixmap
514 minstallfile ${file} ${destdir}/${destfile} || die
515 }
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 minstalldir /etc/pam.d || die
543
544 # install our configfile
545 minstallfile ${file} /etc/pam.d/${pamfile} || die
546 }
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 minstalldir /etc/cron.${loop} || die
578 mchmod 0750 /etc/cron.${loop} || die
579
580 # install our cronfile
581 minstallexec ${file} /etc/cron.${loop}/${cronfile} || die
582 mchmod 0750 ${file} /etc/cron.${loop}/${cronfile} || die
583 }
584
585 # installs logrotate configuration files
586 # minstalllog /path/to/logrotatefile {destfilename}
587 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 minstalldir /etc/logrotate.d || die
611
612 # install our configfile
613 minstallfile ${file} /etc/logrotate.d/${logfile} || die
614 }
615
616 # mark directories undeletable
617 mkeepdir()
618 {
619 local keepdir
620 [[ -z "$1" ]] && die "No directory given"
621
622 keepdir="$1"
623 minstalldir ${keepdir} || die
624 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 minstalldir ${path} || die
639 touch ${BINDIR}/${file} || die
640 }
641
642 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 #[[ -z ${argv} ]] && die "No argument given!"
675
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 }