@@ -16,48 +16,58 @@ get_current_version() {
1616# Accepts optional version argument to skip CDN version fetch
1717install_native () {
1818 local target_version=" ${1:- } "
19+ local use_force=" ${2:- } "
1920 echo " [claude] Installing via native installer (recommended)..." >&2
2021
2122 if [ " $( uname) " = " Darwin" ] || [ " $( uname) " = " Linux" ]; then
2223 # macOS / Linux / WSL
24+ local installer_script=" /tmp/claude-install-$$ .sh"
25+
26+ # Download installer script
27+ if command -v curl > /dev/null 2>&1 ; then
28+ curl -fsSL https://claude.ai/install.sh -o " $installer_script " || return 1
29+ elif command -v wget > /dev/null 2>&1 ; then
30+ wget -qO " $installer_script " https://claude.ai/install.sh || return 1
31+ else
32+ return 1
33+ fi
34+
35+ # Patch installer to add --force flag if needed (handles network timeouts)
36+ if [ " $use_force " = " force" ]; then
37+ echo " [claude] Using --force to bypass network checks..." >&2
38+ sed -i ' s/\$binary_path" install/\$binary_path" install --force/' " $installer_script "
39+ fi
40+
41+ # Run installer with optional version
2342 local installer_args=" "
2443 if [ -n " $target_version " ]; then
2544 installer_args=" $target_version "
2645 echo " [claude] Using version: $target_version " >&2
2746 fi
2847
29- if command -v curl > /dev/null 2>&1 ; then
30- if curl -fsSL https://claude.ai/install.sh | bash -s -- $installer_args ; then
31- return 0
32- fi
33- # If failed and we didn't specify version, retry with known version from GitHub
34- if [ -z " $target_version " ]; then
35- echo " [claude] Installer failed, retrying with explicit version..." >&2
36- local github_version
37- github_version=$( get_latest_version)
38- if [ -n " $github_version " ]; then
39- echo " [claude] Using version from GitHub: $github_version " >&2
40- curl -fsSL https://claude.ai/install.sh | bash -s -- " $github_version "
41- return $?
42- fi
43- fi
44- return 1
45- elif command -v wget > /dev/null 2>&1 ; then
46- if wget -qO- https://claude.ai/install.sh | bash -s -- $installer_args ; then
47- return 0
48- fi
49- if [ -z " $target_version " ]; then
50- echo " [claude] Installer failed, retrying with explicit version..." >&2
51- local github_version
52- github_version=$( get_latest_version)
53- if [ -n " $github_version " ]; then
54- echo " [claude] Using version from GitHub: $github_version " >&2
55- wget -qO- https://claude.ai/install.sh | bash -s -- " $github_version "
56- return $?
48+ if bash " $installer_script " $installer_args ; then
49+ rm -f " $installer_script "
50+ return 0
51+ fi
52+
53+ # If failed without force, retry with force and explicit version
54+ if [ " $use_force " != " force" ]; then
55+ echo " [claude] Installer failed, retrying with --force..." >&2
56+ local github_version
57+ github_version=$( get_latest_version)
58+ if [ -n " $github_version " ]; then
59+ echo " [claude] Using version from GitHub: $github_version " >&2
60+ # Patch to add --force
61+ sed -i ' s/\$binary_path" install/\$binary_path" install --force/' " $installer_script "
62+ if bash " $installer_script " " $github_version " ; then
63+ rm -f " $installer_script "
64+ return 0
5765 fi
5866 fi
59- return 1
6067 fi
68+
69+ rm -f " $installer_script "
70+ return 1
6171 fi
6272
6373 return 1
0 commit comments