-
Notifications
You must be signed in to change notification settings - Fork 0
/
opamconfig_install.sh
106 lines (85 loc) · 2.06 KB
/
opamconfig_install.sh
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
### opamconfig_install.sh -- A standalone installer for opamconfig
# opamconfig (https://github.com/michipili/opamconfig)
# This file is part of opamconfig
#
# Copyright © 2016–2017 Michael Grünewald
#
# This file must be used under the terms of the MIT license.
# This source file is licensed as described in the file LICENSE, which
# you should have received as part of this distribution. The terms
# are also available at
# https://opensource.org/licenses/MIT
# This script allows to install opamconfig without depending on BSD
# Owl and bmake.
PACKAGE='opamconfig_install'
# tmpfile_initializer TMPFILE
# Create a temporary file
#
# The path to that file is saved in TMPFILE. A hook is registered
# to remove that file upon program termination.
tmpfile_initializer()
{
local _tmpfile _script
_tmpfile=$(mktemp -t "${PACKAGE}-XXXXXX")
_script=$(printf 'rm -f "%s"' "${_tmpfile}")
trap "${_script}" INT TERM EXIT
eval $1="${_tmpfile}"
export $1
}
# configdb
# Print the configuration database
#
# The database is extracted from Makefile.config thanks to a sed
# script. It relies on the fact that REPLACESUBST is the last
# variable declared and the only to use the `+=` assignment to
# produce the correct output.
configdb()
{
sed -n -e '
$ {
x
s/\n/ /g
p
}
/^#/d
/^$/d
s/[[:blank:]]*//g
s/[?]=/=/
/^REPLACESUBST=/{
h
b
}
/^REPLACESUBST+=/{
s/REPLACESUBST+=//
H
b
}
p
' Makefile.config
}
# configscript
# A sed script to replace configuration values
configscript()
{
configdb | sed -e 's/\(.*\)=\(.*\)/s|@\1@|\2|g/'
}
# replace
# Replace configuration values in script
replace()
{
sed -e "$(configscript)" "$@"
}
# actual_install PREFIX
# Install the script in PREFIX
actual_install()
{
tmpfile_initializer opamconfig_output
if ! [ -r "${opamconfig_output}" ]; then
wlog 'Error: %s: Cannot create temporary file.' "${opamconfig_output}"
exit 1
fi
replace opamconfig.sh > "${opamconfig_output}"
install -m 755 "${opamconfig_output}" "$1/bin/opamconfig"
exit $?
}
actual_install "$@"