Skip to content

Commit

Permalink
feat: Update OS detection support and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekMasher committed Feb 5, 2025
1 parent c04e1b8 commit 0ffc119
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
42 changes: 13 additions & 29 deletions geek/.geek/updates.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
#!/bin/bash

unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
distoOut="$(lsb_release -si)"
case "${distoOut}" in
Ubuntu*) distro=Ubuntu;;
Pop*) distro=PopOS;;
Debian*) distro=Debian;;
*) distro=""
esac

# Base commands
if [[ "$distro" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then
if [[ "$OSDISTRO" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then
alias deb-install="sudo dpkg -i $1 && sudo apt install -f"
fi

update() {
if [[ "$machine" == "Linux" ]]; then
if [[ "$distro" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then
if [[ "$OSTYPE" == "Linux" ]]; then
if [[ "$OSDISTRO" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then
sudo apt update -y
else
echo "Unknown Distro / Package Manager"
fi

elif [[ "$machine" == "Mac" ]]; then
elif [[ "$OSTYPE" == "Macos" ]]; then
brew update
else
echo "Unknown OS: $machine"
fi
}

upgrade() {
if [[ "$machine" == "Linux" ]]; then
if [[ "$distro" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then
if [[ "$OSTYPE" == "Linux" ]]; then
if [[ "$OSDISTRO" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then
echo "Updating apt..."
sudo apt upgrade -y
sudo apt dist-upgrade -y
Expand All @@ -52,7 +36,7 @@ upgrade() {
if [[ -x "$(flatpak)" ]]; then
flatpak update
fi
elif [[ "$machine" == "Darwin" ]]; then
elif [[ "$OSTYPE" == "Macos" ]]; then
echo "Updating brew..."
brew update
brew upgrade
Expand All @@ -77,23 +61,23 @@ install() {
# Update first before search
update

if [[ "$machine" == "Linux" ]]; then
if [[ "$distro" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then
if [[ "$OSTYPE" == "Linux" ]]; then
if [[ "$OSDISTRO" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then
sudo apt install -y "$*"
fi
elif [[ "$machine" == "Darwin" ]]; then
elif [[ "$OSTYPE" == "Macos" ]]; then
brew install "$*"
else
echo "Unknown OS: $machine"
fi
}

search() {
if [[ "$machine" == "Linux" ]]; then
if [[ "$distro" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then
if [[ "$OSTYPE" == "Linux" ]]; then
if [[ "$OSDISTRO" =~ ^(Ubuntu|PopOS|Debian)$ ]]; then
sudo apt-cache search "$*"
fi
elif [[ "$machine" == "Darwin" ]]; then
elif [[ "$OSTYPE" == "Macos" ]]; then
brew search "$*"
else
echo "Unknown OS: $machine"
Expand Down
28 changes: 27 additions & 1 deletion zsh/.zshrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
#!/bin/bash

# OS Detection
case "$(uname -s)" in
Linux*)
export OSTYPE=Linux;;
Darwin*)
export OSTYPE=Macos;;
*)
echo "Unknown Operating System: $(uname -s)"
esac

# Export different paths
export PATH=$HOME/.geek/bin:$HOME/.local:/usr/local/bin:$PATH

if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ "$OSTYPE" == "Macos" ]]; then
export ZSH=/Users/$USER/.oh-my-zsh
# Assumes zsh suggestions are from brew
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh

plugins=(
1password
git
Expand All @@ -17,6 +31,14 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
zsh-autosuggestions
)
else
# Distro
case "$(lsb_release -si)" in
Ubuntu*) distro=Ubuntu;;
Pop*) distro=PopOS;;
Debian*) distro=Debian;;
*) distro=""
esac

export ZSH=$HOME/.oh-my-zsh
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins
plugins=(
Expand Down Expand Up @@ -63,3 +85,7 @@ if [ -x "$(command -v fastfetch)" ]; then
fastfetch
fi


export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

0 comments on commit 0ffc119

Please sign in to comment.