-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodemeta-installer.tmpl
115 lines (92 loc) · 2.27 KB
/
codemeta-installer.tmpl
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
#!/bin/sh
#
# Set the package name and version to install
#
PACKAGE="$name$"
VERSION="$version$"
RELEASE="https://github.com/caltechlibrary/$$PACKAGE/releases/tag/v$$VERSION"
#
# Get the name of this script.
#
INSTALLER="$$(basename "$$0")"
#
# Figure out what the zip file is named
#
OS_NAME="$$(uname -o)"
MACHINE="$$(uname -m)"
case "$$OS_NAME" in
Darwin)
OS_NAME="macOS"
;;
"GNU/Linux")
OS_NAME="Linux"
;;
esac
ZIPFILE="$$PACKAGE-v$$VERSION-$$OS_NAME-$$MACHINE.zip"
#
# Check to see if this zip file has been downloaded.
#
DOWNLOAD_URL="https://github.com/caltechlibrary/$$PACKAGE/releases/download/v$$VERSION/$$ZIPFILE"
if ! curl -L -o "$$HOME/Downloads/$$ZIPFILE" "$$DOWNLOAD_URL"; then
echo "Curl failed to get $$DOWNLOAD_URL"
fi
cat<<EOT
Retrieved $$DOWNLOAD_URL
Saved as $$HOME/Downloads/$$ZIPFILE
EOT
if [ ! -f "$$HOME/Downloads/$$ZIPFILE" ]; then
cat<<EOT
To install $$PACKAGE you need to download
$$ZIPFILE
from
$$RELEASE
You can do that with your web browser. After
that you should be able to re-run $$INSTALLER
EOT
exit 1
fi
START="$$(pwd)"
mkdir -p "$$HOME/.$$PACKAGE/installer"
cd "$$HOME/.$$PACKAGE/installer" || exit 1
unzip "$$HOME/Downloads/$$ZIPFILE" "bin/*"
#
# Copy the application into place
#
mkdir -p "$$HOME/bin"
EXPLAIN_OS_POLICY="yes"
find bin -type f | while read -r APP; do
V=$$("./$$APP" --version)
if [ "$$V" = "" ]; then
EXPLAIN_OS_POLICY="yes"
fi
mv "$$APP" "$$HOME/bin/"
done
#
# Make sure $$HOME/bin is in the path
#
DIR_IN_PATH='no'
for P in $$PATH; do
if [ "$$P" = "$$HOME/bin" ]; then
DIR_IN_PATH='yes'
fi
done
if [ "$$DIR_IN_PATH" = "no" ]; then
# shellcheck disable=SC2016
echo 'export PATH="$$HOME/bin:$$PATH"' >>"$$HOME/.bashrc"
# shellcheck disable=SC2016
echo 'export PATH="$$HOME/bin:$$PATH"' >>"$$HOME/.zshrc"
fi
rm -fR "$$HOME/.$$PACKAGE/installer"
cd "$$START" || exit 1
# shellcheck disable=SC2031
if [ "$$EXPLAIN_OS_POLICY" = "no" ]; then
cat <<EOT
You need to take additional steps to complete installation.
Your operating systems' security policied need to "allow"
running programs from $$PACKAGE.
Example: on macOS you can type open the programs in finder.
open $$HOME/bin
Find the program(s) and right click on the program(s)
installed to enable them to run.
EOT
fi