Skip to content

Commit 7082465

Browse files
authored
Merge pull request #16 from Its-Satyajit/is-branch-1
feat(update): Add self-update functionality to phpv
2 parents 19b8868 + 20a6b24 commit 7082465

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ Replace `<version>` with the desired shorthand.
137137

138138
### Troubleshooting
139139

140+
### Updates
141+
142+
To update `phpv` to the latest version from the repository:
143+
144+
```bash
145+
phpv --self-update
146+
```
147+
140148
### Troubleshooting
141149

142150
#### c-client Dependency

phpv

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,33 @@ install_c_client() {
113113
fi
114114
}
115115

116+
# Function to self-update phpv
117+
self_update() {
118+
print_info "Checking for updates..."
119+
local update_url="https://raw.githubusercontent.com/Its-Satyajit/phpv/main/phpv"
120+
local temp_file="/tmp/phpv_update"
121+
122+
if curl -fsSL -o "$temp_file" "$update_url"; then
123+
# Basic validation: check if it looks like a bash script
124+
if grep -q "#!/bin/bash" "$temp_file"; then
125+
print_info "Installing update..."
126+
# cp preserves permissions, but let's be explicit about +x
127+
cp "$temp_file" "$0"
128+
chmod +x "$0"
129+
print_success "PHPV has been updated to the latest version!"
130+
rm -f "$temp_file"
131+
exit 0
132+
else
133+
print_error "Downloaded file does not look like a valid script. Update aborted."
134+
rm -f "$temp_file"
135+
exit 1
136+
fi
137+
else
138+
print_error "Failed to download update from GitHub."
139+
exit 1
140+
fi
141+
}
142+
116143
# Function to build and install PHP version using makepkg
117144
build_and_install_php() {
118145
local version="$1"
@@ -301,6 +328,10 @@ while [[ $# -gt 0 ]]; do
301328
NO_CHECK="true"
302329
shift
303330
;;
331+
-u|--self-update)
332+
action="self_update"
333+
shift
334+
;;
304335
-*)
305336
print_error "Unknown magic spell: $1"
306337
exit 1
@@ -325,6 +356,7 @@ if [ -z "$action" ]; then
325356
print_info " $0 -i <version> --nocheck : Skip tests during build"
326357
print_info " $0 -e <extension> <version> : Install PHP extension (e.g., 'imagick 81')"
327358
print_info " $0 <version> : Switch to PHP version"
359+
print_info " $0 -u, --self-update : Update phpv to the latest version"
328360
print_info " $0 -v : Show version"
329361
exit 1
330362
fi
@@ -339,6 +371,9 @@ install_or_update)
339371
install_extension)
340372
install_extension "$extension" "$version"
341373
;;
374+
self_update)
375+
self_update
376+
;;
342377
switch)
343378
switch_php_version "$version"
344379
;;

0 commit comments

Comments
 (0)