-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinux_setup
More file actions
executable file
·137 lines (125 loc) · 4.69 KB
/
linux_setup
File metadata and controls
executable file
·137 lines (125 loc) · 4.69 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
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
echo "===> Running setup for Linux..."
# 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..."
sudo apt-get update
# Add rbenv init and path to .bashrc if they're not already there
source ~/.bashrc
if ! command -v bundle &>/dev/null; then
echo "Ruby is not installed, installing Rbenv..."
sudo apt install rbenv git curl -y
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 "Bundle is not installed, adding shims and rbenv init to bashrc..."
echo 'export PATH="$PATH:$HOME/.rbenv/shims"' >> ~/.bashrc
source ~/.bashrc
rbenv init
echo "===> Running RBENV Doctor to check the installation..."
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
sudo apt-get install pkg-config
sudo apt-get install libpq-dev
sudo apt-get install imagemagick libmagickwand-dev
else
echo "Bundle has been installed."
fi
# Enable Ruby version
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..."
sudo apt-get update
# Check if PostgreSQL is installed
which psql > /dev/null 2>&1
if [ $? -ne 0 ]; then
# PostgreSQL not installed, proceed with installation
echo "===> Installing PostgreSQL..."
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib libpq-dev -y
else
echo "===> PostgreSQL is already installed."
fi
# Check if user exists, if not, create it
if sudo -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='$USER'" | grep -q 1; then
echo "===> User $USER already exists, updating password..."
sudo -u postgres psql -c "ALTER USER $USER WITH PASSWORD '$USER';"
else
echo "===> Creating user $USER..."
sudo -u postgres psql -c "CREATE USER $USER WITH PASSWORD '$USER';"
fi
# Check for SUPERUSER permission
if sudo -u postgres psql -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..."
sudo -u postgres psql -c "ALTER USER $USER WITH SUPERUSER;"
fi
# Check for CREATEDB permission
if sudo -u postgres psql -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..."
sudo -u postgres psql -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
# Check if Redis is installed
which redis-server > /dev/null 2>&1
if [ $? -ne 0 ]; then
# Redis not installed, proceed with installation
echo "===> Installing Redis..."
# Add the Redis GPG key
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
# Add the Redis repository
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list > /dev/null
# Update and install Redis
sudo apt-get install redis -y
else
echo "===> Redis is already installed."
fi
echo "===> Setup complete!"
# Step 5: Make sure Redis & PostgreSQL service is running
echo "Starting PostgreSQL..."
sudo service postgresql start
echo "Starting Redis..."
sudo service redis-server start
return 1