I don’t tend to do much php but it comes up from time to time.
The package manager for php is composer and it’s generally not in
distro packages. So I wrote the following for my home dir to make it
easier to get on the odd time I need it.
This would go in ~/bin/composer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| #!/bin/bash
compdir="$HOME/.config/php-cli"
compbin="$HOME/.config/php-cli/composer.phar"
die() {
echo "ERROR: $*"
exit 1
}
if [[ ! -f "$compbin" ]]; then
mkdir -p "$compdir"
opwd="$(pwd)"
cd "$compdir" || die "Couldn't go to $compdir."
gitsig="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
calcsig="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [[ "$gitsig" != "$calcsig" ]]; then
rm composer-setup.php
die 'Invalid installer signature.'
fi
php composer-setup.php --quiet \
|| die "composer-setup.php failed - look in $opwd for more info."
rm composer-setup.php
cd "$opwd" || die "Couldn't go to $compdir."
fi
$compbin "$@"
|