This repository was archived by the owner on Jun 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-dev
More file actions
executable file
·218 lines (180 loc) · 6.71 KB
/
Copy pathsetup-dev
File metadata and controls
executable file
·218 lines (180 loc) · 6.71 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
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
#!/bin/bash
# keep the sudo session alive as long as the script is running
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# remove temporary files used in this installation
rm -f /tmp/post_install_list
rm -f /tmp/setup_todo_list
rm -f /tmp/setup_checklist
rm -f /tmp/laravel_install.log
rm -f /tmp/additional_packages
######################################################## start configuration and environment checks
# path configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SHARED_SCRIPTS="$SCRIPT_DIR/modules/shared/scripts"
SHARED_DATA_LISTS="$SCRIPT_DIR/modules/shared/data-lists"
source "$SCRIPT_DIR/modules/shared/lib/functions.sh"
source "$SCRIPT_DIR/modules/shared/lib/styles.sh"
# create a file in the root of the project to store extra packages history per installed app
PACKAGES_HISTORY="$SCRIPT_DIR/.installed_packages"
[[ ! -f "$PACKAGES_HISTORY" ]] && touch "$PACKAGES_HISTORY"
# create a file in the root of the project to store history of installed apps
APP_HISTORY="$SCRIPT_DIR/.installed_apps"
[[ ! -f "$APP_HISTORY" ]] && touch "$APP_HISTORY"
# start framework selector and configure installation path
INSTALLER_PATH=$("$SHARED_SCRIPTS/select-installation") || exit 1
INSTALLATION_PATH="$SCRIPT_DIR/modules/$INSTALLER_PATH"
# start services
PHP_V=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')
$SHARED_SCRIPTS/start-service apache2 || exit 1
$SHARED_SCRIPTS/start-service mysql || exit 1
$SHARED_SCRIPTS/start-service "php$PHP_V-fpm" || exit 1
# check dependencies
$SHARED_SCRIPTS/check-php-modules || exit 1
$SHARED_SCRIPTS/check-php-consistency || exit 1
$SHARED_SCRIPTS/check-apache2-modrewrite || exit 1
######################################################## start user input
# prompt for git params
source "$SHARED_SCRIPTS/git-init-configuration"
# prompt for projectname
source "$SHARED_SCRIPTS/prompt-and-check-projectname"
# prompt for additional packages
source "$SHARED_SCRIPTS/select-additional-packages"
######################################################## start installer
# setup summary
gum style \
--border double \
--padding "1 2" \
--align center \
--width 100 \
--border-foreground 212 \
--foreground 212 \
"This bash script sets up a local development environment featuring :" \
"" \
"Laravel & Livewire" \
"MySQL database with a dedicated user" \
"Test environment with in-memory SQLite (for this showcase)" \
"Apache vhost with logs linked to storage/logs" \
"Custom daily logging" \
"Installation of additional packages & post-install actions" \
"Continuous Integration setup & GitHub deployment" \
"" \
"Please refer to the README.md file for more information"
# install database and user
if $SHARED_SCRIPTS/install-db-and-user "$DB_NAME" "$DB_USER" "$DB_PASSWORD"; then
success "database and user added"
else
error "database installation failed"
exit 1
fi
# configure project root directory
PROJECT_ROOT="/var/www/$PROJECT_NAME"
# install laravel and navigate to the project root
cd /var/www || { error "Error: cannot find /var/www"; exit 1; }
$INSTALLATION_PATH/installer $PROJECT_NAME
cd "$PROJECT_ROOT" || { error "Error: cannot find project directory"; exit 1; }
# set project permissions
if $INSTALLATION_PATH/set-project-permissions "$PROJECT_NAME"; then
success "permissions configured"
else
warning "failed to configure permissions"
add_to_do "Check the permissions for this project"
fi
# configure database connection for project
if $INSTALLATION_PATH/configure-db-environment "$DB_NAME" "$DB_USER" "$DB_PASSWORD" "$PROJECT_NAME"; then
success "database credentials are saved to config file"
else
warning "failed to save database credentials to config file"
fi
# configure apache2 vhost
if $INSTALLATION_PATH/install-apache-vhost "$PROJECT_NAME" "$SERVER_NAME"; then
success "apache vhost was installed"
else
warning "failed to install apache vhost"
fi
# configure app environment
if $INSTALLATION_PATH/configure-app-environment "$PROJECT_NAME"; then
success "configured app environment"
else
warning "failed to configure app environment"
fi
# configure test environment with sqlite in memory
if $INSTALLATION_PATH/configure-test-environment "$PROJECT_NAME"; then
success "configured test environment"
else
warning "failed to configure test environment"
fi
# install additional packages
if [[ -s "/tmp/additional_packages" ]]; then
$SHARED_SCRIPTS/install-additional-packages "/tmp/additional_packages" "$PROJECT_NAME"
success "additional packages are installed"
fi
# run post-install actions
if [[ -s "/tmp/post_install_list" ]]; then
$SHARED_SCRIPTS/run-post-install-actions "/tmp/post_install_list"
success "post-install actions completed"
fi
# configure logging for daily logs
if $INSTALLATION_PATH/configure-logging "$PROJECT_NAME"; then
success "configured logging"
else
warning "failed to configure logging"
fi
# Creating README.md file
if $SHARED_SCRIPTS/add-readme-file "$PROJECT_NAME"; then
success "README.md file added"
else
warning "failed to add README.md file"
fi
# build frontend
if $INSTALLATION_PATH/install-frontend "$PROJECT_NAME"; then
success "configured frontend"
else
warning "failed to configure frontend"
fi
# make the project ci ready
if $INSTALLATION_PATH/set-project-ci-ready; then
success "project is ci ready"
else
warning "failed to set project ci ready"
fi
# check if project is ready to be pushed to github ; otherwise show failed and manual actions
if [ -s "/tmp/setup_todo_list" ]; then
TO_DO_LIST=$(cat /tmp/setup_todo_list)
gum style --border double --padding "1 2" "MANUAL ACTIONS:" "$TO_DO_LIST"
rm /tmp/setup_todo_list
else
# push project to github if permissioned
if "${GIT_PARAMS[permission]}"; then
$SHARED_SCRIPTS/git-init "$PROJECT_NAME" "${GIT_PARAMS[visibility]}"
fi
fi
if [ -s "/tmp/setup_checklist" ]; then
CHECKLIST=$(cat /tmp/setup_checklist)
gum style --border double --padding "1 2" "Check this to be sure:" "$CHECKLIST"
rm /tmp/setup_checklist
fi
TERMINAL_WIDTH=$(tput cols)
echo ""
gum style \
--background 212 \
--foreground 0 \
--width "$TERMINAL_WIDTH" \
"" \
" Copy following lines to your C:\Windows\System32\drivers\etc\hosts file (open hosts file as administrator!) :" \
"" \
"127.0.0.1 $PROJECT_NAME.local" \
"::1 $PROJECT_NAME.local" \
"" \
" When using subdomains, you should also add them to your hosts file, like this :" \
"" \
"127.0.0.1 $PROJECT_NAME.local" \
"::1 $PROJECT_NAME.local" \
"127.0.0.1 domain.$PROJECT_NAME.local" \
"::1 domain.$PROJECT_NAME.local" \
""
echo ""
MINUTES=$(( SECONDS / 60 ))
SECONDS=$(( SECONDS % 60 ))
info "This script ran $MINUTES minutes and $SECONDS seconds"
exit 0