diff --git a/README.md b/README.md index 6d3cd09..543095f 100755 --- a/README.md +++ b/README.md @@ -14,16 +14,16 @@ I'd recommend getting the GNOME version as it's easier to setup unless you're pl ### 1. Clone dotfiles to home directory -Open a shell and begin the setup process. This setup will prompt you various questions such as your desired hostname and if the system you are installing is supposed to be a server or workstation. - -Feel free to use an exisiting hostname to restore an old system or chose a new name. +Open a shell and begin the setup process. This setup requires you to provide a hostname as a parameter. You can use an existing hostname to restore an old system or choose a new name. If you are running this in a VM be sure to answer yes if it prompts you. ```bash -curl -L https://df.mvl.sh | bash +curl -L https://df.mvl.sh | bash -s your-hostname ``` +Replace `your-hostname` with your desired hostname for this machine. + ### 2. Reboot It's probably a good idea that you either reboot or log out and log back in to make sure all the changes are applied. diff --git a/setup.sh b/setup.sh index 9795a67..7c5bbfb 100755 --- a/setup.sh +++ b/setup.sh @@ -180,27 +180,23 @@ install_home_manager() { prepare_hostname() { local hostname_file="$HOME/.hostname" - local hostname + local hostname="$1" - # Only check for NixOS if hardware configuration is not found - if [ -f "$hostname_file" ]; then + # If a hostname was provided as argument + if [ -n "$hostname" ]; then + if ! validate_hostname "$hostname"; then + die "Invalid hostname provided. Please use a valid hostname." + fi + log_info "Using provided hostname: $hostname" + # Check if hostname is already set + elif [ -f "$hostname_file" ]; then hostname=$(cat "$hostname_file") log_success "Hostname already found in $hostname_file. Using $hostname." return + else + die "No hostname provided. Please provide a hostname as the first argument." fi - # Ensure interactive input before hostname prompt - ensure_interactive - - while true; do - log_info "Enter the hostname for this machine:" - read -r hostname - if validate_hostname "$hostname"; then - break - fi - log_error "Invalid hostname. Please enter a valid hostname:" - done - log_info "Setting hostname to $hostname..." sudo hostnamectl set-hostname "$hostname" || die "Failed to set hostname" @@ -364,30 +360,30 @@ main() { # Check prerequisites check_prerequisites + # First argument should be the hostname + local hostname="${1:-}" + local continue_flag="${2:-}" + + # Require hostname + if [ -z "$hostname" ]; then + die "Hostname is required as the first argument. Usage: $0 [--continue]" + fi + # Clone dotfiles if needed if [ ! -d "$DOTFILES_PATH" ]; then log_info "Cloning dotfiles repo..." git clone "$GIT_REPO" "$DOTFILES_PATH" || die "Failed to clone dotfiles repository" fi - if [ -n "${1:-}" ]; then - CONTINUE=$1 - if [ "$CONTINUE" = "--continue" ]; then - log_info "Continuing setup..." - else - warning_prompt - prepare_hostname - check_selinux - install_nix - fi + if [ "$continue_flag" = "--continue" ]; then + log_info "Continuing setup..." else warning_prompt - prepare_hostname + prepare_hostname "$hostname" check_selinux install_nix fi - install_home_manager setup_symlinks @@ -395,7 +391,6 @@ main() { ensure_shell # Get hostname - local hostname hostname=$(cat "$HOME/.hostname") || die "Failed to read hostname" export PATH=$PATH:$DOTFILES_PATH/bin