-
Notifications
You must be signed in to change notification settings - Fork 468
/
cloud9-toolkit-install.sh
139 lines (124 loc) · 4.91 KB
/
cloud9-toolkit-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
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
#!/bin/env bash
# By default, this script gets the latest VSIX from:
# https://github.com/aws/aws-toolkit-vscode/releases/
# else the first argument must be a URL or file pointing to a toolkit VSIX or
# ZIP (containing a VSIX).
#
# USAGE:
# cloud9-toolkit-install.sh [URL|FILE]
# curl -LO https://raw.githubusercontent.com/aws/aws-toolkit-vscode/master/cloud9-toolkit-install.sh && bash cloud9-toolkit-install.sh
# EXAMPLES:
# cloud9-toolkit-install.sh https://github.com/aws/aws-toolkit-vscode/releases/download/v1.24.0/aws-toolkit-vscode-1.24.0.vsix
# cloud9-toolkit-install.sh toolkit.zip
set -eu
# Script currently depends on $HOME so running as root is not supported.
if [ "$(whoami)" = root ]; then
echo "cannot run as root"
exit 1
fi
_log() {
echo >&2 "$@"
}
# Runs whatever is passed.
#
# On failure:
# - prints the command output
# - exits the script
_run() {
local out
if ! out="$("$@" 2>&1)"; then
_log "Command failed (output below): '${*}'"
echo "$out" | sed 's/^/ /'
_log "Command failed (output above): '${*}'"
exit 1
fi
}
# Gets the first existing directory, or exits if none are found.
_any_dir() {
for d in "$@"; do
if test -d "$d"; then
echo "$d"
return
fi
done
_log "error: None of the expected dirs exist:"
for d in "$@"; do
_log " $d"
done
exit 1
}
_setglobals() {
# Example:
# https://github.com/aws/aws-toolkit-vscode/releases/tag/v1.24.0
TOOLKIT_LATEST_RELEASE_URL="$(curl -Ls -o /dev/null -w '%{url_effective}' 'https://github.com/aws/aws-toolkit-vscode/releases/latest')"
# Example:
# 1.24.0
TOOLKIT_LATEST_VERSION="$(echo "$TOOLKIT_LATEST_RELEASE_URL" | grep -oh '[0-9]\+\.[0-9]\+\.[0-9]\+$')"
# Example:
# https://github.com/aws/aws-toolkit-vscode/releases/download/v1.24.0/aws-toolkit-vscode-1.24.0.vsix
TOOLKIT_LATEST_ARTIFACT_URL="https://github.com/aws/aws-toolkit-vscode/releases/download/v${TOOLKIT_LATEST_VERSION}/aws-toolkit-vscode-${TOOLKIT_LATEST_VERSION}.vsix"
# URL or local filepath pointing to toolkit VSIX or ZIP (containing a VSIX).
TOOLKIT_FILE=${1:-}
TOOLKIT_INSTALL_PARENT="$(_any_dir "/projects/.c9/aws-toolkit-vscode" "$HOME/.c9/dependencies/aws-toolkit-vscode" "$HOME/environment/.c9/extensions" "$HOME/.c9/aws-toolkit-vscode")"
# Hash name is 128 chars long.
TOOLKIT_INSTALL_DIR="$(_any_dir "$(realpath ${TOOLKIT_INSTALL_PARENT}/????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????)" "$(realpath ${TOOLKIT_INSTALL_PARENT}/extension)")"
SCRIPT_WORKDIR="$HOME/toolkit"
}
_main() {
(
if test -f "$TOOLKIT_FILE"; then
# Ensure full path (before `cd` below).
TOOLKIT_FILE="$(readlink -f "$TOOLKIT_FILE")"
fi
echo "Script will DELETE these directories:"
echo " ${TOOLKIT_INSTALL_DIR}"
echo " ${SCRIPT_WORKDIR}"
read -n1 -r -p "ENTER to continue, CTRL-c to cancel"
rm -rf "${TOOLKIT_INSTALL_DIR}.old"
mv "$TOOLKIT_INSTALL_DIR" "${TOOLKIT_INSTALL_DIR}.old"
rm -rf "$SCRIPT_WORKDIR"
cd "$HOME/"
mkdir -p "$SCRIPT_WORKDIR"
mkdir -p "$TOOLKIT_INSTALL_PARENT"
cd "${SCRIPT_WORKDIR}"
# Set default URL if no argument was provided.
if test -z "$TOOLKIT_FILE"; then
_log "Latest release:"
_log " URL : $TOOLKIT_LATEST_RELEASE_URL"
_log " version: $TOOLKIT_LATEST_VERSION"
_log " VSIX : $TOOLKIT_LATEST_ARTIFACT_URL"
TOOLKIT_FILE="$TOOLKIT_LATEST_ARTIFACT_URL"
fi
TOOLKIT_FILE_EXTENSION="${TOOLKIT_FILE: -4}"
if test -f "$TOOLKIT_FILE"; then
_log "Local file (not URL): ${TOOLKIT_FILE}"
if [ "$TOOLKIT_FILE_EXTENSION" = ".zip" ] || [ "$TOOLKIT_FILE_EXTENSION" = ".ZIP" ]; then
_log 'File is a .zip file'
_run unzip -- "$TOOLKIT_FILE"
_run unzip -- *.vsix
else
_log 'File is not .zip file, assuming .vsix'
_run unzip -- "$TOOLKIT_FILE"
fi
else
_log "URL: ${TOOLKIT_FILE}"
_log 'Deleting toolkit.zip'
rm -rf toolkit.zip
_log 'Downloading...'
curl -o toolkit.zip -L "$TOOLKIT_FILE"
if [ "$TOOLKIT_FILE_EXTENSION" = ".zip" ] || [ "$TOOLKIT_FILE_EXTENSION" = ".ZIP" ]; then
_log 'File is a .zip file'
_run unzip -- toolkit.zip
_run unzip -- *.vsix
else
_log 'File is not .zip file, assuming .vsix'
_run unzip -- toolkit.zip
fi
fi
mv extension "$TOOLKIT_INSTALL_DIR"
_log "Toolkit installed to: $TOOLKIT_INSTALL_DIR"
_log "Refresh Cloud9 to load it"
)
}
_setglobals "$@"
_main