33main () {
44 # Parse command-line arguments
55 USER_INSTALL=false
6- for arg in " $@ " ; do
7- case " $arg " in
6+ VERSION=" "
7+ while [ $# -gt 0 ]; do
8+ case " $1 " in
89 --user)
910 USER_INSTALL=true
11+ shift
12+ ;;
13+ --version)
14+ if [ -z " $2 " ]; then
15+ echo " Error: --version requires a value (e.g. --version 0.5.6 or --version v0.5.6)"
16+ exit 1
17+ fi
18+ VERSION=" $2 "
19+ shift 2
20+ ;;
21+ --version=* )
22+ VERSION=" ${1# --version=} "
23+ if [ -z " $VERSION " ]; then
24+ echo " Error: --version requires a value (e.g. --version=0.5.6)"
25+ exit 1
26+ fi
27+ shift
1028 ;;
1129 * )
12- echo " Unknown argument: $arg "
13- echo " Usage: $0 [--user]"
30+ echo " Unknown argument: $1 "
31+ echo " Usage: $0 [--user] [--version <version>] "
1432 exit 1
1533 ;;
1634 esac
1735 done
1836
37+ # Strip a leading 'v' from a user-supplied version (we add it back when needed)
38+ if [ -n " $VERSION " ]; then
39+ VERSION=" ${VERSION# v} "
40+ fi
41+
1942 # Detect if running in Termux
2043 IS_TERMUX=false
2144 case " ${HOME:- } " in
@@ -55,8 +78,14 @@ main() {
5578 exit 1
5679 fi
5780
58- # Get the latest version
59- if [ -n " ${GITHUB_TOKEN} " ]; then
81+ # Get the version: use the user-specified one if provided, otherwise fetch latest
82+ if [ -n " $VERSION " ]; then
83+ if [ -n " ${GITHUB_TOKEN} " ]; then
84+ API_RESPONSE=$( curl --silent --header " Authorization: Bearer ${GITHUB_TOKEN} " " https://api.github.com/repos/version-fox/vfox/releases/tags/v${VERSION} " )
85+ else
86+ API_RESPONSE=$( curl --silent " https://api.github.com/repos/version-fox/vfox/releases/tags/v${VERSION} " )
87+ fi
88+ elif [ -n " ${GITHUB_TOKEN} " ]; then
6089 API_RESPONSE=$( curl --silent --header " Authorization: Bearer ${GITHUB_TOKEN} " " https://api.github.com/repos/version-fox/vfox/releases/latest" )
6190 else
6291 API_RESPONSE=$( curl --silent " https://api.github.com/repos/version-fox/vfox/releases/latest" )
@@ -69,11 +98,16 @@ main() {
6998 exit 1
7099 fi
71100
72- VERSION=$( echo " $API_RESPONSE " | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/' | cut -c 2-)
73- if [ -z " $VERSION " ]; then
74- echo " Failed to get the latest version. Please check your network connection and try again."
101+ RESOLVED_VERSION=$( echo " $API_RESPONSE " | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/' | cut -c 2-)
102+ if [ -z " $RESOLVED_VERSION " ]; then
103+ if [ -n " $VERSION " ]; then
104+ echo " Failed to find vfox version v${VERSION} on GitHub. Please verify the version exists at https://github.com/version-fox/vfox/releases."
105+ else
106+ echo " Failed to get the latest version. Please check your network connection and try again."
107+ fi
75108 exit 1
76109 fi
110+ VERSION=" $RESOLVED_VERSION "
77111 echo " Installing vfox v$VERSION ..."
78112
79113 # Check if the OS is supported
0 commit comments