Skip to content

Commit b9ff279

Browse files
authored
Merge pull request #12 from Its-Satyajit/is-branch-2
feat(phpv): Add PHP extension installation and version display
2 parents 78fcc3d + 5ed45ae commit b9ff279

6 files changed

Lines changed: 280 additions & 15 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
10+
name: release-please
11+
12+
jobs:
13+
release-please:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: google-github-actions/release-please-action@v4
17+
with:
18+
token: ${{ secrets.GITHUB_TOKEN }}
19+
config-file: release-please-config.json
20+
manifest-file: .release-please-manifest.json

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "1.1.0"
3+
}

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
3+
## [1.1.0] - 2026-02-17
4+
5+
### Added
6+
- **Extension Support (`-e`)**: Easily install PHP extensions (e.g., `phpv -e imagick 81`) from the AUR.
7+
- **Smart Install**: Prioritizes prebuilt binaries from configured repositories (like Chaotic-AUR) to speed up installation, falling back to AUR compilation if not found.
8+
- **Automated Dependencies**: Automatically handles the missing `c-client` dependency by downloading a prebuilt binary from the repository.
9+
- **Force Build (`--build`)**: Added flag to force compilation from source, bypassing binary checks.
10+
- **Version Flag (`-v`)**: Added `--version` / `-v` to check current installed version.
11+
12+
### Changed
13+
- Refactored argument parsing logic.
14+
- Improved help & usage instructions.

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,40 @@ Replace `<version>` with the desired shorthand (e.g., 80 for 8.0, 74 for 7.4).
8585

8686
![](assets/20240716_210224_update_10.png)
8787

88+
#### Smart Install (Binary Support)
89+
90+
By default, `phpv` tries to install prebuilt binaries using `pacman` (if available in your configured repositories, like Chaotic-AUR). This saves time by avoiding compilation.
91+
92+
If a prebuilt binary is not found, it automatically falls back to building from the AUR.
93+
94+
#### Force Build from Source
95+
96+
If you prefer to compile from source (skipping the binary check), use the `--build` (or `-b`) flag:
97+
98+
```bash
99+
phpv -i <version> --build
100+
```
101+
102+
Example: `phpv -i 81 -b`
103+
104+
#### Skipping Tests
105+
106+
If the installation fails during the testing phase (common with some extensions like `imagick`), you can skip tests using `--nocheck`:
107+
108+
```bash
109+
phpv -e imagick 81 --nocheck
110+
```
111+
112+
#### Installing PHP Extensions
113+
114+
To install PHP extensions (e.g., imagick, redis) for a specific PHP version, use the `-e` flag:
115+
116+
```bash
117+
phpv -e <extension> <version>
118+
```
119+
120+
Example: `phpv -e imagick 81` will install `php81-imagick` from the AUR.
121+
88122
#### Switching PHP Versions
89123

90124
To switch PHP versions, use the following command:
@@ -103,7 +137,12 @@ Replace `<version>` with the desired shorthand.
103137

104138
### Troubleshooting
105139

106-
If you encounter issues with the c-client dependency, follow the steps outlined below for manual installation.
140+
### Troubleshooting
141+
142+
#### c-client Dependency
143+
PHPV automatically detects if `c-client` is missing and attempts to install it for you using the prebuilt binary from this repository. You typically don't need to do anything.
144+
145+
However, if the automatic installation fails, you can follow the manual steps below.
107146
108147
#### Pre-built Binary for Easy Resolution
109148

phpv

Lines changed: 191 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

33
# Color definitions
4+
VERSION="1.1.0"
45
RED='\033[0;31m'
56
GREEN='\033[0;32m'
67
YELLOW='\033[0;33m'
@@ -73,17 +74,84 @@ clone_or_update_php() {
7374
fi
7475
}
7576

77+
# Function to check if package exists in repositories and install it
78+
install_via_pacman() {
79+
local package="$1"
80+
if pacman -Si "$package" &>/dev/null; then
81+
print_info "Found prebuilt binary for $package! Installing via pacman..."
82+
sudo pacman -S --noconfirm "$package" || return 1
83+
return 0
84+
else
85+
return 1
86+
fi
87+
}
88+
89+
# Function to install c-client if missing
90+
install_c_client() {
91+
if pacman -Qi c-client &>/dev/null; then
92+
return 0
93+
fi
94+
95+
print_info "c-client dependency is missing (required for PHP build)."
96+
print_info "Downloading prebuilt c-client from official repository..."
97+
98+
local c_client_url="https://github.com/Its-Satyajit/phpv/raw/main/c-client/c-client-2007f-20-x86_64.pkg.tar.zst"
99+
local c_client_file="/tmp/c-client-2007f-20-x86_64.pkg.tar.zst"
100+
101+
if curl -L -o "$c_client_file" "$c_client_url"; then
102+
print_info "Installing c-client..."
103+
if sudo pacman -U --noconfirm "$c_client_file"; then
104+
print_success "c-client installed successfully!"
105+
return 0
106+
else
107+
print_error "Failed to install c-client via pacman."
108+
return 1
109+
fi
110+
else
111+
print_error "Failed to download c-client from GitHub."
112+
return 1
113+
fi
114+
}
115+
76116
# Function to build and install PHP version using makepkg
77117
build_and_install_php() {
78118
local version="$1"
119+
120+
# Try to install via pacman first if --build is not set
121+
if [ "$FORCE_BUILD" != "true" ]; then
122+
if install_via_pacman "php${version}"; then
123+
print_success "Installed PHP ${version} via pacman!"
124+
return 0
125+
fi
126+
print_info "Prebuilt binary not found. Falling back to AUR build..."
127+
fi
128+
129+
# Ensure c-client is installed
130+
install_c_client || {
131+
print_error "Failed to handle c-client dependency. Build might fail."
132+
# We don't exit here, let makepkg try/fail so user sees the native error too
133+
}
134+
79135
print_info "Mixing potions to build and install PHP version $version..."
80136
print_info "This may take a while... Gather 'round, wizards!"
81-
makepkg -si --noconfirm || {
137+
138+
# Explicitly skipping PGP check can sometimes help with old AUR keys, but standard is secure.
139+
# Using --noconfirm to avoid interactive prompts which break automation.
140+
# Using --cleanbuild to remove the build directory ($srcdir/) before starting (or after packaging with -c),
141+
# ensuring a fresh build environment and preventing errors on re-runs (like prepare() failing).
142+
local makepkg_args="-si --noconfirm --cleanbuild"
143+
if [ "$NO_CHECK" == "true" ]; then
144+
makepkg_args="$makepkg_args --nocheck"
145+
print_warning "Skipping tests as requested..."
146+
fi
147+
148+
makepkg $makepkg_args || {
82149
print_error "Failed the incantation to build or install PHP version $version. Did someone mispronounce 'makepkg'?"
83150
exit 1
84151
}
85152
}
86153

154+
87155
# Function to create symbolic links for PHP binaries
88156
create_symlinks() {
89157
local version="$1"
@@ -119,6 +187,69 @@ create_symlinks() {
119187
fi
120188
}
121189

190+
# Function to install PHP extension
191+
install_extension() {
192+
local extension="$1"
193+
local version="$2"
194+
local package_name="php${version}-${extension}"
195+
local aur_repo="https://aur.archlinux.org/${package_name}.git"
196+
local install_dir="$HOME/src/${package_name}"
197+
198+
print_info "Preparing to install extension: ${extension} for PHP ${version}..."
199+
200+
# Try to install via pacman first if --build is not set
201+
if [ "$FORCE_BUILD" != "true" ]; then
202+
if install_via_pacman "${package_name}"; then
203+
print_success "Extension ${extension} for PHP ${version} installed via pacman!"
204+
return 0
205+
fi
206+
print_info "Prebuilt binary not found. Falling back to AUR build..."
207+
fi
208+
209+
# Create source directory if it doesn't exist
210+
if [ ! -d "$HOME/src" ]; then
211+
mkdir -p "$HOME/src" || {
212+
print_error "Failed to create directory $HOME/src."
213+
exit 1
214+
}
215+
fi
216+
217+
# Check if directory exists and is not empty
218+
if [ -d "$install_dir" ] && [ -n "$(ls -A $install_dir)" ]; then
219+
print_info "Updating existing extension source..."
220+
cd "$install_dir" || exit 1
221+
git pull origin master || git pull origin main || {
222+
print_error "Failed to update extension source."
223+
exit 1
224+
}
225+
else
226+
print_info "Cloning extension from ${aur_repo}..."
227+
git clone "$aur_repo" "$install_dir" || {
228+
print_error "Failed to clone extension repository. Does it exist in AUR?"
229+
exit 1
230+
}
231+
cd "$install_dir" || exit 1
232+
fi
233+
234+
print_info "Building and installing usage makepkg..."
235+
local makepkg_args="-si --noconfirm --cleanbuild"
236+
if [ "$NO_CHECK" == "true" ]; then
237+
makepkg_args="$makepkg_args --nocheck"
238+
print_warning "Skipping tests as requested..."
239+
fi
240+
241+
# Manual cleanup to be absolutely sure
242+
print_info "Sweeping away old build artifacts (src/ pkg/)..."
243+
rm -rf src pkg
244+
245+
makepkg $makepkg_args || {
246+
print_error "Failed to build/install extension ${package_name}."
247+
exit 1
248+
}
249+
250+
print_success "Extension ${extension} for PHP ${version} installed successfully!"
251+
}
252+
122253
# Function to switch PHP version
123254
switch_php_version() {
124255
local version="$1"
@@ -139,29 +270,75 @@ switch_php_version() {
139270

140271
# Main script logic
141272

142-
# Check if PHP version argument is provided
143-
if [ $# -ne 1 ] && [ $# -ne 2 ]; then
144-
print_info "Magic instructions: $0 -i <version> to install/update | $0 <version> to switch."
145-
exit 1
146-
fi
273+
# Main script logic
147274

148-
if [ $# -eq 2 ] && [ "$1" == "-i" ]; then
149-
action="install_or_update"
150-
version="$2"
151-
elif [ $# -eq 1 ]; then
152-
action="switch"
153-
version="$1"
154-
else
155-
print_error "The spell has been mispronounced! Invalid command incantation."
275+
FORCE_BUILD="false"
276+
NO_CHECK="false"
277+
278+
# Check arguments
279+
while [[ $# -gt 0 ]]; do
280+
case $1 in
281+
-i)
282+
action="install_or_update"
283+
version="$2"
284+
shift 2
285+
;;
286+
-e)
287+
action="install_extension"
288+
extension="$2"
289+
version="$3"
290+
shift 3
291+
;;
292+
-v|--version)
293+
echo "PHPV Version: $VERSION"
294+
exit 0
295+
;;
296+
-b|--build)
297+
FORCE_BUILD="true"
298+
shift
299+
;;
300+
--nocheck)
301+
NO_CHECK="true"
302+
shift
303+
;;
304+
-*)
305+
print_error "Unknown magic spell: $1"
306+
exit 1
307+
;;
308+
*)
309+
if [ -z "$action" ]; then
310+
action="switch"
311+
version="$1"
312+
shift
313+
else
314+
print_error "Too many ingredients in the cauldron!"
315+
exit 1
316+
fi
317+
;;
318+
esac
319+
done
320+
321+
if [ -z "$action" ]; then
322+
print_info "Magic instructions:"
323+
print_info " $0 -i <version> : Install/Update PHP version"
324+
print_info " $0 -i <version> --build : Force build from source (ignore binary)"
325+
print_info " $0 -i <version> --nocheck : Skip tests during build"
326+
print_info " $0 -e <extension> <version> : Install PHP extension (e.g., 'imagick 81')"
327+
print_info " $0 <version> : Switch to PHP version"
328+
print_info " $0 -v : Show version"
156329
exit 1
157330
fi
158331

332+
159333
case "$action" in
160334
install_or_update)
161335
clone_or_update_php "$version"
162336
build_and_install_php "$version"
163337
create_symlinks "$version"
164338
;;
339+
install_extension)
340+
install_extension "$extension" "$version"
341+
;;
165342
switch)
166343
switch_php_version "$version"
167344
;;

release-please-config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3+
"bootstrap-sha": "HEAD",
4+
"packages": {
5+
".": {
6+
"release-type": "simple",
7+
"package-name": "phpv",
8+
"version-file": "phpv",
9+
"extra-files": ["phpv"]
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)