|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Print an error message and exit with 1 |
| 4 | +unsupported_os () { |
| 5 | + echo "Detected OS ($1) is unsupported." |
| 6 | + echo "Please open an issue (PRs welcome ❤️) on:" |
| 7 | + echo " https://github.com/lambdaclass/cairo-vm/issues" |
| 8 | + echo "" |
| 9 | + echo "NOTE: you can still try installing dependencies manually" |
| 10 | + echo "If your OS differs from the detected one, you can look \ |
| 11 | +for the installation script for your OS in the install-scripts folder." |
| 12 | + exit 1 |
| 13 | +} |
| 14 | + |
| 15 | +# Print the detected OS |
| 16 | +print_os() { |
| 17 | + echo "Detected OS: $1" |
| 18 | +} |
| 19 | + |
| 20 | +# Print a message and run the script |
| 21 | +run_script() { |
| 22 | + echo "Running $1..." |
| 23 | + . $1 |
| 24 | +} |
| 25 | + |
| 26 | +# Detect Linux distro |
| 27 | +install_linux() { |
| 28 | + # taken from: https://unix.stackexchange.com/a/6348 |
| 29 | + # tries different methods to detect the Linux distro |
| 30 | + if [ -f /etc/os-release ]; then |
| 31 | + # freedesktop.org and systemd |
| 32 | + . /etc/os-release |
| 33 | + OS=$NAME |
| 34 | + VER=$VERSION_ID |
| 35 | + elif type lsb_release >/dev/null 2>&1; then |
| 36 | + # linuxbase.org |
| 37 | + OS=$(lsb_release -si) |
| 38 | + VER=$(lsb_release -sr) |
| 39 | + elif [ -f /etc/lsb-release ]; then |
| 40 | + # For some versions of Debian/Ubuntu without lsb_release command |
| 41 | + . /etc/lsb-release |
| 42 | + OS=$DISTRIB_ID |
| 43 | + VER=$DISTRIB_RELEASE |
| 44 | + elif [ -f /etc/debian_version ]; then |
| 45 | + # Older Debian/Ubuntu/etc. |
| 46 | + OS=Debian |
| 47 | + VER=$(cat /etc/debian_version) |
| 48 | + elif [ -f /etc/SuSe-release ]; then |
| 49 | + # Older SuSE/etc. |
| 50 | + OS="Old SuSE" |
| 51 | + elif [ -f /etc/redhat-release ]; then |
| 52 | + # Older Red Hat, CentOS, etc. |
| 53 | + OS="Old RedHat" |
| 54 | + else |
| 55 | + # Fall back to uname, e.g. "Linux <version>", also works for BSD, etc. |
| 56 | + OS=$(uname -s) |
| 57 | + VER=$(uname -r) |
| 58 | + fi |
| 59 | + |
| 60 | + print_os $OS |
| 61 | + |
| 62 | + # NOTE: we don't use $VER for now, but this might change |
| 63 | + case "$OS" in |
| 64 | + Ubuntu*) run_script "install-scripts/install-ubuntu.sh" ;; |
| 65 | + Debian*) run_script "install-scripts/install-debian.sh" ;; |
| 66 | + *) unsupported_os "linux: $OS" ;; |
| 67 | + esac |
| 68 | +} |
| 69 | + |
| 70 | +install_macos() { |
| 71 | + print_os "MacOS" |
| 72 | + run_script install-scripts/install-macos.sh |
| 73 | +} |
| 74 | + |
| 75 | +case "$OSTYPE" in |
| 76 | + linux*) install_linux ;; |
| 77 | + darwin*) install_macos ;; |
| 78 | + msys*|cygwin*) unsupported_os "Windows" ;; |
| 79 | + solaris*) unsupported_os "Solaris" ;; |
| 80 | + bsd*) unsupported_os "BSD" ;; |
| 81 | + *) unsupported_os "unknown: ${OSTYPE}" ;; |
| 82 | +esac |
0 commit comments