#!/bin/bash

set -e

# Check if Zsh is already installed
if command -v zsh &> /dev/null; then
    echo "Zsh is already installed. Skipping installation."
else
    echo "Updating package list..."
    sudo apt-get update

    echo "Installing Zsh..."
    sudo apt-get install -y zsh

    if ! command -v zsh &> /dev/null; then
        echo "Error: Zsh installation failed."
        exit 1
    fi
fi

echo "Changing default shell to Zsh for user $(whoami)..."
zsh_path=$(command -v zsh)
sudo chsh -s "$zsh_path" "$(whoami)"

echo "Zsh installation and setup complete. Please log out and log back in for changes to take effect."
