From 098244b34360961a450950da115717f85772ac49 Mon Sep 17 00:00:00 2001 From: IceCodeNew <32576256+IceCodeNew@users.noreply.github.com> Date: Thu, 24 Sep 2020 15:30:01 +0800 Subject: [PATCH 1/3] Show download progress. Fix #128. --- install-dat-release.sh | 6 ++++-- install-release.sh | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/install-dat-release.sh b/install-dat-release.sh index a537cf8..68b9b55 100644 --- a/install-dat-release.sh +++ b/install-dat-release.sh @@ -13,6 +13,8 @@ # 0 0 * * * /usr/local/bin/install-dat-release > /dev/null 2>&1 +alias curl='curl --false-start --http2 --tlsv1.2 -L' + # You can modify it to /usr/local/lib/v2ray V2RAY="/usr/local/share/v2ray" DOWNLOAD_LINK_GEOIP="https://github.com/v2fly/geoip/releases/latest/download/geoip.dat" @@ -31,11 +33,11 @@ check_if_running_as_root() { } download_files() { - if ! curl -L -H 'Cache-Control: no-cache' -o "${dir_tmp}/${2}" "${1}"; then + if ! curl -R -H 'Cache-Control: no-cache' -o "${dir_tmp}/${2}" "${1}"; then echo 'error: Download failed! Please check your network or try again.' exit 1 fi - if ! curl -L -H 'Cache-Control: no-cache' -o "${dir_tmp}/${2}.sha256sum" "${1}.sha256sum"; then + if ! curl -R -H 'Cache-Control: no-cache' -o "${dir_tmp}/${2}.sha256sum" "${1}.sha256sum"; then echo 'error: Download failed! Please check your network or try again.' exit 1 fi diff --git a/install-release.sh b/install-release.sh index 84463ef..408e611 100644 --- a/install-release.sh +++ b/install-release.sh @@ -27,6 +27,8 @@ red=$(tput setaf 1) green=$(tput setaf 2) reset=$(tput sgr0) +alias curl='curl --false-start --http2 --tlsv1.2 -L' + check_if_running_as_root() { # If you want to run as another user, please modify $UID to be owned by this user if [[ "$UID" -ne '0' ]]; then @@ -211,7 +213,7 @@ get_version() { TMP_FILE="$(mktemp)" install_software curl # DO NOT QUOTE THESE `${PROXY}` VARIABLES! - if ! "curl" ${PROXY} -sSL -H "Accept: application/vnd.github.v3+json" -o "$TMP_FILE" 'https://api.github.com/repos/v2fly/v2ray-core/releases/latest'; then + if ! curl ${PROXY} -sS -H "Accept: application/vnd.github.v3+json" -o "$TMP_FILE" 'https://api.github.com/repos/v2fly/v2ray-core/releases/latest'; then "rm" "$TMP_FILE" echo 'error: Failed to get release list, please check your network.' exit 1 @@ -254,12 +256,12 @@ get_version() { download_v2ray() { DOWNLOAD_LINK="https://github.com/v2fly/v2ray-core/releases/download/$RELEASE_VERSION/v2ray-linux-$MACHINE.zip" echo "Downloading V2Ray archive: $DOWNLOAD_LINK" - if ! "curl" ${PROXY} -sSLR -H "Accept: application/vnd.github.v3+json" -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK"; then + if ! curl ${PROXY} -R -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK"; then echo 'error: Download failed! Please check your network or try again.' return 1 fi echo "Downloading verification file for V2Ray archive: $DOWNLOAD_LINK.dgst" - if ! "curl" ${PROXY} -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE.dgst" "$DOWNLOAD_LINK.dgst"; then + if ! curl ${PROXY} -sSR -H 'Cache-Control: no-cache' -o "$ZIP_FILE.dgst" "$DOWNLOAD_LINK.dgst"; then echo 'error: Download failed! Please check your network or try again.' return 1 fi From 5c0bfb6532849ec32f949a035018fefe85b14e6b Mon Sep 17 00:00:00 2001 From: IceCodeNew <32576256+IceCodeNew@users.noreply.github.com> Date: Thu, 24 Sep 2020 15:38:59 +0800 Subject: [PATCH 2/3] Retry when transient error occurred --- install-dat-release.sh | 2 +- install-release.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/install-dat-release.sh b/install-dat-release.sh index 68b9b55..35955f7 100644 --- a/install-dat-release.sh +++ b/install-dat-release.sh @@ -13,7 +13,7 @@ # 0 0 * * * /usr/local/bin/install-dat-release > /dev/null 2>&1 -alias curl='curl --false-start --http2 --tlsv1.2 -L' +alias curl='"curl" --retry 5 --retry-delay 10 --retry-max-time 60 --false-start --http2 --tlsv1.2 -L' # You can modify it to /usr/local/lib/v2ray V2RAY="/usr/local/share/v2ray" diff --git a/install-release.sh b/install-release.sh index 408e611..cb8935c 100644 --- a/install-release.sh +++ b/install-release.sh @@ -27,7 +27,7 @@ red=$(tput setaf 1) green=$(tput setaf 2) reset=$(tput sgr0) -alias curl='curl --false-start --http2 --tlsv1.2 -L' +alias curl='"curl" --retry 5 --retry-delay 10 --retry-max-time 60 --false-start --http2 --tlsv1.2 -L' check_if_running_as_root() { # If you want to run as another user, please modify $UID to be owned by this user From b990f89b6ef7b329e6dcf4e4f391218188358edd Mon Sep 17 00:00:00 2001 From: IceCodeNew <32576256+IceCodeNew@users.noreply.github.com> Date: Thu, 24 Sep 2020 16:40:26 +0800 Subject: [PATCH 3/3] `shfmt -i 2 -ci -sr install-release.sh` --- install-release.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install-release.sh b/install-release.sh index cb8935c..d8e3419 100644 --- a/install-release.sh +++ b/install-release.sh @@ -172,7 +172,7 @@ judgment_parameters() { install_software() { COMPONENT="$1" - command -v "$COMPONENT" >/dev/null 2>&1 && return + command -v "$COMPONENT" > /dev/null 2>&1 && return if ${PACKAGE_MANAGEMENT_INSTALL} "$COMPONENT"; then echo "info: $COMPONENT is installed." else @@ -314,7 +314,7 @@ install_v2ray() { # Install V2Ray configuration file to $JSON_PATH if [[ -z "$JSONS_PATH" ]] && [[ ! -d "$JSON_PATH" ]]; then install -d "$JSON_PATH" - echo "{}" >"${JSON_PATH}/config.json" + echo "{}" > "${JSON_PATH}/config.json" CONFIG_NEW='1' fi