-
Notifications
You must be signed in to change notification settings - Fork 0
/
laravel-installer.sh
266 lines (224 loc) · 8.17 KB
/
laravel-installer.sh
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/bash
## Written by Ed on 18.03.2024
clear
echo '###################################'
echo 'Laravel Installer'
echo 'Written in March, 2024'
echo '###################################'
#project name
while true; do
# Prompt the user for the project name
read -p "What is your preferred project name? " project_name
# Check if the project name is empty
if [ -z "$project_name" ]; then
echo "Project name cannot be empty."
elif [[ "$project_name" == *" "* ]]; then
echo "Project name cannot contain spaces."
elif [ -d "$project_name" ]; then
echo "A directory with the name '$project_name' already exists."
else
break # Exit the loop if project name is not empty and directory doesn't exist
fi
done
#Run composer and get Silver Stripe
composer create-project laravel/laravel $project_name
cd $project_name
# Specify the patterns to be added to .gitignore
patterns="/node_modules
/public/*
/storage/*
/vendor
.env
.env.backup
.phpunit.result.cache
docker-compose.override.yml
npm-debug.log
yarn-error.log
/.idea
/.vscode"
#add DB details
clear
echo '################ MySQL Database Connection ################'
while true; do
# Prompt the user for the host name
read -p "What is your database hostname? " DB_HOST
read -p "What is your database name? " DB_NAME
read -p "What is your database username? " DB_USER
read -p "What is your database password? " DB_PASS
# Specify the path to the .env file
ENV_FILE=".env"
# Check if the .env file exists
if [ ! -f "$ENV_FILE" ]; then
echo "Error: .env file not found at $ENV_FILE"
exit 1
fi
# Remove the specified lines from the .env file
sed -i '/^# DB_HOST=127\.0\.0\.1$/d' "$ENV_FILE"
sed -i '/^# DB_PORT=3306$/d' "$ENV_FILE"
sed -i '/^# DB_DATABASE=laravel$/d' "$ENV_FILE"
sed -i '/^# DB_USERNAME=root$/d' "$ENV_FILE"
sed -i '/^# DB_PASSWORD=$/d' "$ENV_FILE"
# Add missing lines to the .env file
if ! grep -q "^DB_CONNECTION=" "$ENV_FILE"; then
echo "DB_CONNECTION=$DB_CONNECTION" >> "$ENV_FILE"
fi
if ! grep -q "^DB_PORT=" "$ENV_FILE"; then
echo "DB_PORT=3306" >> "$ENV_FILE"
fi
if ! grep -q "^DB_HOST=" "$ENV_FILE"; then
echo "DB_HOST=" >> "$ENV_FILE"
fi
if ! grep -q "^DB_DATABASE=" "$ENV_FILE"; then
echo "DB_DATABASE=" >> "$ENV_FILE"
fi
if ! grep -q "^DB_USERNAME=" "$ENV_FILE"; then
echo "DB_USERNAME=" >> "$ENV_FILE"
fi
if ! grep -q "^DB_PASSWORD=" "$ENV_FILE"; then
echo "DB_PASSWORD=" >> "$ENV_FILE"
fi
# Replace the values in the .env file
sed -i "s/DB_CONNECTION=.*/DB_CONNECTION=mysql/" "$ENV_FILE"
sed -i "s/DB_PORT=.*/DB_PORT=3306/" "$ENV_FILE"
sed -i "s/DB_HOST=.*/DB_HOST=$DB_HOST/" "$ENV_FILE"
sed -i "s/DB_DATABASE=.*/DB_DATABASE=$DB_NAME/" "$ENV_FILE"
sed -i "s/DB_USERNAME=.*/DB_USERNAME=$DB_USER/" "$ENV_FILE"
sed -i "s/DB_PASSWORD=.*/DB_PASSWORD=$DB_PASS/" "$ENV_FILE"
# Attempt to connect to the database using Laravel Artisan
php artisan migrate:fresh > /dev/null 2>&1
# Check the exit status
if [ $? -eq 0 ]; then
echo "Laravel database connection successful"
break
else
echo "Error: Failed to connect to the Laravel database"
fi
done
#install laravel breeze
composer require laravel/breeze --dev
COMMAND="@php artisan breeze:install --dark blade"
sed -i "/\"post-update-cmd\": \[/a\ \ \ \ \"$COMMAND\"," "composer.json"
#install laravel sanctum
composer require laravel/sanctum
#Update composer
echo 'Updating Composer'
composer update
#remove laravel breeze install command
sed -i "/$COMMAND/d" "composer.json"
#install other packages
composer require owen-it/laravel-auditing
composer require spatie/laravel-html
composer require yajra/laravel-datatables:^11.0
composer require yajra/laravel-datatables-buttons:^11.0
# Specify the path to your PHP file
PHP_FILE="config/app.php"
# Lines to add
LINES=(
" OwenIt\\Auditing\\AuditingServiceProvider::class,"
" Spatie\\Html\\HtmlServiceProvider::class,"
" Yajra\\DataTables\\DataTablesServiceProvider::class,"
" Yajra\\DataTables\\ButtonsServiceProvider::class,"
)
# Add the lines after the specified line in the PHP file
for LINE in "${LINES[@]}"; do
LINE=$(echo "$LINE" | sed 's/\\/\\\\/g') # Escape backslashes
sed -i "/'providers' => ServiceProvider::defaultProviders()->merge(\[/a $LINE" "$PHP_FILE"
echo "Added: $LINE"
done
# Lines to add
LINES=(
" 'DataTables' => Yajra\DataTables\Facades\DataTables::class,"
" 'Html' => Spatie\Html\Facades\Html::class,"
)
# Add the lines after the specified line in the PHP file
for LINE in "${LINES[@]}"; do
LINE=$(echo "$LINE" | sed 's/\\/\\\\/g') # Escape backslashes
sed -i "/'aliases' => Facade::defaultAliases()->merge(\[/a $LINE" "$PHP_FILE"
echo "Added: $LINE"
done
clear
while true; do
# Prompt the user for the client name
read -p "What is the client name? " client_name
# Check if the client name is empty
if [ -z "$client_name" ]; then
echo "Client name cannot be empty."
else
# Line to add
LINE=" 'company' => env('APP_COMPANY', '$client_name'),"
# Add the line after the 'return [' statement in the PHP file
sed -i "/return \[/a $LINE" "$PHP_FILE"
break
fi
done
#get Laravel base
git clone https://github.com/thelogicstudio/laravel-base.git
cp -R laravel-base/* .
rm -rf laravel-base/
clear
#Add scripts to composer
#Specify the path to your composer.json file
COMPOSER_JSON_FILE="composer.json"
# Commands to add
COMMANDS=(
"@php artisan db:seed --class=UserRoleSeeder"
"@php artisan db:seed --class=PrivilegeRoleSeeder"
"@php artisan db:seed --class=PrivilegeSeeder"
"@php artisan db:seed --class=RoleSeeder"
"@php artisan db:seed --class=UserSeeder"
"@php artisan migrate"
"@php artisan vendor:publish --provider=\\\"OwenIt\\\Auditing\\\AuditingServiceProvider\\\" --tag=migrations"
"@php artisan vendor:publish --provider=\\\"OwenIt\\\Auditing\\\AuditingServiceProvider\\\" --tag=config"
"@php artisan vendor:publish --tag=datatables-buttons"
"@php artisan vendor:publish --tag=datatables"
)
# Add each command after "post-update-cmd" in composer.json
for COMMAND in "${COMMANDS[@]}"; do
COMMAND=$(echo "$COMMAND" | sed 's/\\/\\\\/g') # Escape backslashes
sed -i "/\"post-update-cmd\": \[/a\ \ \ \ \"$COMMAND\"," "$COMPOSER_JSON_FILE"
echo "Added: $COMMAND"
done
#add Helper file
# Line to add
LINE='"files": ["app/Helpers/route.php"],'
# Add the line under "autoload" in composer.json
sed -i '/"autoload": {/a\ \ \ \ '"$LINE"'' "$COMPOSER_JSON_FILE"
echo "Added: $COMPOSER_JSON_FILE"
#update composer
composer update
# Remove each command from "post-update-cmd" in composer.json
# Commands to remove
COMMANDS=(
"@php artisan vendor:publish --provider=\\\"OwenIt\\\Auditing\\\AuditingServiceProvider\\\" --tag=migrations"
"@php artisan vendor:publish --provider=\\\"OwenIt\\\Auditing\\\AuditingServiceProvider\\\" --tag=config"
"@php artisan vendor:publish --tag=datatables"
"@php artisan vendor:publish --tag=datatables-buttons"
"@php artisan migrate"
"@php artisan db:seed --class=UserSeeder"
"@php artisan db:seed --class=RoleSeeder"
"@php artisan db:seed --class=PrivilegeSeeder"
"@php artisan db:seed --class=PrivilegeRoleSeeder"
"@php artisan db:seed --class=UserRoleSeeder"
)
for COMMAND in "${COMMANDS[@]}"; do
sed -i "/\"$COMMAND\",/d" "$COMPOSER_JSON_FILE"
echo "Removed: $COMMAND"
done
# Remove lines containing "artisan vendor:publish" from composer.json
sed -i '/artisan vendor:publish --provider/d' "$COMPOSER_JSON_FILE"
echo '########################'
echo 'All Done.'
echo 'Make sure you run following commands in your developer terminal'
echo 'npm install'
echo 'npm run dev (2 times)'
echo 'php artisan serve'
echo 'You can run npm run watch to use Browsersync'
echo 'default user is [email protected]'
echo 'default password is admin123'
echo 'Enjoy!'
echo '########################'
pause() {
read -p "Press Enter to continue..."
}
pause
clear