Magellan Linux

Annotation of /trunk/include/mtools.sminc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 21094 - (hide annotations) (download)
Tue Mar 11 08:44:45 2014 UTC (10 years, 7 months ago) by niro
File size: 12563 byte(s)
-mdelete(): honor symlinks
1 niro 14029 # $Id$
2 niro 2 # some special build tools
3    
4 niro 19668 # get the pname right with split-packages
5 niro 4804 mpname()
6     {
7     local pname="${PNAME}"
8 niro 4807 [[ ! -z ${SPLIT_PACKAGE_BASE} ]] && pname="${SPLIT_PACKAGE_BASE}"
9 niro 4804
10     echo "${pname}"
11     }
12    
13 niro 19670 # 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 niro 2 # 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 niro 4804 file="${SOURCEDIR}/$(mpname)/$1"
167 niro 2 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 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/env.d/${envdfile} || die
183 niro 2 }
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 niro 4804 file="${SOURCEDIR}/$(mpname)/$1"
198 niro 2 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 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/conf.d/${confdfile} || die
214 niro 2 }
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 niro 4804 file="${SOURCEDIR}/$(mpname)/$1"
230 niro 2 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 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${etcfile} || die
253 niro 2 }
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 niro 1113 install -v -m0644 ${file} ${BINDIR}/usr/share/man/${mandir}/${manfile} || die
272 niro 2 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 niro 1113 install -v -m0644 ${file} ${BINDIR}/usr/share/info/$(basename ${file}) || die
287 niro 2 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 niro 1113 install -v -m0644 ${file} ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/html/${prefix}$(basename ${file}) || die
321 niro 2 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 niro 4804 file="${SOURCEDIR}/$(mpname)/$1"
339 niro 2 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 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${destfile} || die
362 niro 2 }
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 niro 4804 file="${SOURCEDIR}/$(mpname)/$1"
377 niro 2 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 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/pam.d/${pamfile} || die
393 niro 2 }
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 niro 4804 file="${SOURCEDIR}/$(mpname)/$2"
412 niro 2 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 niro 1113 install -v -m 0750 -o root -g root ${file} ${BINDIR}/etc/cron.${loop}/${cronfile} || die
428 niro 2 }
429    
430    
431     # installs logrotate configuration files
432 niro 8809 # minstalllog /path/to/logrotatefile {destfilename}
433 niro 2 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 niro 4804 file="${SOURCEDIR}/$(mpname)/$1"
444 niro 2 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 niro 1113 install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/logrotate.d/${logfile} || die
460 niro 2 }
461    
462 niro 2166 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 niro 11761 opts="-R"
472 niro 2166 source="$2"
473     dest="$3"
474     fi
475    
476     # recursive
477     if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]]
478     then
479 niro 11761 opts="-R -f"
480 niro 2166 source="$2"
481     dest="$3"
482     fi
483    
484 niro 9862 if [[ $1 = -a ]]
485     then
486 niro 11761 opts="-a"
487 niro 9862 source="$2"
488     dest="$3"
489     fi
490    
491 niro 2166 [[ -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 niro 12652 mdelete()
498     {
499     local dest="$1"
500     local opts
501    
502 niro 17041 # enforce
503     if [[ $1 = -f ]]
504     then
505     opts="-f"
506     dest="$2"
507     fi
508    
509 niro 12652 # 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 niro 21094 if [[ -e ${BINDIR}/${dest} ]] || [[ -L ${BINDIR}/${dest} ]]
525     then
526     rm -v ${opts} ${BINDIR}/${dest} || die
527     else
528     die "${BINDIR}/${dest} does not exist."
529     fi
530 niro 12652 }
531    
532 niro 2166 mmove()
533     {
534     local source="$1"
535     local dest="$2"
536     local opts
537    
538     # force
539     if [[ $1 = -f ]]
540     then
541 niro 11761 opts="-f"
542 niro 2166 source="$2"
543     dest="$3"
544     fi
545    
546     [[ -z ${source} ]] && die "No source given."
547     [[ -z ${dest} ]] && die "No dest given."
548    
549     mv -v ${opts} ${source} ${BINDIR}/${dest} || die
550     }
551    
552     # mark directories undeletable
553 niro 2 mkeepdir()
554     {
555     local keepdir
556     [[ -z "$1" ]] && die "No directory given"
557    
558     keepdir="$1"
559 niro 1113 install -v -d ${BINDIR}/${keepdir} || die
560 niro 2 touch ${BINDIR}/${keepdir}/.keep || die
561     }
562    
563     # creates empty files
564     memptyfile()
565     {
566     local file
567     local path
568    
569     [[ -z "$1" ]] && die "No file given"
570    
571     file="$1"
572     path="$(dirname ${file})"
573    
574     install -d ${BINDIR}/${path} || die
575     touch ${BINDIR}/${file} || die
576     }
577    
578     mchown()
579     {
580     local owner="$1"
581     local path="$2"
582     local recursive
583    
584     # recursive
585     if [[ $1 = -r ]] || [[ $1 = -R ]]
586     then
587 niro 11761 local recursive="-R"
588 niro 2 local owner="$2"
589     local path="$3"
590     fi
591    
592     [[ -z ${owner} ]] && die "No owner given."
593     [[ -z ${path} ]] && die "No path given."
594    
595 niro 1113 chown -v ${recursive} ${owner} ${BINDIR}/${path} || die
596 niro 2 }
597    
598     mchmod()
599     {
600     local posix="$1"
601     local path="$2"
602     local recursive
603    
604     # recursive
605     if [[ $1 = -r ]] || [[ $1 = -R ]]
606     then
607 niro 11761 local recursive="-R"
608 niro 2 local posix="$2"
609     local path="$3"
610     fi
611    
612     [[ -z ${posix} ]] && die "No posix given."
613     [[ -z ${path} ]] && die "No path given."
614    
615 niro 1113 chmod -v ${recursive} ${posix} ${BINDIR}/${path} || die
616 niro 2 }
617    
618     mlink()
619     {
620     local symlink="$1"
621     local pathto="$2"
622 niro 4806 local verbose="-v"
623 niro 2
624 niro 4806 # check for busybox as it doesn'tz support 'ln -v'
625     [[ $(readlink $(which ln)) = */busybox ]] && verbose=""
626    
627 niro 2 [[ -z ${symlink} ]] && die "No symlink given."
628     [[ -z ${pathto} ]] && die "No path given."
629    
630 niro 4806 ln ${verbose} -snf ${symlink} ${BINDIR}/${pathto} || die
631 niro 2 }
632 niro 7874
633 niro 8469 mclearconfig()
634     {
635     local confdir
636     local prefix="${BINDIR}"
637     [[ -z ${MCONFIG} ]] && die "No \$MCONFIG given!"
638    
639     # no bindir prefix if requested
640     case $1 in
641     -b|--no-bindir) prefix="";;
642     esac
643    
644     confdir="$(dirname ${MCONFIG})"
645     if [[ ! -d ${prefix}/${confdir} ]]
646     then
647     install -d ${prefix}/${confdir} || die
648     fi
649     : > ${prefix}/${MCONFIG}
650     }
651    
652     maddconfig()
653     {
654     local argv="$1"
655     local confdir
656     local prefix="${BINDIR}"
657    
658     [[ -z ${MCONFIG} ]] && die "No \$MCONFIG given!"
659    
660     # no bindir prefix if requested
661     case $1 in
662     -b|--no-bindir) prefix=""; argv="$2" ;;
663     esac
664    
665 niro 16994 #[[ -z ${argv} ]] && die "No argument given!"
666 niro 8469
667     confdir="$(dirname ${MCONFIG})"
668     if [[ ! -d ${prefix}/${confdir} ]]
669     then
670     install -d ${prefix}/${confdir} || die
671     fi
672     echo "${argv}" >> ${prefix}/${MCONFIG} || die
673     }