Skip to content

Commit 4b811a4

Browse files
committed
feat: logic seperation to seperate sh files
1 parent d478a42 commit 4b811a4

File tree

8 files changed

+205
-131
lines changed

8 files changed

+205
-131
lines changed

helpers/shell_helper

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# Reload shell
3+
reload_shell() {
4+
if [ -n "$ZSH_VERSION" ]; then
5+
source ~/.zshrc
6+
elif [ -n "$BASH_VERSION" ]; then
7+
source ~/.bashrc
8+
fi
9+
echo "✅ Shell reloaded."
10+
}

install_android_studio

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
install_android_studio() {
2+
if [ "$(uname)" == "Darwin" ]; then
3+
if [ ! -d "/Applications/Android Studio.app" ]; then
4+
brew list --cask android-studio || brew install --cask android-studio
5+
else
6+
echo "✅ Android Studio is already installed"
7+
return 0
8+
fi
9+
else
10+
if [ ! -d "/snap/bin/android-studio" ]; then
11+
sudo snap install android-studio --classic
12+
else
13+
echo "✅ Android Studio is already installed"
14+
return 0
15+
fi
16+
fi
17+
echo "✅ Android Studio Installed"
18+
}

install_fvm

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
install_fvm() {
2+
install_fvm_if_not_installed
3+
4+
configure_shell
5+
6+
source $SHELL_CONFIG
7+
8+
fvm list | grep 'stable' || fvm install stable
9+
10+
fvm global stable
11+
12+
export PATH="$HOME/fvm/default/bin:$PATH"
13+
14+
flutter doctor
15+
}
16+
17+
install_fvm_if_not_installed() {
18+
if ! brew list fvm &> /dev/null; then
19+
brew tap leoafarias/fvm
20+
brew install fvm
21+
echo "✅ FVM Installed"
22+
else
23+
echo "✅ FVM already Installed"
24+
fi
25+
}
26+
27+
configure_shell() {
28+
if [ "$(uname)" == "Darwin" ]; then
29+
SHELL_CONFIG=~/.zshrc
30+
else
31+
SHELL_CONFIG=~/.bashrc
32+
fi
33+
34+
if ! grep -q 'export PATH="$PATH":"$HOME/.pub-cache/bin"' $SHELL_CONFIG; then
35+
echo 'export PATH="$PATH":"$HOME/.pub-cache/bin"' >> $SHELL_CONFIG
36+
echo "✅ Added flutter executables to path."
37+
fi
38+
39+
if ! grep -q 'export PATH="$PATH":"$HOME/fvm/default/bin"' $SHELL_CONFIG; then
40+
if [ "$(uname)" == "Darwin" ]; then
41+
sed -i '' '1i\
42+
export PATH="$PATH":"$HOME/fvm/default/bin"' $SHELL_CONFIG
43+
else
44+
sed -i '1i\
45+
export PATH="$PATH":"$HOME/fvm/default/bin"' $SHELL_CONFIG
46+
fi
47+
fi
48+
}
49+
50+

install_homebrew

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
check_install_homebrew() {
2+
if ! command -v brew &> /dev/null; then
3+
echo "Installing Homebrew..."
4+
install_homebrew
5+
6+
if [ "$(uname)" == "Darwin" ]; then
7+
setup_macos_path
8+
if ! command brew -v &> /dev/null; then
9+
echo "Homebrew not found. Please check the Homebrew installation and PATH setup."
10+
exit 1
11+
fi
12+
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
13+
setup_linux_path
14+
if ! command -v snap &> /dev/null; then
15+
install_snap
16+
fi
17+
fi
18+
else
19+
echo "✅ Homebrew Installed"
20+
fi
21+
}
22+
23+
install_homebrew() {
24+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
25+
}
26+
27+
setup_macos_path() {
28+
if [ ! -f ~/.zshrc ]; then
29+
touch ~/.zshrc
30+
fi
31+
32+
if ! grep -q 'eval "$(/opt/homebrew/bin/brew shellenv)"' ~/.zprofile; then
33+
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile
34+
eval "$(/opt/homebrew/bin/brew shellenv)"
35+
fi
36+
}
37+
38+
setup_linux_path() {
39+
if ! grep -q 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' ~/.bashrc && ! grep -q 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' ~/.zshrc; then
40+
if [ -n "$ZSH_VERSION" ]; then
41+
echo 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' >> ~/.zshrc
42+
elif [ -n "$BASH_VERSION" ]; then
43+
echo 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' >> ~/.bashrc
44+
fi
45+
fi
46+
}
47+
48+
install_snap() {
49+
sudo apt-get update
50+
sudo apt-get install -y snapd
51+
}

install_java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
install_java() {
2+
if [ "$(uname)" == "Darwin" ]; then
3+
if ! /usr/libexec/java_home -V 2>&1 | grep -q "No Java runtime present"; then
4+
echo "✅ Java is already installed on macOS."
5+
else
6+
if ! brew list --cask adoptopenjdk/openjdk/adoptopenjdk &> /dev/null; then
7+
if ! brew install --cask adoptopenjdk/openjdk/adoptopenjdk11; then
8+
echo "❌ Failed to install Java using Homebrew."
9+
exit 1
10+
fi
11+
else
12+
echo "✅ Java is already installed using Homebrew."
13+
fi
14+
fi
15+
else
16+
if ! command -v java &> /dev/null; then
17+
if [ -x "$(command -v apt-get)" ]; then
18+
if ! sudo apt-get install -y openjdk-11-jdk; then
19+
echo "❌ Failed to install Java using apt-get."
20+
exit 1
21+
fi
22+
elif [ -x "$(command -v yum)" ]; then
23+
if ! sudo yum install -y java-11-openjdk-devel; then
24+
echo "❌ Failed to install Java using yum."
25+
exit 1
26+
fi
27+
else
28+
echo "❌ Package manager not found. Please install Java manually."
29+
exit 1
30+
fi
31+
else
32+
echo "✅ Java is already installed."
33+
fi
34+
fi
35+
echo "✅ Java installation successful."
36+
}

install_vs_code

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
install_vs_code() {
2+
if [ "$(uname)" == "Darwin" ]; then
3+
if [ ! -d "/Applications/Visual Studio Code.app" ]; then
4+
brew list --cask visual-studio-code || brew install --cask visual-studio-code
5+
else
6+
echo "✅ Visual studio code is already installed"
7+
return 0
8+
fi
9+
else
10+
if [ ! -d "/snap/bin/code" ]; then
11+
sudo snap install --classic code
12+
else
13+
echo "✅ Visual studio code is already installed"
14+
return 0
15+
fi
16+
fi
17+
18+
echo "✅ Visual studio code installed"
19+
}

setup-flutter

Lines changed: 0 additions & 131 deletions
This file was deleted.

setup_flutter

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
source "./install_homebrew"
4+
source "./helpers/shell_helper"
5+
source "./install_java"
6+
source "./install_android_studio"
7+
source "./install_fvm"
8+
9+
# Install Homebrew
10+
check_install_homebrew
11+
12+
# Reload shell configuration to apply PATH changes
13+
reload_shell
14+
15+
# Install Android studio if not already installed
16+
install_android_studio
17+
18+
19+
20+
21+
install_fvm

0 commit comments

Comments
 (0)