feat: require hostname as a parameter during setup and improve hostname handling
Some checks failed
Nix Format Check / check-format (push) Failing after 38s
Some checks failed
Nix Format Check / check-format (push) Failing after 38s
This commit is contained in:
@ -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
|
### 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.
|
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.
|
||||||
|
|
||||||
Feel free to use an exisiting hostname to restore an old system or chose a new name.
|
|
||||||
|
|
||||||
If you are running this in a VM be sure to answer yes if it prompts you.
|
If you are running this in a VM be sure to answer yes if it prompts you.
|
||||||
|
|
||||||
```bash
|
```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
|
### 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.
|
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.
|
||||||
|
51
setup.sh
51
setup.sh
@ -180,27 +180,23 @@ install_home_manager() {
|
|||||||
|
|
||||||
prepare_hostname() {
|
prepare_hostname() {
|
||||||
local hostname_file="$HOME/.hostname"
|
local hostname_file="$HOME/.hostname"
|
||||||
local hostname
|
local hostname="$1"
|
||||||
|
|
||||||
# Only check for NixOS if hardware configuration is not found
|
# If a hostname was provided as argument
|
||||||
if [ -f "$hostname_file" ]; then
|
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")
|
hostname=$(cat "$hostname_file")
|
||||||
log_success "Hostname already found in $hostname_file. Using $hostname."
|
log_success "Hostname already found in $hostname_file. Using $hostname."
|
||||||
return
|
return
|
||||||
|
else
|
||||||
|
die "No hostname provided. Please provide a hostname as the first argument."
|
||||||
fi
|
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..."
|
log_info "Setting hostname to $hostname..."
|
||||||
sudo hostnamectl set-hostname "$hostname" || die "Failed to set hostname"
|
sudo hostnamectl set-hostname "$hostname" || die "Failed to set hostname"
|
||||||
|
|
||||||
@ -364,30 +360,30 @@ main() {
|
|||||||
# Check prerequisites
|
# Check prerequisites
|
||||||
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
|
# Clone dotfiles if needed
|
||||||
if [ ! -d "$DOTFILES_PATH" ]; then
|
if [ ! -d "$DOTFILES_PATH" ]; then
|
||||||
log_info "Cloning dotfiles repo..."
|
log_info "Cloning dotfiles repo..."
|
||||||
git clone "$GIT_REPO" "$DOTFILES_PATH" || die "Failed to clone dotfiles repository"
|
git clone "$GIT_REPO" "$DOTFILES_PATH" || die "Failed to clone dotfiles repository"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${1:-}" ]; then
|
if [ "$continue_flag" = "--continue" ]; then
|
||||||
CONTINUE=$1
|
log_info "Continuing setup..."
|
||||||
if [ "$CONTINUE" = "--continue" ]; then
|
|
||||||
log_info "Continuing setup..."
|
|
||||||
else
|
|
||||||
warning_prompt
|
|
||||||
prepare_hostname
|
|
||||||
check_selinux
|
|
||||||
install_nix
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
warning_prompt
|
warning_prompt
|
||||||
prepare_hostname
|
prepare_hostname "$hostname"
|
||||||
check_selinux
|
check_selinux
|
||||||
install_nix
|
install_nix
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
install_home_manager
|
install_home_manager
|
||||||
|
|
||||||
setup_symlinks
|
setup_symlinks
|
||||||
@ -395,7 +391,6 @@ main() {
|
|||||||
ensure_shell
|
ensure_shell
|
||||||
|
|
||||||
# Get hostname
|
# Get hostname
|
||||||
local hostname
|
|
||||||
hostname=$(cat "$HOME/.hostname") || die "Failed to read hostname"
|
hostname=$(cat "$HOME/.hostname") || die "Failed to read hostname"
|
||||||
export PATH=$PATH:$DOTFILES_PATH/bin
|
export PATH=$PATH:$DOTFILES_PATH/bin
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user