#!/bin/zsh # created by Dennis Kidd # This script installs the selected applications # Check if the script is running as root if [ "$EUID" -ne 0 ]; then echo 'Please run this script with sudo:' echo 'sudo $0' exit 1 fi CURRENT_USER=$(ls -l /dev/console | awk '{print $3}') # Get system info and log to server COMPUTER_NAME=$(scutil --get ComputerName) IP_ADDRESS=$(ipconfig getifaddr en0) SERIAL_NUMBER=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}') MACOS_VERSION=$(sw_vers -productVersion) APPS="sitemap.xml" curl -X POST https://macapps.jh.edu/log-system-info \ -d "computer_name=$COMPUTER_NAME&ip_address=$IP_ADDRESS&serial_number=$SERIAL_NUMBER&macos_version=$MACOS_VERSION&apps=$APPS" INSTALLER_DIR="/var/tmp/macapps-$(date +%Y%m%d%H%M%S)" rm -rf "$INSTALLER_DIR" && mkdir "$INSTALLER_DIR" && cd "$INSTALLER_DIR" clear echo '' echo 'MacApps.jh.edu created by 👨‍💻 Dennis Kidd dennis@jhu.edu' echo '' echo '🚀 Installing your selected applications...' echo '' # Function to check for errors but continue check_error() { if [ $? -ne 0 ]; then echo X ${1} installation failed. echo "X ${1} installation failed." >> $INSTALLER_DIR/install_errors.log else echo ✓ ${1} installed. echo "✓ ${1} installed successfully." >> $INSTALLER_DIR/install_log.log fi } # Function to install .dmg applications install_app() { local name="$1" local url="$2" local dmg_path="$INSTALLER_DIR/${name}.dmg" local volume_name="$3" echo '☁️ Downloading '${name}'...' curl -# -L -o "${dmg_path}" "${url}" hdiutil attach "${dmg_path}" -quiet -nobrowse cp -pPR "/Volumes/${volume_name}/${name}.app" /Applications/ hdiutil detach "/Volumes/${volume_name}" -quiet > /dev/null 2>&1 check_error ${name} if $4; then sudo -u $CURRENT_USER open -a '/Applications/'"$1"'.app' fi } # Display installation summary display_summary() { echo '📋 Installation Summary:' if [ -f $INSTALLER_DIR/install_log.log ]; then cat $INSTALLER_DIR/install_log.log fi if [ -f $INSTALLER_DIR/install_errors.log ]; then echo '' echo '❗️ Errors occurred during installation:' cat $INSTALLER_DIR/install_errors.log else echo '' echo '🎉 All applications were installed successfully.' echo '' fi } # Function to install Rosetta 2 (for Apple Silicon Macs) install_rosetta() { if [[ "$(uname -m)" == "arm64" ]]; then echo 'Apple Silicon Mac detected.' if /usr/bin/pgrep oahd >/dev/null 2>&1; then echo 'Rosetta 2 is already installed.' else echo 'Rosetta 2 is not installed. Installing now...' echo '☁️ Installing Rosetta 2...'; /usr/sbin/softwareupdate --install-rosetta --agree-to-license >/dev/null 2>&1; if [ $? -eq 0 ]; then echo '✓ Rosetta 2 installed.' else echo '⚠️ Rosetta 2 installation failed.' fi fi else echo 'Intel Mac detected. No need to install Rosetta.' fi } echo 'Application "sitemap.xml" is not recognized.' display_summary