1 #!/bin/sh
2 #
3 # POSIX shell script to install oils-for-unix into the proper directory.
4 # Distributed with the source tarball.
5 #
6 # Also shared with the old "oil.ovm" build.
7
8 # NOTE: 'install' is part of coreutils and busybox.
9
10 # The variable DESTDIR allows staged installs, where the installed files are
11 # not placed directly into the location they're expected to be executed from.
12 # They are placed in a temp dir first, which they are NOT expected to run out of.
13 #
14 # https://www.gnu.org/prep/standards/html_node/DESTDIR.html
15 #
16 # Staged installs are the default method of installation by package managers
17 # such as gentoo-portage.
18 #
19 # https://devmanual.gentoo.org/quickstart/index.html
20
21 # old tarball
22
23 readonly OVM_NAME=oil.ovm
24 readonly OVM_PATH=_bin/$OVM_NAME
25
26 readonly OILS_PATH=_bin/cxx-opt-sh/oils-for-unix.stripped
27
28
29 log() {
30 # indent it a bit
31 echo " $@" 1>&2
32 }
33
34 die() {
35 echo "FATAL install error: $@" 1>&2
36 exit 1
37 }
38
39 install_bin_and_links() {
40 ### Install an executable and symlinks.
41
42 bin_src=$1
43 bin_new_name=$2
44 shift 2
45
46 # symlinks are the remaining args
47
48 # NOTE: The configure step generates this
49 if ! . _build/detected-config.sh; then
50 die "Can't find _build/detected-config.sh. Run './configure'"
51 fi
52 # Now $PREFIX should be defined
53
54 #
55 # Install the shell binary
56 #
57
58 bin_dest_dir="${DESTDIR}${PREFIX}/bin"
59 bin_dest="$bin_dest_dir/$bin_new_name"
60
61 if ! install -v -d "$bin_dest_dir"; then
62 die "Couldn't create $bin_dest_dir"
63 fi
64
65 if ! install -v "$bin_src" "$bin_dest"; then
66 die "Couldn't install $bin_src -> $bin_dest"
67 fi
68 log "Installed $bin_dest"
69
70 working_dir=$PWD # save for later
71
72 cd "$bin_dest_dir"
73 for link in "$@"; do
74 if ! ln -s -f "$bin_new_name" "$link"; then # -f to overwrite
75 die "Couldn't create $link symlink"
76 fi
77 log "Created '$link' symlink"
78 done
79
80 #
81 # Install man page
82 #
83
84 # Relevant:
85 # https://unix.stackexchange.com/questions/90759/where-should-i-install-manual-pages-in-user-directory
86 # https://www.freebsd.org/cgi/man.cgi?query=install
87
88 cd "$working_dir"
89
90 # e.g. /usr/local/share/man/man1
91 man_dest_dir="${DESTDIR}${DATAROOTDIR}/man/man1"
92
93 if ! install -v -d "$man_dest_dir"; then
94 die "Couldn't create $man_dest_dir"
95 fi
96 log "Installed man page"
97
98 # -t to install to a directory and make them, -m so it's not executable
99 if ! install -v -m 644 doc/osh.1 "$man_dest_dir"; then
100 die "Couldn't install man page"
101 fi
102 }
103
104 if test -f "$OVM_PATH"; then
105 # Python tarball keeps 'oil' for compatibility
106 install_bin_and_links "$OVM_PATH" "$OVM_NAME" osh ysh oil
107 elif test -f "$OILS_PATH"; then
108 # new name is 'ysh', which points at oils-for-unix
109 install_bin_and_links "$OILS_PATH" 'oils-for-unix' osh ysh
110 else
111 die "Couldn't find $OVM_PATH or $OILS_PATH"
112 fi
113