feat: add Nginx to Caddy migration toolkit with scripts and usage guide
This commit is contained in:
51
setup/nginx-to-caddy/lib.sh
Executable file
51
setup/nginx-to-caddy/lib.sh
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ -t 2 ]]; then
|
||||
_C_RESET='\033[0m'
|
||||
_C_RED='\033[0;31m'
|
||||
_C_GREEN='\033[0;32m'
|
||||
_C_YELLOW='\033[0;33m'
|
||||
_C_BLUE='\033[0;34m'
|
||||
else
|
||||
_C_RESET='' _C_RED='' _C_GREEN='' _C_YELLOW='' _C_BLUE=''
|
||||
fi
|
||||
|
||||
log_info() {
|
||||
printf '%b[INFO]%b %s\n' "$_C_BLUE" "$_C_RESET" "$*" >&2
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
printf '%b[WARN]%b %s\n' "$_C_YELLOW" "$_C_RESET" "$*" >&2
|
||||
}
|
||||
|
||||
log_error() {
|
||||
printf '%b[ERROR]%b %s\n' "$_C_RED" "$_C_RESET" "$*" >&2
|
||||
}
|
||||
|
||||
log_success() {
|
||||
printf '%b[OK]%b %s\n' "$_C_GREEN" "$_C_RESET" "$*" >&2
|
||||
}
|
||||
|
||||
require_cmd() {
|
||||
local cmd
|
||||
for cmd in "$@"; do
|
||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||
log_error "Required command not found: $cmd"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
confirm_action() {
|
||||
local prompt="${1:-Continue?}"
|
||||
local auto_yes="${2:-false}"
|
||||
|
||||
if [[ "$auto_yes" == "true" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
printf '%s [y/N] ' "$prompt"
|
||||
read -r reply
|
||||
[[ "$reply" =~ ^[Yy]$ ]]
|
||||
}
|
||||
Reference in New Issue
Block a user