-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.sh
executable file
·155 lines (96 loc) · 2.76 KB
/
functions.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
#!/bin/bash
function removeDatabaseCredentials {
rm ./.mysql-credentials.cnf
}
function setDatabaseCredentials {
# creating temporary credentials file
CREDENTIALS_FILE=./.mysql-credentials.cnf
echo "[client]" > $CREDENTIALS_FILE
echo "user=$DB_ROOT" >> $CREDENTIALS_FILE
echo "password=$DB_ROOT_PASSWORD" >> $CREDENTIALS_FILE
echo "host=$DB_HOST" >> $CREDENTIALS_FILE
}
function createCategory {
if [[ "$RANDOMIZE_EVERY_ITEM" == "yes" || -z "$CATEGORY_DESC_LEVEL1" ]]
then
CATEGORY_DESC_LEVEL1=$(curl -s "$RANDOM_SENTENCE_API_URL"1)
fi
CATEGORY_ID=$(wp term create category "$1" \
--path=$WP_PATH \
--description="$CATEGORY_DESC_LEVEL1" | grep -o -E '[0-9]+')
}
function getPostTitle {
if [[ "$RANDOMIZE_EVERY_ITEM" == "yes" || -z "$POST_TITLE_LEVEL1" ]]
then
POST_TITLE_LEVEL1=$(curl -s "$RANDOM_SENTENCE_API_URL"1)
fi
}
function getPostContent {
if [[ "$RANDOMIZE_EVERY_ITEM" == "yes" || ! -f .tempPost ]]
then
curl -s $RANDOM_TEXT_API_URL$COUNT_PARAGRAPHS > .tempPost
fi
}
function getPostExcerpt {
if [[ "$RANDOMIZE_EVERY_ITEM" == "yes" || -z "$POST_EXCERPT_LEVEL1" ]]
then
POST_EXCERPT_LEVEL1=$(curl -s "$RANDOM_SENTENCE_API_URL"1)
fi
}
function getPostTags {
if [[ "$RANDOMIZE_EVERY_ITEM" == "yes" || -z "$TAGS_LEVEL1" ]]
then
JSON_TAGS_LEVEL1=$(curl -s $RANDOM_WORD_API_URL$COUNT_TAGS)
TAGS_LEVEL1=$(echo "${JSON_TAGS_LEVEL1//[\"|\]]}" | sed 's/\[//g')
fi
}
function getPostImage {
if [[ "$RANDOMIZE_EVERY_ITEM" == "yes" || ! -f .tempImage.jpg ]]
then
curl --silent --output .tempImage.jpg --location $RANDOM_IMAGE_API_URI
IMAGE_TITLE_LEVEL1=$(curl -s "$RANDOM_SENTENCE_API_URL"1)
fi
}
function createPost {
getPostTitle
getPostContent
getPostExcerpt
getPostTags
POST_ID=$(wp post create .tempPost \
--path=$WP_PATH \
--post_title="$POST_TITLE_LEVEL1" \
--post_status="publish" \
--post_category="$CATEGORY_ID" \
--tags_input="$TAGS_LEVEL1" \
--post_excerpt="$POST_EXCERPT_LEVEL1" \
--meta_input="$META_INPUT" | grep -o -E '[0-9]+')
getPostImage
# add one featured image to post
wp media import .tempImage.jpg \
--path=$WP_PATH \
--post_id=$POST_ID \
--title="$IMAGE_TITLE_LEVEL1" \
--featured_image \
--quiet
# create revisions
echo -e "\r\nCreating $COUNT_POST_REVISIONS post revisions..."
POST_REVISION_INDEX=1
while [ $POST_REVISION_INDEX -le $COUNT_POST_REVISIONS ]
do
echo -e ".\c"
getPostContent
wp post update $POST_ID \
.tempPost \
--path=$WP_PATH \
--post_name=something \
--quiet
((POST_REVISION_INDEX++))
done
# add additional image to post
getPostImage
wp media import .tempImage.jpg \
--path=$WP_PATH \
--post_id=$POST_ID \
--title="$IMAGE_TITLE_LEVEL1"
echo "...Done"
}