Magellan Linux

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

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

revision 5218 by niro, Mon Dec 16 10:20:15 2013 UTC revision 5224 by niro, Mon Dec 16 13:58:37 2013 UTC
# Line 10  mpname() Line 10  mpname()
10   echo "${pname}"   echo "${pname}"
11  }  }
12    
 # installs given source to dest, but does not create any dest directories  
 # mcopy {[-r|-rf|-a]} /path/to/source /path/to/dest  
 mcopy()  
 {  
  local source="$1"  
  local dest="$2"  
  local opts  
   
  # recursive  
  if [[ $1 = -r ]] || [[ $1 = -R ]]  
  then  
  opts="-R"  
  source="$2"  
  dest="$3"  
  fi  
   
  # recursive  
  if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]]  
  then  
  opts="-R -f"  
  source="$2"  
  dest="$3"  
  fi  
   
  if [[ $1 = -a ]]  
  then  
  opts="-a"  
  source="$2"  
  dest="$3"  
  fi  
   
  [[ -z ${source} ]] && die "No source given."  
  [[ -z ${dest} ]] && die "No dest given."  
   
  cp -v ${opts} ${source} ${BINDIR}/${dest} || die  
 }  
   
 # deletes given target  
 # mdelete {[-f|-r|-rf]} /path/to/target  
 mdelete()  
 {  
  local dest="$1"  
  local opts  
   
  # enforce  
  if [[ $1 = -f ]]  
  then  
  opts="-f"  
  dest="$2"  
  fi  
   
  # recursive  
  if [[ $1 = -r ]] || [[ $1 = -R ]]  
  then  
  opts="-r"  
  dest="$2"  
  fi  
   
  # recursive  
  if [[ $1 = -rf ]] || [[ $1 = -fr ]] || [[ $1 = -Rf ]] || [[ $1 = -fR ]]  
  then  
  opts="-r -f"  
  dest="$2"  
  fi  
   
  [[ -z ${dest} ]] && die "No dest given."  
  [[ ! -e ${BINDIR}/${dest} ]] && die "${BINDIR}/${dest} does not exist."  
   
  rm -v ${opts} ${BINDIR}/${dest} || die  
 }  
   
 # moves given source to dest, but does not create any dest directories  
 # mmove {-f} /path/to/source /path/to/dest  
 mmove()  
 {  
  local source="$1"  
  local dest="$2"  
  local opts  
   
  # force  
  if [[ $1 = -f ]]  
  then  
  opts="-f"  
  source="$2"  
  dest="$3"  
  fi  
   
  [[ -z ${source} ]] && die "No source given."  
  [[ -z ${dest} ]] && die "No dest given."  
   
  mv -v ${opts} ${source} ${BINDIR}/${dest} || die  
 }  
   
 # changes owner of destination  
 # mchown {-r} owner /path/to/dest  
 mchown()  
 {  
  local owner="$1"  
  local path="$2"  
  local recursive  
   
  # recursive  
  if [[ $1 = -r ]] || [[ $1 = -R ]]  
  then  
  local recursive="-R"  
  local owner="$2"  
  local path="$3"  
  fi  
   
  [[ -z ${owner} ]] && die "No owner given."  
  [[ -z ${path} ]] && die "No path given."  
   
  chown -v ${recursive} ${owner} ${BINDIR}/${path} || die  
 }  
   
 # changes permission of destination  
 # mchmod {-r} permision /path/to/dest  
 mchmod()  
 {  
  local posix="$1"  
  local path="$2"  
  local recursive  
   
  # recursive  
  if [[ $1 = -r ]] || [[ $1 = -R ]]  
  then  
  local recursive="-R"  
  local posix="$2"  
  local path="$3"  
  fi  
   
  [[ -z ${posix} ]] && die "No posix given."  
  [[ -z ${path} ]] && die "No path given."  
   
  chmod -v ${recursive} ${posix} ${BINDIR}/${path} || die  
 }  
   
 # creates a symlink of source to destination  
 # mlink /path/to/source /path/to/symlink  
 mlink()  
 {  
  local symlink="$1"  
  local pathto="$2"  
  local verbose="-v"  
   
  # check for busybox as it doesn't support 'ln -v'  
  need_busybox_support ln && verbose=""  
   
  [[ -z ${symlink} ]] && die "No symlink given."  
  [[ -z ${pathto} ]] && die "No path given."  
   
  ln ${verbose} -snf ${symlink} ${BINDIR}/${pathto} || die  
 }  
   
13  # installs given directories  # installs given directories
14  # minstalldir /path/to/dest/dir {/path/to/dest/dirN}  # minstalldir /path/to/dest/dir {/path/to/dest/dirN}
15  minstalldir()  minstalldir()
# Line 195  minstallfile() Line 41  minstallfile()
41   if [[ -z $3 ]]   if [[ -z $3 ]]
42   then   then
43   dest=/usr/bin   dest=/usr/bin
44     install -d ${BINDIR}/${dest} || die
45   fi   fi
46   else   else
47   file="$1"   file="$1"
# Line 202  minstallfile() Line 49  minstallfile()
49   if [[ -z $2 ]]   if [[ -z $2 ]]
50   then   then
51   dest=/usr/bin   dest=/usr/bin
52     install -d ${BINDIR}/${dest} || die
53   fi   fi
54   fi   fi
55    
  # needed directory  
  minstalldir ${dest} || die  
   
56   # install our configfile   # install our configfile
57   install -v -m 0644 -o root -g root ${file} ${BINDIR}/${dest} || die   install -v -m 0644 -o root -g root ${file} ${BINDIR}/${dest} || die
58  }  }
# Line 228  minstallexec() Line 73  minstallexec()
73   if [[ -z $3 ]]   if [[ -z $3 ]]
74   then   then
75   dest=/usr/bin   dest=/usr/bin
76     install -d ${BINDIR}/${dest} || die
77   fi   fi
78   else   else
79   file="$1"   file="$1"
# Line 235  minstallexec() Line 81  minstallexec()
81   if [[ -z $2 ]]   if [[ -z $2 ]]
82   then   then
83   dest=/usr/bin   dest=/usr/bin
84     install -d ${BINDIR}/${dest} || die
85   fi   fi
86   fi   fi
87    
  # needed directory  
  minstalldir ${dest} || die  
   
88   # install our configfile   # install our configfile
89   install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die   install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die
90  }  }
# Line 251  minstalllib() Line 95  minstalllib()
95  {  {
96   local file   local file
97   local dest   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"   [[ -z $1 ]] && die "No file given"
104    
# Line 261  minstalllib() Line 109  minstalllib()
109   if [[ -z $3 ]]   if [[ -z $3 ]]
110   then   then
111   dest=/usr/$(mlibdir)   dest=/usr/$(mlibdir)
112     install -d ${BINDIR}/${dest} || die
113   fi   fi
114   else   else
115   file="$1"   file="$1"
# Line 268  minstalllib() Line 117  minstalllib()
117   if [[ -z $2 ]]   if [[ -z $2 ]]
118   then   then
119   dest=/usr/$(mlibdir)   dest=/usr/$(mlibdir)
120     install -d ${BINDIR}/${dest} || die
121   fi   fi
122   fi   fi
123    
  # needed directory  
  minstalldir ${dest} || die  
   
124   # install our library   # install our library
125   minstallexec ${file} ${dest} || die   install -v -m 0755 -o root -g root ${file} ${BINDIR}/${dest} || die
126    
127   # prefer scanelf   # prefer scanelf
128   if [[ -x $(type -P scanelf) ]]   if [[ -x $(type -P scanelf) ]]
129   then   then
130   local soname="$(scanelf -qBF '%S#p' ${file})"   local soname="$(scanelf -qBF '%S#p' ${file})"
131   mlink $(basename ${file}) ${dest}/${soname} || die   ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/${soname} || die
132   else   else
133   echo -e "${COLYELLOW}minstalllib(): Warning: scanelf not found, using fallback symlink method${COLDEFAULT}"   echo -e "${COLYELLOW}minstalllib(): Warning: scanelf not found, using fallback symlink method${COLDEFAULT}"
134    
# Line 289  minstalllib() Line 136  minstalllib()
136   # 1. - library.so.1.0.0 -> library.so.1.0   # 1. - library.so.1.0.0 -> library.so.1.0
137   if [ "${file%.*}" != *.so ]   if [ "${file%.*}" != *.so ]
138   then   then
139   mlink $(basename ${file}) ${dest}/$(basename ${file%.*}) || die   ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*}) || die
140   fi   fi
141   # 2. - library.so.1.0.0 -> library.so.1   # 2. - library.so.1.0.0 -> library.so.1
142   if [ "${file%.*.*}" != *.so ]   if [ "${file%.*.*}" != *.so ]
143   then   then
144   mlink $(basename ${file}) ${dest}/$(basename ${file%.*.*}) || die   ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*}) || die
145   fi   fi
146   # 3. - library.so.1.0.0.0 -> library.so.1   # 3. - library.so.1.0.0.0 -> library.so.1
147   if [ "${file%.*.*.*}" != *.so ]   if [ "${file%.*.*.*}" != *.so ]
148   then   then
149   mlink $(basename ${file}) ${dest}/$(basename ${file%.*.*.*}) || die   ln ${verbose} -snf $(basename ${file}) ${BINDIR}/${dest}/$(basename ${file%.*.*.*}) || die
150   fi   fi
151   fi   fi
152  }  }
# Line 329  minstallenv() Line 176  minstallenv()
176   fi   fi
177    
178   # needed directory   # needed directory
179   minstalldir /etc/env.d || die   install -d ${BINDIR}/etc/env.d || die
180    
181   # install our envfile   # install our envfile
182   minstallfile ${file} /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 360  minstallconf() Line 207  minstallconf()
207   fi   fi
208    
209   # needed directory   # needed directory
210   minstalldir /etc/conf.d || die   install -d ${BINDIR}/etc/conf.d || die
211    
212   # install our configfile   # install our configfile
213   minstallfile ${file} /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 399  minstalletc() Line 246  minstalletc()
246   fi   fi
247    
248   # needed directory   # needed directory
249   minstalldir ${destdir} || die   install -d ${BINDIR}/${destdir} || die
250    
251   # install our configfile   # install our configfile
252   minstallfile ${file} ${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 420  minstallman() Line 267  minstallman()
267   manfile="$(basename ${file})"   manfile="$(basename ${file})"
268   mandir="man${manfile##*.}"   mandir="man${manfile##*.}"
269    
270   minstalldir /usr/share/man/${mandir} || die   install -d ${BINDIR}/usr/share/man/${mandir} || die
271   minstallfile ${file} /usr/share/man/${mandir}/${manfile} || die   install -v -m0644 ${file} ${BINDIR}/usr/share/man/${mandir}/${manfile} || die
272   done   done
273  }  }
274    
# Line 435  minstallinfo() Line 282  minstallinfo()
282    
283   for file in $@   for file in $@
284   do   do
285   minstalldir /usr/share/info || die   install -d ${BINDIR}/usr/share/info || die
286   minstallfile ${file} /usr/share/info/$(basename ${file}) || die   install -v -m0644 ${file} ${BINDIR}/usr/share/info/$(basename ${file}) || die
287   done   done
288  }  }
289    
# Line 458  minstallhtml() Line 305  minstallhtml()
305    
306   for file in $@   for file in $@
307   do   do
308   minstalldir /usr/share/doc/${PNAME}-${PVER}/html${prefix} || die   install -d ${BINDIR}/usr/share/doc/${PNAME}-${PVER}/html${prefix} || die
309    
310   if [[ -d ${file} ]]   if [[ -d ${file} ]]
311   then   then
# Line 470  minstallhtml() Line 317  minstallhtml()
317   minstallhtml --prefix ${subprefix} ${subfile} || die   minstallhtml --prefix ${subprefix} ${subfile} || die
318   done   done
319   else   else
320   minstallfile ${file} /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 508  minstallpixmap() Line 355  minstallpixmap()
355   fi   fi
356    
357   # needed directory   # needed directory
358   minstalldir ${destdir} || die   install -d ${BINDIR}/${destdir} || die
359    
360   # install our pixmap   # install our pixmap
361   minstallfile ${file} ${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 539  minstallpam() Line 386  minstallpam()
386   fi   fi
387    
388   # needed directory   # needed directory
389   minstalldir /etc/pam.d || die   install -d ${BINDIR}/etc/pam.d || die
390    
391   # install our configfile   # install our configfile
392   minstallfile ${file} /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 574  minstallcron() Line 421  minstallcron()
421   fi   fi
422    
423   # needed directory   # needed directory
424   minstalldir /etc/cron.${loop} || die   install -m0750 -d ${BINDIR}/etc/cron.${loop} || die
  mchmod 0750 /etc/cron.${loop} || die  
425    
426   # install our cronfile   # install our cronfile
427   minstallexec ${file} /etc/cron.${loop}/${cronfile} || die   install -v -m 0750 -o root -g root ${file} ${BINDIR}/etc/cron.${loop}/${cronfile} || die
  mchmod 0750 ${file} /etc/cron.${loop}/${cronfile} || die  
428  }  }
429    
430    
431  # installs logrotate configuration files  # installs logrotate configuration files
432  # minstalllog /path/to/logrotatefile {destfilename}  # minstalllog /path/to/logrotatefile {destfilename}
433  minstalllog()  minstalllog()
# Line 607  minstalllog() Line 453  minstalllog()
453   fi   fi
454    
455   # needed directory   # needed directory
456   minstalldir /etc/logrotate.d || die   install -d ${BINDIR}/etc/logrotate.d || die
457    
458   # install our configfile   # install our configfile
459   minstallfile ${file} /etc/logrotate.d/${logfile} || die   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     [[ ! -e ${BINDIR}/${dest} ]] && die "${BINDIR}/${dest} does not exist."
525    
526     rm -v ${opts} ${BINDIR}/${dest} || die
527    }
528    
529    mmove()
530    {
531     local source="$1"
532     local dest="$2"
533     local opts
534    
535     # force
536     if [[ $1 = -f ]]
537     then
538     opts="-f"
539     source="$2"
540     dest="$3"
541     fi
542    
543     [[ -z ${source} ]] && die "No source given."
544     [[ -z ${dest} ]] && die "No dest given."
545    
546     mv -v ${opts} ${source} ${BINDIR}/${dest} || die
547  }  }
548    
549  # mark directories undeletable  # mark directories undeletable
# Line 620  mkeepdir() Line 553  mkeepdir()
553   [[ -z "$1" ]] && die "No directory given"   [[ -z "$1" ]] && die "No directory given"
554    
555   keepdir="$1"   keepdir="$1"
556   minstalldir ${keepdir} || die   install -v -d ${BINDIR}/${keepdir} || die
557   touch ${BINDIR}/${keepdir}/.keep || die   touch ${BINDIR}/${keepdir}/.keep || die
558  }  }
559    
# Line 635  memptyfile() Line 568  memptyfile()
568   file="$1"   file="$1"
569   path="$(dirname ${file})"   path="$(dirname ${file})"
570    
571   minstalldir ${path} || die   install -d ${BINDIR}/${path} || die
572   touch ${BINDIR}/${file} || die   touch ${BINDIR}/${file} || die
573  }  }
574    
575    mchown()
576    {
577     local owner="$1"
578     local path="$2"
579     local recursive
580    
581     # recursive
582     if [[ $1 = -r ]] || [[ $1 = -R ]]
583     then
584     local recursive="-R"
585     local owner="$2"
586     local path="$3"
587     fi
588    
589     [[ -z ${owner} ]] && die "No owner given."
590     [[ -z ${path} ]] && die "No path given."
591    
592     chown -v ${recursive} ${owner} ${BINDIR}/${path} || die
593    }
594    
595    mchmod()
596    {
597     local posix="$1"
598     local path="$2"
599     local recursive
600    
601     # recursive
602     if [[ $1 = -r ]] || [[ $1 = -R ]]
603     then
604     local recursive="-R"
605     local posix="$2"
606     local path="$3"
607     fi
608    
609     [[ -z ${posix} ]] && die "No posix given."
610     [[ -z ${path} ]] && die "No path given."
611    
612     chmod -v ${recursive} ${posix} ${BINDIR}/${path} || die
613    }
614    
615    mlink()
616    {
617     local symlink="$1"
618     local pathto="$2"
619     local verbose="-v"
620    
621     # check for busybox as it doesn'tz support 'ln -v'
622     [[ $(readlink $(which ln)) = */busybox ]] && verbose=""
623    
624     [[ -z ${symlink} ]] && die "No symlink given."
625     [[ -z ${pathto} ]] && die "No path given."
626    
627     ln ${verbose} -snf ${symlink} ${BINDIR}/${pathto} || die
628    }
629    
630  mclearconfig()  mclearconfig()
631  {  {
632   local confdir   local confdir

Legend:
Removed from v.5218  
changed lines
  Added in v.5224