Skip to content

Commit 4b5c932

Browse files
Copilotbytemain
andauthored
Add --version flag to install.sh to install a specific GitHub release (#659)
Agent-Logs-Url: https://github.com/version-fox/vfox/sessions/6ab6e3d5-ea72-4885-8cbd-5dd3cc02dcbd Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com>
1 parent 9522202 commit 4b5c932

3 files changed

Lines changed: 71 additions & 9 deletions

File tree

docs/guides/quick-start.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ This will:
8080
- Automatically create the directory if it doesn't exist
8181
- Provide instructions to add `~/.local/bin` to your `PATH`
8282

83+
**Install a Specific Version**
84+
85+
By default the script installs the latest GitHub release. To install a specific version, use the `--version` flag (with or without the leading `v`):
86+
87+
```shell
88+
curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash -s -- --version 0.5.6
89+
```
90+
91+
`--version` can be combined with `--user`, for example:
92+
93+
```shell
94+
curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash -s -- --user --version 0.5.6
95+
```
96+
8397
</TabItem>
8498
</Tabs>
8599

docs/zh-hans/guides/quick-start.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | b
8080
- 如果目录不存在,会自动创建
8181
- 提供将 `~/.local/bin` 添加到 `PATH` 的说明
8282

83+
**安装指定版本**
84+
85+
默认情况下安装脚本会安装最新的 GitHub Release。如果想安装指定版本,可以使用 `--version` 参数(版本号可带或不带前缀 `v`):
86+
87+
```shell
88+
curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash -s -- --version 0.5.6
89+
```
90+
91+
`--version` 可以与 `--user` 组合使用,例如:
92+
93+
```shell
94+
curl -sSL https://raw.githubusercontent.com/version-fox/vfox/main/install.sh | bash -s -- --user --version 0.5.6
95+
```
96+
8397
</TabItem>
8498
</Tabs>
8599

install.sh

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,42 @@
33
main() {
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

Comments
 (0)