From 69d55ed599aae7937baf765bbe5bf675054239bf Mon Sep 17 00:00:00 2001 From: Joakim Hunskaar Date: Fri, 22 May 2026 16:22:27 +0200 Subject: [PATCH 1/2] install tools using bash script on mac --- mac/mac_installer.sh | 179 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 mac/mac_installer.sh diff --git a/mac/mac_installer.sh b/mac/mac_installer.sh new file mode 100644 index 0000000..d8c17fe --- /dev/null +++ b/mac/mac_installer.sh @@ -0,0 +1,179 @@ +#!/bin/bash + +# TDT4102 Tools Installation Script for macOS +# Installs: Xcode CLI Tools, Homebrew, Meson, Ninja, SDL2 libraries + +set -e # Exit on error + +MIN_MACOS_VERSION="13.0.0" +MIN_MESON_VERSION="1.3.0" + +version_gte() { + local v1 v2 + IFS='.' read -ra v1 <<< "$1" + IFS='.' read -ra v2 <<< "$2" + for i in 0 1 2; do + local n1=${v1[$i]:-0} n2=${v2[$i]:-0} + (( n1 > n2 )) && return 0 + (( n1 < n2 )) && return 1 + done + return 0 +} + +check_macos_version() { + local version + version=$(sw_vers -productVersion) + if ! version_gte "$version" "$MIN_MACOS_VERSION"; then + echo "macOS $version is not supported (minimum: $MIN_MACOS_VERSION)" + echo "Please update macOS or contact course staff." + return 1 + fi +} + +install_xcode_tools() { + if xcode-select -p &>/dev/null; then + return 0 + fi + + echo "Installing Xcode Command Line Tools..." + echo "A dialog may appear - please follow the instructions." + echo "This may take a while..." + + xcode-select --install 2>/dev/null || true + + #xcode-select --install returns immediately (new process starts), so we timeout to wait for installation + local timeout=1800 elapsed=0 + while ! xcode-select -p &>/dev/null; do + sleep 5 + elapsed=$((elapsed + 5)) + if [ $elapsed -ge $timeout ]; then + echo "Xcode installation timed out. Run manually: xcode-select --install" + return 1 + fi + done + return 0 + +} + +install_homebrew() { + if command -v brew &>/dev/null; then + return 0 + fi + + echo "Installing Homebrew..." + echo "You might be asked for your password during installation." + + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + + local arch + arch=$(uname -m) + + # Apple Silicon + if [ "$arch" = "arm64" ]; then + if [ ! -f ~/.zshenv ] || ! grep -q '/opt/homebrew/bin/brew shellenv' ~/.zshenv; then + echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshenv + fi + eval "$(/opt/homebrew/bin/brew shellenv)" + else + # Intel + if [ ! -f ~/.zshenv ] || ! grep -q '/usr/local/opt' ~/.zshenv; then + echo 'PATH="/usr/local/opt:$PATH"' >> ~/.zshenv + fi + export PATH="/usr/local/opt:$PATH" + fi + + [ -f ~/.zshenv ] && source ~/.zshenv + + if command -v brew &>/dev/null; then + return 0 + else + echo "Homebrew installation failed." + return 1 + fi +} + + +install_brew_tools() { + echo "Installing Meson, Ninja, and required libraries..." + local packages=( + "meson" + "sdl2" + "sdl2_image" + "sdl2_mixer" + "jpeg-turbo" + "libpng" + "libtiff" + "cmake" + ) + brew install "${packages[@]}" + + # Check Meson + if ! command -v meson &>/dev/null; then + echo "Meson installation failed." + return 1 + fi + local meson_version + meson_version=$(meson --version) + if ! version_gte "$meson_version" "$MIN_MESON_VERSION"; then + echo "Meson version outdated. Try: brew upgrade meson" + return 1 + fi + # Check Ninja + if ! command -v ninja &>/dev/null; then + echo "Ninja installation failed." + return 1 + fi + # Check libraries + local installed all_ok=true + installed=$(brew list) + for pkg in "sdl2" "sdl2_image" "sdl2_mixer" "jpeg-turbo" "libpng" "libtiff" "cmake"; do + if ! echo "$installed" | grep -q "$pkg"; then + echo "Package '$pkg' failed to install." + all_ok=false + fi + done + if [ "$all_ok" = true ]; then + return 0 + else + echo "One or more libraries failed to install." + return 1 + fi +} + +main() { + echo "TDT4102 Tools Installation Script for macOS" + echo "" + + # Check macOS version + if ! check_macos_version; then + exit 1 + fi + + # Install Xcode Command Line Tools + if ! install_xcode_tools; then + exit 1 + fi + # Implicitly verifies clang + + # Install Homebrew + if ! install_homebrew; then + exit 1 + fi + + # Update Homebrew + echo "Updating Homebrew..." + brew update || echo "brew update failed, proceeding..." + brew upgrade || echo "brew upgrade failed, proceeding..." + + # Install Meson, Ninja, and libraries (all Homebrew tools) + if ! install_brew_tools; then + exit 1 + fi + + echo "" + echo "Installation complete!" + echo "Please restart VS Code to apply changes." +} + +#Run main +main "$@" From ba7fec64976d116329d4990b40bd36b318b326e2 Mon Sep 17 00:00:00 2001 From: Joakim Hunskaar Date: Tue, 26 May 2026 15:25:54 +0200 Subject: [PATCH 2/2] added flags and verbose logging --- {mac => setup}/mac_installer.sh | 109 ++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 39 deletions(-) rename {mac => setup}/mac_installer.sh (65%) diff --git a/mac/mac_installer.sh b/setup/mac_installer.sh similarity index 65% rename from mac/mac_installer.sh rename to setup/mac_installer.sh index d8c17fe..83fd048 100644 --- a/mac/mac_installer.sh +++ b/setup/mac_installer.sh @@ -5,8 +5,14 @@ set -e # Exit on error -MIN_MACOS_VERSION="13.0.0" -MIN_MESON_VERSION="1.3.0" +# +MIN_MACOS_VERSION="14.0.0" +MIN_MESON_VERSION="1.11.0" + +INSTALL_XCODE=0 +INSTALL_HOMEBREW=0 +INSTALL_MESON=0 +INSTALL_LIBS=0 version_gte() { local v1 v2 @@ -31,10 +37,13 @@ check_macos_version() { } install_xcode_tools() { + echo "Checking if Xcode Command Line Tools are installed... " if xcode-select -p &>/dev/null; then + echo "Xcode Command Line Tools are already installed, skipping..." return 0 fi + echo "Xcode Command Line Tools are not installed!" echo "Installing Xcode Command Line Tools..." echo "A dialog may appear - please follow the instructions." echo "This may take a while..." @@ -51,15 +60,18 @@ install_xcode_tools() { return 1 fi done + echo "Xcode Command Line Tools installed." return 0 - } install_homebrew() { + echo "Checking if Homebrew is installed..." if command -v brew &>/dev/null; then + echo "Homebrew is already installed, skipping..." return 0 fi + echo "Homebrew is not installed!" echo "Installing Homebrew..." echo "You might be asked for your password during installation." @@ -85,6 +97,7 @@ install_homebrew() { [ -f ~/.zshenv ] && source ~/.zshenv if command -v brew &>/dev/null; then + echo "Homebrew installed." return 0 else echo "Homebrew installation failed." @@ -92,21 +105,11 @@ install_homebrew() { fi } +install_meson() { + echo "Installing Meson and Ninja" -install_brew_tools() { - echo "Installing Meson, Ninja, and required libraries..." - local packages=( - "meson" - "sdl2" - "sdl2_image" - "sdl2_mixer" - "jpeg-turbo" - "libpng" - "libtiff" - "cmake" - ) - brew install "${packages[@]}" - + brew install meson + # Check Meson if ! command -v meson &>/dev/null; then echo "Meson installation failed." @@ -119,10 +122,26 @@ install_brew_tools() { return 1 fi # Check Ninja - if ! command -v ninja &>/dev/null; then + if ! command --version ninja &>/dev/null; then echo "Ninja installation failed." return 1 fi +} + + +install_libraries() { + echo "Installing required libraries..." + local libs=( + "sdl2" + "sdl2_image" + "sdl2_mixer" + "jpeg-turbo" + "libpng" + "libtiff" + "cmake" + ) + brew install "${libs[@]}" + # Check libraries local installed all_ok=true installed=$(brew list) @@ -133,6 +152,7 @@ install_brew_tools() { fi done if [ "$all_ok" = true ]; then + echoe "All libraries installed." return 0 else echo "One or more libraries failed to install." @@ -142,37 +162,48 @@ install_brew_tools() { main() { echo "TDT4102 Tools Installation Script for macOS" - echo "" + echo "PLEASE KEEP THIS WINDOW OPEN UNTIL PROMPTED" + + # default install everything + if [[ $# -eq 0 ]]; then + INSTALL_XCODE=1 + INSTALL_HOMEBREW=1 + INSTALL_MESON=1 + INSTALL_LIBS=1 + else + while [[ $# -gt 0 ]]; do + case $1 in + --xcode) INSTALL_XCODE=1 ;; + --homebrew) INSTALL_HOMEBREW=1 ;; + --meson) INSTALL_MESON=1 ;; + --libs) INSTALL_LIBS=1 ;; + *) err "Unknown option: $1";; + esac + shift + done + fi + # Check macOS version if ! check_macos_version; then exit 1 fi - # Install Xcode Command Line Tools - if ! install_xcode_tools; then - exit 1 - fi - # Implicitly verifies clang + + [[ $INSTALL_XCODE -eq 1 ]] && install_xcode + [[ $INSTALL_HOMEBREW -eq 1 ]] && install_brew - # Install Homebrew - if ! install_homebrew; then - exit 1 + if [[ $INSTALL_HOMEBREW -eq 1 || $INSTALL_MESON -eq 1 || $INSTALL_LIBS -eq 1 ]]; then + echo "Updating Homebrew..." + brew update || echo "update failed" + brew upgrade || echo "upgrade failed" fi - # Update Homebrew - echo "Updating Homebrew..." - brew update || echo "brew update failed, proceeding..." - brew upgrade || echo "brew upgrade failed, proceeding..." - - # Install Meson, Ninja, and libraries (all Homebrew tools) - if ! install_brew_tools; then - exit 1 - fi + [[ $INSTALL_MESON -eq 1 ]] && install_meson + [[ $INSTALL_LIBS -eq 1 ]] && install_libraries - echo "" - echo "Installation complete!" - echo "Please restart VS Code to apply changes." + echo "\nInstallation completed! Please restart VS Code before continuing\n" + read -r -p "Press enter to exit" } #Run main