refactor: enhance setup script with compat checks
All checks were successful
Nix Format Check / check-format (pull_request) Successful in 37s
All checks were successful
Nix Format Check / check-format (pull_request) Successful in 37s
This commit is contained in:
parent
c651722b73
commit
d92d0ed883
86
setup.sh
86
setup.sh
@ -309,6 +309,12 @@ warning_prompt() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_selinux() {
|
check_selinux() {
|
||||||
|
# Check if distro has SELinux at all:
|
||||||
|
if [ ! -f /etc/selinux ]; then
|
||||||
|
log_success "SELinux not found. Skipping..."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Check if getenforce is returning Enforcing
|
# Check if getenforce is returning Enforcing
|
||||||
if [ "$(getenforce)" = "Enforcing" ]; then
|
if [ "$(getenforce)" = "Enforcing" ]; then
|
||||||
log_warning "SELinux is enabled. Adjusting SELinux to permissive mode..."
|
log_warning "SELinux is enabled. Adjusting SELinux to permissive mode..."
|
||||||
@ -321,7 +327,86 @@ EOF
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ensure_pipx() {
|
||||||
|
if ! command -v pipx >/dev/null 2>&1; then
|
||||||
|
log_info "Installing pipx..."
|
||||||
|
|
||||||
|
# On Fedora/RedHat, install pipx using dnf
|
||||||
|
if command -v dnf >/dev/null 2>&1; then
|
||||||
|
sudo dnf install pipx || die "Failed to install pipx"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# On Ubuntu/Debian, install pipx using apt
|
||||||
|
if command -v apt >/dev/null 2>&1; then
|
||||||
|
sudo apt install pipx || die "Failed to install pipx"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# On Arch Linux, install pipx using pacman
|
||||||
|
if command -v pacman >/dev/null 2>&1; then
|
||||||
|
sudo pacman -S python-pipx || die "Failed to install pipx"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ensurepath globally
|
||||||
|
sudo pipx ensurepath --global || die "Failed to ensure pipx path"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_ansible() {
|
||||||
|
ensure_pipx
|
||||||
|
|
||||||
|
log_info "Installing Ansible..."
|
||||||
|
pipx install ansible || die "Failed to install Ansible"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_command_availibility() {
|
||||||
|
local command="$1"
|
||||||
|
if ! command -v "$command" >/dev/null 2>&1; then
|
||||||
|
die "$command is required but not installed"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check compatibility checks for supported distros:
|
||||||
|
# - Fedora
|
||||||
|
# - Ubuntu
|
||||||
|
# - Arch Linux (Untested)
|
||||||
|
check_compatibility() {
|
||||||
|
# Check if we are running under bash
|
||||||
|
if [ -z "${BASH_VERSION:-}" ]; then
|
||||||
|
die "This script was designed to run using bash, please run using bash"
|
||||||
|
fi
|
||||||
|
|
||||||
|
check_command_availibility "awk"
|
||||||
|
check_command_availibility "tail"
|
||||||
|
check_command_availibility "echo"
|
||||||
|
check_command_availibility "git"
|
||||||
|
check_command_availibility "sudo"
|
||||||
|
|
||||||
|
local distro
|
||||||
|
distro=$(awk -F= '/^NAME/{print $2}' /etc/os-release | tr -d '"')
|
||||||
|
|
||||||
|
case "$distro" in
|
||||||
|
Fedora Linux)
|
||||||
|
log_success "Detected Fedora. Proceeding with setup..."
|
||||||
|
check_command_availibility "dnf"
|
||||||
|
;;
|
||||||
|
Ubuntu)
|
||||||
|
log_success "Detected Ubuntu. Proceeding with setup..."
|
||||||
|
check_command_availibility "apt"
|
||||||
|
;;
|
||||||
|
Arch*)
|
||||||
|
log_warning "Detected Arch Linux. Setup has not been tested on Arch Linux."
|
||||||
|
log_warning "Proceed at your own risk..."
|
||||||
|
check_command_availibility "pacman"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
die "Unsupported distribution: $distro"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
check_compatibility
|
||||||
|
|
||||||
# Check if setup has already been run
|
# Check if setup has already been run
|
||||||
if [ -f "$SETUP_MARKER" ]; then
|
if [ -f "$SETUP_MARKER" ]; then
|
||||||
log_info "Setup has already been run, exiting..."
|
log_info "Setup has already been run, exiting..."
|
||||||
@ -357,6 +442,7 @@ main() {
|
|||||||
|
|
||||||
install_home_manager
|
install_home_manager
|
||||||
setup_symlinks
|
setup_symlinks
|
||||||
|
setup_ansible
|
||||||
|
|
||||||
# Get hostname
|
# Get hostname
|
||||||
local hostname
|
local hostname
|
||||||
|
Loading…
x
Reference in New Issue
Block a user