fix case macos tar error when overwrite

This commit is contained in:
hardy 2023-10-21 14:07:35 +08:00
parent 9568e800ca
commit 5b9e76280f
1 changed files with 35 additions and 10 deletions

View File

@ -52,19 +52,31 @@ function print_footprint() {
echo "" echo ""
} }
__try() { function __try() {
if [[ $try_status -eq 0 ]]; then if [[ $try_status -eq 0 ]]; then
! exception=$( $@ 2>&1 >/dev/null ) ! exception=$( $@ 2>&1 >/dev/null )
try_status=${PIPESTATUS[0]} try_status=${PIPESTATUS[0]}
fi fi
} }
__catch() { function __catch() {
_old_try=$try_status _old_try=$try_status
try_status=0 try_status=0
[[ $_old_try -ne 0 ]] [[ $_old_try -ne 0 ]]
} }
function confirm() {
display_str=$1
default_ans=$2
if [[ $default_ans == 'y/N' ]]; then
must_match='[yY]'
else
must_match='[nN]'
fi
read -p"${display_str} [${default_ans}]:" ans
[[ $ans == $must_match ]]
}
function get_latest_version() { function get_latest_version() {
echo $(curl -m3 -s "https://release.infinilabs.com/.latest" |sed 's/",/"/;s/"//g;s/://1' |grep -Ev '^[{}]' |grep "$program_name" |awk '{print $NF}') echo $(curl -m3 -s "https://release.infinilabs.com/.latest" |sed 's/",/"/;s/"//g;s/://1' |grep -Ev '^[{}]' |grep "$program_name" |awk '{print $NF}')
} }
@ -82,9 +94,11 @@ function check_dir() {
echo -e "Error: The installation directory ${install_dir} should be owner by current user.\nsudo chown -R \$(whoami) ${install_dir}" >&2; exit 1; echo -e "Error: The installation directory ${install_dir} should be owner by current user.\nsudo chown -R \$(whoami) ${install_dir}" >&2; exit 1;
fi fi
#if [[ "$(ls -A ${install_dir})" ]]; then if [[ "$(ls -A ${install_dir})" ]]; then
# echo "Error: The installation directory ${install_dir} should be clean." >&2; exit 1; confirm "RISK WARN: Replace or upgrade exists agent version, Proceed?" 'y/N' && echo || exit 1;
#fi uninstall_service
rm -rf ${install_dir}/*
fi
} }
function check_platform() { function check_platform() {
@ -283,7 +297,7 @@ node:
EOF EOF
} }
function install_service() { function uninstall_service() {
agent_svc=${install_dir}/${program_name}-${file_ext%%.*} agent_svc=${install_dir}/${program_name}-${file_ext%%.*}
chmod 755 $agent_svc chmod 755 $agent_svc
@ -295,18 +309,28 @@ function install_service() {
$agent_svc -service stop &>/dev/null $agent_svc -service stop &>/dev/null
$agent_svc -service uninstall &>/dev/null $agent_svc -service uninstall &>/dev/null
fi fi
sleep 3
}
function install_service() {
agent_svc=${install_dir}/${program_name}-${file_ext%%.*}
chmod 755 $agent_svc
echo "[agent] waiting service install & start" echo "[agent] waiting service install & start"
$agent_svc -service install &>/dev/null $agent_svc -service install &>/dev/null
$agent_svc -service start &>/dev/null $agent_svc -service start &>/dev/null
sleep 5 sleep 3
} }
function register_agent() { function register_agent() {
token={{token}}
console_endpoint="{{console_endpoint}}" console_endpoint="{{console_endpoint}}"
echo "[agent] waiting registering to INFINI Console" token={{token}}
__try curl -s --retry 1 --retry-delay 3 -m30 -XPOST -o ${install_dir}/setup.log "${console_endpoint}/agent/instance?token=${token}" echo '[agent] waiting registering to INFINI Console'
until curl -s -m30 -XPOST "${console_endpoint}/agent/instance?token=${token}";
do
echo -n '.'; sleep 3;
done;
echo
#__try curl -s --retry 1 --retry-delay 3 -m30 -XPOST -o ${install_dir}/setup.log "${console_endpoint}/agent/instance?token=${token}"
} }
function main() { function main() {
@ -337,6 +361,7 @@ function main() {
install_binary install_binary
install_certs install_certs
install_config install_config
uninstall_service
install_service install_service
register_agent register_agent