Update README.md

This commit is contained in:
Sangye Ince-Johannsen 2024-10-07 08:09:59 +02:00
parent 92c7b9e159
commit 5af72f464d

View file

@ -2,26 +2,21 @@
## 1. Installation and Setup
You're right, using git clone is a better approach. Here's the revised installation section:
- Ensure you have Anaconda or Miniconda installed on your system.
## 1. Installation and Setup
- Install Python 3.x and required libraries: `yaml`, `requests`, `loguru`, `python-dotenv`:
```bash
pip install pyyaml requests loguru python-dotenv
```
- Obtain Cloudflare API token from your account
- Clone the repository and set up the script:
- Clone the repository:
```bash
git clone https://sij.ai/sij/cf.git
cd cf
sudo ln -s "$(pwd)/cf.py" /usr/local/bin/cf
sudo chmod +x cf.py
```
- Create `.env` file with `CLOUDFLARE_API_TOKEN=your_token_here`:
- Run the setup script to create the conda environment and install dependencies:
```bash
chmod +x setup.sh
./setup.sh
```
- Create `.env` file with your Cloudflare API token:
```bash
echo "CLOUDFLARE_API_TOKEN=your_token_here" > .env
```
@ -49,7 +44,12 @@ domain2.net:
Replace the example values with your actual Cloudflare zone IDs and DNS record IDs for each domain and subdomain you want to manage with this script.
- Ensure Caddy is installed and `/etc/caddy/Caddyfile` is writable:
- (Optional) Create a symlink to use the script from anywhere:
```bash
sudo ln -sf "$(pwd)/cf" /usr/local/bin/cf
```
- Ensure Caddy is installed and `/etc/caddy/Caddyfile` is writable (Ubuntu/Debian example):
```bash
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
@ -60,33 +60,37 @@ sudo chown caddy:caddy /etc/caddy/Caddyfile
sudo chmod 644 /etc/caddy/Caddyfile
```
## 2. Usage
### 2.1 DDNS Update
```
cf ddns [--force]
./cf ddns [--force]
```
Updates all domains with current IP. Use `--force` to update regardless of IP change.
### 2.2 Adding/Updating Domain Configuration
```
cf <full-domain> [--ip <ip address>] --port <port>
./cf <full-domain> [--ip <ip address>] --port <port>
```
Adds or updates domain in Cloudflare and Caddyfile. Default IP is localhost.
### 2.3 Updating All Domains
```
cf all [--force]
./cf all [--force]
```
Updates all domains and Caddyfile configurations.
Note: If you created the symlink, you can use `cf` instead of `./cf` from any directory.
## 3. File and Environment Structure
- `Caddyfile`: Caddy server configuration
- `cf_domains.yaml`: Stores domain info and DNS record IDs
- `.env`: Contains `CLOUDFLARE_API_TOKEN` and `CURRENT_IP`
- `cf_script.log`: Logs script actions
- `environment.yml`: Conda environment specification
- `cf`: Wrapper script to activate conda environment and run the Python script
- `cf.py`: Main Python script
## 4. Key Functions and Error Handling
@ -95,8 +99,21 @@ Updates all domains and Caddyfile configurations.
- `update_or_create_record()`: Manages Cloudflare DNS records
Common errors:
- API authentication failures: Check API token
- API authentication failures: Check API token in `.env` file
- Permission issues: Run with sudo for Caddyfile changes
- Domain not found: Ensure domain is in `cf_domains.yaml`
Logs are in `cf_script.log` for troubleshooting.
## 5. Updating
To update the script and its dependencies:
1. Pull the latest changes:
```bash
git pull
```
2. Update the conda environment:
```bash
conda env update -f environment.yml -p ./cf-env
```