Skip to content

Commit

Permalink
Add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaijin66 committed Oct 22, 2024
1 parent 9cd4a15 commit 8bc2990
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 109 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ function install_packages {
Installs and configures additional tools like skhd, Kitty, Terraform, Python, and Ansible:

```bash
function install_skhd {
brew install koekeishiya/formulae/skhd
skhd --start-service
}

function install_kitty {
/bin/bash -c "$(curl -fsSL https://sw.kovidgoyal.net/kitty/installer.sh)"
}
Expand All @@ -80,10 +75,6 @@ function install_python {
brew install [email protected]
curl -O https://bootstrap.pypa.io/get-pip.py
}

function install_ansible {
brew install ansible
}
```

### Dotfiles Setup
Expand All @@ -110,7 +101,8 @@ Creates required directories:

```bash
function setup_directories {
mkdir -p ~/src/personal/github ~/src/work
mkdir -p ~/src/personal/{github,books,docs,experiments,personal,projects,work} \
~/src/work/{books,docs,experiments,personal,projects,work}
}
```

Expand Down
190 changes: 103 additions & 87 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,90 +27,64 @@ function install_brew {
fi
}

# Function to install skhd
function install_skhd {
runcmd brew install koekeishiya/formulae/skhd
runcmd skhd --start-service
# runcmd brew services restart skhd
}

# Function to install Ansible
function install_ansible {
runcmd brew install ansible
}

# Function to install Python
function install_python {
runcmd brew install [email protected]
runcmd /bin/bash -c "curl -O https://bootstrap.pypa.io/get-pip.py"
if ! command -v python3 &> /dev/null || ! command -v pip3 &> /dev/null; then
echo "Python or pip not found. Installing..."
runcmd brew install [email protected]
if ! command -v pip3 &> /dev/null; then
echo "pip not found. Installing..."
runcmd /bin/bash -c "curl -O https://bootstrap.pypa.io/get-pip.py"
runcmd python3 get-pip.py
runcmd rm get-pip.py
fi
else
echo "Python and pip are already installed. Skipping..."
fi
}

# Function to install various packages
function install_packages {
runcmd brew install bat \
gcc \
ripgrep \
pipenv \
black \
neovim \
fzf \
go-task \
tree \
nvm \
go \
openjdk \
tfenv \
helm \
helmfile \
kubectx \
kubectl \
sops \
docker \
docker-compose \
colima \
docker-credential-helper \
aylei/tap/kubectl-debug \
git-delta \
git-absorb \
shellcheck \
awscli \
hadolint \
aquasecurity/trivy/trivy \
figlet \
lolcat \
mkcert \
nmap \
ansible \
derailed/k9s/k9s \
snappy \
awscurl \
jid \
watch \
wget \
telnet \
terraformer \
tfsec \
tree-sitter \
terraform-docs \
bats-core \
eksup \
kubent \
mtr \
nettle \
tcpdump \
unbound \
velero
packages=(
bat gcc ansible koekeishiya/formulae/skhd ripgrep pipenv black neovim fzf go-task tree nvm go openjdk
tfenv helm helmfile kubectx kubectl sops docker docker-compose colima
docker-credential-helper aylei/tap/kubectl-debug git-delta git-absorb
shellcheck awscli hadolint aquasecurity/trivy/trivy figlet lolcat
mkcert nmap ansible derailed/k9s/k9s snappy awscurl jid watch wget
telnet terraformer tfsec tree-sitter terraform-docs bats-core kubent
mtr nettle tcpdump unbound velero
)

for package in "${packages[@]}"; do
if ! brew list "$package" &>/dev/null; then
echo "Installing $package..."
runcmd brew install "$package"
else
echo "$package is already installed, skipping..."
fi
done
}

# Function to install Terraform

# Function to install Kitty
function install_kitty {
runcmd /bin/bash -c "$(curl -fsSL https://sw.kovidgoyal.net/kitty/installer.sh)"
if [ ! -d "/Applications/kitty.app" ]; then
echo "Kitty not found. Installing..."
runcmd /bin/bash -c "$(curl -fsSL https://sw.kovidgoyal.net/kitty/installer.sh)"
else
echo "Kitty is already installed. Skipping..."
fi
}

# Function to install Terraform
function install_terraform {
runcmd brew tap hashicorp/tap
runcmd brew install hashicorp/tap/terraform
if ! command -v terraform &> /dev/null; then
echo "Terraform not found. Installing..."
runcmd brew tap hashicorp/tap
runcmd brew install hashicorp/tap/terraform
else
echo "Terraform is already installed. Skipping..."
fi
}

# Function to set up dotfiles
Expand All @@ -119,48 +93,90 @@ function setup_dotfiles {
# Zsh
# Oh My Zsh
if [ ! -d "$HOME/.oh-my-zsh" ]; then
KEEP_ZSHRC=yes sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
if ! KEEP_ZSHRC=yes sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"; then
echo "Error: Failed to install Oh My Zsh" >&2
return 1
fi
fi
if ! ln -sf "$DOTFILES"/zsh/zshrc "$HOME"/.zshrc; then
echo "Error: Failed to create symlink for .zshrc" >&2
return 1
fi
ln -sf "$DOTFILES"/zsh/zshrc "$HOME"/.zshrc

# Yabai
ln -sf "$DOTFILES"/yabai/yabairc "$HOME"/.yabairc
chmod +x ~/.yabairc
if ! ln -sf "$DOTFILES"/yabai/yabairc "$HOME"/.yabairc; then
echo "Error: Failed to create symlink for .yabairc" >&2
return 1
fi
if ! chmod +x ~/.yabairc; then
echo "Error: Failed to make .yabairc executable" >&2
return 1
fi

# skhd
ln -sf "$DOTFILES"/skhd/skhdrc "$HOME"/.skhdrc
chmod +x ~/.skhdrc
if ! ln -sf "$DOTFILES"/skhd/skhdrc "$HOME"/.skhdrc; then
echo "Error: Failed to create symlink for .skhdrc" >&2
return 1
fi
if ! chmod +x ~/.skhdrc; then
echo "Error: Failed to make .skhdrc executable" >&2
return 1
fi

echo "Dotfiles setup completed successfully"
}

# Function to create required directories
function setup_directories {
# Create all required directories
mkdir -p ~/src/personal/github ~/src/work
if ! mkdir -p ~/src/personal/github ~/src/work; then
echo "Error: Failed to create required directories" >&2
return 1
fi
echo "Directories created successfully"
}

# Function to set up configuration files
function setup_config_files {
# Neovim
rm -rf "$HOME"/.config/nvim
ln -s "$DOTFILES"/nvim "$HOME"/.config/nvim
if [ -d "$HOME/.config/nvim" ]; then
if ! rm -rf "$HOME/.config/nvim"; then
echo "Error: Failed to remove existing Neovim config directory" >&2
return 1
fi
fi
if ! ln -s "$DOTFILES/nvim" "$HOME/.config/nvim"; then
echo "Error: Failed to create symlink for Neovim config" >&2
return 1
fi

# Kitty
rm -rf "$HOME"/.config/kitty
ln -s "$DOTFILES"/kitty "$HOME"/.config/kitty
if [ -d "$HOME/.config/kitty" ]; then
if ! rm -rf "$HOME/.config/kitty"; then
echo "Error: Failed to remove existing Kitty config directory" >&2
return 1
fi
fi
if ! ln -s "$DOTFILES/kitty" "$HOME/.config/kitty"; then
echo "Error: Failed to create symlink for Kitty config" >&2
return 1
fi

# Git
ln -sf "$DOTFILES"/git/gitconfig "$HOME"/.gitconfig
if ! ln -sf "$DOTFILES/git/gitconfig" "$HOME/.gitconfig"; then
echo "Error: Failed to create symlink for Git config" >&2
return 1
fi

echo "Config files setup completed successfully"
}

# Run the installation functions
install_brew
install_packages
install_skhd
install_kitty
install_terraform
install_python
install_ansible


# Additional setup steps
setup_dotfiles
Expand All @@ -173,4 +189,4 @@ function start_services {
}


echo "completed"
echo "completed !!!"
13 changes: 1 addition & 12 deletions zsh/zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,10 @@ function kyaml() { kubectl get "$@" -o yaml | kubectl-neat }
alias krmfailed='kctl delete pods --field-selector=status.phase=Failed'


function lgn() { cia sso -p "$@" && cluster_login }

alias kx='kubectx'

alias prd='export AWS_PROFILE=prod && kx production'
alias pex='export AWS_PROFILE=prod && kx prd-external'
alias pit='export AWS_PROFILE=prod && kx prd-internal'
alias stg='export AWS_PROFILE=pre-prod && kx devtest'
alias dev='export AWS_PROFILE=pre-prod && kx dev'
alias tst='export AWS_PROFILE=pre-prod && kx sre-test'

# FZF
alias sd="cd ~ && \$(find Documents work Desktop Downloads -type d -maxdepth 4 | fzf)"
alias sd="cd ~ && \$(find Documents src Desktop Downloads -type d -maxdepth 45 | fzf)"

# Key bindings
bind '^f' 'sd' # Open fzf finder quicker
Expand All @@ -151,5 +142,3 @@ source <(alias s=switch)

source <(compdef _switcher switch)

# Pull in env vars necessary for Capsule development
source /Users/pthapa/.config/cia/.cia_envvars

0 comments on commit 8bc2990

Please sign in to comment.