-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_project.sh
executable file
·141 lines (117 loc) · 4.72 KB
/
create_project.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
#!/bin/bash
# Choose a folder name
while [ -z ${FOLDER_NAME} ];
do
printf "Choose name of target folder (e.g.: myproject): "
read FOLDER_NAME
done
# Choose a destination path
PATH_VALID="false"
while [ ${PATH_VALID} == "false" ];
do
printf "Choose a destination path (without trailing /): "
read DESTINATION_PATH
if [ ! -d ${DESTINATION_PATH} ] || [[ ${DESTINATION_PATH} == "" ]];
then
echo -e "\033[41mChosen path is not valid !!!\033[0m"
else
PATH_VALID="true"
fi
done
# Choose Hostname local dev
DEFAULT_HOST="docker.test"
while [ -z ${HOST_NAME} ];
do
read -e -p "Choose hostname for local development [docker.test]:" HOST_NAME
HOST_NAME="${HOST_NAME:-${DEFAULT_HOST}}"
done
# Choose local dev web port
DEFAULT_PORT="80"
while [ -z ${WEB_PORT} ];
do
read -e -p "Choose web port for local development [80]:" WEB_PORT
WEB_PORT="${WEB_PORT:-${DEFAULT_PORT}}"
done
# Choose Hostname staging
DEFAULT_STAGING_HOST="staging.domain"
while [ -z ${STAGE_HOST_NAME} ];
do
read -e -p "Choose hostname for staging [staging.domain]:" STAGE_HOST_NAME
STAGE_HOST_NAME="${STAGE_HOST_NAME:-${DEFAULT_STAGING_HOST}}"
done
# Choose DBname
DEFAULT_DB="docker"
while [ -z ${DB_NAME} ];
do
read -e -p "Choose database name [docker]:" DB_NAME
DB_NAME="${DB_NAME:-${DEFAULT_DB}}"
done
PS3='Please enter your choice: '
options=("php:7.1-apache" "php:7.2-apache" "php:7.3-apache" "php:5.6-apache")
select opt in "${options[@]}"
do
case $REPLY in
[1-4]*)
break
;;
*) echo "invalid option $REPLY, please select 1-4";;
esac
done
# With Wordpress?
DEFAULT_WPYESNO="no"
while [ -z ${WP_YESNO} ];
do
read -e -p "Install Wordpress? yes|no [no]:" WP_YESNO
WP_YESNO="${WP_YESNO:-${DEFAULT_WPYESNO}}"
done
# Create project folder
mkdir ${DESTINATION_PATH}/${FOLDER_NAME}
# Copy scripts
cp {start_system.sh,stop_system.sh,docker-compose.yml} ${DESTINATION_PATH}/${FOLDER_NAME}/
# Create docker folder
mkdir ${DESTINATION_PATH}/${FOLDER_NAME}/docker
mkdir ${DESTINATION_PATH}/${FOLDER_NAME}/docker/db
cp docker/db/.gitignore ${DESTINATION_PATH}/${FOLDER_NAME}/docker/db/
mkdir ${DESTINATION_PATH}/${FOLDER_NAME}/docker/logs
cp docker/logs/.gitignore ${DESTINATION_PATH}/${FOLDER_NAME}/docker/logs/
mkdir ${DESTINATION_PATH}/${FOLDER_NAME}/docker/webserver
cp {docker/webserver/Dockerfile,docker/webserver/php.ini,docker/webserver/docker-php-pecl-install} ${DESTINATION_PATH}/${FOLDER_NAME}/docker/webserver
# Insert PHP engine into dockerfile
sed -i '' "s/\php:7\.2-apache/${opt}/g" ${DESTINATION_PATH}/${FOLDER_NAME}/docker/webserver/Dockerfile
# Create env file
echo "HOST=${HOST_NAME}" > ${DESTINATION_PATH}/${FOLDER_NAME}/.env
echo "DB=${DB_NAME}" >> ${DESTINATION_PATH}/${FOLDER_NAME}/.env
echo "DB_ROOT_PASSWORD=docker" >> ${DESTINATION_PATH}/${FOLDER_NAME}/.env
echo "DB_USER=dockeruser" >> ${DESTINATION_PATH}/${FOLDER_NAME}/.env
echo "DB_PASSWORD=12345678" >> ${DESTINATION_PATH}/${FOLDER_NAME}/.env
echo "WEB_PORT=${WEB_PORT}" >> ${DESTINATION_PATH}/${FOLDER_NAME}/.env
# Create staging env file
mkdir ${DESTINATION_PATH}/${FOLDER_NAME}/build
mkdir ${DESTINATION_PATH}/${FOLDER_NAME}/build/staging
echo "HOST=${STAGE_HOST_NAME}" > ${DESTINATION_PATH}/${FOLDER_NAME}/build/staging/.env
echo "DB=${DB_NAME}" >> ${DESTINATION_PATH}/${FOLDER_NAME}/build/staging/.env
echo "DB_ROOT_PASSWORD=fhur8§hhdAA!!a" >> ${DESTINATION_PATH}/${FOLDER_NAME}/build/staging/.env
echo "DB_USER=dockeruser" >> ${DESTINATION_PATH}/${FOLDER_NAME}/build/staging/.env
echo "DB_PASSWORD=4hfGggJaj2!" >> ${DESTINATION_PATH}/${FOLDER_NAME}/build/staging/.env
echo "WEB_PORT=80" >> ${DESTINATION_PATH}/${FOLDER_NAME}/build/staging/.env
# Create first run check file
touch ${DESTINATION_PATH}/${FOLDER_NAME}/.firstrun
if [ $WP_YESNO=='yes' ]; then
mkdir ${DESTINATION_PATH}/${FOLDER_NAME}/public
# Insert public path into docker compose file
sed -i '' "s/www:/public:/g" ${DESTINATION_PATH}/${FOLDER_NAME}/docker-compose.yml
# Insert composer install into start file
sed -i '' "s/##wordpress##/composer install/g" ${DESTINATION_PATH}/${FOLDER_NAME}/start_system.sh
# Copy wordpress files
cp wordpress/composer.json ${DESTINATION_PATH}/${FOLDER_NAME}/
cp wordpress/index.php ${DESTINATION_PATH}/${FOLDER_NAME}/public/
cp wordpress/.htaccess ${DESTINATION_PATH}/${FOLDER_NAME}/public/
cp wordpress/.gitignore ${DESTINATION_PATH}/${FOLDER_NAME}/
cp wordpress/exclude.txt ${DESTINATION_PATH}/${FOLDER_NAME}/
else
# Create www folder
mkdir ${DESTINATION_PATH}/${FOLDER_NAME}/www
cp www/index.php ${DESTINATION_PATH}/${FOLDER_NAME}/www/index.php
cp www/dbtest.php ${DESTINATION_PATH}/${FOLDER_NAME}/www/dbtest.php
fi
echo -e "\033[32mEverything done!\033[0m"