|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -# Set the base URL |
4 | | -RAW_GITHUB_URL="https://raw.githubusercontent.com/shan-shaji/setup-flutter/main" |
| 3 | +# Check and Install Home Brew |
| 4 | +check_install_homebrew() { |
| 5 | + if ! command -v brew &> /dev/null; then |
| 6 | + echo "Installing Homebrew..." |
| 7 | + install_homebrew |
5 | 8 |
|
6 | | -# Source the helper functions |
7 | | -source <(curl -fsSL "$RAW_GITHUB_URL/helpers/shell_helper") |
8 | | -source <(curl -fsSL "$RAW_GITHUB_URL/install_homebrew") |
9 | | -source <(curl -fsSL "$RAW_GITHUB_URL/install_java") |
10 | | -source <(curl -fsSL "$RAW_GITHUB_URL/install_android_studio") |
11 | | -source <(curl -fsSL "$RAW_GITHUB_URL/install_fvm") |
12 | | -source <(curl -fsSL "$RAW_GITHUB_URL/install_vs_code") |
| 9 | + if [ "$(uname)" == "Darwin" ]; then |
| 10 | + setup_macos_path |
| 11 | + if ! command brew -v &> /dev/null; then |
| 12 | + echo "Homebrew not found. Please check the Homebrew installation and PATH setup." |
| 13 | + exit 1 |
| 14 | + fi |
| 15 | + elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then |
| 16 | + setup_linux_path |
| 17 | + if ! command -v snap &> /dev/null; then |
| 18 | + install_snap |
| 19 | + fi |
| 20 | + fi |
| 21 | + else |
| 22 | + echo "✅ Homebrew Installed." |
| 23 | + fi |
| 24 | +} |
13 | 25 |
|
| 26 | +install_homebrew() { |
| 27 | + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 28 | +} |
| 29 | + |
| 30 | +setup_macos_path() { |
| 31 | + if [ ! -f ~/.zshrc ]; then |
| 32 | + touch ~/.zshrc |
| 33 | + fi |
| 34 | + |
| 35 | + if ! grep -q 'eval "$(/opt/homebrew/bin/brew shellenv)"' ~/.zprofile; then |
| 36 | + (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile |
| 37 | + eval "$(/opt/homebrew/bin/brew shellenv)" |
| 38 | + fi |
| 39 | +} |
| 40 | + |
| 41 | +setup_linux_path() { |
| 42 | + if ! grep -q 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' ~/.bashrc && ! grep -q 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' ~/.zshrc; then |
| 43 | + if [ -n "$ZSH_VERSION" ]; then |
| 44 | + echo 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' >> ~/.zshrc |
| 45 | + elif [ -n "$BASH_VERSION" ]; then |
| 46 | + echo 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' >> ~/.bashrc |
| 47 | + fi |
| 48 | + fi |
| 49 | +} |
| 50 | + |
| 51 | +install_snap() { |
| 52 | + sudo apt-get update |
| 53 | + sudo apt-get install -y snapd |
| 54 | +} |
| 55 | + |
| 56 | +install_android_studio() { |
| 57 | + if [ "$(uname)" == "Darwin" ]; then |
| 58 | + if [ ! -d "/Applications/Android Studio.app" ]; then |
| 59 | + brew list --cask android-studio || brew install --cask android-studio |
| 60 | + else |
| 61 | + echo "✅ Android Studio is already installed." |
| 62 | + return 0 |
| 63 | + fi |
| 64 | + else |
| 65 | + if [ ! -d "/snap/bin/android-studio" ]; then |
| 66 | + sudo snap install android-studio --classic |
| 67 | + else |
| 68 | + echo "✅ Android Studio is already installed." |
| 69 | + return 0 |
| 70 | + fi |
| 71 | + fi |
| 72 | + echo "✅ Android Studio Installed." |
| 73 | +} |
| 74 | + |
| 75 | +install_vs_code() { |
| 76 | + if [ "$(uname)" == "Darwin" ]; then |
| 77 | + if [ ! -d "/Applications/Visual Studio Code.app" ]; then |
| 78 | + brew list --cask visual-studio-code || brew install --cask visual-studio-code |
| 79 | + else |
| 80 | + echo "✅ Visual studio code is already installed." |
| 81 | + return 0 |
| 82 | + fi |
| 83 | + else |
| 84 | + if [ ! -d "/snap/bin/code" ]; then |
| 85 | + sudo snap install --classic code |
| 86 | + else |
| 87 | + echo "✅ Visual studio code is already installed." |
| 88 | + return 0 |
| 89 | + fi |
| 90 | + fi |
| 91 | + |
| 92 | + echo "✅ Visual studio code installed." |
| 93 | +} |
| 94 | + |
| 95 | +install_fvm() { |
| 96 | + install_fvm_if_not_installed |
| 97 | + |
| 98 | + configure_shell |
| 99 | + |
| 100 | + source $SHELL_CONFIG |
| 101 | + |
| 102 | + fvm list | grep 'stable' || fvm install stable |
| 103 | + |
| 104 | + fvm global stable |
| 105 | + |
| 106 | + export PATH="$HOME/fvm/default/bin:$PATH" |
| 107 | + |
| 108 | + flutter doctor |
| 109 | +} |
| 110 | + |
| 111 | +install_fvm_if_not_installed() { |
| 112 | + if ! brew list fvm &> /dev/null; then |
| 113 | + brew tap leoafarias/fvm |
| 114 | + brew install fvm |
| 115 | + echo "✅ FVM Installed." |
| 116 | + else |
| 117 | + echo "✅ FVM already Installed." |
| 118 | + fi |
| 119 | +} |
| 120 | + |
| 121 | +configure_shell() { |
| 122 | + if [ "$(uname)" == "Darwin" ]; then |
| 123 | + SHELL_CONFIG=~/.zshrc |
| 124 | + else |
| 125 | + SHELL_CONFIG=~/.bashrc |
| 126 | + fi |
| 127 | + |
| 128 | + if ! grep -q 'export PATH="$PATH":"$HOME/.pub-cache/bin"' $SHELL_CONFIG; then |
| 129 | + echo 'export PATH="$PATH":"$HOME/.pub-cache/bin"' >> $SHELL_CONFIG |
| 130 | + echo "✅ Added flutter executables to path." |
| 131 | + fi |
| 132 | + |
| 133 | + if ! grep -q 'export PATH="$PATH":"$HOME/fvm/default/bin"' $SHELL_CONFIG; then |
| 134 | + if [ "$(uname)" == "Darwin" ]; then |
| 135 | + sed -i '' '1i\ |
| 136 | + export PATH="$PATH":"$HOME/fvm/default/bin"' $SHELL_CONFIG |
| 137 | + else |
| 138 | + sed -i '1i\ |
| 139 | + export PATH="$PATH":"$HOME/fvm/default/bin"' $SHELL_CONFIG |
| 140 | + fi |
| 141 | + fi |
| 142 | +} |
| 143 | + |
| 144 | +# Reload shell |
| 145 | +reload_shell() { |
| 146 | + if [ -n "$ZSH_VERSION" ]; then |
| 147 | + source ~/.zshrc |
| 148 | + elif [ -n "$BASH_VERSION" ]; then |
| 149 | + source ~/.bashrc |
| 150 | + fi |
| 151 | + echo "✅ Shell reloaded." |
| 152 | +} |
14 | 153 |
|
15 | 154 | # Install Homebrew |
16 | 155 | check_install_homebrew |
|
0 commit comments