-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevit-linux.sh
More file actions
executable file
·131 lines (105 loc) · 3.85 KB
/
devit-linux.sh
File metadata and controls
executable file
·131 lines (105 loc) · 3.85 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
#!/bin/bash
echo "Checking if Docker, Docker Compose, PHP, and Composer are installed..."
echo "Setting permissions to 777 for project directory files..."
sudo chmod -R 777 /home/devit/Work/laravel/devit-laravel
if ! command -v docker &> /dev/null; then
echo "Docker is not installed. Installing Docker..."
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce=5:26.1.5~3-0~ubuntu-focal docker-ce-cli=5:26.1.5~3-0~ubuntu-focal containerd.io
if [ $? -ne 0 ]; then
echo "Failed to install Docker. Exiting."
exit 1
fi
else
echo "Docker is installed."
fi
if ! command -v docker-compose &> /dev/null; then
echo "Docker Compose is not installed. Installing Docker Compose..."
curl -SL https://github.com/docker/compose/releases/download/v2.27.1/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
if [ $? -ne 0 ]; then
echo "Failed to install Docker Compose. Exiting."
exit 1
fi
else
echo "Docker Compose is installed."
fi
if ! command -v php &> /dev/null; then
echo "PHP is not installed. Installing PHP 8.3.20..."
sudo apt-get update
sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php8.3 php8.3-cli php8.3-common php8.3-mbstring php8.3-xml php8.3-zip php8.3-curl
if [ $? -ne 0 ]; then
echo "Failed to install PHP. Exiting."
exit 1
fi
else
echo "PHP is installed."
fi
if ! command -v composer &> /dev/null; then
echo "Composer is not installed. Installing Composer 2.8.8..."
EXPECTED_SIGNATURE=$(wget -qO - https://composer.github.io/installer.sig)
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('sha384', 'composer-setup.php');")
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]; then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi
php composer-setup.php --version=2.8.8
if [ $? -ne 0 ]; then
echo "Failed to install Composer. Exiting."
exit 1
fi
sudo mv composer.phar /usr/local/bin/composer
rm composer-setup.php
else
echo "Composer is installed."
fi
if [ -f ".env.example" ]; then
echo "Copying .env.example to .env..."
cp .env.example .env
else
echo "No .env.example file found. Skipping .env file creation."
fi
echo "Running composer install..."
composer install
if [ $? -ne 0 ]; then
echo "Composer install failed. Exiting."
exit 1
fi
echo "Generating application key..."
php artisan key:generate
if [ $? -ne 0 ]; then
echo "Failed to generate application key. Exiting."
exit 1
fi
sudo chmod -R 775 storage
sudo chown -R www-data:www-data storage
echo "Starting Docker containers..."
docker-compose up -d --build
if [ $? -ne 0 ]; then
echo "Failed to start Docker containers. Exiting."
exit 1
fi
echo "Waiting for containers to start..."
while ! docker-compose ps | grep -q 'Up'; do
echo "Containers are not up yet. Waiting 1 second..."
sleep 1
done
echo "Containers are up. Waiting 3 seconds..."
sleep 3
echo "Now, restarting the containers again..."
docker-compose up -d
echo "Containers have been restarted!"
PORT=$(grep -oP '^APP_PORT=\K.*' .env)
echo ""
echo "✅ Application is now running!"
echo "🌐 Visit: http://127.0.0.1:$PORT"
echo "Powered by https://devit.uz"