summaryrefslogtreecommitdiff
path: root/static/thesiah-mac.sh
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2024-04-29 10:16:09 -0400
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2024-04-29 10:16:09 -0400
commit2cd42b9d71238abc14748566134ead380d5f0969 (patch)
tree03b479b0d92781add4c196bb515886f0b981e842 /static/thesiah-mac.sh
Init
Diffstat (limited to 'static/thesiah-mac.sh')
-rwxr-xr-xstatic/thesiah-mac.sh148
1 files changed, 148 insertions, 0 deletions
diff --git a/static/thesiah-mac.sh b/static/thesiah-mac.sh
new file mode 100755
index 0000000..b793c9a
--- /dev/null
+++ b/static/thesiah-mac.sh
@@ -0,0 +1,148 @@
+#!/bin/sh
+
+# Soomin's Auto Rice Bootstrapping Script (THESIAH) adapted for macOS
+# Adaptation by: Soomin Im <si@thesiah.xyz>
+# License: GNU GPLv3
+
+
+### VARIABLES ###
+dotfilesrepo="https://github.com/thesiah/.dotfiles.git"
+progsfile="https://raw.githubusercontent.com/thesiah/THESIAH/main/static/macprogs.csv"
+repobranch="main"
+name=$(whoami) # Use the current user's name
+
+
+### 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
+}
+
+# Install Homebrew packages
+installpkg() {
+ if brew list "$1" &>/dev/null; then
+ echo "$1 is already installed."
+ else
+ echo "Installing $1..."
+ 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..."
+ 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"
+ brew install "$pkg" || error "Failed to install $pkg from tap."
+}
+
+# Install mac apps with mas
+masinstall() {
+ echo "Installing the mac app: $1"
+ if ! command -v mas &>/dev/null; then
+ installpkg mas # This installs mas
+ fi
+
+ # Search for the app by name and get its ID using awk to parse the output
+ id=$(mas search "$1" | awk -F ' ' '{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
+ echo "Installing the app with ID $id..."
+ 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 </tmp/programs.csv
+}
+
+finalize() {
+ # Farewell
+ echo "All done!"
+ echo "Congrats! Provided there were no hidden errors, the script completed successfully and all the programs and configuration files should be in place.\\n\\nTo run the new graphical environment, log out and log back in as your new user, then run the command \"startx\" to start the graphical environment (it will start automatically in tty1).\\n\\n.t Soomin"
+}
+
+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
+}
+
+### Main Installation Process ###
+
+# Ensure Homebrew is installed
+brewinstall || error "Failed to install Homebrew."
+
+# Start the installation loop for software from the CSV
+installationloop
+
+# Setup Dotfiles
+putgitrepo "$dotfilesrepo" "$HOME" "$repobranch"
+
+# Clean up any unwanted files from the dotfiles repo
+rm -rf "$HOME/.git" "$HOME/README.md" "$HOME/LICENSE" "$HOME/FUNDING.yml" "/tmp/programs.csv"
+
+ln -s ~/.dotfiles/mac/.zprofile ~/.zprofile
+
+# Final
+finalize