### Install Cog using fetch
Source: https://cog.run/install
Example command to download and execute the Cog installation script directly using fetch. This is another alternative for fetching the installation script, often found on BSD systems.
```shell
sh -c "$(fetch -o - https://raw.githubusercontent.com/replicate/cog/main/tools/install.sh)"
```
--------------------------------
### Docker Compose Quick Start Example
Source: https://github.com/docker/compose
A basic example of a Docker Compose file defining web and redis services. It shows how to build an image from a Dockerfile, map ports, and mount volumes.
```yaml
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- ".:/code"
redis:
image: redis
```
--------------------------------
### Install Cog using wget
Source: https://cog.run/install
Example command to download and execute the Cog installation script directly using wget. This is an alternative to curl for fetching the installation script.
```shell
sh -c "$(wget -qO- https://raw.githubusercontent.com/replicate/cog/main/tools/install.sh)"
```
--------------------------------
### Install Cog using curl
Source: https://cog.run/install
Example command to download and execute the Cog installation script directly using curl. This is a common method for unattended or quick installations.
```shell
sh -c "$(curl -fsSL https://raw.githubusercontent.com/replicate/cog/main/tools/install.sh)"
```
--------------------------------
### Dockerfile: Running Apache with ENTRYPOINT
Source: https://docs.docker.com/engine/reference/builder/
Demonstrates using ENTRYPOINT to run a service like Apache in the foreground, ensuring it becomes PID 1 within the container. Includes necessary setup like package installation, port exposure, and volume definitions.
```dockerfile
FROM debian:stable
RUN apt-get update && apt-get install -y --force-yes apache2
EXPOSE 80 443
VOLUME ["/var/www", "/var/log/apache2", "/etc/apache2"]
ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
```
--------------------------------
### Docker Compose README Overview
Source: https://github.com/docker/compose
Extracts the main structure and key sections from the Docker Compose README file. This includes sections on Docker Compose v2, installation methods for different operating systems, quick start guides, contribution information, and legacy details.
```markdown
# Docker Compose v2
## Table of Contents
* [Docker Compose v2](#docker-compose-v2)
* [Where to get Docker Compose](#where-to-get-docker-compose)
* [Windows and macOS](#windows-and-macos)
* [Linux](#linux)
* [Quick Start](#quick-start)
* [Contributing](#contributing)
* [Legacy](#legacy)
## Docker Compose v2
(Content for Docker Compose v2 would follow here in a full README)
## Where to get Docker Compose
### Windows and macOS
(Installation instructions for Windows and macOS)
### Linux
(Installation instructions for Linux)
## Quick Start
(Guide to getting started with Docker Compose)
## Contributing
(Information for contributors)
## Legacy
(Details on older versions or legacy information)
```
--------------------------------
### Install Cog CLI
Source: https://github.com/replicate/cog/blob/12ac02091d93beebebed037f38a0c99cd8749806/docs/getting-started
Download and install the Cog command-line interface. This script fetches the latest release for your system architecture and makes it executable.
```bash
sudo curl -o /usr/local/bin/cog -L https://github.com/replicate/cog/releases/latest/download/cog_`uname -s`_`uname -m`
sudo chmod +x /usr/local/bin/cog
```
--------------------------------
### Example Manifest File Format
Source: https://github.com/replicate/pget
An example structure for a manifest file, where each line contains a URL followed by its corresponding local destination file path.
```text
https://example.com/image1.jpg /local/path/to/image1.jpg
https://example.com/document.pdf /local/path/to/document.pdf
https://example.com/music.mp3 /local/path/to/music.mp3
```
--------------------------------
### Download Cog Install Script Separately
Source: https://cog.run/install
Demonstrates downloading the Cog installation script first using wget, and then executing it. This allows for inspection of the script before running.
```shell
wget https://raw.githubusercontent.com/replicate/cog/main/tools/install.sh
sh install.sh
```
--------------------------------
### Execute Custom Setup Commands
Source: https://cog.run/llms.txt
Lists commands to run after system and Python packages are installed, similar to Dockerfile's `RUN` instruction. Commands do not have access to the user's code. Supports secret mounts for secure credential passing.
```yaml
build:
run:
- curl -L https://github.com/cowsay-org/cowsay/archive/refs/tags/v3.7.0.tar.gz | tar -xzf -
- cd cowsay-3.7.0 && make install
```
```yaml
build:
run:
- command: pip install
mounts:
- type: secret
id: pip
target: /etc/pip.conf
```
--------------------------------
### Cog Jupyter Notebook Setup
Source: https://cog.run/llms.txt
Instructions for installing JupyterLab within a Cog environment and running a Jupyter notebook server.
```yaml
build:
python_packages:
- "jupyterlab==3.3.4"
```
--------------------------------
### Execute Custom Setup Commands
Source: https://context7_llms
Lists commands to run after system and Python packages are installed, similar to Dockerfile's `RUN` instruction. Commands do not have access to the user's code. Supports secret mounts for secure credential passing.
```yaml
build:
run:
- curl -L https://github.com/cowsay-org/cowsay/archive/refs/tags/v3.7.0.tar.gz | tar -xzf -
- cd cowsay-3.7.0 && make install
```
```yaml
build:
run:
- command: pip install
mounts:
- type: secret
id: pip
target: /etc/pip.conf
```
--------------------------------
### Cog Jupyter Notebook Setup
Source: https://context7_llms
Instructions for installing JupyterLab within a Cog environment and running a Jupyter notebook server.
```yaml
build:
python_packages:
- "jupyterlab==3.3.4"
```
--------------------------------
### Build and Install Cog from Source
Source: https://cog.run/llms.txt
Builds Cog from its source code using the `make` command and then installs it. This is useful for developers who want to build Cog themselves.
```console
make
sudo make install
```
--------------------------------
### Install Cog with Install Script
Source: https://cog.run/llms.txt
Installs Cog using the official installation script provided by Cog. Supports different shell environments like fish, bash, and zsh, and can be executed via curl or wget.
```fish
sh (curl -fsSL https://cog.run/install.sh | psub)
```
```bash
sh <(curl -fsSL https://cog.run/install.sh)
```
```shell
wget -qO- https://cog.run/install.sh
sh ./install.sh
```
--------------------------------
### Build and Install PGet from Source
Source: https://github.com/replicate/pget
Builds PGet from source code, requiring Go 1.19 or later. This process creates a static binary that can be installed system-wide, making it suitable for containerized environments.
```shell
make
sudo make install
```
--------------------------------
### Build and Install Cog from Source
Source: https://context7_llms
Builds Cog from its source code using the `make` command and then installs it. This is useful for developers who want to build Cog themselves.
```console
make
sudo make install
```
--------------------------------
### Install Cog with Install Script
Source: https://context7_llms
Installs Cog using the official installation script provided by Cog. Supports different shell environments like fish, bash, and zsh, and can be executed via curl or wget.
```fish
sh (curl -fsSL https://cog.run/install.sh | psub)
```
```bash
sh <(curl -fsSL https://cog.run/install.sh)
```
```shell
wget -qO- https://cog.run/install.sh
sh ./install.sh
```
--------------------------------
### Cog Installation Script
Source: https://cog.run/install
The main shell script for installing the Cog CLI. It sets up the installation directory, checks for necessary tools like Docker, and downloads the appropriate binary based on the system architecture. It handles existing files and prompts the user for confirmation before overwriting.
```shell
#!/bin/sh
#
# This script should be run via curl:
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/replicate/cog/main/tools/install.sh)"
# or via wget:
# sh -c "$(wget -qO- https://raw.githubusercontent.com/replicate/cog/main/tools/install.sh)"
# or via fetch:
# sh -c "$(fetch -o - https://raw.githubusercontent.com/replicate/cog/main/tools/install.sh)"
#
# As an alternative, you can first download the install script and run it afterwards:
# wget https://raw.githubusercontent.com/replicate/cog/main/tools/install.sh
# sh install.sh
#
# You can tweak the install location by setting the INSTALL_DIR env var when running the script.
# INSTALL_DIR=~/my/custom/install/location sh install.sh
#
# By default, cog will be installed at /usr/local/bin/cog
# This install script is based on that of ohmyzsh[1], which is licensed under the MIT License
# [1] https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh
# MIT License
# Copyright (c) 2009-2022 Robby Russell and contributors (https://github.com/ohmyzsh/ohmyzsh/contributors)
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
set -e
SUDO="sudo"
# Check if sudo is installed
command_exists() {
command -v "$@" >/dev/null 2>&1
}
user_can_sudo() {
# Check if sudo is installed
command_exists $SUDO || return 1
# Termux can't run sudo, so we can detect it and exit the function early.
case "$PREFIX" in
*com.termux*)
return 1
;;
esac
# The following command has 3 parts:
#
# 1. Run `sudo` with `-v`. Does the following:
# • with privilege: asks for a password immediately.
# • without privilege: exits with error code 1 and prints the message:
# Sorry, user may not run sudo on
#
# 2. Pass `-n` to `sudo` to tell it to not ask for a password. If the
# password is not required, the command will finish with exit code 0.
# If one is required, sudo will exit with error code 1 and print the
# message:
# sudo: a password is required
#
# 3. Check for the words "may not run sudo" in the output to really tell
# whether the user has privileges or not. For that we have to make sure
# to run `sudo` in the default locale (with `LANG=`) so that the message
# stays consistent regardless of the user's locale.
! LANG= $SUDO -n -v 2>&1 | grep -q "may not run $SUDO"
}
check_docker() {
if ! command_exists docker;
then
echo "Docker is not installed on your system. Please install Docker before proceeding."
exit 1
fi
if ! docker run hello-world >/dev/null 2>&1;
then
echo "WARNING: Docker engine is not running, or docker cannot be run without sudo. Please setup Docker so that your user has permission to run it: https://docs.docker.com/engine/install/linux-postinstall/"
fi
}
setup_cog() {
COG_LOCATION="${INSTALL_DIR}/cog"
BINARY_URI="https://github.com/replicate/cog/releases/latest/download/cog_$(uname -s)_$(uname -m)"
if [ -f "$COG_LOCATION" ]; then
echo "A file already exists at $COG_LOCATION"
echo "Do you want to delete this file and continue with this installation anyway?"
read -p "Delete file? (y/N): " choice
case "$choice" in
y|Y)
echo "Deleting existing file and continuing with installation..."
$SUDO rm $COG_LOCATION
;;
*)
echo "Exiting installation."
exit 1
;;
esac
fi
if command_exists curl;
then
$SUDO curl -o $COG_LOCATION -L $BINARY_URI
elif command_exists wget;
then
$SUDO wget $BINARY_URI -O $COG_LOCATION
elif command_exists fetch;
then
$SUDO fetch -o $COG_LOCATION $BINARY_URI
else
echo "One of c"
```
--------------------------------
### Docker Compose Start Command
Source: https://docs.docker.com/engine/reference/builder/
Starts existing containers. This command brings up services that have already been created.
```docker
docker compose start [OPTIONS] [SERVICE...]
Starts existing containers.
```
--------------------------------
### Install Replicate Python Library
Source: https://replicate.com/blog/fine-tune-llama-2
Installs the necessary Python library to interact with the Replicate API for training and running models. This is the first step before using any Replicate functionalities in Python.
```bash
pip install replicate
```
--------------------------------
### Install Cog Manually from GitHub
Source: https://cog.run/llms.txt
Manually installs the latest release of Cog by downloading the pre-compiled binary directly from GitHub releases. This method requires `curl` and `chmod`.
```console
sudo curl -o /usr/local/bin/cog -L "https://github.com/replicate/cog/releases/latest/download/cog_$(uname -s)_$(uname -m)"
sudo chmod +x /usr/local/bin/cog
```
--------------------------------
### Install Cog Manually from GitHub
Source: https://context7_llms
Manually installs the latest release of Cog by downloading the pre-compiled binary directly from GitHub releases. This method requires `curl` and `chmod`.
```console
sudo curl -o /usr/local/bin/cog -L "https://github.com/replicate/cog/releases/latest/download/cog_$(uname -s)_$(uname -m)"
sudo chmod +x /usr/local/bin/cog
```
--------------------------------
### Install Cog CLI
Source: https://context7_llms
Provides the necessary commands to download and install the Cog command-line interface on macOS or Linux systems. It fetches the latest release and makes it executable.
```sh
sudo curl -o /usr/local/bin/cog -L https://github.com/replicate/cog/releases/latest/download/cog_`uname -s`_`uname -m`
sudo chmod +x /usr/local/bin/cog
```
--------------------------------
### Install PGet via curl
Source: https://github.com/replicate/pget
Installs the latest PGet release to /usr/local/bin using curl. This command downloads the binary and makes it executable, suitable for direct use on Linux and macOS systems.
```shell
sudo curl -o /usr/local/bin/pget -L "https://github.com/replicate/pget/releases/latest/download/pget_$(uname -s)_$(uname -m)"
sudo chmod +x /usr/local/bin/pget
```
--------------------------------
### Install Cog CLI
Source: https://cog.run/llms.txt
Provides the necessary commands to download and install the Cog command-line interface on macOS or Linux systems. It fetches the latest release and makes it executable.
```sh
sudo curl -o /usr/local/bin/cog -L https://github.com/replicate/cog/releases/latest/download/cog_`uname -s`_`uname -m`
sudo chmod +x /usr/local/bin/cog
```
--------------------------------
### Docker Documentation Navigation Links
Source: https://docs.docker.com/build/architecture/
This HTML snippet represents navigation links within the Docker documentation. It includes links to Get Started, Guides, Manuals, and Reference sections, as well as a link to the Docker Docs home page.
```html
Docker Docs home page
* [Get started](/get-started/)
* [Guides](/guides/)
* [Manuals](/manuals/)
* [Reference](/reference/)
```
--------------------------------
### Example llms.txt Content
Source: https://llmstxt.org/
Demonstrates the structure and content of an llms.txt file, including project descriptions, important notes, documentation links, and example references. This format is designed for LLM consumption.
```markdown
# FastHTML
> FastHTML is a python library which brings together Starlette, Uvicorn, HTMX, and fastcore's `FT` "FastTags" into a library for creating server-rendered hypermedia applications.
Important notes:
- Although parts of its API are inspired by FastAPI, it is *not* compatible with FastAPI syntax and is not targeted at creating API services
- FastHTML is compatible with JS-native web components and any vanilla JS library, but not with React, Vue, or Svelte.
## Docs
- [FastHTML quick start](https://fastht.ml/docs/tutorials/quickstart_for_web_devs.html.md): A brief overview of many FastHTML features
- [HTMX reference](https://github.com/bigskysoftware/htmx/blob/master/www/content/reference.md): Brief description of all HTMX attributes, CSS classes, headers, events, extensions, js lib methods, and config options
## Examples
- [Todo list application](https://github.com/AnswerDotAI/fasthtml/blob/main/examples/adv_app.py): Detailed walk-thru of a complete CRUD app in FastHTML showing idiomatic use of FastHTML and HTMX patterns.
## Optional
- [Starlette full documentation](https://gist.githubusercontent.com/jph00/809e4a4808d4510be0e3dc9565e9cbd3/raw/9b717589ca44cedc8aaf00b2b8cacef922964c0f/starlette-sml.md): A subset of the Starlette documentation useful for FastHTML development.
```
--------------------------------
### OpenAPI Info Object Example
Source: https://swagger.io/specification/
A concrete example of an Info Object, demonstrating how to populate fields like title, summary, description, contact, license, and version for an API.
```JSON
{
"title": "Example Pet Store App",
"summary": "A pet store manager.",
"description": "This is an example server for a pet store.",
"termsOfService": "https://example.com/terms/",
"contact": {
"name": "API Support",
"url": "https://www.example.com/support",
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0.1"
}
```
--------------------------------
### Cog Predictor Setup Method
Source: https://cog.run/llms.txt
The `setup()` method is an optional step in Cog models used for one-off, expensive operations before predictions begin. This includes loading trained models, initializing data transformations, or downloading model weights. It helps optimize prediction efficiency by performing these tasks only once.
```APIDOC
Predictor.setup()
- Prepares the model for efficient multiple predictions.
- Use for one-off operations like loading trained models, data transformations, or downloading weights.
- Optional method.
- Advantages of downloading weights in setup(): Smaller image sizes, faster build times, faster pushes and inference on Replicate.
- Disadvantages: May significantly increase setup() time.
- Alternative: Store weights directly in the image alongside cog.yaml (increases image size/build time but offers faster setup() and reproducibility).
- When downloading weights, use the `--separate-weights` flag on `cog build` to store weights in a separate layer.
```
--------------------------------
### Create Cog Project Directory
Source: https://github.com/replicate/cog/blob/12ac02091d93beebebed037f38a0c99cd8749806/docs/getting-started
Sets up a new directory for your Cog project and navigates into it. This is the starting point for building and running Cog models.
```bash
mkdir cog-quickstart
cd cog-quickstart
```
--------------------------------
### Cog Predictor Setup Method
Source: https://context7_llms
The `setup()` method is an optional step in Cog models used for one-off, expensive operations before predictions begin. This includes loading trained models, initializing data transformations, or downloading model weights. It helps optimize prediction efficiency by performing these tasks only once.
```APIDOC
Predictor.setup()
- Prepares the model for efficient multiple predictions.
- Use for one-off operations like loading trained models, data transformations, or downloading weights.
- Optional method.
- Advantages of downloading weights in setup(): Smaller image sizes, faster build times, faster pushes and inference on Replicate.
- Disadvantages: May significantly increase setup() time.
- Alternative: Store weights directly in the image alongside cog.yaml (increases image size/build time but offers faster setup() and reproducibility).
- When downloading weights, use the `--separate-weights` flag on `cog build` to store weights in a separate layer.
```
--------------------------------
### OpenAPI Path Item Object Example
Source: https://swagger.io/specification/
An example illustrating the structure of an OpenAPI Path Item Object, demonstrating how to define a GET operation and path parameters.
```JSON
{
"get": {
"description": "Returns pets based on ID",
"summary": "Find pets by ID",
"operationId": "getPetsById",
"responses": {
"200": {
"description": "pet response",
"content": {
"*/*": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Pet"
}
}
}
}
},
"default": {
"description": "error payload",
"content": {
"text/html": {
"schema": {
"$ref": "#/components/schemas/ErrorModel"
}
}
}
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"description": "ID of pet to use",
"required": true,
"schema": {
"type": "array",
"items": {
"type": "string"
}
},
"style": "simple"
}
]
}
```
```YAML
get:
description: Returns pets based on ID
summary: Find pets by ID
operationId: getPetsById
responses:
'200':
description: pet response
content:
'*/*':
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
default:
description: error payload
content:
text/html:
schema:
$ref: '#/components/schemas/ErrorModel'
parameters:
- name: id
in: path
description: ID of pet to use
required: true
schema:
type: array
items:
type: string
style: simple
```
--------------------------------
### Dockerfile: FROM Instruction Syntax and Usage
Source: https://docs.docker.com/engine/reference/builder/
Details the FROM instruction, which initializes a new build stage and sets the base image. It explains the different syntax forms, the use of aliases (AS), optional tags/digests, and the --platform flag for multi-platform images.
```APIDOC
FROM [--platform=] [AS ]
FROM [--platform=] [:] [AS ]
FROM [--platform=] [@] [AS ]
Description:
Initializes a new build stage and sets the base image for subsequent instructions. A Dockerfile must start with a FROM instruction. ARG instructions can precede the first FROM.
Usage:
- FROM can appear multiple times to create multiple images or stages.
- Each FROM instruction clears previous stage state.
- Use 'AS name' to alias a build stage for reference in subsequent FROM, COPY --from, or RUN --mount instructions.
- Omitting tag/digest defaults to 'latest'.
- The --platform flag specifies the platform for multi-platform images (e.g., 'linux/amd64').
Example:
FROM ubuntu:latest AS builder
FROM alpine:3.14
COPY --from=builder /app /app
```
--------------------------------
### Docker Engine Installation Paths
Source: https://docs.docker.com/build/architecture/
This HTML snippet lists installation paths for Docker Engine on various operating systems. It provides direct links to specific installation guides for Ubuntu, Debian, RHEL, Fedora, Raspberry Pi OS, CentOS, and SLES.
```html
* [Open source](https://docs.docker.com/opensource/)
* [Docker Engine](https://docs.docker.com/engine/)
* [Install](https://docs.docker.com/engine/install/)
* [Ubuntu](https://docs.docker.com/engine/install/ubuntu/ "Ubuntu")
* [Debian](https://docs.docker.com/engine/install/debian/ "Debian")
* [RHEL](https://docs.docker.com/engine/install/rhel/ "RHEL")
* [Fedora](https://docs.docker.com/engine/install/fedora/ "Fedora")
* [Raspberry Pi OS (32-bit)](https://docs.docker.com/engine/install/raspberry-pi-os/ "Raspberry Pi OS (32-bit)")
* [CentOS](https://docs.docker.com/engine/install/centos/ "CentOS")
* [SLES (s390x)](https://docs.docker.com/engine/install/sles/ "SLES (s390x)")
```
--------------------------------
### FastAPI Basic API Example (Sync)
Source: https://fastapi.tiangolo.com/
A simple FastAPI application defining two GET endpoints: a root endpoint and an endpoint that accepts a path parameter and an optional query parameter. This example uses synchronous functions.
```python
from typing import Union
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
```
--------------------------------
### Dockerfile: Create greeting.txt with COPY and Here-Doc
Source: https://docs.docker.com/engine/reference/builder/
Demonstrates creating a file named 'greeting.txt' with the content 'hello world' using a Dockerfile COPY instruction with a simple here-document.
```Dockerfile
# syntax=docker/dockerfile:1
FROM alpine
COPY </dev/null 2>&1
}
# Check if user has sudo privileges
user_can_sudo() {
sudo -n true 2>/dev/null
}
# Set installation directory based on user input or default
set_install_dir() {
read -p "Enter the installation directory (default: $INSTALL_DIR): " user_dir
if [[ -n "$user_dir" ]]; then
INSTALL_DIR="$user_dir"
fi
echo "Cog will be installed in $INSTALL_DIR"
}
# Check for Docker availability (though not directly used in this snippet, it's in the original logic)
check_docker() {
if ! command_exists docker; then
echo "Warning: Docker is not installed. Some Cog features might require Docker."
fi
}
# Setup Cog: download, make executable, add to PATH
setup_cog() {
echo "Downloading Cog binary..."
# Determine the correct binary URI based on architecture (simplified for example)
# In a real script, you'd check uname -m
BINARY_URI="https://github.com/replicate/cog/releases/latest/download/cog-linux-amd64"
COG_LOCATION="$INSTALL_DIR/cog"
# Check for wget or curl
if command_exists wget;
then
wget -qO $COG_LOCATION $BINARY_URI
elif command_exists curl;
then
curl -sSL -o $COG_LOCATION $BINARY_URI
else
echo "Error: wget or curl is required to download the Cog binary."
exit 1
fi
# Verify download
if [ ! -s $COG_LOCATION ]; then
echo "Error: Cog binary download failed. Check the URI or your network connection."
exit 1
fi
# Make the binary executable
echo "Making Cog executable..."
$SUDO chmod +x $COG_LOCATION
# Add Cog to PATH if not already present
SHELL_NAME=$(basename "$SHELL")
if [[ ":$PATH:" != ".*:${INSTALL_DIR}:"* ]]; then
echo "Adding $INSTALL_DIR to PATH in .$SHELL_NAME"
echo "" >> ~/.$SHELL_NAME"rc"
echo "# Created by \`cog\` install script on $(date)" >> ~/".${SHELL_NAME}rc"
echo "export PATH=\$PATH:$INSTALL_DIR" >> ~/".${SHELL_NAME}rc"
source ~/".${SHELL_NAME}rc"
echo "You may need to open a new terminal window to run cog for the first time."
fi
}
# Success message
print_success() {
echo "Successfully installed cog. Run \`cog login\` to configure Replicate access"
}
# --- Main Execution ---
main() {
# Check if macOS
if [ "$(uname -s)" = "Darwin" ]; then
echo "On macOS, it is recommended to install cog using Homebrew instead:"
echo \`brew install cog\`
echo "Do you want to continue with this installation anyway?"
read -p "Continue? (y/N): " choice
case "$choice" in
y|Y )
echo "Continuing with installation...";;
* )
echo "Exiting installation."
exit 1;;
esac
fi
set_install_dir
# Check if `cog` command already exists
if command_exists cog;
then
echo "A cog command already exists on your system at the following location: $(which cog)".
echo "The installations may interfere with one another."
echo "Do you want to continue with this installation anyway?"
read -p "Continue? (y/N): " choice
case "$choice" in
y|Y )
echo "Continuing with installation...";;
* )
echo "Exiting installation."
exit 1;;
esac
fi
# Check the users sudo privileges
if [ -z "${SUDO+set}" ]; then
SUDO="sudo"
fi
if [ ! user_can_sudo ] && [ "${SUDO}" != "" ]; then
echo "You need sudo permissions to run this install script. Please try again as a sudoer."
exit 1
fi
check_docker
setup_cog
if command_exists cog;
then
print_success
else
echo 'Error: cog not installed.'
exit 1
fi
}
main "$@"
```
--------------------------------
### Install PGet via Homebrew
Source: https://github.com/replicate/pget
Installs PGet on macOS using Homebrew. This involves tapping the replicate repository and then installing the pget formula.
```shell
brew tap replicate/tap
brew install replicate/tap/pget
```