Magellan Linux

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

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

trunk/core/include/mtools.sminc revision 4807 by niro, Sun Jan 3 20:34:10 2010 UTC trunk/include/mtools.sminc revision 21095 by niro, Tue Mar 11 08:58:44 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
 # this will provide the service management functions  
 INHERITS="${INHERITS} mtools"  
   
 # get the pname right with splitpackages  
5  mpname()  mpname()
6  {  {
7   local pname="${PNAME}"   local pname="${PNAME}"
# Line 14  mpname() Line 10  mpname()
10   echo "${pname}"   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}/$(mpname)/$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   then
71   rcscript="$2"   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   else
79   rcscript="$(basename ${file})"   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   fi
87    
88   # needed directory   # install our configfile
89   install -d ${BINDIR}/etc/rc.d/init.d || die   install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die
90    }
91    
92   # install our initscript  # installs executables to given path
93   install -v -m 0755 -o root -g root ${file} ${BINDIR}/etc/rc.d/init.d/${rcscript} || die  # 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  # installs environment files
# Line 146  minstalletc() Line 252  minstalletc()
252   install -v -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    
 minstalludevrule()  
 {  
  local udevrule  
  local file  
   
  [[ -z "$1" ]] && die "No udev rule given"  
   
  # if no fullpath given use file from sourcedir  
  if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]  
  then  
  file="${SOURCEDIR}/$(mpname)/$1"  
  else  
  file="$1"  
  fi  
   
  if [[ -n "$2" ]]  
  then  
  udevrule="$2"  
  else  
  udevrule="$(basename ${file})"  
  fi  
   
  # needed directory  
  install -d ${BINDIR}/etc/udev/rules.d || die  
   
  # install our udev rule  
  install -v -m 0644 -o root -g root ${file} ${BINDIR}/etc/udev/rules.d/${udevrule} || die  
 }  
   
 minstalludevhelper()  
 {  
  local udevhelper  
  local file  
   
  [[ -z "$1" ]] && die "No udev helper given"  
   
  # if no fullpath given use file from sourcedir  
  if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]  
  then  
  file="${SOURCEDIR}/$(mpname)/$1"  
  else  
  file="$1"  
  fi  
   
  if [[ -n "$2" ]]  
  then  
  udevhelper="$2"  
  else  
  udevhelper="$(basename ${file})"  
  fi  
   
  # needed directory  
  install -d ${BINDIR}/lib/udev || die  
   
  # install our udev-helper  
  install -v -m 0755 -o root -g root ${file} ${BINDIR}/lib/udev/${udevhelper} || die  
 }  
   
 minstallhalinformation()  
 {  
  local halrule  
  local file  
   
  [[ -z "$1" ]] && die "No hal rule given"  
   
  # if no fullpath given use file from sourcedir  
  if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]  
  then  
  file="${SOURCEDIR}/$(mpname)/$1"  
  else  
  file="$1"  
  fi  
   
  if [[ -n "$2" ]]  
  then  
  halrule="$2"  
  else  
  halrule="$(basename ${file})"  
  fi  
   
  # needed directory  
  install -d ${BINDIR}/usr/share/hal/fdi/information/20thirdparty || die  
   
  # install our udev rule  
  install -v -m 0644 -o root -g root ${file} ${BINDIR}/usr/share/hal/fdi/information/20thirdparty/${halrule} || die  
 }  
   
 minstallhalpolicy()  
 {  
  local halrule  
  local file  
   
  [[ -z "$1" ]] && die "No hal rule given"  
   
  # if no fullpath given use file from sourcedir  
  if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]  
  then  
  file="${SOURCEDIR}/$(mpname)/$1"  
  else  
  file="$1"  
  fi  
   
  if [[ -n "$2" ]]  
  then  
  halrule="$2"  
  else  
  halrule="$(basename ${file})"  
  fi  
   
  # needed directory  
  install -d ${BINDIR}/usr/share/hal/fdi/policy/20thirdparty || die  
   
  # install our udev rule  
  install -v -m 0644 -o root -g root ${file} ${BINDIR}/usr/share/hal/fdi/policy/20thirdparty/${halrule} || die  
 }  
   
 minstallhalpreprobe()  
 {  
  local halrule  
  local file  
   
  [[ -z "$1" ]] && die "No hal rule given"  
   
  # if no fullpath given use file from sourcedir  
  if [[ -z $(dirname $1) ]] || [[ $(dirname $1) = . ]]  
  then  
  file="${SOURCEDIR}/$(mpname)/$1"  
  else  
  file="$1"  
  fi  
   
  if [[ -n "$2" ]]  
  then  
  halrule="$2"  
  else  
  halrule="$(basename ${file})"  
  fi  
   
  # needed directory  
  install -d ${BINDIR}/usr/share/hal/fdi/preprobe/10osvendor || die  
   
  # install our udev rule  
  install -v -m 0644 -o root -g root ${file} ${BINDIR}/usr/share/hal/fdi/preprobe/10osvendor/${halrule} || die  
 }  
   
255  # install man files to appropiate dirs  # install man files to appropiate dirs
256  # minstallman /path/to/manfile.foo  # minstallman /path/to/manfile.foo
257  minstallman()  minstallman()
# Line 468  minstallcron() Line 429  minstallcron()
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 498  minstalllog() Line 459  minstalllog()
459   install -v -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()  
 {  
  local argv="$@"  
  local dest  
   
  [[ -z ${argv} ]] && die "No dest dir given"  
  for dest in ${argv}  
  do  
  [[ -d ${BINDIR}${dest} ]] && continue  
  install -v -d ${BINDIR}/${dest} || die  
  done  
 }  
   
   
 # install files to given path (defaults to /usr/bin)  
 # minstallfile {-s} /path/to/file {/path/to/dest}  
 minstallfile()  
463  {  {
464   local file   local source="$1"
465   local dest   local dest="$2"
466     local opts
  [[ -z $1 ]] && die "No etc file given"  
467    
468   if [[ $1 = -s ]]   # recursive
469     if [[ $1 = -r ]] || [[ $1 = -R ]]
470   then   then
471   file="${SOURCEDIR}/$(mpname)/$2"   opts="-R"
472     source="$2"
473   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  
474   fi   fi
475    
476   # install our configfile   # recursive
477   install -v -m 0644 -o root -g root ${file} ${BINDIR}/${dest} || die   if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]]
 }  
   
 # installs executables to given path  
 # minstallexec {-s} /path/to/exec {/path/to/dest}  
 minstallexec()  
 {  
  local file  
  local dest  
   
  [[ -z $1 ]] && die "No file given"  
   
  if [[ $1 = -s ]]  
478   then   then
479   file="${SOURCEDIR}/$(mpname)/$2"   opts="-R -f"
480     source="$2"
481   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  
482   fi   fi
483    
484   # install our configfile   if [[ $1 = -a ]]
  install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die  
 }  
   
 # installs executables to given path  
 # minstalllib {-s} /path/to/exec {/path/to/dest}  
 minstalllib()  
 {  
  local file  
  local dest  
  local verbose="-v"  
   
  # check for busybox as it doesn'tz support 'ln -v'  
  [[ $(readlink $(which ln)) = */busybox ]] && verbose=""  
   
  [[ -z $1 ]] && die "No file given"  
   
  if [[ $1 = -s ]]  
485   then   then
486   file="${SOURCEDIR}/$(mpname)/$2"   opts="-a"
487     source="$2"
488   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  
489   fi   fi
490    
491   # install our library   [[ -z ${source} ]] && die "No source given."
492   install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die   [[ -z ${dest} ]] && die "No dest given."
493    
494   # create libtool symlinks   cp -v ${opts} ${source} ${BINDIR}/${dest} || die
  # 1. - library.so.1.0.0 -> library.so.1.0  
  if [ "${file%.*}" != *.so ]  
  then  
  ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*})  
  fi  
  # 2. - library.so.1.0.0 -> library.so.1  
  if [ "${file%.*.*}" != *.so ]  
  then  
  ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*})  
  fi  
495  }  }
496    
497  mcopy()  mdelete()
498  {  {
499   local source="$1"   local dest="$1"
  local dest="$2"  
500   local opts   local opts
501    
502     # enforce
503     if [[ $1 = -f ]]
504     then
505     opts="-f"
506     dest="$2"
507     fi
508    
509   # recursive   # recursive
510   if [[ $1 = -r ]] || [[ $1 = -R ]]   if [[ $1 = -r ]] || [[ $1 = -R ]]
511   then   then
512   opts="--recursive"   opts="-r"
513   source="$2"   dest="$2"
  dest="$3"  
514   fi   fi
515    
516   # recursive   # recursive
517   if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]]   if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]]
518   then   then
519   opts="--recursive --force"   opts="-r -f"
520   source="$2"   dest="$2"
  dest="$3"  
521   fi   fi
522    
  [[ -z ${source} ]] && die "No source given."  
523   [[ -z ${dest} ]] && die "No dest given."   [[ -z ${dest} ]] && die "No dest given."
524     for i in $(eval echo ${dest})
525   cp -v ${opts} ${source} ${BINDIR}/${dest} || die   do
526     if [[ -e ${BINDIR}/${dest} ]] || [[ -L ${BINDIR}/${dest} ]]
527     then
528     rm -v ${opts} ${BINDIR}/${dest} || die
529     else
530     die "${BINDIR}/${dest} does not exist."
531     fi
532     done
533  }  }
534    
535  mmove()  mmove()
# Line 664  mmove() Line 541  mmove()
541   # force   # force
542   if [[ $1 = -f ]]   if [[ $1 = -f ]]
543   then   then
544   opts="--force"   opts="-f"
545   source="$2"   source="$2"
546   dest="$3"   dest="$3"
547   fi   fi
# Line 710  mchown() Line 587  mchown()
587   # recursive   # recursive
588   if [[ $1 = -r ]] || [[ $1 = -R ]]   if [[ $1 = -r ]] || [[ $1 = -R ]]
589   then   then
590   local recursive="--recursive"   local recursive="-R"
591   local owner="$2"   local owner="$2"
592   local path="$3"   local path="$3"
593   fi   fi
# Line 730  mchmod() Line 607  mchmod()
607   # recursive   # recursive
608   if [[ $1 = -r ]] || [[ $1 = -R ]]   if [[ $1 = -r ]] || [[ $1 = -R ]]
609   then   then
610   local recursive="--recursive"   local recursive="-R"
611   local posix="$2"   local posix="$2"
612   local path="$3"   local path="$3"
613   fi   fi
# Line 755  mlink() Line 632  mlink()
632    
633   ln ${verbose} -snf ${symlink} ${BINDIR}/${pathto} || die   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    }

Legend:
Removed from v.4807  
changed lines
  Added in v.21095