@@ -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
117144build_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
330362fi
@@ -339,6 +371,9 @@ install_or_update)
339371install_extension)
340372 install_extension " $extension " " $version "
341373 ;;
374+ self_update)
375+ self_update
376+ ;;
342377switch)
343378 switch_php_version " $version "
344379 ;;
0 commit comments