Skip to content

Commit 9253c79

Browse files
committed
feat: added installer.sh
1 parent 9dd4891 commit 9253c79

File tree

3 files changed

+231
-1
lines changed

3 files changed

+231
-1
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ifeq ($(OS), Windows)
2929
EXT = .exe
3030
endif
3131

32-
build: version.go $(PROGRAMS) CITATION.cff about.md
32+
build: version.go $(PROGRAMS) CITATION.cff about.md installer.sh
3333

3434
version.go: .FORCE
3535
@echo 'package $(PROJECT)' >version.go
@@ -53,6 +53,12 @@ CITATION.cff: codemeta.json .FORCE
5353
cat codemeta.json | sed -E 's/"@context"/"at__context"/g;s/"@type"/"at__type"/g;s/"@id"/"at__id"/g' >_codemeta.json
5454
if [ -f $(PANDOC) ]; then echo "" | $(PANDOC) --metadata title="Cite $(PROJECT)" --metadata-file=_codemeta.json --template=codemeta-cff.tmpl >CITATION.cff; fi
5555

56+
installer.sh: .FORCE
57+
echo '' | pandoc --metadata title="$(PACKAGE)" --metadata-file codemeta.json --template codemeta-installer.tmpl >installer.sh
58+
chmod 775 installer.sh
59+
git add -f installer.sh
60+
61+
5662
$(PROGRAMS): $(PACKAGE)
5763
@mkdir -p bin
5864
go build -o bin/$@$(EXT) cmd/$@/*.go

codemeta-installer.tmpl

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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

installer.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/sh
2+
3+
#
4+
# Set the package name and version to install
5+
#
6+
PACKAGE="datatools"
7+
VERSION="1.2.2"
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

Comments
 (0)