arthas/bin/install.sh

49 lines
969 B
Bash
Raw Normal View History

2018-08-31 11:49:48 +08:00
#! /bin/bash
# temp file of as.sh
TEMP_ARTHAS_FILE="./as.sh.$$"
# target file of as.sh
TARGET_ARTHAS_FILE="./as.sh"
# update timeout(sec)
SO_TIMEOUT=60
# default downloading url
2018-09-06 18:53:30 +08:00
ARTHAS_FILE_URL="https://alibaba.github.io/arthas/as.sh"
2018-08-31 11:49:48 +08:00
# exit shell with err_code
# $1 : err_code
# $2 : err_msg
exit_on_err()
{
[[ ! -z "${2}" ]] && echo "${2}" 1>&2
exit ${1}
}
# check permission to download && install
2019-03-19 11:28:18 +08:00
[[ ! -w ./ ]] && exit_on_err 1 "permission denied, target directory ./ was not writable."
2018-08-31 11:49:48 +08:00
2019-03-19 11:28:18 +08:00
if [[ $# -gt 1 ]] && [[ $1 = "--url" ]]; then
2018-08-31 11:49:48 +08:00
shift
ARTHAS_FILE_URL=$1
shift
fi
# download from aliyunos
echo "downloading... ${TEMP_ARTHAS_FILE}"
curl \
-sLk \
--connect-timeout ${SO_TIMEOUT} \
2019-03-19 11:28:18 +08:00
${ARTHAS_FILE_URL} \
2018-08-31 11:49:48 +08:00
-o ${TEMP_ARTHAS_FILE} \
|| exit_on_err 1 "download failed!"
2019-03-19 11:28:18 +08:00
# write or overwrite local file
2018-08-31 11:49:48 +08:00
rm -rf as.sh
mv ${TEMP_ARTHAS_FILE} ${TARGET_ARTHAS_FILE}
chmod +x ${TARGET_ARTHAS_FILE}
# done
2019-03-19 11:28:18 +08:00
echo "Arthas install succeeded."