-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_textpattern.zsh
More file actions
executable file
·80 lines (67 loc) · 1.8 KB
/
setup_textpattern.zsh
File metadata and controls
executable file
·80 lines (67 loc) · 1.8 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
#!/bin/zsh
# --- CONFIGURABLE VARIABLES ---
REPO_URL="https://github.com/textpattern/textpattern.git"
REPO_BRANCH="dev"
REPO_DIR="textpattern"
TMP_DIR="textpattern_tmp"
SETUP_JSON="setup.json"
# List of files/folders (relative to $REPO_DIR) to delete; extend/alter as needed
TO_DELETE=(
".git"
".github"
".gitignore"
".gitattributes"
".phpstorm.meta.php"
"phpcs.xml"
"composer.lock"
"composer.json"
"package.json"
"HISTORY.txt"
"UPGRADE.txt"
"INSTALL.txt"
"LICENSE.txt"
"README.txt"
"README.md"
"CONTRIBUTING.md"
"CODE_OF_CONDUCT.md"
"SECURITY.md"
"rpc"
"sites"
)
# --- SCRIPT START ---
set -e # Exit on errors
# 1. Clone the repo
git clone "$REPO_URL" --branch "$REPO_BRANCH" --depth 1
# 2. Delete listed files/folders
for item in $TO_DELETE; do
target="$REPO_DIR/$item"
if [[ -e $target ]]; then
rm -rf "$target"
echo "Deleted: $target"
fi
done
# 3. Rename the folder
mv "$REPO_DIR" "$TMP_DIR"
# 4. Copy contents to base folder
cp -a "$TMP_DIR/." .
# 5. Delete leftover folder
rm -rf "$TMP_DIR"
# 6. Read setup.json and create MySQL DB if it doesn't exist
if [[ ! -f $SETUP_JSON ]]; then
echo "ERROR: $SETUP_JSON not found!"
exit 1
fi
db_host=$(jq -r '.database.host' "$SETUP_JSON")
db_user=$(jq -r '.database.user' "$SETUP_JSON")
db_pass=$(jq -r '.database.password' "$SETUP_JSON")
db_name=$(jq -r '.database.db_name' "$SETUP_JSON")
db_char=$(jq -r '.database.charset' "$SETUP_JSON")
if mysql -h"$db_host" -u"$db_user" -p"$db_pass" -e "USE \`$db_name\`;" 2>/dev/null; then
echo "Database $db_name already exists. Exiting."
exit 1
else
mysql -h"$db_host" -u"$db_user" -p"$db_pass" --default-character-set="$db_char" -e "CREATE DATABASE \`$db_name\`;"
echo "Database $db_name created."
fi
# 7. Run setup
php textpattern/setup/setup.php --config="$SETUP_JSON"