-
-
Save blizzz/a9ff3b54d397037d2ad0425d8d5f19b3 to your computer and use it in GitHub Desktop.
shortcut for "sudo -u http php[vv] occ"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Require: run from a Nextcloud root dir | |
if [ ! -f lib/versioncheck.php ]; then | |
echo "Enter the Nextcloud root dir first" > /dev/stderr | |
exit 255; | |
fi | |
# Test general php bin first | |
if php lib/versioncheck.php 1>/dev/null ; then | |
sudo -u http php occ "$@" | |
exit $? | |
fi | |
# Walk through installed binaries, from highest version downwards | |
# ⚠ requires bfs, which is a drop-in replacement for find, see https://tavianator.com/projects/bfs.html | |
BINARIES+=$(bfs /usr/bin/ -type f -regextype posix-extended -regex '.*/php[0-9]{2}$' | sort -r) | |
for PHPBIN in ${BINARIES}; do | |
if "${PHPBIN}" lib/versioncheck.php 1>/dev/null ; then | |
sudo -u http ${PHPBIN} occ "$@" | |
exit $? | |
fi | |
done | |
echo "No suitable PHP binary found" > /dev/stderr | |
exit 254 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Written for Arch with various php version installed from AUR, as well as bfs. It finds the appropriate PHP binary that will run in the Nextcloud checkout in the current directory.
Run it from with a nextcloud root folder. So instead of
sudo -u http php81 occ
simply run
occ
(provided you store in a location included in
$PATH
)