forked from wttech/CQ-Unix-Toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·143 lines (135 loc) · 3.62 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh
# CQ Unix Toolkit
# Copyright (C) 2013 Cognifide Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
INSTALL_DIR="/usr/local/bin"
if [ "${USER}" != 'root' ]
then
echo "Please execute with superuser privileges" >&2
exit 1
fi
BSD_PRESENT=$(echo "${OSTYPE}" | grep -c -E '(darwin|bsd)')
if [ "${BSD_PRESENT}" -gt 0 ]
then
BSD=1
fi
if [ -n "${BSD}" ]
then
ECHOX="echo "
else
ECHOX=$(which echo)
if [ ${?} -ne 0 -o -z "${ECHOX}" ]
then
# fallback to echo
ECHOX="echo "
else
${ECHOX} --version >/dev/null 2>/dev/null
BSDECHO=${?}
[ ${BSDECHO} -eq 0 ] && ECHOX="${ECHOX} -e " || ECHOX="echo "
fi
fi
dir=$(dirname "${0}")
basedir=$(readlink -f "${dir}")
${ECHOX} "I assume that CQ UNIX toolkit are in: '${basedir}'\n"
if [ ! -d "${INSTALL_DIR}" ]
then
echo "Cannot find '${INSTALL_DIR}' directory" >&2
exit 1
fi
existing_tools=""
warning=0
count=0
total=0
cmds=""
for cmd in cq*
do
if [ -x "${basedir}/${cmd}" ]
then
total=$((total+1))
if [ -f "${INSTALL_DIR}/${cmd}" ]
then
if [ -L "${INSTALL_DIR}/${cmd}" ]
then
target=$(readlink -f "${INSTALL_DIR}/${cmd}")
output="${INSTALL_DIR}/${cmd} --> ${target} (symbolic link)\n"
else
output="${INSTALL_DIR}/${cmd} (binary file)\n"
fi
count=$((count+1))
existing_tools="${existing_tools}${output}"
warning=1
fi
cmds="${cmds} ${cmd}"
fi
done
if [ ! -z "${existing_tools}" ]
then
${ECHOX} "${count} currently existing commands will be overwritten:"
${ECHOX} "${existing_tools}"
fi
ask=0
force=0
options=""
${ECHOX} \
"${total} commands (symbolic links) will be installed in: ${INSTALL_DIR}\n"
if [ ${warning} -eq 1 ]
then
${ECHOX} "Would you like to:"
${ECHOX} "-- replace (a)ll ${count} links and install new files,"
${ECHOX} "-- replace (i)ndividual ones, install new files"
${ECHOX} "-- (s)kip existing ones, install new files"
${ECHOX} "-- (q)uit\n"
read -p " (a/i/s/q) ? " REPLY
if [ "${REPLY}" != "A" -a "${REPLY}" != "a" -a "${REPLY}" != "i" \
-a "${REPLY}" != "I" -a "${REPLY}" != "s" -a "${REPLY}" != "S" ]
then
echo "Aborted"
exit 1
fi
options=""
case "${REPLY}" in
A) force=1; options="-f" ;;
a) force=1; options="-f" ;;
I) ask=1; options="-f";;
i) ask=1; options="-f";;
esac
else
read -p "Do you want to continue (Y/N) ? " REPLY
if [ "${REPLY}" != "Y" -a "${REPLY}" != "y" ]
then
echo "Aborted"
exit 1
fi
fi
for cmd in ${cmds}
do
confirmed=1
if [ ${ask} -eq 1 ]
then
read -p "Would you like to replace '${INSTALL_DIR}/${cmd}' (Y/N) ? "\
REPLY
if [ "${REPLY}" != "Y" -a "${REPLY}" != "y" ]
then
confirmed=0
fi
fi
if [ ${confirmed} -eq 1 ]
then
if [ ${force} -eq 1 -o ! -f "${INSTALL_DIR}/${cmd}" ]
then
ln ${options} -s "${basedir}/${cmd}" "${INSTALL_DIR}/${cmd}"
fi
fi
done
${ECHOX} "\nInstallation finished."