-
Notifications
You must be signed in to change notification settings - Fork 0
/
app
executable file
·167 lines (139 loc) · 6.99 KB
/
app
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
export SITE_TITLE='MY WEBSITE'
export ADMIN_USER='madmin'
export ADMIN_PASSWORD='root'
export ADMIN_EMAIL='mr.madu@ya.ru'
# Все урлы указываем без слэша / в конце адреса, иначе импорт БД не сработает.
URL_LOCAL=http://localhost:8000
URL_DEV=https://test.site
URL_PROD=https://prod.site
# THEME_DIRECTORY='wp-theme' # Не меняем для корректной работы CI/CD.
# THEME_SLUG='wp-theme' # Название темы. Латиница без пробелов и спецсимволов.
export REPOSITORY_NAME=$(basename $(git rev-parse --show-toplevel))
export THEME_DIRECTORY='wp-theme'
plugins=()
for line in $(cat wp-content/themes/$THEME_DIRECTORY/plugins.txt); do
plugins+=("$line")
done
current_date_time=$(date +”%Y%m%d%H%M”)
# alias wp="docker compose run --rm -e HOME=/tmp --user 33:33 wpcli"
if [ -f .env ]; then
export $(echo $(cat .env | sed 's/#.*//g' | xargs) | envsubst)
# else
# echo "Looks like you don't have .ENV file!"
# exit
fi
if [ "$1" == "up" ]; then
docker compose up -d
retries=0
while :; do
if docker compose run --rm -e HOME=/tmp --user 33:33 wpcli core install --url=$URL_LOCAL --title=$URL_LOCAL --admin_user=$ADMIN_USER --admin_password=$ADMIN_PASSWORD --admin_email=$ADMIN_EMAIL; then
break
else
retries=$((retries + 1))
echo "Couldn't connect to DB. Try - ${retries}. Sleeping 5 seconds and will retry ..."
sleep 5
fi
if [ "${retries}" -eq "30" ]; then
echo "Couldn't connect to DB 30 times. Exiting."
exit 1
fi
done
rm -rf wp-content/themes/twentytwentyfour wp-content/themes/twentytwentythree wp-content/themes/twentytwentytwo
# mv wp-content/themes/* wp-content/themes/$THEME_DIRECTORY
# rm -rf wp-content/themes/$THEME_DIRECTORY/style.css
# touch wp-content/themes/$THEME_DIRECTORY/style.css
# echo "/**
# * Theme Name: $THEME_SLUG
# */" | cat - wp-content/themes/$THEME_DIRECTORY/style.css >temp && mv temp wp-content/themes/$THEME_DIRECTORY/style.css
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli theme activate $THEME_DIRECTORY
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli plugin uninstall hello
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli plugin uninstall akismet
for value in "${plugins[@]}"; do
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli plugin install $value
done
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli plugin install "https://connect.advancedcustomfields.com/v2/plugins/download?p=pro&k=$ACF_KEY" --allow-root --activate
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli plugin activate --all
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli config set WP_DEBUG true --raw
# xdg-open http://localhost:8000/wp-admin
open http://localhost:8000/wp-admin
# start http://localhost:8000/wp-admin
# python3 -m webbrowser http://localhost:8000/wp-admin
exit
elif [ "$1" == "stop" ]; then
docker compose stop
exit
elif [ "$1" == "user-create" ]; then
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli user create --prompt --role=administrator --user_registered= --display_name= --user_nicename= --user_url= --nickname= --first_name= --last_name= --description= --rich_editing= --send-email= --porcelain=n
exit
# elif [ "$1" == "config" ]; then
# # rm -rf wp-content/themes/twentytwentyfour wp-content/themes/twentytwentythree wp-content/themes/twentytwentytwo
# docker compose run --rm -e HOME=/tmp --user 33:33 wpcli rewrite structure '/%postname%/'
# docker compose run --rm -e HOME=/tmp --user 33:33 wpcli post update 2 --post_title=Home --post_name=home
# docker compose run --rm -e HOME=/tmp --user 33:33 wpcli option update page_on_front 2
# docker compose run --rm -e HOME=/tmp --user 33:33 wpcli option update show_on_front page
# exit
elif [ "$1" == "db-export" ]; then
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli db export dbdump.sql --allow-root
docker cp ${REPOSITORY_NAME}_wpcli://var/www/html/dbdump.sql .
docker compose run --rm wordpress rm -rf dbdump.sql
exit
elif [ "$1" == "db-import" ]; then
# docker compose run --rm -e HOME=/tmp --user 33:33 wpcli db export --tables=wp_users,wp_usermeta users.sql --allow-root
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli db export $current_date_time.sql --allow-root
docker cp ${REPOSITORY_NAME}_wpcli://var/www/html/$current_date_time.sql ./backup-db/
docker compose run --rm wordpress rm -rf $current_date_time.sql
docker cp *.sql ${REPOSITORY_NAME}_wpcli://var/www/html/
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli db clean --allow-root
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli db import *.sql --allow-root
docker compose run --rm wordpress rm -rf *.sql
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli search-replace ${URL_DEV} ${URL_LOCAL}
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli search-replace ${URL_PROD} ${URL_LOCAL}
# docker compose run --rm -e HOME=/tmp --user 33:33 wpcli db import users.sql --allow-root
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli user create ${ADMIN_USER} ${ADMIN_EMAIL} --user_pass=${ADMIN_PASSWORD} --role=administrator --user_registered= --display_name= --user_nicename= --user_url= --nickname= --first_name= --last_name= --description= --rich_editing= --send-email= --porcelain=n
exit
elif [ "$1" == "debug-on" ]; then
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli config set WP_DEBUG true --raw
exit
elif [ "$1" == "debug-off" ]; then
docker compose run --rm -e HOME=/tmp --user 33:33 wpcli config set WP_DEBUG false --raw
exit
elif [ "$1" == "composer-install" ]; then
cd wp-content/themes/$THEME_DIRECTORY
composer install
cd ../../..
exit
elif [ "$1" == "lint:php" ]; then
cd wp-content/themes/$THEME_DIRECTORY
composer lint:php
cd ../../..
exit
elif [ "$1" == "lint:wpcs" ]; then
cd wp-content/themes/$THEME_DIRECTORY
composer lint:wpcs
cd ../../..
exit
elif [ "$1" == "npm-install" ]; then
cd wp-content/themes/$THEME_DIRECTORY
npm install
cd ../../..
exit
elif [ "$1" == "watch" ]; then
cd wp-content/themes/$THEME_DIRECTORY
npm run watch
cd ../../..
exit
elif [ "$1" == "clean" ]; then
docker compose down
rm -rf .srv --force
rm -rf wp-content/plugins
rm -rf wp-content/uploads
rm -rf wp-content/upgrade
rm -rf wp-content/index.php
rm -rf wp-content/themes/index.php
rm -rf wp-content/themes/twentytwentyfour wp-content/themes/twentytwentythree wp-content/themes/twentytwentytwo wp-content/themes/twentytwentyone
rm -rf wp-content/themes/$THEME_DIRECTORY/composer.lock
rm -rf wp-content/themes/$THEME_DIRECTORY/vendor
rm -rf wp-content/themes/$THEME_DIRECTORY/package-lock.json
rm -rf wp-content/themes/$THEME_DIRECTORY/node_modules
exit
fi