diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-09-06 16:15:53 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-09-06 16:15:53 +0900 |
| commit | b8d398796160091ad0d92a1a9b2597f2682dad9d (patch) | |
| tree | 65f8b84586704d3e60f88cc6d0f19564b0d503c3 | |
| parent | 31fd2aa475c90dadfe83f0979302dd7d495ca6ab (diff) | |
modified static/macprogs.csv, modified static/thesiah-mac.sh
| -rw-r--r-- | static/macprogs.csv | 1 | ||||
| -rwxr-xr-x | static/thesiah-mac.sh | 576 |
2 files changed, 290 insertions, 287 deletions
diff --git a/static/macprogs.csv b/static/macprogs.csv index ad38bec..f182ddf 100644 --- a/static/macprogs.csv +++ b/static/macprogs.csv @@ -101,5 +101,6 @@ M,WeatherBug,forecasts weather on the menu bar. C,whatsapp,is a native desktop client for Whatsapp. ,wget,is an internet file retriever. C,xquartz,is an open-source version of the x.org x window system. +T,zegervdv/zathura,is a CLI pdf viewer. ,zoxide,is a shell extension to navigate filesystem faster. ,7-Zip,is a file archiever with a high compression ratio. diff --git a/static/thesiah-mac.sh b/static/thesiah-mac.sh index 38f25ad..ec06100 100755 --- a/static/thesiah-mac.sh +++ b/static/thesiah-mac.sh @@ -4,7 +4,7 @@ # Adaptation by: Soomin Im <si@thesiah.xyz> # License: GNU GPLv3 -set -e # Exit on error +set -e # Exit on error ### VARIABLES ### dotfilesrepo="https://github.com/TheSiahxyz/.dotfiles.git" @@ -22,378 +22,380 @@ export HOMEBREW_NO_ENV_HINTS=1 # Print formatted output print_header() { - echo "==================================================" - echo "$1" - echo "==================================================" + echo "==================================================" + echo "$1" + echo "==================================================" } print_step() { - echo " -> $1" + echo " -> $1" } print_success() { - echo " [OK] $1" + echo " [OK] $1" } print_error() { - echo " [ERROR] $1" >&2 + echo " [ERROR] $1" >&2 } print_warning() { - echo " [WARNING] $1" + echo " [WARNING] $1" } # Check if command exists command_exists() { - command -v "$1" >/dev/null 2>&1 + command -v "$1" >/dev/null 2>&1 } # Check if directory exists and is writable check_directory() { - if [ ! -d "$1" ]; then - print_step "Creating directory: $1" - mkdir -p "$1" || error "Failed to create directory: $1" - fi - - if [ ! -w "$1" ]; then - error "Directory is not writable: $1" - fi + if [ ! -d "$1" ]; then + print_step "Creating directory: $1" + mkdir -p "$1" || error "Failed to create directory: $1" + fi + + if [ ! -w "$1" ]; then + error "Directory is not writable: $1" + fi } # Notify function using macOS's notification system notify() { - if command_exists osascript; then - osascript -e "display notification \"$2\" with title \"$1\"" 2>/dev/null || true - fi + if command_exists osascript; then + osascript -e "display notification \"$2\" with title \"$1\"" 2>/dev/null || true + fi } # Error function for error handling and notification error() { - print_error "$1" - notify "Installation Failed" "$1" - exit 1 + print_error "$1" + notify "Installation Failed" "$1" + exit 1 } # Install Homebrew brewinstall() { - print_step "Checking Homebrew installation..." - + print_step "Checking Homebrew installation..." + + if ! command_exists brew; then + print_step "Installing Homebrew..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + + # Add Homebrew to PATH for Apple Silicon Macs + if [ -f "/opt/homebrew/bin/brew" ]; then + eval "$(/opt/homebrew/bin/brew shellenv)" + elif [ -f "/usr/local/bin/brew" ]; then + eval "$(/usr/local/bin/brew shellenv)" + fi + + # Verify brew is now available if ! command_exists brew; then - print_step "Installing Homebrew..." - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - - # Add Homebrew to PATH for Apple Silicon Macs - if [ -f "/opt/homebrew/bin/brew" ]; then - eval "$(/opt/homebrew/bin/brew shellenv)" - elif [ -f "/usr/local/bin/brew" ]; then - eval "$(/usr/local/bin/brew shellenv)" - fi - - # Verify brew is now available - if ! command_exists brew; then - error "Homebrew installation failed - brew command not found" - fi - else - print_success "Homebrew already installed" + error "Homebrew installation failed - brew command not found" fi - - print_step "Updating Homebrew..." - brew update >/dev/null 2>&1 || print_warning "Homebrew update failed, continuing..." - brew upgrade >/dev/null 2>&1 || print_warning "Homebrew upgrade failed, continuing..." + else + print_success "Homebrew already installed" + fi + + print_step "Updating Homebrew..." + brew update >/dev/null 2>&1 || print_warning "Homebrew update failed, continuing..." + brew upgrade >/dev/null 2>&1 || print_warning "Homebrew upgrade failed, continuing..." } # Install Homebrew packages with non-interactive flags installpkg() { - pkg="$1" - if brew list "$pkg" >/dev/null 2>&1; then - print_success "$pkg already installed" - else - print_step "Installing $pkg..." - # Use non-interactive flags to prevent user input prompts - brew install --force-bottle --no-quarantine "$pkg" 2>/dev/null || \ - brew install "$pkg" || error "Failed to install $pkg" - print_success "$pkg installed successfully" - fi + pkg="$1" + if brew list "$pkg" >/dev/null 2>&1; then + print_success "$pkg already installed" + else + print_step "Installing $pkg..." + # Use non-interactive flags to prevent user input prompts + brew install --force-bottle --no-quarantine "$pkg" 2>/dev/null || + brew install "$pkg" || error "Failed to install $pkg" + print_success "$pkg installed successfully" + fi } # Install Homebrew Cask applications caskinstall() { - pkg="$1" - if brew list --cask "$pkg" >/dev/null 2>&1; then - print_success "$pkg already installed" - else - print_step "Installing $pkg..." - # Use non-interactive flags for cask installations - brew install --cask --force --no-quarantine "$pkg" 2>/dev/null || \ - brew install --cask "$pkg" || error "Failed to install $pkg" - print_success "$pkg installed successfully" - fi + pkg="$1" + if brew list --cask "$pkg" >/dev/null 2>&1; then + print_success "$pkg already installed" + else + print_step "Installing $pkg..." + # Use non-interactive flags for cask installations + brew install --cask --force --no-quarantine "$pkg" 2>/dev/null || + brew install --cask "$pkg" || error "Failed to install $pkg" + print_success "$pkg installed successfully" + fi } # Install Python packages with pip pipinstall() { - pkg="$1" - print_step "Installing Python package: $pkg" - - if ! command_exists pip3; then - print_step "Installing Python (includes pip3)..." - installpkg python - fi - - # Use --quiet flag to prevent pip from asking questions - pip3 install --quiet "$pkg" || error "Failed to install Python package $pkg" - print_success "$pkg installed successfully" + pkg="$1" + print_step "Installing Python package: $pkg" + + if ! command_exists pip3; then + print_step "Installing Python (includes pip3)..." + installpkg python + fi + + # Use --quiet flag to prevent pip from asking questions + pip3 install --quiet "$pkg" || error "Failed to install Python package $pkg" + print_success "$pkg installed successfully" } # Install Homebrew Tap packages tapinstall() { - repo=$(echo "$1" | cut -d'/' -f1) - pkg=$(echo "$1" | cut -d'/' -f2) + repo="$1" + pkg=$(echo "$1" | cut -d'/' -f2) - print_step "Adding tap: $repo" - brew tap "$repo" || error "Failed to tap $repo" + print_step "Adding tap: $repo" + brew tap "$repo" || error "Failed to tap $repo" - print_step "Installing package: $pkg from tap" - # Use non-interactive flags for tap packages too - brew install --force-bottle --no-quarantine "$pkg" 2>/dev/null || \ + print_step "Installing package: $pkg from tap" + # Use non-interactive flags for tap packages too + brew install --force-bottle --no-quarantine "$pkg" 2>/dev/null || brew install "$pkg" || error "Failed to install $pkg from tap" - print_success "$pkg installed successfully" + echo "$pkg" >>"$HOME/appify.txt" + print_success "$pkg installed successfully" + print_success "After restart, create a $pkg.app if you need. You can check $HOME/appify.txt" } # Install mac apps with mas masinstall() { - app_name="$1" - print_step "Installing Mac App Store app: $app_name" - - # Search for the app by name and get its ID - id=$(mas search "$app_name" | awk -v appName="$app_name" ' - tolower($0) ~ tolower(appName) { - print $1; - exit + app_name="$1" + print_step "Installing Mac App Store app: $app_name" + + # Search for the app by name and get its ID + id=$(mas search "$app_name" | awk -v appName="$app_name" ' + tolower($0) ~ tolower(appName) { + print $1; + exit } ') - - if [ -z "$id" ]; then - error "Failed to find an ID for the app named $app_name" - else - print_step "Installing app ID: $id" - mas install "$id" || error "Failed to install the app $app_name" - print_success "$app_name installed successfully" - fi + + if [ -z "$id" ]; then + error "Failed to find an ID for the app named $app_name" + else + print_step "Installing app ID: $id" + mas install "$id" || error "Failed to install the app $app_name" + print_success "$app_name installed successfully" + fi } # Clone and setup dotfiles putgitrepo() { - repo="$1" - target="$2" - branch="${3:-$repobranch}" - - print_step "Downloading and installing config files..." - notify "Installation" "Downloading and installing config files..." - - # Check if git is available - if ! command_exists git; then - error "Git is not installed. Please install git first." - fi - - # Check target directory - check_directory "$target" - - dir=$(mktemp -d) - - print_step "Cloning repository: $repo" - git clone --depth 1 --single-branch --no-tags -q --recursive -b "$branch" "$repo" "$dir" || \ - error "Failed to clone $repo" - - print_step "Copying files to target directory" - cp -Rf "$dir/"* "$target" 2>/dev/null || true - rm -rf "$dir" - print_success "Config files installed successfully" + repo="$1" + target="$2" + branch="${3:-$repobranch}" + + print_step "Downloading and installing config files..." + notify "Installation" "Downloading and installing config files..." + + # Check if git is available + if ! command_exists git; then + error "Git is not installed. Please install git first." + fi + + # Check target directory + check_directory "$target" + + dir=$(mktemp -d) + + print_step "Cloning repository: $repo" + git clone --depth 1 --single-branch --no-tags -q --recursive -b "$branch" "$repo" "$dir" || + error "Failed to clone $repo" + + print_step "Copying files to target directory" + cp -Rf "$dir/"* "$target" 2>/dev/null || true + rm -rf "$dir" + print_success "Config files installed successfully" } # Installation loop for processing the programs.csv file installationloop() { - csv_file="/tmp/programs.csv" - - print_header "Installing Software Packages" - - # Download programs file - if [ -f "$progsfile" ]; then - print_step "Using local programs file: $progsfile" - cp "$progsfile" "$csv_file" - else - print_step "Downloading programs list from: $progsfile" - if ! curl -Ls "$progsfile" | sed '/^#/d' > "$csv_file"; then - error "Failed to download programs file from $progsfile" - fi - - # Verify file was downloaded and has content - if [ ! -s "$csv_file" ]; then - error "Downloaded programs file is empty" - fi + csv_file="/tmp/programs.csv" + + print_header "Installing Software Packages" + + # Download programs file + if [ -f "$progsfile" ]; then + print_step "Using local programs file: $progsfile" + cp "$progsfile" "$csv_file" + else + print_step "Downloading programs list from: $progsfile" + if ! curl -Ls "$progsfile" | sed '/^#/d' >"$csv_file"; then + error "Failed to download programs file from $progsfile" fi - - # Count total packages for progress - total_packages=$(wc -l < "$csv_file" 2>/dev/null | tr -d ' ' || echo "0") - if [ "$total_packages" -eq 0 ]; then - error "No packages found in programs file" + + # Verify file was downloaded and has content + if [ ! -s "$csv_file" ]; then + error "Downloaded programs file is empty" fi - - current=0 - - while IFS=, read -r tag program comment; do - # Skip empty lines - if [ -z "$tag" ] || [ -z "$program" ]; then - continue - fi - - current=$((current + 1)) - echo "" - print_step "[$current/$total_packages] $comment" - - case "$tag" in - "P") pipinstall "$program" ;; - "C") caskinstall "$program" ;; - "M") masinstall "$program" ;; - "T") tapinstall "$program" ;; - *) installpkg "$program" ;; - esac - done < "$csv_file" - - rm -f "$csv_file" - print_success "All packages installed successfully" + fi + + # Count total packages for progress + total_packages=$(wc -l <"$csv_file" 2>/dev/null | tr -d ' ' || echo "0") + if [ "$total_packages" -eq 0 ]; then + error "No packages found in programs file" + fi + + current=0 + + while IFS=, read -r tag program comment; do + # Skip empty lines + if [ -z "$tag" ] || [ -z "$program" ]; then + continue + fi + + current=$((current + 1)) + echo "" + print_step "[$current/$total_packages] $comment" + + case "$tag" in + "P") pipinstall "$program" ;; + "C") caskinstall "$program" ;; + "M") masinstall "$program" ;; + "T") tapinstall "$program" ;; + *) installpkg "$program" ;; + esac + done <"$csv_file" + + rm -f "$csv_file" + print_success "All packages installed successfully" } # Setup shell configuration setup_shell() { - print_header "Setting up Shell Configuration" - - print_step "Creating symbolic links for shell configs..." - - # Create backup of existing configs - timestamp=$(date +%Y%m%d_%H%M%S) - - [ -f ~/.zprofile ] && mv ~/.zprofile ~/.zprofile.backup.$timestamp - [ -f ~/.bash_profile ] && mv ~/.bash_profile ~/.bash_profile.backup.$timestamp - [ -f ~/.bashrc ] && mv ~/.bashrc ~/.bashrc.backup.$timestamp - - # Create new symbolic links - ln -sf ~/.dotfiles/mac/.config/shell/profile ~/.zprofile - ln -sf ~/.dotfiles/mac/.config/bash/bash_profile ~/.bash_profile - ln -sf ~/.dotfiles/mac/.config/bash/bashrc ~/.bashrc - - print_success "Shell configuration setup completed" + print_header "Setting up Shell Configuration" + + print_step "Creating symbolic links for shell configs..." + + # Create backup of existing configs + timestamp=$(date +%Y%m%d_%H%M%S) + + [ -f ~/.zprofile ] && mv ~/.zprofile ~/.zprofile.backup.$timestamp + [ -f ~/.bash_profile ] && mv ~/.bash_profile ~/.bash_profile.backup.$timestamp + [ -f ~/.bashrc ] && mv ~/.bashrc ~/.bashrc.backup.$timestamp + + # Create new symbolic links + ln -sf ~/.dotfiles/mac/.config/shell/profile ~/.zprofile + ln -sf ~/.dotfiles/mac/.config/bash/bash_profile ~/.bash_profile + ln -sf ~/.dotfiles/mac/.config/bash/bashrc ~/.bashrc + + print_success "Shell configuration setup completed" } # Setup dotfiles with stow setup_dotfiles() { - print_header "Setting up Dotfiles" - - print_step "Installing dotfiles with stow..." - - # Check if stow is available - if ! command_exists stow; then - print_warning "Stow not found, installing..." - installpkg stow - fi - - # Check if dotfiles directory exists - if [ ! -d ~/.dotfiles ]; then - error "Dotfiles directory not found: ~/.dotfiles" - fi - - cd ~/.dotfiles || error "Failed to change to dotfiles directory" - - # Install global configurations - print_step "Installing global configurations..." - if [ -d "global" ]; then - stow --no-folding -S global || error "Failed to stow global configs" - else - print_warning "Global configs directory not found, skipping..." - fi - - # Install macOS specific configurations - print_step "Installing macOS specific configurations..." - if [ -d "mac" ]; then - stow --no-folding -S mac || error "Failed to stow mac configs" - else - print_warning "Mac configs directory not found, skipping..." - fi - - cd - > /dev/null - print_success "Dotfiles setup completed" + print_header "Setting up Dotfiles" + + print_step "Installing dotfiles with stow..." + + # Check if stow is available + if ! command_exists stow; then + print_warning "Stow not found, installing..." + installpkg stow + fi + + # Check if dotfiles directory exists + if [ ! -d ~/.dotfiles ]; then + error "Dotfiles directory not found: ~/.dotfiles" + fi + + cd ~/.dotfiles || error "Failed to change to dotfiles directory" + + # Install global configurations + print_step "Installing global configurations..." + if [ -d "global" ]; then + stow --no-folding -S global || error "Failed to stow global configs" + else + print_warning "Global configs directory not found, skipping..." + fi + + # Install macOS specific configurations + print_step "Installing macOS specific configurations..." + if [ -d "mac" ]; then + stow --no-folding -S mac || error "Failed to stow mac configs" + else + print_warning "Mac configs directory not found, skipping..." + fi + + cd - >/dev/null + print_success "Dotfiles setup completed" } # Finalize installation finalize() { - print_header "Installation Complete!" - echo "" - echo "Congratulations! The installation has completed successfully." - echo "" - echo "What was installed:" - echo " - Homebrew and essential packages" - echo " - Mac App Store applications" - echo " - Python packages" - echo " - Shell configuration files" - echo " - Dotfiles and system configurations" - echo "" - echo "Next steps:" - echo " - Restart your terminal or run: source ~/.zprofile" - echo " - Customize your configuration files in ~/.dotfiles" - echo " - Install additional packages as needed" - echo "" - echo "For support, visit: https://github.com/TheSiahxyz/.dotfiles" - echo "" - echo "Best regards," - echo "Soomin" - echo "" - - notify "Installation Complete" "THESIAH setup finished successfully!" + print_header "Installation Complete!" + echo "" + echo "Congratulations! The installation has completed successfully." + echo "" + echo "What was installed:" + echo " - Homebrew and essential packages" + echo " - Mac App Store applications" + echo " - Python packages" + echo " - Shell configuration files" + echo " - Dotfiles and system configurations" + echo "" + echo "Next steps:" + echo " - Restart your terminal or run: source ~/.zprofile" + echo " - Customize your configuration files in ~/.dotfiles" + echo " - Install additional packages as needed" + echo "" + echo "For support, visit: https://github.com/TheSiahxyz/.dotfiles" + echo "" + echo "Best regards," + echo "Soomin" + echo "" + + notify "Installation Complete" "THESIAH setup finished successfully!" } ### MAIN INSTALLATION PROCESS ### main() { - print_header "THESIAH - macOS Auto Setup Script" - echo "Starting installation process..." - echo "" - - # Check if running on macOS - if [ "$(uname)" != "Darwin" ]; then - error "This script is designed for macOS only" - fi - - # Check if running as root - if [ "$(id -u)" -eq 0 ]; then - error "This script should not be run as root" - fi - - # Ensure Homebrew is installed - brewinstall || error "Failed to install Homebrew" - - # Ensure mas is installed - installpkg "mas" - - # Start the installation loop for software from the CSV - installationloop - - # Setup Dotfiles - putgitrepo "$dotfilesrepo" "$HOME" "$repobranch" - - # Move dotfiles to proper location - dotfiles_dir=$(basename "$dotfilesrepo" .git) - if [ -d "$HOME/$dotfiles_dir" ]; then - mv "$HOME/$dotfiles_dir" "$HOME/.dotfiles" - fi - - # Setup shell configuration - setup_shell - - # Setup dotfiles with stow - setup_dotfiles - - # Finalize - finalize + print_header "THESIAH - macOS Auto Setup Script" + echo "Starting installation process..." + echo "" + + # Check if running on macOS + if [ "$(uname)" != "Darwin" ]; then + error "This script is designed for macOS only" + fi + + # Check if running as root + if [ "$(id -u)" -eq 0 ]; then + error "This script should not be run as root" + fi + + # Ensure Homebrew is installed + brewinstall || error "Failed to install Homebrew" + + # Ensure mas is installed + installpkg "mas" + + # Start the installation loop for software from the CSV + installationloop + + # Setup Dotfiles + putgitrepo "$dotfilesrepo" "$HOME" "$repobranch" + + # Move dotfiles to proper location + dotfiles_dir=$(basename "$dotfilesrepo" .git) + if [ -d "$HOME/$dotfiles_dir" ]; then + mv "$HOME/$dotfiles_dir" "$HOME/.dotfiles" + fi + + # Setup shell configuration + setup_shell + + # Setup dotfiles with stow + setup_dotfiles + + # Finalize + finalize } # Run main function |
