Files
2026-04-15 14:46:50 -07:00

62 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${script_dir}/lib-compose-project.sh"
if [[ $# -lt 2 ]]; then
echo "Usage: ./scripts/nextcloud-occ.sh <env-file> <occ-args...>"
exit 1
fi
env_file="$1"
shift
compose_file="${COMPOSE_FILE:-docker-compose.yml}"
if [[ "${env_file}" != /* ]]; then
env_dir="$(cd "$(dirname "${env_file}")" && pwd)"
env_file="${env_dir}/$(basename "${env_file}")"
fi
ensure_docker_access() {
local docker_path=""
docker_path="$(type -P docker || true)"
if [[ -z "${docker_path}" ]]; then
echo "docker is required"
exit 1
fi
if "${docker_path}" info >/dev/null 2>&1; then
DOCKER_CMD=("${docker_path}")
return 0
fi
if ! command -v sudo >/dev/null 2>&1; then
echo "docker is installed but this user cannot access it, and sudo is unavailable."
exit 1
fi
if sudo -n "${docker_path}" info >/dev/null 2>&1; then
DOCKER_CMD=(sudo "${docker_path}")
return 0
fi
echo "docker requires elevated privileges on this machine."
echo "You may be prompted for your sudo password."
if sudo "${docker_path}" info >/dev/null 2>&1; then
DOCKER_CMD=(sudo "${docker_path}")
return 0
fi
echo "Unable to access docker, even with sudo."
exit 1
}
docker() {
"${DOCKER_CMD[@]}" "$@"
}
ensure_docker_access
export_compose_project_name_from_env "$env_file" || true
docker compose -f "$compose_file" --env-file "$env_file" exec -u www-data app php occ "$@"