-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget-armory-cli
executable file
·140 lines (125 loc) · 5.02 KB
/
get-armory-cli
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
#! /usr/bin/env bash
throw_error_message() {
echo "#############################################################################################################"
echo "# We're so sorry, we couldn't install Armory Version Manager (avm) or the armory CLI."
echo "#"
echo "# $1"
echo "#"
echo "# You can install the armory CLI manually by referring to our docs here - https://docs.armory.io/cd-as-a-service/setup/cli/."
echo "# You can still install avm manually - please refer to the avm release page where you can download and install it https://github.com/armory/avm/releases"
echo "#"
echo "# Please consider running the following commands if you need to install avm manually."
echo ""
echo " 1. Download the AVM for your operating system and CPU architecture."
echo " $ curl -LO https://github.com/armory/avm/releases/latest/download/avm-<os>-<architecture>"
echo ""
echo " 2. Give AVM execute permissions"
echo " $ chmod +x avm-darwin-amd64"
echo ""
echo " 3. Confirm that /usr/local/bin is on your PATH:"
echo " $ echo \"\$PATH\""
echo ""
echo " 4. Give AVM execute permissions"
echo " $ mv avm-darwin-amd64 /usr/local/bin/avm"
echo ""
echo " 5. Run the following command to install the CLI:"
echo " $ avm install"
echo ""
echo " 6. Add the directory that AVM returned when you ran avm install to your path."
echo ""
echo " 7. Run the following command to verify that the CLI is installed:"
echo " $ armory"
echo ""
echo "#############################################################################################################"
exit 1
}
RAW_ARCH=$(uname -m)
OS=
case $(uname) in
'Linux')
OS='linux'
;;
'Darwin')
OS='darwin'
;;
*)
echo "un-supported OS detected: ${OS}-${RAW_ARCH}, exiting..."
exit 1
;;
esac
ARCH=""
case $RAW_ARCH in
x86_64) ARCH="amd64" ;;
arm64) ARCH="arm64" ;;
*)
echo "un-supported os/arch detected: ${OS}-${RAW_ARCH}, exiting..."
exit 1
;;
esac
# Sanity checks
echo "Looking for dependencies..."
if ! command -v curl > /dev/null; then
echo "######################################################################################################"
echo "# curl not found."
echo "#"
echo "# Please install curl on your system using your favorite package manager, then re-run this script."
echo "######################################################################################################"
exit 1
fi
echo "Detected ${OS}-${ARCH}, preparing to install Armory Version Manager and Armory CLI"
DOWNLOAD_URL=https://armory-cli-releases.s3.amazonaws.com/avm/latest/avm-${OS}-${ARCH}
DEST_DIR="${HOME}/.avm/bin"
mkdir -p "$DEST_DIR"
DEST="${DEST_DIR}/avm"
echo "saving '${DOWNLOAD_URL}' to ${DEST}"
curl -sL "${DOWNLOAD_URL}" --output "${DEST}"
if [ ! -f "$DEST" ]; then
throw_error_message "Binary file didn't download."
fi
chmod +x "${DEST}"
export PATH="${PATH}:${DEST_DIR}"
if ! command -v avm > /dev/null; then
throw_error_message "avm was not installed correctly, there was an issue trying to add it to the path"
fi
echo "Installing latest Armory CLI with AVM, to upgrade in the future use 'avm'"
avm install
###
# Logic below for updating profiles are inspired by Nvm and SDKMan
##
PATH_SNIPPIT="\n# This adds the Armory Version Manager (AVM) and Armory CLI to the path\nexport PATH=\"\${PATH}:${HOME}/.avm/bin\""
avm_bash_profile="${HOME}/.bash_profile"
avm_bashrc="${HOME}/.bashrc"
avm_zshrc="${ZDOTDIR:-${HOME}}/.zshrc"
if [[ $OS == 'darwin' ]]; then
touch "$avm_bash_profile"
echo "Attempt update of login bash profile on OSX..."
if [[ -z $(grep "export PATH=\"\${PATH}:${HOME}/.avm/bin" "$avm_bash_profile") ]]; then
echo -e "$PATH_SNIPPIT" >> "$avm_bash_profile"
echo "Added ${HOME}/.avm/bin to path in $avm_bash_profile"
fi
else
echo "Attempt update of interactive bash profile on regular UNIX..."
touch "${avm_bashrc}"
if [[ -z $(grep "export PATH=\"\${PATH}:${HOME}/.avm/bin" "$avm_bashrc") ]]; then
echo -e "$PATH_SNIPPIT" >> "$avm_bashrc"
echo "Added ${HOME}/.avm/bin to path in $avm_bashrc"
fi
fi
echo "Attempt update of zsh profile..."
touch "$avm_zshrc"
if [[ -z $(grep "export PATH=\"\${PATH}:${HOME}/.avm/bin" "$avm_zshrc") ]]; then
echo -e "$PATH_SNIPPIT" >> "$avm_zshrc"
echo "Added ${HOME}/.avm/bin to path in ${avm_zshrc}"
fi
echo "############################################################################################"
echo "# Install of avm and armory complete"
echo "# This install script updates your bash or zsh profile to add ${HOME}/.avm/bin to your path"
echo "# If you aren't using bash or zsh you will need to do this manually"
echo "#"
echo "# Please close and restart the terminal to use the Armory CLI or run the following to use it now:"
if [[ $OS == 'darwin' ]]; then
echo "# source $avm_bash_profile && source $avm_zshrc"
else
echo "# source $avm_bashrc && source $avm_zshrc"
fi
echo "############################################################################################"