-
Notifications
You must be signed in to change notification settings - Fork 6
/
aemw
executable file
·127 lines (107 loc) · 2.99 KB
/
aemw
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
#!/usr/bin/env sh
VERSION=${AEM_CLI_VERSION:-"2.0.1"}
# Define API
# ==========
# https://github.com/client9/shlib/blob/master/uname_os.sh
detect_os() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
# fixed up for https://github.com/client9/shlib/issues/3
case "$os" in
msys*) os="windows" ;;
mingw*) os="windows" ;;
cygwin*) os="windows" ;;
win*) os="windows" ;; # for windows busybox and like # https://frippery.org/busybox/
esac
# other fixups here
echo "$os"
}
# https://github.com/client9/shlib/blob/master/uname_arch.sh
detect_arch() {
arch=$(uname -m)
case $arch in
x86_64) arch="amd64" ;;
x86) arch="386" ;;
i686) arch="386" ;;
i386) arch="386" ;;
aarch64) arch="arm64" ;;
armv5*) arch="armv5" ;;
armv6*) arch="armv6" ;;
armv7*) arch="armv7" ;;
esac
echo ${arch}
}
# https://github.com/client9/shlib/blob/master/http_download.sh
download_file() {
local_file=$1
source_url=$2
header=$3
if [ -z "$header" ]; then
code=$(curl -w '%{http_code}' -sL -o "$local_file" "$source_url")
else
code=$(curl -w '%{http_code}' -sL -H "$header" -o "$local_file" "$source_url")
fi
if [ "$code" != "200" ]; then
echo "Error! Downloading file from URL '$source_url' received HTTP status '$code'"
return 1
fi
return 0
}
download_file_once () {
URL=$1
FILE=$2
if [ ! -f "${FILE}" ]; then
mkdir -p "$(dirname "$FILE")"
FILE_TMP="$2.tmp"
download_file "$FILE_TMP" "$URL"
mv "$FILE_TMP" "$FILE"
fi
}
unarchive_file() {
FILE=$1
DIR=$2
rm -fr "$DIR"
mkdir -p "$DIR"
if [ "${FILE##*.}" = "zip" ] ; then
unzip "$FILE" -d "$DIR"
else
tar -xf "$FILE" -C "$DIR"
fi
}
# Download or use installed tool
# ==============================
OS=$(detect_os)
ARCH=$(detect_arch)
AEM_DIR="aem"
HOME_DIR="${AEM_DIR}/home"
DOWNLOAD_DIR="${HOME_DIR}/opt"
BIN_DOWNLOAD_NAME="aemc-cli"
BIN_ARCHIVE_EXT="tar.gz"
if [ "$OS" = "windows" ] ; then
BIN_ARCHIVE_EXT="zip"
fi
BIN_DOWNLOAD_URL="https://github.com/wttech/aemc/releases/download/v${VERSION}/${BIN_DOWNLOAD_NAME}_${OS}_${ARCH}.${BIN_ARCHIVE_EXT}"
BIN_ROOT="${DOWNLOAD_DIR}/${BIN_DOWNLOAD_NAME}/${VERSION}"
BIN_ARCHIVE_FILE="${BIN_ROOT}/${BIN_DOWNLOAD_NAME}.${BIN_ARCHIVE_EXT}"
BIN_ARCHIVE_DIR="${BIN_ROOT}/${BIN_DOWNLOAD_NAME}"
BIN_NAME="aem"
BIN_EXEC_FILE="${BIN_ARCHIVE_DIR}/${BIN_NAME}"
if [ "${VERSION}" != "installed" ] ; then
if [ ! -f "${BIN_EXEC_FILE}" ]; then
mkdir -p "${BIN_ARCHIVE_DIR}"
download_file_once "${BIN_DOWNLOAD_URL}" "${BIN_ARCHIVE_FILE}"
unarchive_file "${BIN_ARCHIVE_FILE}" "${BIN_ARCHIVE_DIR}"
chmod +x "${BIN_EXEC_FILE}"
fi
aem() {
"./${BIN_EXEC_FILE}" "$@"
}
fi
# Prevent OS or shell-specific glitches
# =====================================
# https://stackoverflow.com/questions/7250130/how-to-stop-mingw-and-msys-from-mangling-path-names-given-at-the-command-line
export MSYS_NO_PATHCONV=1
export MSYS2_ARG_CONV_EXCL="*"
export MSYS2_ENV_CONV_EXCL="*"
# Execute AEM Compose CLI
# =======================
aem "$@"