Skip to content

Instantly share code, notes, and snippets.

@blizzz
Last active April 9, 2025 20:33
Show Gist options
  • Save blizzz/a9ff3b54d397037d2ad0425d8d5f19b3 to your computer and use it in GitHub Desktop.
Save blizzz/a9ff3b54d397037d2ad0425d8d5f19b3 to your computer and use it in GitHub Desktop.
shortcut for "sudo -u http php[vv] occ"
#!/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
@blizzz
Copy link
Author

blizzz commented Dec 19, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment