1 | #!/bin/sh -f |
---|
2 | |
---|
3 | #------------------------------------------------------------------------------ |
---|
4 | # Arguments: |
---|
5 | # |
---|
6 | # -source=1 absolute source directory |
---|
7 | # -name=2 file name |
---|
8 | # -out=3 absolute installation directory |
---|
9 | # -cmd=4 installation system command |
---|
10 | # -cmtpath=5 cmtpath of the package |
---|
11 | # |
---|
12 | # OR |
---|
13 | # |
---|
14 | # -source 1 absolute source directory |
---|
15 | # -name 2 file name |
---|
16 | # -out 3 absolute installation directory |
---|
17 | # -cmd 4 installation system command |
---|
18 | # -cmtpath 5 cmtpath of the package |
---|
19 | # |
---|
20 | # OR |
---|
21 | # |
---|
22 | # 1 absolute source directory |
---|
23 | # 2 file name |
---|
24 | # 3 absolute installation directory |
---|
25 | # 4 installation system command |
---|
26 | # 5 cmtpath of the package |
---|
27 | #------------------------------------------------------------------------------ |
---|
28 | : ${CMTMSGPREFIX:=$0:} |
---|
29 | |
---|
30 | source_dir="" |
---|
31 | file_name="" |
---|
32 | install_dir="" |
---|
33 | install_command="" |
---|
34 | cmtpath="" |
---|
35 | |
---|
36 | #handle_args $* |
---|
37 | # |
---|
38 | #------------------------------------------------------------------------------ |
---|
39 | #handle_args () |
---|
40 | #{ |
---|
41 | opt="-source" |
---|
42 | |
---|
43 | while test $# -gt 0; do |
---|
44 | arg=$1 |
---|
45 | shift |
---|
46 | |
---|
47 | val=${arg} |
---|
48 | |
---|
49 | case ${arg} in |
---|
50 | -?*=*) |
---|
51 | opt=${arg%%"="*} |
---|
52 | val=${arg#"${opt}="} |
---|
53 | ;; |
---|
54 | -?*) |
---|
55 | opt=${arg} |
---|
56 | val= |
---|
57 | if test $# -gt 0; then |
---|
58 | val=$1 |
---|
59 | shift |
---|
60 | fi |
---|
61 | ;; |
---|
62 | esac |
---|
63 | |
---|
64 | case ${opt} in |
---|
65 | -source) |
---|
66 | source_dir=${val}; |
---|
67 | opt="-name"; |
---|
68 | ;; |
---|
69 | -name) |
---|
70 | file_name=${val}; |
---|
71 | opt="-out"; |
---|
72 | ;; |
---|
73 | -out) |
---|
74 | install_dir=${val}; |
---|
75 | opt="-cmd"; |
---|
76 | ;; |
---|
77 | -cmd) |
---|
78 | install_command=${val}; |
---|
79 | opt="-cmtpath"; |
---|
80 | ;; |
---|
81 | -cmtpath) |
---|
82 | cmtpath=${val}; |
---|
83 | opt=""; |
---|
84 | ;; |
---|
85 | *) |
---|
86 | ;; |
---|
87 | esac |
---|
88 | |
---|
89 | done |
---|
90 | |
---|
91 | if test "${source_dir}" = ""; then |
---|
92 | echo "cmt_install_action.sh> no source directory" |
---|
93 | exit 1 |
---|
94 | fi |
---|
95 | |
---|
96 | if test "${file_name}" = ""; then |
---|
97 | echo "cmt_install_action.sh> no file name" |
---|
98 | exit 1 |
---|
99 | fi |
---|
100 | |
---|
101 | if test "${install_dir}" = ""; then |
---|
102 | echo "cmt_install_action.sh> no install dir" |
---|
103 | exit 1 |
---|
104 | fi |
---|
105 | |
---|
106 | if test "${install_command}" = ""; then |
---|
107 | echo "cmt_install_action.sh> no install command" |
---|
108 | exit 1 |
---|
109 | fi |
---|
110 | |
---|
111 | if test "${cmtpath}" = ""; then |
---|
112 | if [ "${CMTDEBUG:-}" ]; then |
---|
113 | unset CMTDEBUG |
---|
114 | set -x |
---|
115 | fi |
---|
116 | package=`cmt show macro_value package` || exit |
---|
117 | cmtpath=`cmt show macro_value ${package}_cmtpath` || exit |
---|
118 | fi |
---|
119 | |
---|
120 | if test ! -d "${cmtpath}"; then |
---|
121 | echo "cmt_install_action.sh> no cmtpath" |
---|
122 | exit 1 |
---|
123 | fi |
---|
124 | #} |
---|
125 | |
---|
126 | dest_file_path=${install_dir}/${file_name} |
---|
127 | ref_file=${dest_file_path}.cmtref |
---|
128 | full_source_name=${source_dir}/${file_name} |
---|
129 | |
---|
130 | case `pwd -P` in |
---|
131 | `(cd ${cmtpath}; pwd -P)`*) : ;; |
---|
132 | *) echo "Current directory outside of the installation area. Cannot proceed"; |
---|
133 | exit 0 ;; |
---|
134 | esac |
---|
135 | |
---|
136 | if test ! -d ${install_dir}; then |
---|
137 | mkdir -p ${install_dir} || |
---|
138 | { echo "Cannot install file ${file_name} into installation directory ${install_dir}"; exit 0; } |
---|
139 | fi |
---|
140 | |
---|
141 | if test -L ${dest_file_path} -o -f ${dest_file_path}; then |
---|
142 | /bin/rm -f ${dest_file_path} |
---|
143 | fi |
---|
144 | |
---|
145 | if test -f ${ref_file}; then |
---|
146 | /bin/rm -f ${ref_file} |
---|
147 | fi |
---|
148 | |
---|
149 | if test "${cmtmsg}"; then |
---|
150 | echo "${CMTMSGPREFIX}" "installing file ${file_name} into ${install_dir}" |
---|
151 | fi |
---|
152 | if test "${makecmd}"; then set -v; fi |
---|
153 | eval ${install_command} ${full_source_name} ${dest_file_path} || exit |
---|
154 | echo ${full_source_name} >${ref_file} || exit |
---|
155 | if test "${makecmd}"; then set +v; fi |
---|