Repository navigation
Expand file tree
/
Copy pathinstaller.sh
More file actions
executable file
·188 lines (153 loc) · 4.42 KB
/
Copy pathinstaller.sh
File metadata and controls
executable file
·188 lines (153 loc) · 4.42 KB
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
187
#!/bin/sh
# generated with CMTools 2.5.1 fed6142
#
# Set the package name and version to install
#
PACKAGE="dataset"
VERSION="2.5.1"
GIT_GROUP="caltechlibrary"
RELEASE="https://github.com/$GIT_GROUP/$PACKAGE/releases/tag/v$VERSION"
if [ "$PKG_VERSION" != "" ]; then
VERSION="${PKG_VERSION}"
echo "${PKG_VERSION} used for version v${VERSION}"
fi
#
# Get the name of this script.
#
INSTALLER="$(basename "$0")"
#
# Figure out what the zip file is named
#
OS_NAME="$(uname)"
MACHINE="$(uname -m)"
case "$OS_NAME" in
Darwin)
OS_NAME="macOS"
;;
GNU/Linux)
OS_NAME="Linux"
;;
esac
if [ "$1" != "" ]; then
VERSION="$1"
echo "Version set to v${VERSION}"
fi
ZIPFILE="$PACKAGE-v$VERSION-$OS_NAME-$MACHINE.zip"
CHECKSUM_FILE="$PACKAGE-v$VERSION-checksums.txt"
#
# Check to see if this zip file has been downloaded.
#
mkdir -p "$HOME/Downloads"
DOWNLOAD_URL="https://github.com/$GIT_GROUP/$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
#
# Verify checksum if tools are available
#
CHECKSUM_URL="https://github.com/$GIT_GROUP/$PACKAGE/releases/download/v$VERSION/$CHECKSUM_FILE"
if command -v sha256sum >/dev/null 2>&1 || command -v shasum >/dev/null 2>&1; then
if curl -L -s -o "$HOME/Downloads/$CHECKSUM_FILE" "$CHECKSUM_URL"; then
EXPECTED=$(grep "$ZIPFILE" "$HOME/Downloads/$CHECKSUM_FILE" | awk '{print $1}')
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL=$(sha256sum "$HOME/Downloads/$ZIPFILE" | awk '{print $1}')
else
ACTUAL=$(shasum -a 256 "$HOME/Downloads/$ZIPFILE" | awk '{print $1}')
fi
if [ -n "$EXPECTED" ] && [ "$EXPECTED" = "$ACTUAL" ]; then
echo "Checksum verified: $ZIPFILE"
elif [ -z "$EXPECTED" ]; then
echo "WARNING: $ZIPFILE not found in checksum file, skipping verification"
else
echo "WARNING: Checksum mismatch for $ZIPFILE"
echo " Expected: $EXPECTED"
echo " Actual: $ACTUAL"
echo " Proceeding anyway — verify the download manually if concerned"
fi
else
echo "WARNING: Could not download $CHECKSUM_FILE, skipping verification"
fi
fi
START="$(pwd)"
mkdir -p "$HOME/.$PACKAGE/installer"
cd "$HOME/.$PACKAGE/installer" || exit 1
unzip "$HOME/Downloads/$ZIPFILE" "bin/*" "man/*"
#
# Copy the application into place
#
mkdir -p "$HOME/bin"
EXPLAIN_OS_POLICY="no"
find bin -type f >.binfiles.tmp
while read -r APP; do
V=$("./$APP" --version)
if [ "$V" = "" ]; then
EXPLAIN_OS_POLICY="yes"
fi
mv "$APP" "$HOME/bin/"
done <.binfiles.tmp
rm .binfiles.tmp
#
# Make sure $HOME/bin is in the path
#
case :$PATH: in
*:$HOME/bin:*)
;;
*)
# shellcheck disable=SC2016
echo 'export PATH="$HOME/bin:$PATH"' >>"$HOME/.bashrc"
# shellcheck disable=SC2016
echo 'export PATH="$HOME/bin:$PATH"' >>"$HOME/.zshrc"
;;
esac
# shellcheck disable=SC2031
if [ "$EXPLAIN_OS_POLICY" = "yes" ]; then
cat <<EOT
You need to take additional steps to complete installation.
Your operating system security policies needs 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.
More information about security policies see INSTALL_NOTES_macOS.md
EOT
fi
#
# Copy the manual pages into place
#
EXPLAIN_MAN_PATH="no"
for SECTION in 1 2 3 4 5 6 7; do
if [ -d "man/man${SECTION}" ]; then
EXPLAIN_MAN_PATH="yes"
mkdir -p "$HOME/man/man${SECTION}"
find "man/man${SECTION}" -type f | while read -r MAN; do
cp -v "$MAN" "$HOME/man/man${SECTION}/"
done
fi
done
if [ "$EXPLAIN_MAN_PATH" = "yes" ]; then
cat <<EOT
The man pages have been installed at '$HOME/man'. You
need to have that location in your MANPATH for man to
find the pages. E.g. For the Bash shell add the
following to your following to your '$HOME/.bashrc' file.
export MANPATH="$HOME/man:$MANPATH"
EOT
fi
rm -fR "$HOME/.$PACKAGE/installer"
cd "$START" || exit 1