Skip to content

Commit 9f7db0c

Browse files
committed
fix: update configuration refresh interval to 7 days and improve version selection logic in installation script
1 parent fe32a76 commit 9f7db0c

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ SGS CLI downloads configuration files to `~/.sgs/` on first run or when `sgs fet
4242
- `~/.sgs/metadata.yaml` - CLI metadata (last fetch timestamp)
4343
- `~/.sgs/cache/` - Token cache for OIDC authentication
4444

45-
The configuration is automatically refreshed if more than 24 hours have passed since the last fetch.
45+
The configuration is automatically refreshed if more than 7 days have passed since the last fetch.
4646

4747
## Prerequisites
4848

@@ -83,7 +83,7 @@ make build && make install
8383

8484
### Auto-Update
8585

86-
The CLI automatically runs `sgs fetch` when any command is executed and the last fetch was more than 24 hours ago. This checks for new versions and offers to update.
86+
The CLI automatically runs `sgs fetch` when any command is executed and the last fetch was more than 7 days ago. This checks for new versions and offers to update.
8787

8888
## Build
8989

internal/client/client.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,22 @@ func setLastFetched() error {
115115
return os.WriteFile(metadataPath(), data, 0600)
116116
}
117117

118-
// shouldAutoFetch returns true if 24+ hours have passed since last fetch
118+
// shouldAutoFetch returns true if 7+ days have passed since last fetch
119119
func shouldAutoFetch() bool {
120120
lastFetched, err := getLastFetched()
121121
if err != nil {
122122
// If we can't read metadata, don't auto-fetch
123123
return false
124124
}
125125

126-
return time.Since(lastFetched) >= 24*time.Hour
126+
return time.Since(lastFetched) >= 7*24*time.Hour
127127
}
128128

129129
// configURL is the URL to download the kubeconfig from
130130
const configURL = "https://raw.githubusercontent.com/bacchus-snu/sgs/refs/heads/master/controller/config.yaml"
131131

132132
// EnsureConfig checks if config exists, if not, fetches it.
133-
// Also auto-fetches if 24+ hours have passed since last fetch.
133+
// Also auto-fetches if 7+ days have passed since last fetch.
134134
func EnsureConfig() error {
135135
configFile := configPath()
136136

@@ -139,12 +139,15 @@ func EnsureConfig() error {
139139
return FetchConfig()
140140
}
141141

142-
// Check if we should auto-fetch (24+ hours since last fetch)
142+
// Check if we should auto-fetch (7+ days since last fetch)
143143
if shouldAutoFetch() {
144-
fmt.Println("Configuration is older than 24 hours, refreshing...")
144+
fmt.Println("Configuration is older than 7 days, refreshing...")
145145
if err := FetchConfig(); err != nil {
146146
// Don't fail if auto-fetch fails, just warn
147147
fmt.Printf("Warning: failed to refresh configuration: %v\n", err)
148+
} else {
149+
// Check for CLI updates (same as 'sgs fetch')
150+
PromptForUpdate()
148151
}
149152
}
150153

scripts/install.sh

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,21 @@ fetch_versions() {
5050
# Interactive version selection
5151
select_version() {
5252
printf "${BLUE}Available versions:${NC}\n"
53-
printf " 1) latest\n"
54-
i=2
53+
i=1
5554
for v in $RELEASES; do
56-
printf " %d) %s\n" "$i" "$v"
55+
if [ "$i" = "1" ]; then
56+
printf " %d) %s (latest)\n" "$i" "$v"
57+
else
58+
printf " %d) %s\n" "$i" "$v"
59+
fi
5760
i=$((i + 1))
5861
done
5962

6063
printf "\nSelect version [1]: "
6164
read -r choice </dev/tty
6265
choice=${choice:-1}
6366

64-
if [ "$choice" = "1" ]; then
65-
VERSION="latest"
66-
else
67-
VERSION=$(echo "$RELEASES" | sed -n "$((choice - 1))p")
68-
fi
67+
VERSION=$(echo "$RELEASES" | sed -n "${choice}p")
6968
}
7069

7170
# Select installation path
@@ -90,11 +89,7 @@ select_install_path() {
9089

9190
# Download and install
9291
install_binary() {
93-
if [ "$VERSION" = "latest" ]; then
94-
DOWNLOAD_URL="https://github.com/$REPO/releases/latest/download/sgs-$OS-$ARCH"
95-
else
96-
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$VERSION/sgs-$OS-$ARCH"
97-
fi
92+
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$VERSION/sgs-$OS-$ARCH"
9893

9994
# Add .exe for Windows
10095
if [ "$OS" = "windows" ]; then
@@ -153,12 +148,12 @@ main() {
153148

154149
# Check if any releases exist
155150
if [ -z "$RELEASES" ]; then
156-
printf "${YELLOW}No releases found. Installing latest...${NC}\n"
157-
VERSION="latest"
158-
else
159-
select_version
151+
printf "${RED}No releases found. Please check the repository.${NC}\n"
152+
exit 1
160153
fi
161154

155+
select_version
156+
162157
select_install_path
163158
install_binary
164159
}

0 commit comments

Comments
 (0)