RN rnmake  3.0.0
doinstall.sh
1 #!/bin/sh
2 # Package: RN Makefile System Utility
3 # File: doinstall.sh
4 # Desc: Install files for source directory to destination directory
5 # Usage: doinstall.sh [-s] mode source_dir dest_dir
6 #
7 # /*! \file */
8 # /*! \cond RNMAKE_DOXY*/
9 
10 # The options string
11 optstr="s"
12 
13 # Option defaults
14 silent=0
15 
16 # Positional arguments
17 mode=
18 srcdir=
19 dstdir=
20 
21 #
22 # Get options. Note: first colon says that getopts will not print errors.
23 #
24 while getopts :${optstr} opt
25 do
26  case $opt in
27  s) silent=1 ;;
28 
29  *) echo "rnmake: $0: error: Unknown opt: $opt"; exit 2;;
30  esac
31 done
32 
33 shift $(($OPTIND - 1))
34 
35 mode=${1}
36 srcdir=${2}
37 dstdir=${3}
38 
39 if [ "$mode" = "" ]
40 then
41  echo "rnmake: $0: error: No file creation mode specified."
42  exit 2
43 fi
44 
45 if [ "$srcdir" = "" ]
46 then
47  echo "rnmake: $0: error: No source directory specified."
48  exit 2
49 fi
50 
51 if [ "$dstdir" = "" ]
52 then
53  echo "rnmake: $0: error: No destination install directory specified."
54  exit 2
55 fi
56 
57 install -d -p -m 775 ${dstdir}
58 
59 cd ${srcdir} >/dev/null
60 
61 #
62 # Install files
63 #
64 find . -type f -o -type l | \
65 grep -v \.svn | \
66 while read srcpath
67 do
68  # strip leading './'
69  src="${srcpath##./}"
70  # destination [sub]directory name
71  dname=${dstdir}/$(dirname ${src})
72  # create directory if it does not exist
73  if [ ! -d ${dname} ]
74  then
75  install -d -p -m 775 ${dname}
76  fi
77  # destination file name
78  dst="${dstdir}/${src}"
79  if [ $silent = 0 ]
80  then
81  echo " ${dst}"
82  fi
83  # 'install' symlink file
84  if [ -h ${srcpath} ]
85  then
86  lnk=$(readlink ${srcpath})
87  cd ${dname} >/dev/null
88  fname=$(basename ${srcpath})
89  if [ ! -f ${fname} ]
90  then
91  ln -s ${lnk} ${fname}
92  fi
93  cd - >/dev/null
94  # install regular file with given permissions
95  else
96  install -p -m ${mode} ${srcpath} ${dst}
97  fi
98 done
99 
100 #/*! \endcond RNMAKE_DOXY */