-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer
executable file
·187 lines (149 loc) · 3.8 KB
/
installer
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#! /bin/sh
#
# (c) 2015, coded by Nat!, Mulle KybernetiK
#
[ "${TRACE}" = 'YES' ] && set -x && : "$0" "$@"
if [ "${MULLE_NO_COLOR}" != 'YES' ]
then
# Escape sequence and resets
C_RESET="\033[0m"
# Useable Foreground colours, for black/white white/black
C_RED="\033[0;31m" C_GREEN="\033[0;32m"
C_BLUE="\033[0;34m" C_MAGENTA="\033[0;35m"
C_CYAN="\033[0;36m"
C_BR_RED="\033[0;91m"
C_BOLD="\033[1m"
#
# restore colors if stuff gets wonky
#
trap 'printf "${C_RESET} >&2 ; exit 1"' TERM INT
fi
installer_fail()
{
printf "${C_BR_RED}Error: $*${C_RESET}\n" >&2
exit 1
}
#
# https://github.com/hoelzro/useful-scripts/blob/master/decolorize.pl
#
#
# stolen from:
# https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
# ----
#
_installer_prepend_path_if_relative()
{
case "$2" in
/*)
printf "%s\n" "$2"
;;
*)
printf "%s/%s\n" "$1" "$2"
;;
esac
}
installer_resolve_symlinks()
{
filepath="`readlink "$1"`"
if [ $? -eq 0 ]
then
dir_context=`dirname -- "$1"`
installer_resolve_symlinks "`_installer_prepend_path_if_relative "$dir_context" "$filepath"`"
else
printf "%s\n" "$1"
fi
}
installer_canonicalize_path()
{
if [ -d "$1" ]
then
(
cd "$1" 2>/dev/null && pwd -P
)
else
dir="`dirname "$1"`"
file="`basename -- "$1"`"
(
cd "${dir}" 2>/dev/null &&
echo "`pwd -P`/${file}"
)
fi
}
installer_realpath()
{
installer_canonicalize_path "`installer_resolve_symlinks "$1"`"
}
installer_get_windows_path()
{
directory="$1"
if [ -z "${directory}" ]
then
return 1
fi
( cd "$directory" ; pwd -PW ) || installer_fail "installer_failed to get pwd"
return 0
}
installer_get_sh_windows_path()
{
directory="`which sh`"
directory="`dirname -- "${directory}"`"
directory="`installer_get_windows_path "${directory}"`"
if [ -z "${directory}" ]
then
installer_fail "could not find sh.exe"
fi
printf "%s\n" "${directory}/sh.exe"
}
installer_sed_mangle_escape_slashes()
{
sed -e 's|/|\\\\|g'
}
r_installer_install_prefix()
{
prefix="`installer_realpath "$1" 2> /dev/null`"
if [ ! -d "${prefix}" ]
then
installer_fail "\"${prefix}\" does not exist"
fi
directory="`dirname -- "$0"`"
cd "${directory}" || installer_fail "Could not cd to \"$directory\" ($PWD)"
cd .. || installer_fail "Could not cd to \"..\" ($PWD)" # compensate for installer being in bin
bindir="${prefix}/bin"
if [ -d "${bindir}" ]
then
bindir="`installer_realpath "${bindir}"`"
fi
RVAL="`dirname -- "${bindir}"`"
}
main()
{
prefix=${1:-"/usr/local"}
[ $# -eq 0 ] || shift
mode=${1:-755}
[ $# -eq 0 ] || shift
libexecdirname="${1:-libexec}"
[ $# -eq 0 ] || shift
if [ -z "${prefix}" -o "${prefix}" = "--help" ] || [ -z "${mode}" ]
then
installer_fail "usage: installer [prefix] [mode] [libexecdirname]"
fi
r_installer_install_prefix "${prefix}"
prefix="${RVAL}"
bin="${prefix}/bin"
share="${prefix}/share/mulle-sde" # sic!
libexec="${prefix}/${libexecdirname}/mulle-test"
mkdir -p "${bin}" || installer_fail "could not create ${bin}"
mkdir -p "${share}" || installer_fail "could not create ${share}"
mkdir -p "${libexec}" || installer_fail "could not create ${libexec}"
install -m "${mode}" "mulle-test" "${bin}/mulle-test" || exit 1
printf "install: ${C_MAGENTA}${C_BOLD}%s${C_RESET}\n" "${bin}/mulle-test" >&2
for i in src/*.sh
do
mkdir -p "${libexec}" 2> /dev/null
install ${VERBOSE} -m "${mode}" "${i}" "${libexec}" || exit 1
done
EXTENSION_DIR="${share}/extensions"
mkdir -p "${EXTENSION_DIR}" || exit 1
cp -Rp ${VERBOSE} "src/mulle-sde" "${EXTENSION_DIR}/" || exit 1
}
main "$@"