libre-workspace
libre-workspace copied to clipboard
Add AppAPI Functionality to Nextloud (local docker socket)
This is what the AI said to me:
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# ==============================================================================
# CONFIGURATION - PLEASE EDIT THESE VARIABLES
# ==============================================================================
# The absolute path to your Nextcloud installation's root directory.
# Example: "/var/www/html/nextcloud"
NEXTCLOUD_PATH="/var/www/nextcloud"
# The user that your web server (e.g., Apache, Nginx) runs as.
# On Debian/Ubuntu, this is typically 'www-data'. On CentOS/RHEL, it's 'apache' or 'httpd'.
WWW_USER="www-data"
# The full public URL of your Nextcloud instance. This must be reachable by the
# containers that will be deployed.
# Example: "https://cloud.mydomain.com"
NEXTCLOUD_URL="https://your-nextcloud-url.com"
# The name you want to give the HaRP Docker container.
HARP_CONTAINER_NAME="nextcloud-appapi-harp"
# The unique internal name for the deploy daemon in Nextcloud.
DAEMON_NAME="harp_proxy_local"
# (Optional) The GPU device to expose. Options: cpu | cuda | rocm
# Set to "cpu" if you don't have a dedicated GPU for this purpose.
COMPUTE_DEVICE="cpu"
# ==============================================================================
# SCRIPT LOGIC - DO NOT EDIT BELOW THIS LINE
# ==============================================================================
echo "๐ Starting Nextcloud AppAPI Docker Daemon Configuration..."
# --- Step 1: Check for root privileges ---
if [ "$(id -u)" -ne 0 ]; then
echo "โ This script must be run with root privileges. Please use sudo."
exit 1
fi
# --- Step 2: Generate a secure shared key for HaRP ---
echo "๐ Generating a secure shared key for HaRP..."
HARP_SHARED_KEY=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c32)
echo "โ
Secure key generated."
# --- Step 3: Stop and remove any existing HaRP container ---
echo "๐งน Cleaning up any previous HaRP containers..."
if [ "$(docker ps -q -f name=^/${HARP_CONTAINER_NAME}$)" ]; then
echo " -> Stopping existing container..."
docker stop "$HARP_CONTAINER_NAME"
fi
if [ "$(docker ps -aq -f status=exited -f name=^/${HARP_CONTAINER_NAME}$)" ]; then
echo " -> Removing existing container..."
docker rm "$HARP_CONTAINER_NAME"
fi
echo "โ
Cleanup complete."
# --- Step 4: Run the HaRP container ---
echo "๐ณ Launching the HaRP Docker container..."
echo " This will pull the latest 'release' image if you don't have it."
docker run \
-d \
--name "$HARP_CONTAINER_NAME" \
--restart unless-stopped \
-e HP_SHARED_KEY="$HARP_SHARED_KEY" \
-e NC_INSTANCE_URL="$NEXTCLOUD_URL" \
-v /var/run/docker.sock:/var/run/docker.sock \
-p 127.0.0.1:8780:8780 \
-p 127.0.0.1:8782:8782 \
ghcr.io/nextcloud/nextcloud-appapi-harp:release
echo "โ
HaRP container ('$HARP_CONTAINER_NAME') is now running."
# --- Step 5: Unregister any existing daemon with the same name ---
echo "โ๏ธ Registering the new deploy daemon with Nextcloud via OCC command..."
echo " -> First, attempting to unregister any old daemon with the name '$DAEMON_NAME' to avoid conflicts."
# This command might fail if the daemon doesn't exist, which is fine.
sudo -u "$WWW_USER" php "${NEXTCLOUD_PATH}/occ" app_api:daemon:unregister "$DAEMON_NAME" || true
# --- Step 6: Register the new HaRP daemon in Nextcloud ---
echo " -> Now registering the new HaRP-powered daemon..."
sudo -u "$WWW_USER" php "${NEXTCLOUD_PATH}/occ" app_api:daemon:register \
"$DAEMON_NAME" \
"Local Docker (via HaRP)" \
"docker-install" \
"http" \
"localhost:8780" \
"$NEXTCLOUD_URL" \
--harp \
--harp_frp_address="localhost:8782" \
--harp_shared_key="$HARP_SHARED_KEY" \
--set-default \
--compute_device="$COMPUTE_DEVICE"
echo "โ
Daemon successfully registered in Nextcloud."
echo ""
echo "๐ All done! Your local Docker daemon is now configured for the Nextcloud App API."
echo "โก๏ธ Next step: Go to your Nextcloud Admin settings -> External Apps, and use the 'Test deploy' option to verify the connection."