Update README.md
This commit is contained in:
parent
92c7b9e159
commit
5af72f464d
1 changed files with 38 additions and 21 deletions
57
README.md
57
README.md
|
@ -2,26 +2,21 @@
|
||||||
|
|
||||||
## 1. Installation and Setup
|
## 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
|
- Clone the repository:
|
||||||
|
|
||||||
- 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:
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://sij.ai/sij/cf.git
|
git clone https://sij.ai/sij/cf.git
|
||||||
cd cf
|
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
|
```bash
|
||||||
echo "CLOUDFLARE_API_TOKEN=your_token_here" > .env
|
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.
|
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
|
```bash
|
||||||
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
|
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
|
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
|
sudo chmod 644 /etc/caddy/Caddyfile
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## 2. Usage
|
## 2. Usage
|
||||||
|
|
||||||
### 2.1 DDNS Update
|
### 2.1 DDNS Update
|
||||||
```
|
```
|
||||||
cf ddns [--force]
|
./cf ddns [--force]
|
||||||
```
|
```
|
||||||
Updates all domains with current IP. Use `--force` to update regardless of IP change.
|
Updates all domains with current IP. Use `--force` to update regardless of IP change.
|
||||||
|
|
||||||
### 2.2 Adding/Updating Domain Configuration
|
### 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.
|
Adds or updates domain in Cloudflare and Caddyfile. Default IP is localhost.
|
||||||
|
|
||||||
### 2.3 Updating All Domains
|
### 2.3 Updating All Domains
|
||||||
```
|
```
|
||||||
cf all [--force]
|
./cf all [--force]
|
||||||
```
|
```
|
||||||
Updates all domains and Caddyfile configurations.
|
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
|
## 3. File and Environment Structure
|
||||||
|
|
||||||
- `Caddyfile`: Caddy server configuration
|
- `Caddyfile`: Caddy server configuration
|
||||||
- `cf_domains.yaml`: Stores domain info and DNS record IDs
|
- `cf_domains.yaml`: Stores domain info and DNS record IDs
|
||||||
- `.env`: Contains `CLOUDFLARE_API_TOKEN` and `CURRENT_IP`
|
- `.env`: Contains `CLOUDFLARE_API_TOKEN` and `CURRENT_IP`
|
||||||
- `cf_script.log`: Logs script actions
|
- `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
|
## 4. Key Functions and Error Handling
|
||||||
|
|
||||||
|
@ -95,8 +99,21 @@ Updates all domains and Caddyfile configurations.
|
||||||
- `update_or_create_record()`: Manages Cloudflare DNS records
|
- `update_or_create_record()`: Manages Cloudflare DNS records
|
||||||
|
|
||||||
Common errors:
|
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
|
- Permission issues: Run with sudo for Caddyfile changes
|
||||||
- Domain not found: Ensure domain is in `cf_domains.yaml`
|
- Domain not found: Ensure domain is in `cf_domains.yaml`
|
||||||
|
|
||||||
Logs are in `cf_script.log` for troubleshooting.
|
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
|
||||||
|
```
|
Loading…
Reference in a new issue