ProxmoxVE/.github/CONTRIBUTOR_GUIDE/CONTRIBUTING.md

331 lines
7.2 KiB
Markdown
Raw Normal View History

2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
# Community Scripts Contribution Guide
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
## Overview
Welcome to the community-scripts repository! This guide provides detailed instructions on how to contribute to the project, including code structure, best practices, and setup instructions for contributing to our repository.
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
## Getting Started
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
Before contributing, please ensure that you have the following setup:
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
1. **Visual Studio Code** (recommended for script development)
2. **Necessary VS Code Extensions:**
- [Shell Syntax](https://marketplace.visualstudio.com/items?itemName=bmalehorn.shell-syntax)
- [ShellCheck](https://marketplace.visualstudio.com/items?itemName=timonwong.shellcheck)
- [Shell Format](https://marketplace.visualstudio.com/items?itemName=foxundermoon.shell-format)
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
### Important Notes
- Use `AppName.sh` and `AppName-install.sh` as templates when creating new scripts.
- The call to `community-scripts/ProxmoxVE` should be adjusted to reflect the correct fork URL.
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
---
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
# 🚀 Structure of Installation Scripts (ct/AppName.sh)
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
All installation scripts should follow this standard structure:
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
## 1. 📝 File Header
2024-12-06 12:41:48 +00:00
```bash
#!/usr/bin/env bash
2024-12-06 13:10:04 +00:00
source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
2024-12-06 12:41:48 +00:00
# Copyright (c) 2021-2024 community-scripts ORG
2024-12-06 13:10:04 +00:00
# Author: [YourUserName]
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: [SOURCE_URL]
```
2024-12-06 13:20:57 +00:00
> **Note**:
> - Add your username and source URL
> - For existing scripts, add "| Co-Author [YourUserName]" after the current author
## 2. 🔧 App Default Values
2024-12-06 13:10:04 +00:00
```bash
# App Default Values
APP="[APP_NAME]"
TAGS="[TAGS]"
var_cpu="[CPU]"
var_ram="[RAM]"
var_disk="[DISKSIZE]"
var_os="[OS]"
var_version="[VERSION]"
var_unprivileged="[UNPRIVILEGED]"
```
2024-12-06 13:20:57 +00:00
### Value Declarations 📊
| Variable | Description | Notes |
|----------|-------------|-------|
| `APP` | Application name | Must match ct\AppName.sh |
| `TAGS` | Proxmox display tags | Limit the number |
| `var_cpu` | CPU cores | Number of cores |
| `var_ram` | RAM | In MB |
| `var_disk` | Disk capacity | In GB |
| `var_os` | Operating system | alpine, debian, ubuntu |
| `var_version` | OS version | e.g., 3.20, 11, 12, 20.04 |
| `var_unprivileged` | Container type | 1 = Unprivileged, 0 = Privileged |
### Default Values 🔨
- `TAGS="community-script"` (default)
- `var_cpu="1"`
- `var_ram="1024"`
- `var_disk="4"`
- `var_unprivileged="1"`
- `var_verbose="no"`
#### Example 🌟
2024-12-06 13:10:04 +00:00
```bash
# App Default Values
APP="Google"
TAGS="searching;website"
var_cpu="2"
var_ram="4096"
var_disk="10"
var_os="debian"
var_version="12"
var_unprivileged="0"
```
2024-12-06 13:20:57 +00:00
> Creates a privileged LXC named "google" with 2 CPU cores, 4096 MB RAM, 10 GB disk, on Debian 12
## 3. 📋 App Output & Base Settings
2024-12-06 13:10:04 +00:00
```bash
# App Output & Base Settings
header_info "$APP"
base_settings
```
2024-12-06 13:20:57 +00:00
- `header_info`: Generates ASCII header for APP
- `base_settings`: Allows overwriting variable values
## 4. 🛠 Core Functions
2024-12-06 13:10:04 +00:00
```bash
# Core
variables
color
catch_errors
```
2024-12-06 13:20:57 +00:00
- `variables`: Processes input and prepares variables
- `color`: Sets icons, colors, and formatting
- `catch_errors`: Enables error handling
## 5. 🔄 Update-Script Part
2024-12-06 13:10:04 +00:00
```bash
function update_script() {
header_info
check_container_storage
check_container_resources
# Update-Code
}
```
2024-12-06 13:20:57 +00:00
- `header_info`: Regenerates ASCII AppName
- `check_container_storage`: Checks available storage
- `check_container_resources`: Validates CPU/RAM resources
2024-12-06 13:10:04 +00:00
2024-12-06 13:20:57 +00:00
## 6. 🏁 Script-End
2024-12-06 13:10:04 +00:00
```bash
start
build_container
description
msg_ok "Completed Successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:[PORT]${CL}"
2024-12-06 12:41:48 +00:00
```
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
- `start`: Launches Whiptail dialogue
- `build_container`: Collects and integrates user settings
- `description`: Sets LXC container description
2024-12-06 13:10:04 +00:00
2024-12-06 13:20:57 +00:00
I'll convert the remaining document to a GitHub-flavored Markdown with emojis and improved formatting:
2024-12-06 13:10:04 +00:00
2024-12-06 13:20:57 +00:00
# 🛠 Structure of Installation Scripts (install/AppName-install.sh)
2024-12-06 13:10:04 +00:00
2024-12-06 13:20:57 +00:00
## 1. 📄 File Header
2024-12-06 10:53:04 +00:00
2024-12-06 13:10:04 +00:00
```bash
#!/usr/bin/env bash
# Copyright (c) 2021-2024 community-scripts ORG
# Author: [YourUserName]
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
```
2024-12-06 13:20:57 +00:00
> **Notes**:
> - Add your username
> - For existing scripts, add "| Co-Author [YourUserName]"
## 2. 🔌 Import Functions and Setup
2024-12-06 12:41:48 +00:00
```bash
source /dev/stdin <<< "$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os
```
2024-12-06 13:20:57 +00:00
## 3. 📦 Standard Dependencies
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
```bash
msg_info "Installing Dependencies"
$STD apt-get install -y curl sudo mc
msg_ok "Installed Dependencies"
```
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
## 4. 📝 File Writing Conventions
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
### Writing Config Files 🔧
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
```bash
2024-12-06 13:10:04 +00:00
cat <<EOF >/etc/systemd/system/${APPLICATION}.service
2024-12-06 12:41:48 +00:00
[Unit]
2024-12-06 13:10:04 +00:00
Description=${APPLICATION} Service Description
2024-12-06 12:41:48 +00:00
After=network.target
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
[Service]
Type=simple
ExecStart=/path/to/executable
Restart=always
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
[Install]
WantedBy=multi-user.target
EOF
```
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
### Writing Environment Files 🌍
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
```bash
cat <<EOF >/path/to/.env
VARIABLE="value"
PORT=3000
DB_NAME="${DB_NAME}"
EOF
```
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
## 5. 🚦 Service Management
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
```bash
systemctl enable -q --now service.service
2024-12-06 13:20:57 +00:00
```
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
## 6. 🧹 Cleanup Section
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
```bash
msg_info "Cleaning up"
$STD apt-get -y autoremove
$STD apt-get -y autoclean
msg_ok "Cleaned"
```
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
## 7. 📢 Progress Messages
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
```bash
msg_info "Starting task"
$STD some_command
msg_ok "Task completed"
```
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
## 8. 🏷️ Version Tracking
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
```bash
echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt"
```
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
## 9. 🔐 Credentials Management
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
```bash
{
echo "Application-Credentials"
echo "Username: $USERNAME"
echo "Password: $PASSWORD"
} >> ~/application.creds
```
2024-12-06 13:20:57 +00:00
## 10. 📂 Directory Structure
2024-12-06 12:41:48 +00:00
- Application files: `/opt/application_name/`
- Configuration files: `/etc/application_name/`
- Data files: `/var/lib/application_name/`
2024-12-06 13:20:57 +00:00
## 11. 🚨 Error Handling
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
```bash
catch_errors
```
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
## 12. 🏁 Final Setup
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
```bash
motd_ssh
customize
```
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
---
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
## 📋 Best Practices
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
1. Use `$STD` for suppressed command output
2. Use uppercase for global variables
3. Quote variables with potential spaces
4. Use `-q` for quiet operations
5. Use 2-space indentation
6. Include cleanup sections
7. Use descriptive message strings
2024-12-06 10:53:04 +00:00
2024-12-06 12:41:48 +00:00
---
2024-12-06 10:53:04 +00:00
2024-12-06 13:20:57 +00:00
## 🚀 Building Your Own Scripts
2024-12-06 12:16:25 +00:00
2024-12-06 13:20:57 +00:00
Start with the [template script](https://github.com/community-scripts/ProxmoxVE/blob/main/docs/templates/example-install.sh)
2024-12-06 12:16:25 +00:00
2024-12-06 12:41:48 +00:00
---
2024-12-06 12:16:25 +00:00
2024-12-06 13:20:57 +00:00
## 🤝 Contribution Process
2024-12-06 12:16:25 +00:00
2024-12-06 12:41:48 +00:00
### 1. Fork the Repository
2024-12-06 13:20:57 +00:00
Fork to your GitHub account
2024-12-06 12:16:25 +00:00
2024-12-06 13:20:57 +00:00
### 2. Clone Your Fork
2024-12-06 12:41:48 +00:00
```bash
git clone https://github.com/YOUR_USERNAME/community-scripts.git
```
2024-12-06 12:16:25 +00:00
2024-12-06 12:41:48 +00:00
### 3. Create a New Branch
```bash
git checkout -b your-feature-branch
```
2024-12-06 12:16:25 +00:00
2024-12-06 13:20:57 +00:00
### 4. Commit Changes
2024-12-06 12:41:48 +00:00
```bash
git commit -m "Your commit message"
```
2024-12-06 12:16:25 +00:00
2024-12-06 12:41:48 +00:00
### 5. Push to Your Fork
```bash
git push origin your-feature-branch
```
2024-12-06 12:16:25 +00:00
2024-12-06 12:41:48 +00:00
### 6. Create a Pull Request
2024-12-06 13:20:57 +00:00
Open a PR from your feature branch to the main repository branch
2024-12-06 12:16:25 +00:00
2024-12-06 12:41:48 +00:00
---
2024-12-06 12:16:25 +00:00
2024-12-06 13:20:57 +00:00
## 📚 Wiki Pages
2024-12-06 12:16:25 +00:00
2024-12-06 12:41:48 +00:00
- [Contributing](https://github.com/community-scripts/ProxmoxVE/wiki/Contributing)
- [Installation Guide](https://github.com/community-scripts/ProxmoxVE/wiki/Installation-Guide)
2024-12-06 13:20:57 +00:00
- [Script Templates](https://github.com/community-scripts/ProxmoxVE/wiki/Script-Templates)