Files
serverconfig/install.sh

87 lines
1.5 KiB
Bash

#!/bin/bash
PROJECT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
readonly PROJECT_DIR 2>/dev/null
source "$PROJECT_DIR/utils.sh"
set -euo pipefail
ENV_LIST=(
"EMAIL" "HOSTNAME"
"TELEGRAM_TOKEN" "TELEGRAM_CHAT_ID"
"AWS" "ENDPOINT" "AWS_ACCESS_KEY_ID" "AWS_SECRET_ACCESS_KEY"
"GITHUB_AUTH_SECRET"
)
readonly REQ=(
"curl"
"docker"
"crontab"
"ps"
"top"
"free"
"pgrep"
"pkill"
"uptime"
)
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 "$PROJECT_DIR"/*.sh; do
[ -e "$script" ] || continue
if [[ "$script" == "$(realpath "$0")" ]]; then
continue
fi
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"
for env in "${ENV_LIST[@]}"; do
read -sp "Enter value for $env: " value
echo
env_variable "$env" "$value"
done
install_scripts
log_success "Installation Complete"
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi