|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# |
| 4 | +# Set the package name and version to install |
| 5 | +# |
| 6 | +PACKAGE="$name$" |
| 7 | +VERSION="$version$" |
| 8 | +RELEASE="https://github.com/caltechlibrary/$$PACKAGE/releases/tag/$$VERSION" |
| 9 | + |
| 10 | +# |
| 11 | +# Get the name of this script. |
| 12 | +# |
| 13 | +INSTALLER="$$(basename "$$0")" |
| 14 | + |
| 15 | +# |
| 16 | +# Figure out what the zip file is named |
| 17 | +# |
| 18 | +OS_NAME="$$(uname -o)" |
| 19 | +MACHINE="$$(uname -m)" |
| 20 | +case "$$OS_NAME" in |
| 21 | + Darwin) |
| 22 | + OS_NAME="macos" |
| 23 | + ;; |
| 24 | +esac |
| 25 | +ZIPFILE="$$PACKAGE-v$$VERSION-$$OS_NAME-$$MACHINE.zip" |
| 26 | + |
| 27 | +# |
| 28 | +# Check to see if this zip file has been downloaded. |
| 29 | +# |
| 30 | +DOWNLOAD_URL="https://github.com/caltechlibrary/$$PACKAGE/releases/download/v$$VERSION/$$ZIPFILE" |
| 31 | +if ! curl -L -o "$$HOME/Downloads/$$ZIPFILE" "$$DOWNLOAD_URL"; then |
| 32 | + echo "Curl failed to get $$DOWNLOAD_URL" |
| 33 | +fi |
| 34 | +cat<<EOT |
| 35 | +
|
| 36 | + Retrieved $$DOWNLOAD_URL |
| 37 | + Saved as $$HOME/Downloads/$$ZIPFILE |
| 38 | +
|
| 39 | +EOT |
| 40 | + |
| 41 | +if [ ! -f "$$HOME/Downloads/$$ZIPFILE" ]; then |
| 42 | + cat<<EOT |
| 43 | +
|
| 44 | + To install $$PACKAGE you need to download |
| 45 | +
|
| 46 | + $$ZIPFILE |
| 47 | +
|
| 48 | + from |
| 49 | +
|
| 50 | + $$RELEASE |
| 51 | +
|
| 52 | + You can do that with your web browser. After |
| 53 | + that you should be able to re-run $$INSTALLER |
| 54 | +
|
| 55 | +EOT |
| 56 | + exit 1 |
| 57 | +fi |
| 58 | + |
| 59 | +START="$$(pwd)" |
| 60 | +mkdir -p "$$HOME/.$$PACKAGE/installer" |
| 61 | +cd "$$HOME/.$$PACKAGE/installer" || exit 1 |
| 62 | +unzip "$$HOME/Downloads/$$ZIPFILE" "bin/*" |
| 63 | + |
| 64 | +# |
| 65 | +# Copy the application into place |
| 66 | +# |
| 67 | +mkdir -p "$$HOME/bin" |
| 68 | +EXPLAIN_OS_POLICY="yes" |
| 69 | +find bin -type f | while read -r APP; do |
| 70 | + V=$$("./$$APP" --version) |
| 71 | + if [ "$$V" = "" ]; then |
| 72 | + EXPLAIN_OS_POLICY="yes" |
| 73 | + fi |
| 74 | + mv "$$APP" "$$HOME/bin/" |
| 75 | +done |
| 76 | + |
| 77 | +# |
| 78 | +# Make sure $$HOME/bin is in the path |
| 79 | +# |
| 80 | +DIR_IN_PATH='no' |
| 81 | +for P in $$PATH; do |
| 82 | + if [ "$$P" = "$$HOME/bin" ]; then |
| 83 | + DIR_IN_PATH='yes' |
| 84 | + fi |
| 85 | +done |
| 86 | +if [ "$$DIR_IN_PATH" = "no" ]; then |
| 87 | + # shellcheck disable=SC2016 |
| 88 | + echo 'export PATH="$$HOME/bin:$$PATH"' >>"$$HOME/.bashrc" |
| 89 | + # shellcheck disable=SC2016 |
| 90 | + echo 'export PATH="$$HOME/bin:$$PATH"' >>"$$HOME/.zshrc" |
| 91 | +fi |
| 92 | +rm -fR "$$HOME/.$$PACKAGE/installer" |
| 93 | +cd "$$START" || exit 1 |
| 94 | + |
| 95 | +# shellcheck disable=SC2031 |
| 96 | +if [ "$$EXPLAIN_OS_POLICY" = "no" ]; then |
| 97 | + cat <<EOT |
| 98 | +
|
| 99 | + You need to take additional steps to complete installation. |
| 100 | +
|
| 101 | + Your operating systems' security policied need to "allow" |
| 102 | + running programs from $$PACKAGE. |
| 103 | +
|
| 104 | + Example: on macOS you can type open the programs in finder. |
| 105 | +
|
| 106 | + open $$HOME/bin |
| 107 | +
|
| 108 | + Find the program(s) and right click on the program(s) |
| 109 | + installed to enable them to run. |
| 110 | +
|
| 111 | +EOT |
| 112 | +fi |
0 commit comments