#!/bin/sh # Soomin's Auto Rice Bootstrapping Script (THESIAH) adapted for macOS # Adaptation by: Soomin Im # License: GNU GPLv3 ### VARIABLES ### dotfilesrepo="https://github.com/TheSiahxyz/mac.git" progsfile="https://raw.githubusercontent.com/thesiah/THESIAH/main/static/macprogs.csv" repobranch="main" ### FUNCTIONS ### # Notify function using macOS's notification system notify() { osascript -e "display notification \"$2\" with title \"$1\"" } # Error function for error handling and notification error() { # Log to stderr and exit with failure. printf "%s\n" "$1" >&2 exit 1 } # Get user's password getuserandpass() { # Prompts user for new username an password. pass1=$(echo "Enter a password for that user:") pass2=$(echo "Retype password:") while ! [ "$pass1" = "$pass2" ]; do unset pass2 pass1=$(echo "Passwords do not match.\\n\\nEnter password again:") pass2=$(echo "Retype password:") done } # Install Homebrew brewinstall() { if ! command -v brew &>/dev/null; then /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" fi brew update >/dev/null 2>&1 brew upgrade >/dev/null 2>&1 eval "$(/opt/homebrew/bin/brew shellenv)" } # Install Homebrew packages installpkg() { if brew list "$1" &>/dev/null; then echo "$1 is already installed." else echo "Installing $1..." $pass1 | brew install "$1" || error "Failed to install $1." fi } # Install Homebrew Cask applications caskinstall() { if brew list --cask "$1" &>/dev/null; then echo "$1 is already installed." else echo "Installing $1..." $pass1 | brew install --cask "$1" || error "Failed to install $1." fi } # Install Python packages with pip pipinstall() { echo "Installing the Python package: $1" if ! command -v pip3 &>/dev/null; then installpkg python # This installs pip3 fi pip3 install "$1" || error "Failed to install Python package $1." } # Install Homebrew Tap packages tapinstall() { # Extract the repository and package name local repo=$(echo "$1" | cut -d'/' -f1) local pkg=$(echo "$1" | cut -d'/' -f2) echo "Adding tap: $repo" brew tap "$repo" || error "Failed to tap $repo." echo "Installing package: $pkg from tap" $pass1 | brew install "$pkg" || error "Failed to install $pkg from tap." } # Install mac apps with mas masinstall() { echo "Installing the mac app: $1" # Search for the app by name and get its ID using awk to parse the output id=$(mas search "$1" | awk -v appName="$1" '{if ($0 ~ appName) {print $1; exit}}') # Check if the id variable is set and not empty if [ -z "$id" ]; then error "Failed to find an ID for the app named $1." else mas install "$id" || error "Failed to install the app $1." fi } # Clone and setup dotfiles putgitrepo() { notify "Installation" "Downloading and installing config files..." local dir=$(mktemp -d) if [ ! -d "$2" ]; then mkdir -p "$2" fi git clone --depth 1 --single-branch --no-tags -q --recursive -b "${3:-$repobranch}" "$1" "$dir" || error "Failed to clone $1." cp -Rf "$dir/"* "$2" rm -rf "$dir" # Clean up } # Installation loop for processing the programs.csv file installationloop() { ([ -f "$progsfile" ] && cp "$progsfile" /tmp/programs.csv) || curl -Ls "$progsfile" | sed '/^#/d' >/tmp/programs.csv || error "Failed to download programs file." while IFS=, read -r tag program comment; do echo "$comment" case "$tag" in "P") pipinstall "$program" ;; "C") caskinstall "$program" ;; "M") masinstall "$program" ;; "T") tapinstall "$program" ;; *) installpkg "$program" ;; esac done