-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·94 lines (82 loc) · 2.64 KB
/
install.sh
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
#!/usr/bin/env bash
set -eo pipefail
echo "Installing ge-publish..."
BASE_DIR="${XDG_CONFIG_HOME:-$HOME}"
GE_PUBLISH_DIR="${GE_PUBLISH_DIR-"$BASE_DIR/.ge-publish"}"
GE_PUBLISH_BIN_DIR="$GE_PUBLISH_DIR/bin"
BIN_PATH="$GE_PUBLISH_BIN_DIR/ge-publish"
uname_s=$(uname -s)
PLATFORM=$(echo "$uname_s" | awk '{print tolower($0)}')
case $PLATFORM in
linux) ;;
darwin|mac*)
PLATFORM="darwin"
;;
mingw*|win*)
PLATFORM="windows"
;;
*)
err "unsupported platform: $PLATFORM"
;;
esac
uname_m=$(uname -m)
ARCHITECTURE=$(echo "$uname_m" | awk '{print tolower($0)}')
if [ "${ARCHITECTURE}" = "x86_64" ]; then
# Redirect stderr to /dev/null to avoid printing errors if non Rosetta.
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then
ARCHITECTURE="arm64" # Rosetta.
else
ARCHITECTURE="amd64" # Intel.
fi
elif [ "${ARCHITECTURE}" = "arm64" ] ||[ "${ARCHITECTURE}" = "aarch64" ] ; then
ARCHITECTURE="arm64" # Arm.
else
ARCHITECTURE="amd64" # Amd.
fi
echo "platform="$PLATFORM,"arch="$ARCHITECTURE
BIN_URL="https://github.com/grassrootseconomics/ge-publish/releases/latest/download/ge-publish-${PLATFORM}-${ARCHITECTURE}.zip"
# Create the .ge-publish bin directory and ge-publish binary if it doesn't exist.
mkdir -p $GE_PUBLISH_BIN_DIR
tmp=$(mktemp -d 2>/dev/null)
curl -sSf -L "$BIN_URL" -o "$tmp/download.zip"
unzip -j "$tmp/download.zip" -d $tmp
mv "$tmp/ge-publish-${PLATFORM}-${ARCHITECTURE}" $BIN_PATH
chmod +x $BIN_PATH
# Store the correct profile file (i.e. .profile for bash or .zshenv for ZSH).
case $SHELL in
*/zsh)
PROFILE="${ZDOTDIR-"$HOME"}/.zshenv"
PREF_SHELL=zsh
;;
*/fish)
PROFILE=$HOME/.config/fish/config.fish
PREF_SHELL=fish
;;
*/bash)
PROFILE=$HOME/.bashrc
PREF_SHELL=bash
;;
*/ash)
PROFILE=$HOME/.profile
PREF_SHELL=ash
;;
*)
echo "ge-publish: could not detect shell, manually add ${GE_PUBLISH_BIN_DIRECTORY} to your PATH."
exit 1
esac
# Only add ge-publish if it isn't already in PATH.
if [[ ":$PATH:" != *":${GE_PUBLISH_BIN_DIR}:"* ]]; then
# If the shell is fish, echo fish_add_path instead of export.
if [[ "$PREF_SHELL" == "fish" ]]; then
echo >> "$PROFILE" && echo "fish_add_path -a $GE_PUBLISH_BIN_DIR" >> "$PROFILE"
else
echo >> "$PROFILE" && echo "export PATH=\"\$PATH:$GE_PUBLISH_BIN_DIR\"" >> "$PROFILE"
fi
fi
echo
echo "Detected your preferred shell is $PREF_SHELL and added ge-publish to PATH."
echo "Run 'source $PROFILE' or start a new terminal session to use ge-publish."
echo "Then, simply run 'ge-publish --version' to check the version ans start using it."
tolower() {
echo "$1" | awk '{print tolower($0)}'
}