feat: require hostname as a parameter during setup and improve hostname handling
Some checks failed
Nix Format Check / check-format (push) Failing after 38s

This commit is contained in:
2025-03-11 10:42:31 +01:00
parent 7e1094dd7c
commit d3caf87696
2 changed files with 27 additions and 32 deletions

View File

@ -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 <hostname> [--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