mirror of
https://github.com/guezoloic/serverconfig.git
synced 2026-03-28 18:03:49 +00:00
76 lines
1.7 KiB
Bash
76 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
readonly PROJECT_NAME="serverconfig"
|
|
readonly PROJECT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
|
|
readonly REQ=("curl" "docker")
|
|
|
|
readonly ENV_FILE="${PROJECT_DIR}/.env"
|
|
|
|
readonly GREEN='\033[0;32m'
|
|
readonly RED='\033[0;31m'
|
|
readonly YELLOW='\033[1;33m'
|
|
readonly BLUE='\033[0;34m'
|
|
readonly NC='\033[0m'
|
|
|
|
DATETIME_FORMAT="%d-%m-%Y %H:%M:%S"
|
|
|
|
function log() {
|
|
local type="${1}"
|
|
local color="${2}"
|
|
local message="${3}"
|
|
echo -e "${color}[$(date +"$DATETIME_FORMAT")] [${type}]${NC} ${message}"
|
|
}
|
|
|
|
function log_info() { log "INFO" "$BLUE" "$1"; }
|
|
function log_success() { log "OK " "$GREEN" "$1"; }
|
|
function log_error() { log "ERR " "$RED" "$1" >&2; }
|
|
|
|
function check_root() {
|
|
if [[ $EUID -ne 0 ]]; then
|
|
log_error "The script needs to run as root."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
function check_dependencies() {
|
|
log_info "Checking system dependencies..."
|
|
for cmd in "${REQ[@]}"; do
|
|
if ! command -pv "$cmd" &>/dev/null; then
|
|
log_error "${cmd} is not installed."
|
|
exit 1
|
|
else
|
|
log_success "${cmd} is installed."
|
|
fi
|
|
done
|
|
}
|
|
|
|
function install_scripts() {
|
|
log_info "Installing scripts..."
|
|
for script in "$SCRIPT_FILE"/*.sh; do
|
|
[ -e "$script" ] || continue
|
|
log_info "Configuring $(basename "$script")..."
|
|
if ! bash "$script" --install; then
|
|
log_error "Hook failed for $script"
|
|
fi
|
|
done
|
|
}
|
|
|
|
function main() {
|
|
clear
|
|
echo -e "${YELLOW}${PROJECT_NAME} Installation${NC}"
|
|
|
|
check_root
|
|
check_dependencies
|
|
|
|
log_info "Creating directories and files..."
|
|
touch "$ENV_FILE"
|
|
|
|
install_scripts
|
|
|
|
log_success "Installation Complete"
|
|
}
|
|
|
|
main "$@" |