-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
install
executable file
·174 lines (133 loc) · 3.63 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
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
#!/bin/sh
#
# POSIX shell script to install oils-for-unix into the proper directory.
# Distributed with the source tarball.
#
# For usage, run:
#
# ./install --help
#
# Also shared with the old "oil.ovm" build.
# NOTE: 'install' is part of coreutils and busybox.
# old tarball
readonly OVM_NAME=oil.ovm
readonly OVM_PATH=_bin/$OVM_NAME
log() {
# 4 space indent
echo " $@" >& 2
}
die() {
echo "FATAL install error: $@" >& 2
exit 1
}
my_install() {
### A bit like install -v. OpenBSD doesn't have -v
echo " + install $@" >& 2
install "$@"
}
install_bin_and_links() {
### Install an executable and symlinks.
bin_src=$1
bin_new_name=$2
shift 2
# symlinks are the remaining args
# NOTE: The configure step generates this
if ! . _build/detected-config.sh; then
die "Can't find _build/detected-config.sh. Run './configure'"
fi
# Now $PREFIX should be defined
#
# Install the shell binary
#
bin_dest_dir="${DESTDIR}${PREFIX}/bin"
bin_dest="$bin_dest_dir/$bin_new_name"
if ! my_install -d "$bin_dest_dir"; then
die "Couldn't create $bin_dest_dir"
fi
if ! my_install "$bin_src" "$bin_dest"; then
die "Couldn't install $bin_src -> $bin_dest"
fi
log "Installed $bin_dest"
working_dir=$PWD # save for later
cd "$bin_dest_dir"
for link in "$@"; do
if ! ln -s -f "$bin_new_name" "$link"; then # -f to overwrite
die "Couldn't create $link symlink"
fi
log "Created '$link' symlink"
done
#
# Install man page
#
# Relevant:
# https://unix.stackexchange.com/questions/90759/where-should-i-install-manual-pages-in-user-directory
# https://www.freebsd.org/cgi/man.cgi?query=install
cd "$working_dir"
# e.g. /usr/local/share/man/man1
man_dest_dir="${DESTDIR}${DATAROOTDIR}/man/man1"
if ! my_install -d "$man_dest_dir"; then
die "Couldn't create $man_dest_dir"
fi
# -m so it's not executable
if ! my_install -m 644 doc/osh.1 "$man_dest_dir"; then
die "Couldn't install man page"
fi
log "Installed man page"
}
show_help() {
cat <<'EOF'
Install the oils-for-unix binary, and symlinks to it, like osh.
Usage:
./install # install the stripped binary
./install _bin/cxx-opt-sh/oils-for-unix # or a given binary
./install --help # show this help
DESTDIR=/tmp/foo ./install
The DESTDIR var allows staged installs. This means that the installed files
are placed in a temp dir first, NOT the dir they are run from on the target
machine.
https://www.gnu.org/prep/standards/html_node/DESTDIR.html
Package managers such as gentoo-portage used staged installs by default.
https://devmanual.gentoo.org/quickstart/index.html
EOF
}
FLAG_verbose=
ARG_oils_binary=
parse_flags() {
while true; do
case "$1" in
-h|--help)
show_help
exit 0
;;
-v|--verbose)
FLAG_verbose=true
;;
-*)
die "Invalid flag '$1'"
;;
*)
# No more flags
break
;;
esac
shift
done
# by default, install the stripped binary
ARG_oils_binary=${1:-_bin/cxx-opt-sh/oils-for-unix.stripped}
}
main() {
parse_flags "$@" # sets FLAG_*, or prints help
if test -n "$FLAG_verbose"; then
log "Installing Oils binary $ARG_oils_binary"
fi
if test -f "$OVM_PATH"; then
# Python tarball keeps 'oil' for compatibility
install_bin_and_links "$OVM_PATH" "$OVM_NAME" osh ysh oil
elif test -f "$ARG_oils_binary"; then
# 'osh' and 'ysh' point at 'oils-for-unix'
install_bin_and_links "$ARG_oils_binary" 'oils-for-unix' osh ysh
else
die "Couldn't find $OVM_PATH or $ARG_oils_binary"
fi
}
main "$@"