Skip to content

Commit 9b0141e

Browse files
authored
Merge pull request #41 from jianxiaoguo/main
chore(install.sh): INSTALL_K3S_VERSION urlencode
2 parents ed0dea7 + eb4b14b commit 9b0141e

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

_scripts/install.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ function clean_before_exit {
3333
trap clean_before_exit EXIT
3434
init_arch
3535

36+
urlencode() {
37+
# urlencode <string>
38+
39+
old_lang=$LANG
40+
LANG=C
41+
42+
old_lc_collate=$LC_COLLATE
43+
LC_COLLATE=C
44+
45+
local length="${#1}"
46+
for (( i = 0; i < length; i++ )); do
47+
local c="${1:i:1}"
48+
case $c in
49+
[a-zA-Z0-9.~_-]) printf "$c" ;;
50+
*) printf '%%%02X' "'$c" ;;
51+
esac
52+
done
53+
54+
LANG=$old_lang
55+
LC_COLLATE=$old_lc_collate
56+
}
57+
3658
function install_helm {
3759
if [[ "${INSTALL_DRYCC_MIRROR}" == "cn" ]] ; then
3860
version=$(curl -Ls https://github.com/helm/helm/releases|grep /helm/helm/releases/tag/ | sed -E 's/.*\/helm\/helm\/releases\/tag\/(v[0-9\.]{1,}(-rc.[0-9]{1,})?)".*/\1/g' | head -1)
@@ -171,8 +193,10 @@ function configure_mirrors {
171193
fi
172194
if [ -z "${INSTALL_K3S_VERSION}" ]; then
173195
INSTALL_K3S_VERSION=$(curl -Ls "$K3S_RELEASE_URL" | grep /k3s-io/k3s/releases/tag/ | sed -E 's/.*\/k3s-io\/k3s\/releases\/tag\/(v[0-9\.]{1,}[rc0-9\-]{0,}%2Bk3s[0-9])".*/\1/g' | head -1)
174-
export INSTALL_K3S_VERSION
196+
else
197+
INSTALL_K3S_VERSION=$(urlencode "$INSTALL_K3S_VERSION")
175198
fi
199+
export INSTALL_K3S_VERSION
176200
echo -e "\\033[32m---> Configuring mirrors finish\\033[0m"
177201
}
178202

0 commit comments

Comments
 (0)