-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmac_setup
More file actions
124 lines (101 loc) · 3.59 KB
/
mac_setup
File metadata and controls
124 lines (101 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
echo "===> Running setup for macOS..."
# Step 1: Check and install rbenv and Ruby Version 2.7.6
echo "Checking Ruby version..."
required_ruby_version="2.7.6"
current_ruby_version=$(ruby -v | cut -d " " -f 2 | cut -d "p" -f 1)
if [ "$current_ruby_version" = "$required_ruby_version" ]; then
echo "Required Ruby version is already installed"
return 0
else
echo "Ruby is not found or using the wrong version"
return 1
fi
if [ $? -eq 1 ]; then
echo "===> Installing rbenv and Ruby 2.7.6..."
# Mac uses Homebrew for package installation
brew update
brew install rbenv git curl
# Add rbenv init and path to bash profile or zshrc if they're not already there
if [[ $SHELL == *"/zsh"* ]]; then
profile_file="~/.zshrc"
else
profile_file="~/.bash_profile"
fi
if ! grep -q 'eval "\$(rbenv init -)"' $profile_file; then
echo 'eval "$(rbenv init -)"' >> $profile_file
fi
if ! grep -q "$HOME/.rbenv/shims" $profile_file; then
echo 'export PATH="$PATH:$HOME/.rbenv/shims"' >> $profile_file
fi
source $profile_file
rbenv init
mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
rbenv install 2.7.6
echo "===> Running RBENV Doctor to check the installation..."
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
rbenv global 2.7.6 && rbenv rehash
# Check ruby version
echo "Checking Ruby version once more time..."
wrong_ruby_version
if [ $? -eq 1 ]; then
echo "Ruby has been installed!"
else
echo "UNEXPECTED ERROR: RUBY INSTALLATION FAILED"
fi
else
echo "Ruby version is correct!"
fi
# Step 2: Install Bundler and bundle install
echo "===> Installing Bundler and Bundle Install..."
bundle install
# Step 3: Install PostgreSQL and create user
echo "===> Installing PostgreSQL..."
# Mac uses Homebrew for PostgreSQL installation
brew install postgresql
brew services start postgresql
# Check if user exists, if not, create it
if psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='$USER'" | grep -q 1; then
echo "===> User $USER already exists, updating password..."
psql postgres -c "ALTER USER $USER WITH PASSWORD '$USER';"
else
echo "===> Creating user $USER..."
psql postgres -c "CREATE USER $USER WITH PASSWORD '$USER';"
fi
# Check for SUPERUSER permission
if psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='$USER' AND rolsuper;" | grep -q 1; then
echo "===> User $USER already has SUPERUSER permission."
else
echo "===> Granting SUPERUSER permission to $USER..."
psql postgres -c "ALTER USER $USER WITH SUPERUSER;"
fi
# Check for CREATEDB permission
if psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='$USER' AND rolcreatedb;" | grep -q 1; then
echo "===> User $USER already has CREATEDB permission."
else
echo "===> Granting CREATEDB permission to $USER..."
psql postgres -c "ALTER USER $USER WITH CREATEDB;"
fi
# Create .env file with the database username and password
# Check if .env file exists
if [ ! -f .env ]; then
touch .env
fi
# Check if DATABASE_USERNAME exists in .env
grep -q "^DATABASE_USERNAME=" .env
if [ $? -ne 0 ]; then
echo "DATABASE_USERNAME=$USER" >> .env
fi
# Check if DATABASE_PASSWORD exists in .env
grep -q "^DATABASE_PASSWORD=" .env
if [ $? -ne 0 ]; then
echo "DATABASE_PASSWORD=$USER" >> .env
fi
echo "===> PostgreSQL setup complete!"
# Step 4: Install Redis
echo "===> Installing Redis..."
brew install redis
brew services start redis
echo "===> Setup complete!"
return 1