getInstallInstructions
Get platform-specific installation instructions without installing WireGuard.
Overview
The getInstallInstructions function detects the current platform and available package managers, then returns the appropriate installation command and platform information. This is useful for displaying installation instructions to users or checking platform support.
Signature
getInstallInstructions(): Promise<{
platform: string
packageManager?: string
command?: string
name?: string
supported: boolean
}>Return Value
- Promise<object>: Resolves to an object containing:
platform(string): The detected platform (linux,darwin,win32)packageManager(string, optional): The detected package managercommand(string, optional): The installation command to runname(string, optional): Human-readable platform namesupported(boolean): Whether the platform is supported
Behavior
- Platform Detection: Uses
os.platform()to identify the current platform - Package Manager Detection: Checks for available package managers on the platform
- Command Generation: Returns the appropriate installation command
- Support Status: Indicates whether automatic installation is supported
Example Usage
import { getInstallInstructions } from "@kriper0nind/wg-utils"
// Get installation instructions
async function showInstallInstructions() {
const instructions = await getInstallInstructions()
if (instructions.supported) {
console.log(`Platform: ${instructions.name}`)
console.log(`Package Manager: ${instructions.packageManager}`)
console.log(`Command: ${instructions.command}`)
} else {
console.log(`Platform ${instructions.platform} is not supported`)
console.log("Please install WireGuard manually:")
console.log(" Linux: https://www.wireguard.com/install/")
console.log(" macOS: brew install wireguard-tools")
console.log(" Windows: https://www.wireguard.com/install/")
}
}
// Check platform support
async function checkSupport() {
const instructions = await getInstallInstructions()
if (instructions.supported) {
console.log("✅ Automatic installation supported")
} else {
console.log("❌ Manual installation required")
}
}Platform Detection
Linux
- Ubuntu/Debian: Detects
aptpackage manager - CentOS/RHEL: Detects
yumpackage manager - Fedora: Detects
dnfpackage manager - Arch Linux: Detects
pacmanpackage manager - Alpine Linux: Detects
apkpackage manager
macOS
- Homebrew: Detects
brewpackage manager
Windows
- Chocolatey: Detects
chocopackage manager - Winget: Detects
wingetpackage manager
Use Cases
- Pre-installation checks: Verify platform support before attempting installation
- User guidance: Display installation instructions in CLI tools or web interfaces
- Platform validation: Check if the current environment supports automatic installation
- Documentation generation: Generate platform-specific installation guides
Example Output
// On Ubuntu
{
platform: "linux",
packageManager: "ubuntu",
command: "sudo apt update && sudo apt install -y wireguard",
name: "Ubuntu/Debian",
supported: true
}
// On macOS with Homebrew
{
platform: "darwin",
packageManager: "homebrew",
command: "brew install wireguard-tools",
name: "macOS (Homebrew)",
supported: true
}
// On unsupported platform
{
platform: "freebsd",
supported: false
}Dependencies
- Node.js:
osmodule for platform detection - Package managers: Requires appropriate package manager to be installed for detection
Notes
- Detection only: This function only detects and provides instructions, it doesn't install anything
- No side effects: Safe to call multiple times without any system changes
- Platform specific: Results vary based on the current platform and available tools