Magellan Linux

Diff of /trunk/include/mtools.sminc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/core/include/mtools.sminc revision 2 by niro, Fri Oct 10 13:29:42 2008 UTC trunk/include/mtools.sminc revision 21094 by niro, Tue Mar 11 08:44:45 2014 UTC
# Line 1  Line 1 
1  # $Header: /magellan-cvs/smage/include/mtools.sminc,v 1.39 2008/04/20 08:28:23 niro Exp $  # $Id$
2  # some special build tools  # some special build tools
3    
4  # automatical inherit mtools.minc  # get the pname right with split-packages
5  # this will provide the service management functions  mpname()
6  INHERITS="${INHERITS} mtools"  {
7     local pname="${PNAME}"
8     [[ ! -z ${SPLIT_PACKAGE_BASE} ]] && pname="${SPLIT_PACKAGE_BASE}"
9    
10     echo "${pname}"
11    }
12    
13  # installs initscripts  # installs given directories
14  # minstallrc /path/to/rc-script {destfilename}  # minstalldir /path/to/dest/dir {/path/to/dest/dirN}
15  minstallrc()  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  {  {
  local rcscript  
32   local file   local file
33     local dest
34    
35   [[ -z "$1" ]] && die "No initscript given"   [[ -z $1 ]] && die "No etc file given"
36    
37   # if no fullpath given use file from sourcedir   if [[ $1 = -s ]]
  if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]  
38   then   then
39   file="${SOURCEDIR}/${PNAME}/$1"   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   else
47   file="$1"   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   fi
55    
56   if [[ -n "$2" ]]   # 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   then
107   rcscript="$2"   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   else
115   rcscript="$(basename ${file})"   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   fi
123    
124   # needed directory   # install our library
125   install -d ${BINDIR}/etc/rc.d/init.d || die   install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die
126    
127   # install our initscript   # prefer scanelf
128   install -m 0755 -o root -g root ${file} ${BINDIR}/etc/rc.d/init.d/${rcscript} || die   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  # installs environment files
# Line 48  minstallenv() Line 163  minstallenv()
163   # if no fullpath given use file from sourcedir   # if no fullpath given use file from sourcedir
164   if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]   if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
165   then   then
166   file="${SOURCEDIR}/${PNAME}/$1"   file="${SOURCEDIR}/$(mpname)/$1"
167   else   else
168   file="$1"   file="$1"
169   fi   fi
# Line 64  minstallenv() Line 179  minstallenv()
179   install -d ${BINDIR}/etc/env.d || die   install -d ${BINDIR}/etc/env.d || die
180    
181   # install our envfile   # install our envfile
182   install -m 0644 -o root -g root ${file} ${BINDIR}/etc/env.d/${envdfile} || die   install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/env.d/${envdfile} || die
183  }  }
184    
185  # installs system configuration files  # installs system configuration files
# Line 79  minstallconf() Line 194  minstallconf()
194   # if no fullpath given use file from sourcedir   # if no fullpath given use file from sourcedir
195   if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]   if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
196   then   then
197   file="${SOURCEDIR}/${PNAME}/$1"   file="${SOURCEDIR}/$(mpname)/$1"
198   else   else
199   file="$1"   file="$1"
200   fi   fi
# Line 95  minstallconf() Line 210  minstallconf()
210   install -d ${BINDIR}/etc/conf.d || die   install -d ${BINDIR}/etc/conf.d || die
211    
212   # install our configfile   # install our configfile
213   install -m 0644 -o root -g root ${file} ${BINDIR}/etc/conf.d/${confdfile} || die   install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/conf.d/${confdfile} || die
214  }  }
215    
216  # installs system configuration files to etc  # installs system configuration files to etc
# Line 111  minstalletc() Line 226  minstalletc()
226   # if no fullpath given use file from sourcedir   # if no fullpath given use file from sourcedir
227   if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]   if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
228   then   then
229   file="${SOURCEDIR}/${PNAME}/$1"   file="${SOURCEDIR}/$(mpname)/$1"
230   else   else
231   file="$1"   file="$1"
232   fi   fi
# Line 134  minstalletc() Line 249  minstalletc()
249   install -d ${BINDIR}/${destdir} || die   install -d ${BINDIR}/${destdir} || die
250    
251   # install our configfile   # install our configfile
252   install -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${etcfile} || die   install -v -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${etcfile} || die
253  }  }
254    
255  # install man files to appropiate dirs  # install man files to appropiate dirs
# Line 153  minstallman() Line 268  minstallman()
268   mandir="man${manfile##*.}"   mandir="man${manfile##*.}"
269    
270   install -d ${BINDIR}/usr/share/man/${mandir} || die   install -d ${BINDIR}/usr/share/man/${mandir} || die
271   install -m0644 ${file} ${BINDIR}/usr/share/man/${mandir}/${manfile} || die   install -v -m0644 ${file} ${BINDIR}/usr/share/man/${mandir}/${manfile} || die
272   done   done
273  }  }
274    
# Line 168  minstallinfo() Line 283  minstallinfo()
283   for file in $@   for file in $@
284   do   do
285   install -d ${BINDIR}/usr/share/info || die   install -d ${BINDIR}/usr/share/info || die
286   install -m0644 ${file} ${BINDIR}/usr/share/info/$(basename ${file}) || die   install -v -m0644 ${file} ${BINDIR}/usr/share/info/$(basename ${file}) || die
287   done   done
288  }  }
289    
# Line 202  minstallhtml() Line 317  minstallhtml()
317   minstallhtml --prefix ${subprefix} ${subfile} || die   minstallhtml --prefix ${subprefix} ${subfile} || die
318   done   done
319   else   else
320   install -m0644 ${file} ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/html/${prefix}$(basename ${file}) || die   install -v -m0644 ${file} ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/html/${prefix}$(basename ${file}) || die
321   fi   fi
322   done   done
323  }  }
# Line 220  minstallpixmap() Line 335  minstallpixmap()
335   # if no fullpath given use file from sourcedir   # if no fullpath given use file from sourcedir
336   if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]   if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
337   then   then
338   file="${SOURCEDIR}/${PNAME}/$1"   file="${SOURCEDIR}/$(mpname)/$1"
339   else   else
340   file="$1"   file="$1"
341   fi   fi
# Line 243  minstallpixmap() Line 358  minstallpixmap()
358   install -d ${BINDIR}/${destdir} || die   install -d ${BINDIR}/${destdir} || die
359    
360   # install our pixmap   # install our pixmap
361   install -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${destfile} || die   install -v -m 0644 -o root -g root ${file} ${BINDIR}/${destdir}/${destfile} || die
362  }  }
363    
364  # installs pam configuration files  # installs pam configuration files
# Line 258  minstallpam() Line 373  minstallpam()
373   # if no fullpath given use file from sourcedir   # if no fullpath given use file from sourcedir
374   if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]   if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
375   then   then
376   file="${SOURCEDIR}/${PNAME}/$1"   file="${SOURCEDIR}/$(mpname)/$1"
377   else   else
378   file="$1"   file="$1"
379   fi   fi
# Line 274  minstallpam() Line 389  minstallpam()
389   install -d ${BINDIR}/etc/pam.d || die   install -d ${BINDIR}/etc/pam.d || die
390    
391   # install our configfile   # install our configfile
392   install -m 0644 -o root -g root ${file} ${BINDIR}/etc/pam.d/${pamfile} || die   install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/pam.d/${pamfile} || die
393  }  }
394    
395  # installs cronjobs  # installs cronjobs
# Line 293  minstallcron() Line 408  minstallcron()
408   # if no fullpath given use file from sourcedir   # if no fullpath given use file from sourcedir
409   if [[ -z $(dirname $2) ]] || [[ $(dirname $2) = . ]]   if [[ -z $(dirname $2) ]] || [[ $(dirname $2) = . ]]
410   then   then
411   file="${SOURCEDIR}/${PNAME}/$2"   file="${SOURCEDIR}/$(mpname)/$2"
412   else   else
413   file="$2"   file="$2"
414   fi   fi
# Line 309  minstallcron() Line 424  minstallcron()
424   install -m0750 -d ${BINDIR}/etc/cron.${loop} || die   install -m0750 -d ${BINDIR}/etc/cron.${loop} || die
425    
426   # install our cronfile   # install our cronfile
427   install -m 0750 -o root -g root ${file} ${BINDIR}/etc/cron.${loop}/${cronfile} || die   install -v -m 0750 -o root -g root ${file} ${BINDIR}/etc/cron.${loop}/${cronfile} || die
428  }  }
429    
430    
431  # installs logrotate configuration files  # installs logrotate configuration files
432  # minstallpam /path/to/logrotatefile {destfilename}  # minstalllog /path/to/logrotatefile {destfilename}
433  minstalllog()  minstalllog()
434  {  {
435   local logfile   local logfile
# Line 325  minstalllog() Line 440  minstalllog()
440   # if no fullpath given use file from sourcedir   # if no fullpath given use file from sourcedir
441   if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]   if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]
442   then   then
443   file="${SOURCEDIR}/${PNAME}/$1"   file="${SOURCEDIR}/$(mpname)/$1"
444   else   else
445   file="$1"   file="$1"
446   fi   fi
# Line 341  minstalllog() Line 456  minstalllog()
456   install -d ${BINDIR}/etc/logrotate.d || die   install -d ${BINDIR}/etc/logrotate.d || die
457    
458   # install our configfile   # install our configfile
459   install -m 0644 -o root -g root ${file} ${BINDIR}/etc/logrotate.d/${logfile} || die   install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/logrotate.d/${logfile} || die
460  }  }
461    
462    mcopy()
 # installs given directories  
 # minstalldir /path/to/dest/dir {/path/to/dest/dirN}  
 minstalldir()  
463  {  {
464   local argv="$@"   local source="$1"
465   local dest   local dest="$2"
466     local opts
  [[ -z ${argv} ]] && die "No dest dir given"  
  for dest in ${argv}  
  do  
  [[ -d ${BINDIR}${dest} ]] && continue  
  install -d ${BINDIR}/${dest} || die  
  done  
 }  
467    
468     # recursive
469     if [[ $1 = -r ]] || [[ $1 = -R ]]
470     then
471     opts="-R"
472     source="$2"
473     dest="$3"
474     fi
475    
476  # install files to given path (defaults to /usr/bin)   # recursive
477  # minstallfile {-s} /path/to/file {/path/to/dest}   if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]]
478  minstallfile()   then
479  {   opts="-R -f"
480   local file   source="$2"
481   local dest   dest="$3"
482     fi
  [[ -z $1 ]] && die "No etc file given"  
483    
484   if [[ $1 = -s ]]   if [[ $1 = -a ]]
485   then   then
486   file="${SOURCEDIR}/${PNAME}/$2"   opts="-a"
487     source="$2"
488   dest="$3"   dest="$3"
  if [[ -z $3 ]]  
  then  
  dest=/usr/bin  
  install -d ${BINDIR}/${dest} || die  
  fi  
  else  
  file="$1"  
  dest="$2"  
  if [[ -z $2 ]]  
  then  
  dest=/usr/bin  
  install -d ${BINDIR}/${dest} || die  
  fi  
489   fi   fi
490    
491   # install our configfile   [[ -z ${source} ]] && die "No source given."
492   install -m 0644 -o root -g root ${file} ${BINDIR}/${dest} || die   [[ -z ${dest} ]] && die "No dest given."
493    
494     cp -v ${opts} ${source} ${BINDIR}/${dest} || die
495  }  }
496    
497  # installs executables to given path  mdelete()
 # minstallexec {-s} /path/to/exec {/path/to/dest}  
 minstallexec()  
498  {  {
499   local file   local dest="$1"
500   local dest   local opts
501    
502   [[ -z $1 ]] && die "No file given"   # enforce
503     if [[ $1 = -f ]]
504     then
505     opts="-f"
506     dest="$2"
507     fi
508    
509   if [[ $1 = -s ]]   # recursive
510     if [[ $1 = -r ]] || [[ $1 = -R ]]
511   then   then
512   file="${SOURCEDIR}/${PNAME}/$2"   opts="-r"
  dest="$3"  
  if [[ -z $3 ]]  
  then  
  dest=/usr/bin  
  install -d ${BINDIR}/${dest} || die  
  fi  
  else  
  file="$1"  
513   dest="$2"   dest="$2"
  if [[ -z $2 ]]  
  then  
  dest=/usr/bin  
  install -d ${BINDIR}/${dest} || die  
  fi  
514   fi   fi
515    
516   # install our configfile   # recursive
517   install -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die   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     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  }  }
531    
532  # installs executables to given path  mmove()
 # minstalllib {-s} /path/to/exec {/path/to/dest}  
 minstalllib()  
533  {  {
534   local file   local source="$1"
535   local dest   local dest="$2"
536     local opts
537    
538   [[ -z $1 ]] && die "No file given"   # force
539     if [[ $1 = -f ]]
  if [[ $1 = -s ]]  
540   then   then
541   file="${SOURCEDIR}/${PNAME}/$2"   opts="-f"
542     source="$2"
543   dest="$3"   dest="$3"
  if [[ -z $3 ]]  
  then  
  dest=/usr/$(mlibdir)  
  install -d ${BINDIR}/${dest} || die  
  fi  
  else  
  file="$1"  
  dest="$2"  
  if [[ -z $2 ]]  
  then  
  dest=/usr/$(mlibdir)  
  install -d ${BINDIR}/${dest} || die  
  fi  
544   fi   fi
545    
546   # install our library   [[ -z ${source} ]] && die "No source given."
547   install -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die   [[ -z ${dest} ]] && die "No dest given."
548    
549   # create libtool symlinks   mv -v ${opts} ${source} ${BINDIR}/${dest} || die
  # 1. - library.so.1.0.0 -> library.so.1.0  
  if [ "${file%.*}" != *.so ]  
  then  
  ln -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*})  
  fi  
  # 2. - library.so.1.0.0 -> library.so.1  
  if [ "${file%.*.*}" != *.so ]  
  then  
  ln -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*})  
  fi  
550  }  }
551    
552  # mark directoris undeletable  # mark directories undeletable
553  mkeepdir()  mkeepdir()
554  {  {
555   local keepdir   local keepdir
556   [[ -z "$1" ]] && die "No directory given"   [[ -z "$1" ]] && die "No directory given"
557    
558   keepdir="$1"   keepdir="$1"
559   install -d ${BINDIR}/${keepdir} || die   install -v -d ${BINDIR}/${keepdir} || die
560   touch ${BINDIR}/${keepdir}/.keep || die   touch ${BINDIR}/${keepdir}/.keep || die
561  }  }
562    
# Line 504  mchown() Line 584  mchown()
584   # recursive   # recursive
585   if [[ $1 = -r ]] || [[ $1 = -R ]]   if [[ $1 = -r ]] || [[ $1 = -R ]]
586   then   then
587   local recursive="--recursive"   local recursive="-R"
588   local owner="$2"   local owner="$2"
589   local path="$3"   local path="$3"
590   fi   fi
# Line 512  mchown() Line 592  mchown()
592   [[ -z ${owner} ]] && die "No owner given."   [[ -z ${owner} ]] && die "No owner given."
593   [[ -z ${path} ]] && die "No path given."   [[ -z ${path} ]] && die "No path given."
594    
595   chown ${recursive} ${owner} ${BINDIR}/${path} || die   chown -v ${recursive} ${owner} ${BINDIR}/${path} || die
596  }  }
597    
598  mchmod()  mchmod()
# Line 524  mchmod() Line 604  mchmod()
604   # recursive   # recursive
605   if [[ $1 = -r ]] || [[ $1 = -R ]]   if [[ $1 = -r ]] || [[ $1 = -R ]]
606   then   then
607   local recursive="--recursive"   local recursive="-R"
608   local posix="$2"   local posix="$2"
609   local path="$3"   local path="$3"
610   fi   fi
# Line 532  mchmod() Line 612  mchmod()
612   [[ -z ${posix} ]] && die "No posix given."   [[ -z ${posix} ]] && die "No posix given."
613   [[ -z ${path} ]] && die "No path given."   [[ -z ${path} ]] && die "No path given."
614    
615   chmod ${recursive} ${posix} ${BINDIR}/${path} || die   chmod -v ${recursive} ${posix} ${BINDIR}/${path} || die
616  }  }
617    
618  mlink()  mlink()
619  {  {
620   local symlink="$1"   local symlink="$1"
621   local pathto="$2"   local pathto="$2"
622     local verbose="-v"
623    
624     # check for busybox as it doesn'tz support 'ln -v'
625     [[ $(readlink $(which ln)) = */busybox ]] && verbose=""
626    
627   [[ -z ${symlink} ]] && die "No symlink given."   [[ -z ${symlink} ]] && die "No symlink given."
628   [[ -z ${pathto} ]] && die "No path given."   [[ -z ${pathto} ]] && die "No path given."
629    
630   ln -snf ${symlink} ${BINDIR}/${pathto} || die   ln ${verbose} -snf ${symlink} ${BINDIR}/${pathto} || die
631    }
632    
633    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     #[[ -z ${argv} ]] && die "No  argument given!"
666    
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  }  }

Legend:
Removed from v.2  
changed lines
  Added in v.21094