diff --git a/add_ssh_key.sh b/add_ssh_key.sh index 99a894d..c6e21a2 100644 --- a/add_ssh_key.sh +++ b/add_ssh_key.sh @@ -1,52 +1,94 @@ -#!/bin/bash - -# POSIX-compliant color definitions -ESC=$(printf '\033') -RC="${ESC}[0m" # Reset -RED="${ESC}[31m" # Red -GREEN="${ESC}[32m" # Green -YELLOW="${ESC}[33m" # Yellow -BLUE="${ESC}[34m" # Blue -CYAN="${ESC}[36m" # Cyan - -# Check if zsh is being used -if [ -n "$ZSH_VERSION" ]; then - printf "%sDetected zsh. Using zsh for script execution.%s\n" "${CYAN}" "${RC}" - exec zsh "$0" "$@" - exit -fi +#!/bin/sh + +# Source the common script +eval "$(curl -s https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/dev/common_script.sh)" # Variables SSH_DIR="$HOME/.ssh" AUTHORIZED_KEYS="$SSH_DIR/authorized_keys" -# Ensure the .ssh directory exists -if [ ! -d "$SSH_DIR" ]; then - mkdir -p "$SSH_DIR" - chmod 700 "$SSH_DIR" - printf "%sCreated %s and set permissions to 700.%s\n" "${GREEN}" "$SSH_DIR" "${RC}" -else - printf "%s%s already exists.%s\n" "${YELLOW}" "$SSH_DIR" "${RC}" -fi - -# Ensure the authorized_keys file exists -if [ ! -f "$AUTHORIZED_KEYS" ]; then - touch "$AUTHORIZED_KEYS" - chmod 600 "$AUTHORIZED_KEYS" - printf "%sCreated %s and set permissions to 600.%s\n" "${GREEN}" "$AUTHORIZED_KEYS" "${RC}" -else - printf "%s%s already exists.%s\n" "${YELLOW}" "$AUTHORIZED_KEYS" "${RC}" -fi - -# Add the public key to the authorized_keys file if not already added -printf "%sEnter the public key to add: %s" "${CYAN}" "${RC}" -read PUBLIC_KEY - -if grep -q "$PUBLIC_KEY" "$AUTHORIZED_KEYS"; then - printf "%sPublic key already exists in %s.%s\n" "${YELLOW}" "$AUTHORIZED_KEYS" "${RC}" -else - echo "$PUBLIC_KEY" >> "$AUTHORIZED_KEYS" - printf "%sPublic key added to %s.%s\n" "${GREEN}" "$AUTHORIZED_KEYS" "${RC}" -fi - -printf "%sDone.%s\n" "${GREEN}" "${RC}" +# Function to ensure directory and file exist with correct permissions +ensure_ssh_setup() { + if [ ! -d "$SSH_DIR" ]; then + mkdir -p "$SSH_DIR" + chmod 700 "$SSH_DIR" + print_success "Created $SSH_DIR and set permissions to 700." + else + print_warning "$SSH_DIR already exists." + fi + + if [ ! -f "$AUTHORIZED_KEYS" ]; then + touch "$AUTHORIZED_KEYS" + chmod 600 "$AUTHORIZED_KEYS" + print_success "Created $AUTHORIZED_KEYS and set permissions to 600." + else + print_warning "$AUTHORIZED_KEYS already exists." + fi +} + +# Function to import SSH keys from GitHub +import_ssh_keys() { + print_info "Enter the GitHub username: " + read -r github_user + + ssh_keys_url="https://github.com/$github_user.keys" + keys=$(curl -s "$ssh_keys_url") + + if [ -z "$keys" ]; then + print_error "No SSH keys found for GitHub user: $github_user" + else + print_success "SSH keys found for $github_user:" + printf "%s\n" "$keys" + print_info "Do you want to import these keys? [Y/n]: " + read -r confirm + + case "$confirm" in + [Nn]*) + print_warning "SSH key import cancelled." + ;; + *) + printf "%s\n" "$keys" >> "$AUTHORIZED_KEYS" + chmod 600 "$AUTHORIZED_KEYS" + print_success "SSH keys imported successfully!" + ;; + esac + fi +} + +# Function to add a manually entered public key +add_manual_key() { + print_info "Enter the public key to add: " + read -r PUBLIC_KEY + + if grep -q "$PUBLIC_KEY" "$AUTHORIZED_KEYS"; then + print_warning "Public key already exists in $AUTHORIZED_KEYS." + else + printf "%s\n" "$PUBLIC_KEY" >> "$AUTHORIZED_KEYS" + chmod 600 "$AUTHORIZED_KEYS" + print_success "Public key added to $AUTHORIZED_KEYS." + fi +} + +# Function to show SSH key menu +show_ssh_menu() { + show_menu_item 1 "$selected" "Import from GitHub" + show_menu_item 2 "$selected" "Enter your own public key" +} + +# Main script +ensure_ssh_setup + +# Handle menu selection +handle_menu_selection 2 "Select SSH key option" show_ssh_menu +choice=$? + +case $choice in + 1) + import_ssh_keys + ;; + 2) + add_manual_key + ;; +esac + +print_colored "$GREEN" "SSH key setup completed" diff --git a/common_script.sh b/common_script.sh new file mode 100644 index 0000000..cff8005 --- /dev/null +++ b/common_script.sh @@ -0,0 +1,112 @@ +#!/bin/sh + +# Color definitions +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +MAGENTA='\033[0;35m' +CYAN='\033[0;36m' +GRAY='\033[0;37m' +RC='\033[0m' # Reset color + +# Function to read keyboard input +read_key() { + dd bs=1 count=1 2>/dev/null | od -An -tx1 +} + +# Function to show menu item +show_menu_item() { + if [ "$selected" -eq "$1" ]; then + printf " ${GREEN}→ %s${RC}\n" "$3" + else + printf " %s\n" "$3" + fi +} + +# Function to handle menu selection +handle_menu_selection() { + selected=1 + total_options=$1 + saved_stty=$(stty -g) + + cleanup() { + stty "$saved_stty" + printf "\n${GREEN}Script terminated.${RC}\n" + exit 0 + } + + trap cleanup INT + + while true; do + # Clear screen and show header + printf "\033[2J\033[H" + print_colored "$CYAN" "$2" + echo + + # Call the function that displays menu items + $3 + + printf "\n${MAGENTA}Use arrow keys to navigate, Enter to select, 'q' to exit${RC}\n" + + # Read keyboard input + stty raw -echo + key=$(dd bs=3 count=1 2>/dev/null) + case "$key" in + $'\x1B\x5B\x41') # Up arrow + if [ $selected -eq 1 ]; then + selected=$total_options + else + selected=$((selected - 1)) + fi + ;; + $'\x1B\x5B\x42') # Down arrow + if [ $selected -eq $total_options ]; then + selected=1 + else + selected=$((selected + 1)) + fi + ;; + $'\x0A'|$'\x0D') # Enter + stty "$saved_stty" + return $selected + ;; + $'\x03') # Ctrl+C + stty "$saved_stty" + cleanup + ;; + q|Q) # q or Q + stty "$saved_stty" + cleanup + ;; + esac + stty "$saved_stty" + done +} + +# Function to print colored text +print_colored() { + local color=$1 + local message=$2 + printf "${color}%s${RC}\n" "$message" +} + +# Function to print error message +print_error() { + print_colored "$RED" "ERROR: $1" +} + +# Function to print success message +print_success() { + print_colored "$GREEN" "SUCCESS: $1" +} + +# Function to print warning message +print_warning() { + print_colored "$YELLOW" "WARNING: $1" +} + +# Function to print info message +print_info() { + print_colored "$BLUE" "INFO: $1" +} diff --git a/dock_scripts/dock_manager.sh b/dock_scripts/dock_manager.sh index 2e94669..94a6ad5 100644 --- a/dock_scripts/dock_manager.sh +++ b/dock_scripts/dock_manager.sh @@ -1,24 +1,18 @@ -#!/bin/bash +#!/bin/sh -# POSIX-compliant color definitions -ESC=$(printf '\033') -RC="${ESC}[0m" # Reset -RED="${ESC}[31m" # Red -GREEN="${ESC}[32m" # Green -YELLOW="${ESC}[33m" # Yellow -BLUE="${ESC}[34m" # Blue -CYAN="${ESC}[36m" # Cyan +# Source the common script +eval "$(curl -s https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/dev/common_script.sh)" # Check if a path argument is provided if [ -n "$1" ]; then GITPATH="$1" else - GITPATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + GITPATH="$SCRIPT_DIR" fi -printf "%sGITPATH is set to: %s%s\n" "${CYAN}" "$GITPATH" "${RC}" -printf "%sCurrent working directory: %s%s\n" "${CYAN}" "$(pwd)" "${RC}" -printf "%sScript location: %s%s\n" "${CYAN}" "${BASH_SOURCE[0]}" "${RC}" +print_info "GITPATH is set to: $GITPATH" +print_info "Current working directory: $(pwd)" +print_info "Script location: ${BASH_SOURCE[0]}" # GitHub URL base for the necessary Dock scripts GITHUB_BASE_URL="https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/main/dock_scripts/" @@ -26,12 +20,12 @@ GITHUB_BASE_URL="https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/main # Function to remove Dock items using icon_remove.sh remove_dock_items() { local script_path="$GITPATH/icon_remove.sh" - printf "%sChecking for icon_remove.sh at: %s%s\n" "${CYAN}" "$script_path" "${RC}" + print_info "Checking for icon_remove.sh at: $script_path" if [[ -f "$script_path" ]]; then - printf "%sRunning icon_remove.sh from local directory...%s\n" "${GREEN}" "${RC}" + print_success "Running icon_remove.sh from local directory..." bash "$script_path" else - printf "%sLocal icon_remove.sh not found. Running from GitHub...%s\n" "${YELLOW}" "${RC}" + print_warning "Local icon_remove.sh not found. Running from GitHub..." bash -c "$(curl -fsSL $GITHUB_BASE_URL/icon_remove.sh)" fi } @@ -39,52 +33,43 @@ remove_dock_items() { # Function to add Dock items using icon_add.sh add_dock_items() { local script_path="$GITPATH/icon_add.sh" - printf "%sChecking for icon_add.sh at: %s%s\n" "${CYAN}" "$script_path" "${RC}" + print_info "Checking for icon_add.sh at: $script_path" if [[ -f "$script_path" ]]; then - printf "%sRunning icon_add.sh from local directory...%s\n" "${GREEN}" "${RC}" + print_success "Running icon_add.sh from local directory..." bash "$script_path" else - printf "%sLocal icon_add.sh not found. Running from GitHub...%s\n" "${YELLOW}" "${RC}" + print_warning "Local icon_add.sh not found. Running from GitHub..." bash -c "$(curl -fsSL $GITHUB_BASE_URL/icon_add.sh)" fi } -# Function to manage dock items -manage_dock() { - while true; do - printf "%sPlease select from the following options:%s\n" "${CYAN}" "${RC}" - printf "%s1)%s Add Dock icons\n" "${GREEN}" "${RC}" - printf "%s2)%s Remove Dock icons\n" "${GREEN}" "${RC}" - printf "%s0)%s Return to main menu\n" "${RED}" "${RC}" - printf "Enter your choice (0-2): " - read choice - - case $choice in - 1) - printf "%sAdding Dock items...%s\n" "${CYAN}" "${RC}" - add_dock_items - ;; - 2) - printf "%sRemoving Dock items...%s\n" "${CYAN}" "${RC}" - remove_dock_items - ;; - 0) - printf "%sReturning to main menu.%s\n" "${YELLOW}" "${RC}" - break - ;; - *) - printf "%sInvalid option. Please enter a number between 0 and 2.%s\n" "${RED}" "${RC}" - ;; - esac - printf "\n" - done +# Function to show dock menu items +show_dock_menu() { + show_menu_item 1 "$selected" "Add Dock icons" + show_menu_item 2 "$selected" "Remove Dock icons" + show_menu_item 3 "$selected" "Return to main menu" } -# Run the dock manager -manage_dock +# Keep running until user chooses to exit +while true; do + # Handle menu selection + handle_menu_selection 3 "Dock Manager" show_dock_menu + choice=$? -printf "%s################################%s\n" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s##%s%s Dock management completed. %s##%s\n" "${YELLOW}" "${RC}" "${GREEN}" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s################################%s\n" "${YELLOW}" "${RC}" + case $choice in + 1) + print_info "Adding Dock items..." + add_dock_items + print_colored "$GREEN" "Dock completed" + ;; + 2) + print_info "Removing Dock items..." + remove_dock_items + print_colored "$GREEN" "Dock completed" + ;; + 3) + print_info "Returning to main menu." + break + ;; + esac +done diff --git a/dock_scripts/icon_add.sh b/dock_scripts/icon_add.sh index c3a578e..e89b81a 100644 --- a/dock_scripts/icon_add.sh +++ b/dock_scripts/icon_add.sh @@ -1,30 +1,24 @@ -#!/bin/bash +#!/bin/sh -# POSIX-compliant color definitions -ESC=$(printf '\033') -RC="${ESC}[0m" # Reset -RED="${ESC}[31m" # Red -GREEN="${ESC}[32m" # Green -YELLOW="${ESC}[33m" # Yellow -BLUE="${ESC}[34m" # Blue -CYAN="${ESC}[36m" # Cyan +# Source the common script +eval "$(curl -s https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/dev/common_script.sh)" # Function to install dockutil if not installed install_dockutil() { if ! command -v dockutil &> /dev/null; then - printf "%sdockutil is not installed. Installing dockutil...%s\n" "${YELLOW}" "${RC}" + print_warning "dockutil is not installed. Installing dockutil..." brew install dockutil else - printf "%sdockutil is already installed.%s\n" "${GREEN}" "${RC}" + print_success "dockutil is already installed." fi } # Ensure Homebrew is installed if ! command -v brew &> /dev/null; then - printf "%sHomebrew is required but not installed. Installing Homebrew...%s\n" "${YELLOW}" "${RC}" + print_warning "Homebrew is required but not installed. Installing Homebrew..." /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" else - printf "%sHomebrew is already installed.%s\n" "${GREEN}" "${RC}" + print_success "Homebrew is already installed." fi # Install dockutil if necessary @@ -47,7 +41,7 @@ applications_dir="/Applications" non_standard_apps=() # Find non-standard applications -printf "%sScanning for installed applications...%s\n" "${CYAN}" "${RC}" +print_info "Scanning for installed applications..." while IFS= read -r app; do app_name=$(basename "$app" .app) if [[ ! " ${standard_apps[@]} " =~ " ${app_name} " ]]; then @@ -61,7 +55,7 @@ unset IFS # Display available applications in columns if [ ${#sorted_apps[@]} -gt 0 ]; then - printf "%sAvailable applications:%s\n" "${CYAN}" "${RC}" + print_info "Available applications:" # Calculate number of rows needed for 3 columns total_apps=${#sorted_apps[@]} @@ -72,14 +66,20 @@ if [ ${#sorted_apps[@]} -gt 0 ]; then for (( j=0; j<3; j++ )); do index=$((i + j*rows)) if [ $index -lt $total_apps ]; then - printf "%s%-3d)%s %-25s" "${GREEN}" "$((index+1))" "${RC}" "${sorted_apps[$index]}" + # Format the number with padding + num=$((index+1)) + if [ $num -lt 10 ]; then + num_pad=" $num" + else + num_pad="$num" + fi + printf " %s) %-25s" "$num_pad" "${sorted_apps[$index]}" fi done - printf "\n" + echo done - # Get user selection - printf "\n%sEnter the numbers of the applications you want to add to the Dock (separated by space):%s " "${CYAN}" "${RC}" + print_info "Enter the numbers of the applications you want to add to the Dock (separated by space): " read -r selected_numbers # Process selections @@ -88,11 +88,11 @@ if [ ${#sorted_apps[@]} -gt 0 ]; then if [[ "$num" =~ ^[0-9]+$ ]] && [ "$num" -ge 1 ] && [ "$num" -le ${#sorted_apps[@]} ]; then apps_to_add+=("${sorted_apps[$((num-1))]}") else - printf "%sInvalid selection: %s. Skipping...%s\n" "${RED}" "$num" "${RC}" + print_error "Invalid selection: $num. Skipping..." fi done else - printf "%sNo non-standard applications found in %s%s\n" "${YELLOW}" "$applications_dir" "${RC}" + print_warning "No non-standard applications found in $applications_dir" fi # Flag to check if any changes were made @@ -100,33 +100,27 @@ changes_made=false # Add selected apps to the Dock if [ ${#apps_to_add[@]} -gt 0 ]; then - printf "%sAdding selected apps to the Dock...%s\n" "${CYAN}" "${RC}" + print_info "Adding selected apps to the Dock..." for app in "${apps_to_add[@]}"; do app_path="$applications_dir/$app.app" if [ -d "$app_path" ]; then dockutil --add "$app_path" --allhomes if [ $? -eq 0 ]; then - printf "%s%s successfully added to the Dock.%s\n" "${GREEN}" "$app" "${RC}" + print_success "$app successfully added to the Dock." changes_made=true else - printf "%sFailed to add %s to the Dock. Please check for errors.%s\n" "${RED}" "$app" "${RC}" + print_error "Failed to add $app to the Dock. Please check for errors." fi else - printf "%sApplication %s not found at %s. Skipping...%s\n" "${YELLOW}" "$app" "$app_path" "${RC}" + print_warning "Application $app not found at $app_path. Skipping..." fi done fi # Reset the Dock only if changes were made if [ "$changes_made" = true ]; then - printf "%sResetting the Dock to apply changes...%s\n" "${CYAN}" "${RC}" + print_info "Resetting the Dock to apply changes..." killall Dock else - printf "%sNo changes made to the Dock. Reset not needed.%s\n" "${YELLOW}" "${RC}" + print_warning "No changes made to the Dock. Reset not needed." fi - -printf "%s###################################%s\n" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s##%s%s Dock configuration completed. %s##%s\n" "${YELLOW}" "${RC}" "${GREEN}" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s###################################%s\n" "${YELLOW}" "${RC}" diff --git a/dock_scripts/icon_remove.sh b/dock_scripts/icon_remove.sh index f2cf077..3b5b80f 100644 --- a/dock_scripts/icon_remove.sh +++ b/dock_scripts/icon_remove.sh @@ -1,37 +1,31 @@ -#!/bin/bash +#!/bin/sh -# POSIX-compliant color definitions -ESC=$(printf '\033') -RC="${ESC}[0m" # Reset -RED="${ESC}[31m" # Red -GREEN="${ESC}[32m" # Green -YELLOW="${ESC}[33m" # Yellow -BLUE="${ESC}[34m" # Blue -CYAN="${ESC}[36m" # Cyan +# Source the common script +eval "$(curl -s https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/dev/common_script.sh)" # Function to install dockutil if not installed install_dockutil() { if ! command -v dockutil &> /dev/null; then - printf "%sdockutil is not installed. Installing dockutil...%s\n" "${YELLOW}" "${RC}" + print_warning "dockutil is not installed. Installing dockutil..." brew install dockutil else - printf "%sdockutil is already installed.%s\n" "${GREEN}" "${RC}" + print_success "dockutil is already installed." fi } # Ensure Homebrew is installed if ! command -v brew &> /dev/null; then - printf "%sHomebrew is required but not installed. Installing Homebrew...%s\n" "${YELLOW}" "${RC}" + print_warning "Homebrew is required but not installed. Installing Homebrew..." /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" else - printf "%sHomebrew is already installed.%s\n" "${GREEN}" "${RC}" + print_success "Homebrew is already installed." fi # Install dockutil if necessary install_dockutil # Check which applications are currently in the Dock -printf "%sChecking current Dock applications...%s\n" "${CYAN}" "${RC}" +print_info "Checking current Dock applications..." IFS=$'\n' read -rd '' -a current_dock_apps < <(dockutil --list | awk -F"\t" '{print $1}' && printf '\0') # Array to store apps to be removed from the Dock @@ -39,7 +33,7 @@ apps_to_remove=() # Display a numbered list of current Dock applications and let user pick which ones to remove if [ ${#current_dock_apps[@]} -gt 0 ]; then - printf "%sFound the following applications in the Dock:%s\n" "${CYAN}" "${RC}" + print_info "Found the following applications in the Dock:" # Calculate number of rows needed for 3 columns total_apps=${#current_dock_apps[@]} @@ -50,47 +44,48 @@ if [ ${#current_dock_apps[@]} -gt 0 ]; then for (( j=0; j<3; j++ )); do index=$((i + j*rows)) if [ $index -lt $total_apps ]; then - printf "%s%-3d)%s %-25s" "${GREEN}" "$((index+1))" "${RC}" "${current_dock_apps[$index]}" + # Format the number with padding + num=$((index+1)) + if [ $num -lt 10 ]; then + num_pad=" $num" + else + num_pad="$num" + fi + printf " %s) %-25s" "$num_pad" "${current_dock_apps[$index]}" fi done - printf "\n" + echo done - printf "\n%sEnter the numbers of the applications you want to remove (separated by space):%s " "${CYAN}" "${RC}" + print_info "Enter the numbers of the applications you want to remove (separated by space): " read -r selected_numbers for num in $selected_numbers; do if [[ "$num" =~ ^[0-9]+$ ]] && [ "$num" -ge 1 ] && [ "$num" -le ${#current_dock_apps[@]} ]; then apps_to_remove+=("${current_dock_apps[$((num-1))]}") else - printf "%sInvalid selection: %s. Skipping...%s\n" "${RED}" "$num" "${RC}" + print_error "Invalid selection: $num. Skipping..." fi done else - printf "%sNo applications found in the Dock.%s\n" "${YELLOW}" "${RC}" + print_warning "No applications found in the Dock." fi # Remove selected apps from the Dock if [ ${#apps_to_remove[@]} -gt 0 ]; then - printf "%sRemoving selected apps from the Dock...%s\n" "${CYAN}" "${RC}" + print_info "Removing selected apps from the Dock..." for app in "${apps_to_remove[@]}"; do dockutil --remove "$app" --allhomes if [ $? -eq 0 ]; then - printf "%s\"%s\" successfully removed from the Dock.%s\n" "${GREEN}" "$app" "${RC}" + print_success "\"$app\" successfully removed from the Dock." else - printf "%sFailed to remove \"%s\" from the Dock. Please check for errors.%s\n" "${RED}" "$app" "${RC}" + print_error "Failed to remove \"$app\" from the Dock. Please check for errors." fi done else - printf "%sNo apps selected for removal. Dock remains unchanged.%s\n" "${YELLOW}" "${RC}" + print_warning "No apps selected for removal. Dock remains unchanged." fi # Reset the Dock to apply changes -printf "%sResetting the Dock...%s\n" "${CYAN}" "${RC}" +print_info "Resetting the Dock..." killall Dock - -printf "%s###################################%s\n" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s##%s%s Dock configuration completed. %s##%s\n" "${YELLOW}" "${RC}" "${GREEN}" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s###################################%s\n" "${YELLOW}" "${RC}" diff --git a/homebrew_scripts/brew_installer.sh b/homebrew_scripts/brew_installer.sh index ddcb3cb..249180d 100644 --- a/homebrew_scripts/brew_installer.sh +++ b/homebrew_scripts/brew_installer.sh @@ -1,27 +1,19 @@ -#!/bin/bash +#!/bin/sh -# POSIX-compliant color definitions -ESC=$(printf '\033') -RC="${ESC}[0m" # Reset -RED="${ESC}[31m" # Red -GREEN="${ESC}[32m" # Green -YELLOW="${ESC}[33m" # Yellow -BLUE="${ESC}[34m" # Blue -CYAN="${ESC}[36m" # Cyan +# Source the common script +eval "$(curl -s https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/dev/common_script.sh)" # Function to display a menu and get the user's choice -function show_menu { - printf "%sSelect category:%s\n" "${CYAN}" "${RC}" - printf "%s1.%s Browsers\n" "${GREEN}" "${RC}" - printf "%s2.%s Communications\n" "${GREEN}" "${RC}" - printf "%s3.%s Development\n" "${GREEN}" "${RC}" - printf "%s4.%s Documents\n" "${GREEN}" "${RC}" - printf "%s5.%s Games\n" "${GREEN}" "${RC}" - printf "%s6.%s Multimedia\n" "${GREEN}" "${RC}" - printf "%s7.%s Utilities\n" "${GREEN}" "${RC}" - printf "%s0.%s Exit\n" "${RED}" "${RC}" - printf "Enter your choice [1-7]: " - read choice +function show_installer_menu { + print_info "Select category:" + show_menu_item 1 "$selected" "Browsers" + show_menu_item 2 "$selected" "Communications" + show_menu_item 3 "$selected" "Development" + show_menu_item 4 "$selected" "Documents" + show_menu_item 5 "$selected" "Games" + show_menu_item 6 "$selected" "Multimedia" + show_menu_item 7 "$selected" "Utilities" + show_menu_item 8 "$selected" "Exit" } # Function to print apps in columns @@ -35,10 +27,17 @@ function print_columns { for (( j=0; j<$num_columns; j++ )); do index=$(( i + j * rows )) if [ $index -lt $num_apps ]; then - printf "%s%-3d)%s %-22s" "${GREEN}" "$((index + 1))" "${RC}" "${app_display[$index]}" + # Format the number with padding + num=$((index+1)) + if [ $num -lt 10 ]; then + num_pad=" $num" + else + num_pad="$num" + fi + printf " %s) %-25s" "$num_pad" "${app_display[$index]}" fi done - printf "\n" + echo done } @@ -49,101 +48,95 @@ function install_casks { if [ "$number" -ge 1 ] && [ "$number" -le ${#app_casks[@]} ]; then local app_name="${app_casks[number-1]}" if brew list --cask "$app_name" &>/dev/null; then - printf "%s%s is already installed.%s\n" "${YELLOW}" "$app_name" "${RC}" + print_warning "$app_name is already installed." else - printf "%sInstalling %s...%s\n" "${CYAN}" "$app_name" "${RC}" + print_info "Installing $app_name..." if brew install --cask "$app_name"; then - printf "%s%s installed successfully!%s\n" "${GREEN}" "$app_name" "${RC}" + print_success "$app_name installed successfully!" else - printf "%sFailed to install %s%s\n" "${RED}" "$app_name" "${RC}" + print_error "Failed to install $app_name" fi fi else - printf "%sInvalid selection: %s%s\n" "${RED}" "$number" "${RC}" + print_error "Invalid selection: $number" fi done } # Main script loop while true; do - show_menu + handle_menu_selection 8 "Homebrew Installer" show_installer_menu + choice=$? + case $choice in 1) - printf "%sBrowsers:%s\n" "${CYAN}" "${RC}" + print_info "Browsers:" app_display=("Arc" "Brave" "Google Chrome" "Chromium" "Edge" "Firefox" "Floorp" "LibreWolf" "Mullvad Browser" "Thorium Browser" "Tor Browser" "Ungoogled" "Vivaldi" "Waterfox" "Zen Browser") app_casks=("arc" "brave-browser" "google-chrome" "chromium" "microsoft-edge" "firefox" "floorp" "Librewolf" "mullvad-browser" "alex313031-thorium" "tor-browser" "eloston-chromium" "vivaldi" "waterfox" "zen-browser") print_columns "${app_display[@]}" - printf "Enter the numbers of the browsers you want to install (separated by space): " + print_info "Enter the numbers of the browsers you want to install (separated by space): " read -a selected install_casks "${selected[@]}" ;; 2) - printf "%sCommunications:%s\n" "${CYAN}" "${RC}" + print_info "Communications:" app_display=("Chatterino" "Discord" "Ferdium" "Jami" "Element" "Signal" "Skype" "Microsoft Teams" "Telegram" "Thunderbird" "Viber" "Zoom" "Zulip") app_casks=("chatterino" "discord" "ferdium" "jami" "element" "signal" "skype" "microsoft-teams" "telegram" "thunderbird" "viber" "zoom" "zulip") print_columns "${app_display[@]}" - printf "Enter the numbers of the utilities you want to install (separated by space): " + print_info "Enter the numbers of the utilities you want to install (separated by space): " read -a selected install_casks "${selected[@]}" ;; 3) - printf "%sDevelopment:%s\n" "${CYAN}" "${RC}" + print_info "Development:" app_display=("Anaconda" "CMake" "Docker Desktop" "Fork" "Git Butler" "GitHub Desktop" "Gitify" "GitKraken" "Godot Engine" "Miniconda" "OrbStack" "Postman" "Pulsar" "Sublime Merge" "Sublime Text" "Thonny Python IDE" "Vagrant" "VS Code" "VS Codium" "Wezterm" ) app_casks=("anaconda" "cmake" "docker" "fork" "gitbutler" "github" "gitify" "gitkraken" "godot" "miniconda" "orbstack" "postman" "pulsar" "sublime-merge" "sublime-text" "thonny" "vagrant" "visual-studio-code" "vscodium" "wezterm" ) print_columns "${app_display[@]}" - printf "Enter the numbers of the development tools you want to install (separated by space): " + print_info "Enter the numbers of the development tools you want to install (separated by space): " read -a selected install_casks "${selected[@]}" ;; 4) - printf "%sDocuments:%s\n" "${CYAN}" "${RC}" + print_info "Documents:" app_display=("Adobe Acrobat Reader" "AFFiNE" "Anki" "Calibre" "Foxit PDF Editor" "Foxit Reader" "Joplin" "LibreOffice" "Logseq" "massCode" "NAPS2" "Obsidian" "ONLYOFFICE" "Apache OpenOffice" "PDFsam Basic" "Simplenote" "Znote" "Zotero") app_casks=("adobe-acrobat-reader" "affine" "anki" "calibre" "foxit-pdf-editor" "foxitreader" "joplin" "libreoffice" "logseq" "masscode" "naps2" "obsidian" "onlyoffice" "openoffice" "pdfsam-basic" "simplenote" "znote" "zotero") print_columns "${app_display[@]}" - printf "Enter the numbers of the multimedia apps you want to install (separated by space): " + print_info "Enter the numbers of the multimedia apps you want to install (separated by space): " read -a selected install_casks "${selected[@]}" ;; 5) - printf "%sGames:%s\n" "${CYAN}" "${RC}" + print_info "Games:" app_display=("ATLauncher" "Clone Hero" "EA App" "Epic Games Launcher" "Heroic Games Launcher" "Moonlight" "PS Remote Play" "SideQuest" "Steam" "XEMU") app_casks=("atlauncher" "clone-hero" "ea" "epic-games" "heroic" "moonlight" "sony-ps-remote-play" "sidequest" "steam" "xemu") print_columns "${app_display[@]}" - printf "Enter the numbers of the apps you want to install (separated by space): " + print_info "Enter the numbers of the apps you want to install (separated by space): " read -a selected install_casks "${selected[@]}" ;; 6) - printf "%sMultimedia:%s\n" "${CYAN}" "${RC}" + print_info "Multimedia:" app_display=("Audacity" "Blender" "darktable" "draw.io" "foobar2000" "FreeCAD" "GIMP" "HandBrake" "Inkscape" "Jellyfin Media Player" "Jellyfin Server" "Kdenlive" "KiCad" "Krita" "Mp3tag" "OBS" "Plex Media Server" "Plex Desktop" "Shotcut" "Spotify" "Tidal" "VLC" "XnViewMP" "Yt-dip") app_casks=("audacity" "blender" "darktable" "drawio" "foobar2000" "freecad" "gimp" "handbrake" "inkscape" "jellyfin-media-player" "jellyfin" "kdenlive" "kicad" "krita" "mp3tag" "obs" "plex-media-server" "plex" "shotcut" "spotify" "tidal" "vlc" "xnviewmp" "yt-dip") print_columns "${app_display[@]}" - printf "Enter the numbers of the apps you want to install (separated by space): " + print_info "Enter the numbers of the apps you want to install (separated by space): " read -a selected install_casks "${selected[@]}" ;; 7) - printf "%sUtilities:%s\n" "${CYAN}" "${RC}" + print_info "Utilities:" app_display=("1Password" "Alacritty Terminal" "Alfred" "AnyDesk" "AppCleaner" "Barrier" "Bitwarden" "coconutBattery" "Commander One" "CopyQ" "Cpuinfo" "CustomShortcuts" "DevToys" "Dropbox" "Duplicati" "Espanso" "Etcher" "EtreCheck" "Find Any File" "f.lux" "GrandPerspective" "Hidden Bar" "iTerm2" "Itsycal" "KeePassXC" "KeepingYouAwake" "Macs Fan Control" "Malwarebytes" "Memory Cleaner" "Microsoft Remote Desktop" "MonitorControl" "Motrix" "Mullvad VPN" "Nextcloud" "Numi" "OmniDiskSweeper" "OpenRBG" "Ollama" "onyX" "Orca Slicer" "ownCloud" "Parsec" "PowerShell" "Raspberry Pi Imager" "Raycast" "Rectangle" "Renamer" "PrusaSlicer" "qBittorent" "Spacedrive File Manager" "Syncthing" "Tabby.sh" "Tailscale" "TeamViewer" "Termius" "The Unarchiver" "Tiles" "Transmission" "UTM" "Wireshark" "Xtreme Download Manager" "ZeroTier One" ) app_casks=("1password" "alacritty" "alfred" "anydesk" "appcleaner" "barrier" "bitwarden" "coconutbattery" "commander-one" "copyq" "cpuinfo" "customshortcuts" "devtoys" "dropbox" "duplicati" "espanso" "balenaetcher" "etrecheckpro" "find-any-file" "flux" "grandperspective" "hiddenbar" "iterm2" "itsycal" "keepassxc" "keepingyouawake" "macs-fan-control" "malwarebytes" "memory-cleaner" "microsoft-remote-desktop" "monitorcontrol" "motrix" "mullvadvpn" "nextcloud" "numi" "omnidisksweeper" "openrgb" "ollama" "onyx" "orcaslicer" "owncloud" "parsec" "powershell" "raspberry-pi-imager" "raycast" "rectangle" "renamer" "prusaslicer" "qbittorrent" "spacedrive" "syncthing" "tabby" "tailscale" "teamviewer" "termius" "the-unarchiver" "tiles" "transmission" "utm" "wireshark" "xdm" "zerotier-one" ) print_columns "${app_display[@]}" - printf "Enter the numbers of the apps you want to install (separated by space): " + print_info "Enter the numbers of the apps you want to install (separated by space): " read -a selected install_casks "${selected[@]}" ;; - 0) - printf "%sExiting...%s\n" "${YELLOW}" "${RC}" + 8) + print_info "Exiting..." break ;; - *) - printf "%sInvalid choice. Please try again.%s\n" "${RED}" "${RC}" - ;; esac done -# Completion message -printf "%s##########################%s\n" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s##%s%s Installer completed. %s##%s\n" "${YELLOW}" "${RC}" "${GREEN}" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s##########################%s\n" "${YELLOW}" "${RC}" +print_colored "$GREEN" "Installer completed" diff --git a/homebrew_scripts/brew_manager.sh b/homebrew_scripts/brew_manager.sh index a08561a..1609267 100644 --- a/homebrew_scripts/brew_manager.sh +++ b/homebrew_scripts/brew_manager.sh @@ -1,28 +1,22 @@ -#!/bin/bash +#!/bin/sh -# POSIX-compliant color definitions -ESC=$(printf '\033') -RC="${ESC}[0m" # Reset -RED="${ESC}[31m" # Red -GREEN="${ESC}[32m" # Green -YELLOW="${ESC}[33m" # Yellow -BLUE="${ESC}[34m" # Blue -CYAN="${ESC}[36m" # Cyan +# Source the common script +eval "$(curl -s https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/dev/common_script.sh)" # Set the GITPATH variable to the directory where the script is located -GITPATH="$(cd "$(dirname "$0")" && pwd)" -printf "%sGITPATH is set to: %s%s\n" "${CYAN}" "$GITPATH" "${RC}" +GITPATH="$SCRIPT_DIR" +print_info "GITPATH is set to: $GITPATH" # GitHub URL base for the necessary Homebrew scripts -GITHUB_BASE_URL="https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/main/homebrew_scripts" +GITHUB_BASE_URL="http://10.24.24.6:3030/Jaredy89/mac/raw/branch/main/homebrew_scripts" # Function to run the updater script run_updater() { if [[ -f "$GITPATH/brew_updater.sh" ]]; then - printf "%sRunning Brew Updater from local directory...%s\n" "${GREEN}" "${RC}" + print_success "Running Brew Updater from local directory..." bash "$GITPATH/brew_updater.sh" else - printf "%sRunning Brew Updater from GitHub...%s\n" "${YELLOW}" "${RC}" + print_warning "Running Brew Updater from GitHub..." bash -c "$(curl -fsSL $GITHUB_BASE_URL/brew_updater.sh)" fi } @@ -30,10 +24,10 @@ run_updater() { # Function to run the installer script run_installer() { if [[ -f "$GITPATH/brew_installer.sh" ]]; then - printf "%sRunning Brew Installer from local directory...%s\n" "${GREEN}" "${RC}" + print_success "Running Brew Installer from local directory..." bash "$GITPATH/brew_installer.sh" else - printf "%sRunning Brew Installer from GitHub...%s\n" "${YELLOW}" "${RC}" + print_warning "Running Brew Installer from GitHub..." bash -c "$(curl -fsSL $GITHUB_BASE_URL/brew_installer.sh)" fi } @@ -41,49 +35,47 @@ run_installer() { # Function to run the uninstaller script run_uninstaller() { if [[ -f "$GITPATH/brew_uninstaller.sh" ]]; then - printf "%sRunning Brew Uninstaller from local directory...%s\n" "${GREEN}" "${RC}" + print_success "Running Brew Uninstaller from local directory..." bash "$GITPATH/brew_uninstaller.sh" else - printf "%sRunning Brew Uninstaller from GitHub...%s\n" "${YELLOW}" "${RC}" + print_warning "Running Brew Uninstaller from GitHub..." bash -c "$(curl -fsSL $GITHUB_BASE_URL/brew_uninstaller.sh)" fi } -# Function to manage brew operations -manage_brew() { - while true; do - printf "%sPlease select from the following options:%s\n" "${CYAN}" "${RC}" - printf "%s1)%s Run Brew Updater\n" "${GREEN}" "${RC}" - printf "%s2)%s Run Brew Installer\n" "${GREEN}" "${RC}" - printf "%s3)%s Run Brew Uninstaller\n" "${GREEN}" "${RC}" - printf "%s0)%s Return to main menu\n" "${RED}" "${RC}" - printf "Enter your choice (0-3): " - read choice - - case $choice in - 1) - printf "%sRunning Brew Updater...%s\n" "${CYAN}" "${RC}" - run_updater - ;; - 2) - printf "%sRunning Brew Installer...%s\n" "${CYAN}" "${RC}" - run_installer - ;; - 3) - printf "%sRunning Brew Uninstaller...%s\n" "${CYAN}" "${RC}" - run_uninstaller - ;; - 0) - printf "%sReturning to main menu.%s\n" "${YELLOW}" "${RC}" - break - ;; - *) - printf "%sInvalid option. Please enter a number between 0 and 3.%s\n" "${RED}" "${RC}" - ;; - esac - printf "\n" - done +# Function to show brew menu items +show_brew_menu() { + show_menu_item 1 "$selected" "Run Brew Updater" + show_menu_item 2 "$selected" "Run Brew Installer" + show_menu_item 3 "$selected" "Run Brew Uninstaller" + show_menu_item 4 "$selected" "Return to main menu" } -# Run the brew manager -manage_brew +# Keep running until user chooses to exit +while true; do + # Handle menu selection + handle_menu_selection 4 "Homebrew Manager" show_brew_menu + choice=$? + + case $choice in + 1) + print_info "Running Brew Updater..." + run_updater + print_colored "$GREEN" "Update completed" + ;; + 2) + print_info "Running Brew Installer..." + run_installer + print_colored "$GREEN" "Installer completed" + ;; + 3) + print_info "Running Brew Uninstaller..." + run_uninstaller + print_colored "$GREEN" "Uninstaller completed" + ;; + 4) + print_info "Returning to main menu." + break + ;; + esac +done diff --git a/homebrew_scripts/brew_uninstaller.sh b/homebrew_scripts/brew_uninstaller.sh index b9584d2..db82cc2 100644 --- a/homebrew_scripts/brew_uninstaller.sh +++ b/homebrew_scripts/brew_uninstaller.sh @@ -1,19 +1,13 @@ -#!/bin/bash +#!/bin/sh -# POSIX-compliant color definitions -ESC=$(printf '\033') -RC="${ESC}[0m" # Reset -RED="${ESC}[31m" # Red -GREEN="${ESC}[32m" # Green -YELLOW="${ESC}[33m" # Yellow -BLUE="${ESC}[34m" # Blue -CYAN="${ESC}[36m" # Cyan +# Source the common script +eval "$(curl -s https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/dev/common_script.sh)" # Function to uninstall selected casks function uninstall_casks { local selected_casks=("$@") for cask in "${selected_casks[@]}"; do - printf "%sUninstalling %s...%s\n" "${CYAN}" "$cask" "${RC}" + print_info "Uninstalling $cask..." brew uninstall --cask "$cask" done } @@ -29,24 +23,31 @@ function print_columns { for (( j=0; j<$num_columns; j++ )); do index=$(( i + j * rows )) if [ $index -lt $num_apps ]; then - printf "%s%-3d)%s %-22s" "${GREEN}" "$((index + 1))" "${RC}" "${app_list[$index]}" + # Format the number with padding + num=$((index+1)) + if [ $num -lt 10 ]; then + num_pad=" $num" + else + num_pad="$num" + fi + printf " %s) %-25s" "$num_pad" "${app_list[$index]}" fi done - printf "\n" + echo done } # Function to list installed casks and prompt for uninstallation function list_and_uninstall { - printf "%sChecking installed Homebrew casks...%s\n" "${CYAN}" "${RC}" + print_info "Checking installed Homebrew casks..." installed_casks=$(brew list --cask) if [ -z "$installed_casks" ]; then - printf "%sNo casks are currently installed.%s\n" "${YELLOW}" "${RC}" + print_warning "No casks are currently installed." return fi - printf "%sInstalled casks:%s\n" "${CYAN}" "${RC}" + print_info "Installed casks:" cask_list=() for cask in $installed_casks; do cask_list+=("$cask") @@ -54,7 +55,7 @@ function list_and_uninstall { print_columns "${cask_list[@]}" - printf "Enter the numbers of the casks you want to uninstall (separated by space), or press Enter to skip: " + print_info "Enter the numbers of the casks you want to uninstall (separated by space), or press Enter to skip: " read -a selected if [ ${#selected[@]} -gt 0 ]; then selected_casks=() @@ -63,16 +64,11 @@ function list_and_uninstall { done uninstall_casks "${selected_casks[@]}" else - printf "%sNo casks selected for uninstallation.%s\n" "${YELLOW}" "${RC}" + print_warning "No casks selected for uninstallation." fi } # Main script list_and_uninstall -# Completion message -printf "%s############################%s\n" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s##%s%s Uninstaller completed. %s##%s\n" "${YELLOW}" "${RC}" "${GREEN}" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s############################%s\n" "${YELLOW}" "${RC}" \ No newline at end of file +print_colored "$GREEN" "Uninstaller completed" diff --git a/homebrew_scripts/brew_updater.sh b/homebrew_scripts/brew_updater.sh index 29b1947..8d9583c 100644 --- a/homebrew_scripts/brew_updater.sh +++ b/homebrew_scripts/brew_updater.sh @@ -1,17 +1,11 @@ -#!/bin/bash +#!/bin/sh -# POSIX-compliant color definitions -ESC=$(printf '\033') -RC="${ESC}[0m" # Reset -RED="${ESC}[31m" # Red -GREEN="${ESC}[32m" # Green -YELLOW="${ESC}[33m" # Yellow -BLUE="${ESC}[34m" # Blue -CYAN="${ESC}[36m" # Cyan +# Source the common script +eval "$(curl -s https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/dev/common_script.sh)" # Function to refresh sudo credentials function refresh_sudo { - printf "%sRefreshing sudo credentials...%s\n" "${CYAN}" "${RC}" + print_info "Refreshing sudo credentials..." sudo -v } @@ -32,7 +26,7 @@ function show_spinner { # Function to show a simple progress bar using dots function show_progress { while true; do - printf "%s.%s" "${CYAN}" "${RC}" + printf "." sleep 0.5 done } @@ -40,7 +34,7 @@ function show_progress { # Function to update a specific Homebrew item if it's outdated function update_brew_item { local item=$1 - printf "%sUpdating %s%s" "${CYAN}" "$item" "${RC}" + print_info "Updating $item" show_progress & progress_pid=$! @@ -52,18 +46,18 @@ function update_brew_item { wait $progress_pid 2>/dev/null if echo "$output" | grep -q "password"; then - printf "\r%s%s requires password. Running without progress indicator...%s\n" "${YELLOW}" "$item" "${RC}" + print_warning "$item requires password. Running without progress indicator..." if brew upgrade "$item"; then - printf "%s%s update completed!%s\n" "${GREEN}" "$item" "${RC}" + print_success "$item update completed!" else - printf "\r%sFailed to update %s. Please check manually.%s\n" "${RED}" "$item" "${RC}" + print_error "Failed to update $item. Please check manually." fi elif echo "$output" | grep -q "already installed"; then - printf "\r%s%s is already up to date!%s\n" "${GREEN}" "$item" "${RC}" + print_success "$item is already up to date!" elif brew upgrade "$item" &>/dev/null; then - printf "\r%s%s updated successfully!%s\n" "${GREEN}" "$item" "${RC}" + print_success "$item updated successfully!" else - printf "\r%sFailed to update %s. Please check manually.%s\n" "${RED}" "$item" "${RC}" + print_error "Failed to update $item. Please check manually." fi } @@ -72,7 +66,7 @@ function update_brew_items { installed_formulae=$(brew list --formula) installed_casks=$(brew list --cask) - printf "%sChecking for updates to Homebrew apps and casks...%s\n" "${CYAN}" "${RC}" + print_info "Checking for updates to Homebrew apps and casks..." (brew outdated --formula > /tmp/brew_outdated_formula.txt) & spinner_pid=$! @@ -81,38 +75,15 @@ function update_brew_items { outdated_formulae=$(cat /tmp/brew_outdated_formula.txt) if [ -n "$outdated_formulae" ]; then - printf "%sOutdated formulae found. Updating...%s\n" "${YELLOW}" "${RC}" + print_warning "Outdated formulae found. Updating..." for item in $outdated_formulae; do update_brew_item "$item" done fi - printf "%sUpdating all casks...%s\n" "${CYAN}" "${RC}" + print_info "Updating all casks..." for cask in $installed_casks; do - printf "%sUpdating %s%s" "${CYAN}" "$cask" "${RC}" - show_progress & - progress_pid=$! - - output=$(brew install --cask "$cask" 2>&1 || true) - - # Always kill the progress indicator first - kill $progress_pid > /dev/null 2>&1 - wait $progress_pid 2>/dev/null - - if echo "$output" | grep -q "password"; then - printf "\r%s%s requires password. Running without progress indicator...%s\n" "${YELLOW}" "$cask" "${RC}" - if brew install --cask "$cask"; then - printf "%s%s update completed!%s\n" "${GREEN}" "$cask" "${RC}" - else - printf "\r%sFailed to update %s. Please check manually.%s\n" "${RED}" "$cask" "${RC}" - fi - elif echo "$output" | grep -q "already installed"; then - printf "\r%s%s is already up to date!%s\n" "${GREEN}" "$cask" "${RC}" - elif brew install --cask "$cask" &>/dev/null; then - printf "\r%s%s updated successfully!%s\n" "${GREEN}" "$cask" "${RC}" - else - printf "\r%sFailed to update %s. Please check manually.%s\n" "${RED}" "$cask" "${RC}" - fi + update_brew_item "$cask" done rm /tmp/brew_outdated_formula.txt @@ -122,9 +93,4 @@ function update_brew_items { refresh_sudo update_brew_items -# Final message -printf "%s#################################################%s\n" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s##%s%s All Homebrew apps and casks are up to date! %s##%s\n" "${YELLOW}" "${RC}" "${GREEN}" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s#################################################%s\n" "${YELLOW}" "${RC}" +print_colored "$GREEN" "Update completed" diff --git a/my_apps/upgrade_apps.sh b/my_apps/upgrade_apps.sh deleted file mode 100644 index 970e123..0000000 --- a/my_apps/upgrade_apps.sh +++ /dev/null @@ -1 +0,0 @@ -brew install --cask alex313031-thorium balenaetcher brave-browser chatgpt cloudflare-warp commander-one crystalfetch cursor eloston-chromium firefox grandperspective google-drive handbrake microsoft-edge microsoft-remote-desktop ollama orbstack parsec powershell raspberry-pi-imager raycast rustdesk spotify steam sublime-text tabby tailscale termius the-unarchiver utm visual-studio-code vlc vscodium zoom diff --git a/myzsh/myzsh.sh b/myzsh/myzsh.sh index b444b1a..c4cf8b9 100644 --- a/myzsh/myzsh.sh +++ b/myzsh/myzsh.sh @@ -1,17 +1,11 @@ #!/usr/bin/env zsh -# POSIX-compliant color definitions -ESC=$(printf '\033') -RC="${ESC}[0m" # Reset -RED="${ESC}[31m" # Red -GREEN="${ESC}[32m" # Green -YELLOW="${ESC}[33m" # Yellow -BLUE="${ESC}[34m" # Blue -CYAN="${ESC}[36m" # Cyan +# Source the common script +eval "$(curl -s https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/dev/common_script.sh)" # Set the GITPATH variable to the directory where the script is located -GITPATH="$(cd "$(dirname "$0")" && pwd)" -printf "%sGITPATH is set to: %s%s\n" "${CYAN}" "$GITPATH" "${RC}" +GITPATH="$SCRIPT_DIR" +print_info "GITPATH is set to: $GITPATH" # GitHub URL base for the necessary configuration files GITHUB_BASE_URL="https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/main/myzsh" @@ -21,11 +15,11 @@ installDepend() { # List of dependencies DEPENDENCIES=(zsh zsh-autocomplete bat tree multitail fastfetch wget unzip fontconfig starship fzf zoxide) - printf "%sInstalling dependencies...%s\n" "${CYAN}" "${RC}" + print_info "Installing dependencies..." for package in "${DEPENDENCIES[@]}"; do - printf "%sInstalling %s...%s\n" "${CYAN}" "$package" "${RC}" + print_info "Installing $package..." if ! brew install "$package"; then - printf "%sFailed to install %s. Please check your brew installation.%s\n" "${RED}" "$package" "${RC}" + print_error "Failed to install $package. Please check your brew installation." exit 1 fi done @@ -33,11 +27,11 @@ installDepend() { # List of cask dependencies CASK_DEPENDENCIES=("alacritty" "kitty" "tabby" "font-fira-code-nerd-font") - printf "%sInstalling cask dependencies: %s%s\n" "${CYAN}" "${CASK_DEPENDENCIES[*]}" "${RC}" + print_info "Installing cask dependencies: ${CASK_DEPENDENCIES[*]}" for cask in "${CASK_DEPENDENCIES[@]}"; do - printf "%sInstalling %s...%s\n" "${CYAN}" "$cask" "${RC}" + print_info "Installing $cask..." if ! brew install --cask "$cask"; then - printf "%sFailed to install %s. Please check your brew installation.%s\n" "${RED}" "$cask" "${RC}" + print_error "Failed to install $cask. Please check your brew installation." exit 1 fi done @@ -59,15 +53,15 @@ linkConfig() { # Handle fastfetch config FASTFETCH_CONFIG="$CONFIG_DIR/fastfetch/config.jsonc" if [ -f "$GITPATH/config.jsonc" ]; then - printf "%sLinking config.jsonc...%s\n" "${CYAN}" "${RC}" + print_info "Linking config.jsonc..." ln -svf "$GITPATH/config.jsonc" "$FASTFETCH_CONFIG" || { - printf "%sFailed to create symbolic link for config.jsonc%s\n" "${RED}" "${RC}" + print_error "Failed to create symbolic link for config.jsonc" exit 1 } else - printf "%sDownloading config.jsonc from GitHub...%s\n" "${YELLOW}" "${RC}" + print_warning "Downloading config.jsonc from GitHub..." curl -fsSL "$GITHUB_BASE_URL/config.jsonc" -o "$FASTFETCH_CONFIG" || { - printf "%sFailed to download config.jsonc from GitHub.%s\n" "${RED}" "${RC}" + print_error "Failed to download config.jsonc from GitHub." exit 1 } fi @@ -75,15 +69,15 @@ linkConfig() { # Handle starship config STARSHIP_CONFIG="$CONFIG_DIR/starship.toml" if [ -f "$GITPATH/starship.toml" ]; then - printf "%sLinking starship.toml...%s\n" "${CYAN}" "${RC}" + print_info "Linking starship.toml..." ln -svf "$GITPATH/starship.toml" "$STARSHIP_CONFIG" || { - printf "%sFailed to create symbolic link for starship.toml%s\n" "${RED}" "${RC}" + print_error "Failed to create symbolic link for starship.toml" exit 1 } else - printf "%sDownloading starship.toml from GitHub...%s\n" "${YELLOW}" "${RC}" + print_warning "Downloading starship.toml from GitHub..." curl -fsSL "$GITHUB_BASE_URL/starship.toml" -o "$STARSHIP_CONFIG" || { - printf "%sFailed to download starship.toml from GitHub.%s\n" "${RED}" "${RC}" + print_error "Failed to download starship.toml from GitHub." exit 1 } fi @@ -96,19 +90,19 @@ replace_zshrc() { ZSHRC_SOURCE="$GITPATH/.zshrc" if [ -f "$ZSHRC_FILE" ]; then - printf "%sBacking up existing .zshrc to .zshrc.backup...%s\n" "${YELLOW}" "${RC}" + print_warning "Backing up existing .zshrc to .zshrc.backup..." cp "$ZSHRC_FILE" "$ZSHRC_FILE.backup" fi if [ -f "$ZSHRC_SOURCE" ]; then - printf "%sReplacing .zshrc with the new version...%s\n" "${CYAN}" "${RC}" + print_info "Replacing .zshrc with the new version..." cp "$ZSHRC_SOURCE" "$ZSHRC_FILE" else - printf "%sDownloading .zshrc from GitHub...%s\n" "${YELLOW}" "${RC}" + print_warning "Downloading .zshrc from GitHub..." if curl -fsSL "$GITHUB_BASE_URL/.zshrc" -o "$ZSHRC_FILE"; then - printf "%sDownloaded .zshrc successfully.%s\n" "${GREEN}" "${RC}" + print_success "Downloaded .zshrc successfully." else - printf "%sFailed to download .zshrc from GitHub.%s\n" "${RED}" "${RC}" + print_error "Failed to download .zshrc from GitHub." exit 1 fi fi @@ -118,12 +112,3 @@ replace_zshrc() { installDepend linkConfig replace_zshrc - -# Final message -printf "%s###########################################################################%s\n" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s##%s%s Use the terminal of your choice and change the font to Fira-Code NF. %s##%s\n" "${YELLOW}" "${RC}" "${CYAN}" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s##%s%s Setup completed successfully. %s##%s\n" "${YELLOW}" "${RC}" "${GREEN}" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s##########################################################################%s\n" "${YELLOW}" "${RC}" diff --git a/settings.sh b/settings.sh index 76c7183..126e89b 100644 --- a/settings.sh +++ b/settings.sh @@ -1,20 +1,14 @@ -#!/bin/bash +#!/bin/sh -# POSIX-compliant color definitions -ESC=$(printf '\033') -RC="${ESC}[0m" # Reset -RED="${ESC}[31m" # Red -GREEN="${ESC}[32m" # Green -YELLOW="${ESC}[33m" # Yellow -BLUE="${ESC}[34m" # Blue -CYAN="${ESC}[36m" # Cyan +# Source the common script +eval "$(curl -s https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/dev/common_script.sh)" # Check for sudo privileges and request if needed check_sudo() { if [ "$EUID" -ne 0 ]; then - printf "%sThis script requires sudo privileges for some operations.%s\n" "${YELLOW}" "${RC}" + print_warning "This script requires sudo privileges for some operations." sudo -v || { - printf "%sFailed to obtain sudo privileges. Exiting.%s\n" "${RED}" "${RC}" + print_error "Failed to obtain sudo privileges. Exiting." exit 1 } # Keep sudo alive @@ -24,7 +18,7 @@ check_sudo() { # Function to setup Kitty keyboard shortcut setup_kitty_shortcut() { - printf "%sSetting up Kitty keyboard shortcut...%s\n" "${CYAN}" "${RC}" + print_info "Setting up Kitty keyboard shortcut..." # Create Scripts directory if it doesn't exist mkdir -p ~/Library/Scripts @@ -38,32 +32,32 @@ EOF chmod +x ~/Library/Scripts/open-kitty.scpt - printf "%sKitty shortcut script created at ~/Library/Scripts/open-kitty.scpt%s\n" "${GREEN}" "${RC}" - printf "%sPlease set up your keyboard shortcut manually in System Settings > Keyboard > Keyboard Shortcuts%s\n" "${YELLOW}" "${RC}" + print_success "Kitty shortcut script created at ~/Library/Scripts/open-kitty.scpt" + print_warning "Please set up your keyboard shortcut manually in System Settings > Keyboard > Keyboard Shortcuts" } # Function to toggle window tiling toggle_window_tiling() { - printf "%sToggling window tiling settings...%s\n" "${CYAN}" "${RC}" + print_info "Toggling window tiling settings..." current_state=$(defaults read com.apple.dock window-tiling-enabled) if [ "$current_state" = "1" ]; then defaults write com.apple.dock window-tiling-enabled -bool false defaults write com.apple.dock window-tiling-margin -int 0 - printf "%sWindow tiling disabled%s\n" "${YELLOW}" "${RC}" + print_warning "Window tiling disabled" else defaults write com.apple.dock window-tiling-enabled -bool true defaults write com.apple.dock window-tiling-margin -int 5 - printf "%sWindow tiling enabled%s\n" "${GREEN}" "${RC}" + print_success "Window tiling enabled" fi killall Dock - printf "%sDock restarted with new settings%s\n" "${GREEN}" "${RC}" + print_success "Dock restarted with new settings" } # Function to configure trackpad settings configure_trackpad() { - printf "%sConfiguring trackpad settings...%s\n" "${CYAN}" "${RC}" + print_info "Configuring trackpad settings..." defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true defaults write com.apple.AppleMultitouchTrackpad Clicking -bool true @@ -72,31 +66,31 @@ configure_trackpad() { defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadThreeFingerHorizSwipeGesture -int 1 defaults write com.apple.AppleMultitouchTrackpad TrackpadThreeFingerHorizSwipeGesture -int 1 - printf "%sTrackpad settings updated successfully%s\n" "${GREEN}" "${RC}" + print_success "Trackpad settings updated successfully" } # Function to configure dock settings configure_dock() { - printf "%sConfiguring dock settings...%s\n" "${CYAN}" "${RC}" + print_info "Configuring dock settings..." defaults write com.apple.dock autohide -bool true killall Dock - printf "%sDock settings updated%s\n" "${GREEN}" "${RC}" + print_success "Dock settings updated" } # Function to enable SSH access enable_ssh() { - printf "%sEnabling SSH access...%s\n" "${CYAN}" "${RC}" + print_info "Enabling SSH access..." sudo systemsetup -setremotelogin on sudo systemsetup -getremotelogin - printf "%sSSH access enabled%s\n" "${GREEN}" "${RC}" + print_success "SSH access enabled" } # Main execution -printf "%sStarting macOS setup script...%s\n" "${CYAN}" "${RC}" +print_info "Starting macOS setup script..." check_sudo setup_kitty_shortcut @@ -105,4 +99,4 @@ configure_trackpad configure_dock enable_ssh -printf "%sSetup complete!%s\n" "${GREEN}" "${RC}" \ No newline at end of file +print_colored "$GREEN" "Setup complete!" diff --git a/setup.sh b/setup.sh index 76bb100..35c0220 100644 --- a/setup.sh +++ b/setup.sh @@ -1,20 +1,15 @@ -#!/bin/bash +#!/bin/sh -# POSIX-compliant color definitions using printf -# Store the escape sequence in a more portable way -ESC=$(printf '\033') -RC="${ESC}[0m" -RED="${ESC}[31m" -YELLOW="${ESC}[33m" -CYAN="${ESC}[36m" -GREEN="${ESC}[32m" +# Source the common script +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +eval "$(curl -s https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/dev/common_script.sh)" # Set the GITPATH variable to the directory where the script is located -GITPATH="$(cd "$(dirname "$0")" && pwd)" -echo "GITPATH is set to: $GITPATH" +GITPATH="$SCRIPT_DIR" +print_info "GITPATH is set to: $GITPATH" # GitHub URL base for the necessary configuration files -GITHUB_BASE_URL="https://raw.githubusercontent.com/Jaredy899/mac/refs/heads/main" +GITHUB_BASE_URL="http://10.24.24.6:3030/Jaredy89/mac/raw/branch/main/" # Function to install Homebrew install_homebrew() { @@ -24,10 +19,10 @@ install_homebrew() { # Function to run the brew_manager.sh script from local or GitHub run_brew_manager() { if [[ -f "$GITPATH/homebrew_scripts/brew_manager.sh" ]]; then - echo "Running brew_manager.sh from local directory..." + print_info "Running brew_manager.sh from local directory..." bash "$GITPATH/homebrew_scripts/brew_manager.sh" else - echo "Running brew_manager.sh from GitHub..." + print_warning "Running brew_manager.sh from GitHub..." bash -c "$(curl -fsSL $GITHUB_BASE_URL/homebrew_scripts/brew_manager.sh)" fi } @@ -66,62 +61,75 @@ run_settings() { fi } +# Function to run the add_ssh_key.sh script from local or GitHub +run_ssh_key_setup() { + if [[ -f "$GITPATH/add_ssh_key.sh" ]]; then + print_info "Running add_ssh_key.sh from local directory..." + sh "$GITPATH/add_ssh_key.sh" + else + print_warning "Running add_ssh_key.sh from GitHub..." + sh -c "$(curl -fsSL $GITHUB_BASE_URL/add_ssh_key.sh)" + fi +} + # Check if Homebrew is installed and install it if not if ! command -v brew &> /dev/null; then - echo "Homebrew is required but not installed. Installing Homebrew..." + print_warning "Homebrew is required but not installed. Installing Homebrew..." install_homebrew # Add Homebrew to PATH and source it immediately echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> "$HOME/.zprofile" eval "$(/opt/homebrew/bin/brew shellenv)" else - echo "Homebrew is already installed." + print_success "Homebrew is already installed." # Ensure Homebrew is in PATH for the current session eval "$(/opt/homebrew/bin/brew shellenv)" fi -# Menu to choose which scripts to run +# Function to show menu items +show_setup_menu() { + show_menu_item 1 "$selected" "Run Homebrew Manager to manage Homebrew apps and casks" + show_menu_item 2 "$selected" "Run Dock Manager to manage Dock items" + show_menu_item 3 "$selected" "Run myzsh to enhance your terminal appearance" + show_menu_item 4 "$selected" "Run Settings Manager to configure system settings" + show_menu_item 5 "$selected" "Setup SSH Keys" + show_menu_item 6 "$selected" "Exit" +} + +# Keep running until user chooses to exit while true; do - printf "%sPlease select from the following options:%s\n" "${CYAN}" "${RC}" - printf "%s1)%s Run Homebrew Manager to manage Homebrew apps and casks\n" "${GREEN}" "${RC}" - printf "%s2)%s Run Dock Manager to manage Dock items\n" "${GREEN}" "${RC}" - printf "%s3)%s Run myzsh to enhance your terminal appearance\n" "${GREEN}" "${RC}" - printf "%s4)%s Run Settings Manager to configure system settings\n" "${GREEN}" "${RC}" - printf "%s0)%s Exit\n" "${RED}" "${RC}" - printf "Enter your choice (1-4): " - read choice + # Handle menu selection + handle_menu_selection 6 "Setup Menu" show_setup_menu + choice=$? case $choice in 1) - echo "Running Homebrew Manager..." + print_info "Running Homebrew Manager..." run_brew_manager ;; 2) - echo "Running Dock Manager..." + print_info "Running Dock Manager..." run_dock_manager ;; 3) - echo "Enhancing terminal appearance with myzsh..." + print_info "Enhancing terminal appearance with myzsh..." run_myzsh ;; 4) - echo "Running Settings Manager..." + print_info "Running Settings Manager..." run_settings ;; - 0) - echo "Exiting setup script." - break + 5) + print_info "Setting up SSH Keys..." + run_ssh_key_setup ;; - *) - echo "Invalid option. Please enter a number between 1 and 4." + 6) + print_info "Exiting setup script." + break ;; esac done # Update the completion message -printf "%s#############################%s\n" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s##%s%s Setup script completed. %s##%s\n" "${YELLOW}" "${RC}" "${GREEN}" "${YELLOW}" "${RC}" -printf "%s##%s %s##%s\n" "${YELLOW}" "${RC}" "${YELLOW}" "${RC}" -printf "%s#############################%s\n" "${YELLOW}" "${RC}" +print_colored "$GREEN" "Setup completed"