From cbbbe00cdb19711f283a429e907625084ee2fab8 Mon Sep 17 00:00:00 2001 From: dimti Date: Sun, 10 Jul 2022 11:57:01 +0300 Subject: [PATCH] + deactivate plugins helper wp script + ignore helper wp script for create .gitignore files in some wp-content dirs + nerest quick script example & readmes * update quick scripts with use SCRIPT_DIR logic (where quick scripts placed in subfolder of root project dir) * legacy create mysql example moved to root dir --- wp/new-user.sh => create-mysql-user.sh | 0 wp/.gitignore-example | 6 +-- wp/README.md | 23 +++++++++ wp/nerest-quick.sh | 5 ++ wp/quick/.gitignore-example | 1 + .../create-config.sh} | 12 +++-- wp/quick/deactivate-plugins-from-prod.sh | 5 ++ wp/quick/ignore.sh | 59 ++++++++++++++++++++++ wp/quick/restore-perms.sh | 32 ++++++++++++ wp/restore-perms.sh.example | 10 ---- 10 files changed, 135 insertions(+), 18 deletions(-) rename wp/new-user.sh => create-mysql-user.sh (100%) create mode 100644 wp/README.md create mode 100755 wp/nerest-quick.sh create mode 100644 wp/quick/.gitignore-example rename wp/{create-config.sh.example => quick/create-config.sh} (57%) create mode 100755 wp/quick/deactivate-plugins-from-prod.sh create mode 100644 wp/quick/ignore.sh create mode 100644 wp/quick/restore-perms.sh delete mode 100644 wp/restore-perms.sh.example diff --git a/wp/new-user.sh b/create-mysql-user.sh similarity index 100% rename from wp/new-user.sh rename to create-mysql-user.sh diff --git a/wp/.gitignore-example b/wp/.gitignore-example index c17f5f8..e54130d 100644 --- a/wp/.gitignore-example +++ b/wp/.gitignore-example @@ -15,8 +15,6 @@ /wp-content/cache /wp-content/logs /wp-content/updraft -/wp-content/upgrade -/wp-content/uploads /wp-content/wp-cache-config.php /wp-content/webp-express /wp-content/wp-rocket-config @@ -35,7 +33,7 @@ # IDE ignores /.idea -# Bash script helpers in root dir -/*.sh +# composer root vendor dir ignore +/vendor # Custom ignores diff --git a/wp/README.md b/wp/README.md new file mode 100644 index 0000000..9959be9 --- /dev/null +++ b/wp/README.md @@ -0,0 +1,23 @@ +# Quick scripts + +Create `quick` dir in your root project folder. + +Place `.gitignore` file in that dir with these content: + +``` +*.sh +``` + +Copy needed helper scripts in that `quick/` dir and create copies with `.example` extension for adding example-scripts to your project GIT. + +You might need add worked execute script for create executable copies from examples. + +Add `nerest-quick.sh` to you root project dir: + +```shell +#!/bin/bash +QUICK_DIR=quick + +cd $QUICK_DIR && +find ./ -name "*.sh.example" -exec sh -c 'F={}; cp -u $F ${F%.example} && chmod +x ${F%.example}' \; +``` diff --git a/wp/nerest-quick.sh b/wp/nerest-quick.sh new file mode 100755 index 0000000..9e65a1e --- /dev/null +++ b/wp/nerest-quick.sh @@ -0,0 +1,5 @@ +#!/bin/bash +QUICK_DIR=quick + +cd $QUICK_DIR && +find ./ -name "*.sh.example" -exec sh -c 'F={}; cp -u $F ${F%.example} && chmod +x ${F%.example}' \; diff --git a/wp/quick/.gitignore-example b/wp/quick/.gitignore-example new file mode 100644 index 0000000..c97f963 --- /dev/null +++ b/wp/quick/.gitignore-example @@ -0,0 +1 @@ +*.sh diff --git a/wp/create-config.sh.example b/wp/quick/create-config.sh similarity index 57% rename from wp/create-config.sh.example rename to wp/quick/create-config.sh index bdf7906..53ed3b4 100644 --- a/wp/create-config.sh.example +++ b/wp/quick/create-config.sh @@ -1,10 +1,14 @@ #!/bin/bash -NAME=invatur +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +cd "$SCRIPT_DIR/.." + +NAME=wpstudio wp core config --dbname=$NAME --dbuser=$NAME --dbpass=$NAME --dbhost=db -sed -i 's/ /tmp/out && mv /tmp/out wp-config.php +cat << \EOF | cat - "$SCRIPT_DIR/../wp-config.php" > /tmp/out && mv /tmp/out "$SCRIPT_DIR/../wp-config.php" $FILE + echo "!.gitignore" >> $FILE + fi + + git add -f $FILE +} + +ignore uploads +ignore upgrade + +if [[ $MCLOUD -eq 1 ]]; then + ignore mcloud-reports + ignore mcloud-view-cache +fi + +# Create git ignore in quick script dir + +QUICK_DIR_GIT_IGNORE="${SCRIPT_DIR}/.gitignore" + +if [[ ! -f $QUICK_DIR_GIT_IGNORE ]]; then + echo "/*.sh" > $QUICK_DIR_GIT_IGNORE +fi + +git add -f $QUICK_DIR_GIT_IGNORE diff --git a/wp/quick/restore-perms.sh b/wp/quick/restore-perms.sh new file mode 100644 index 0000000..22fcff9 --- /dev/null +++ b/wp/quick/restore-perms.sh @@ -0,0 +1,32 @@ +#!/bin/bash +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +WP_CONTENT_DIRS=( + plugins + upgrade + uploads + mcloud-reports + mcloud-view-cache +) + +export WEB_GID=33 + +perms() { + sudo chown -R $UID:$WEB_GID "$1" + sudo chmod -R g+rwx "$1" +} + +permsFile() { + sudo chown $UID:$WEB_GID "$1" + sudo chmod g+rw "$1" +} + +for DIR in "${WP_CONTENT_DIRS[@]}"; do + DIR="$SCRIPT_DIR/../wp-content/$DIR" + + if [[ -f $DIR ]]; then + permsFile "$DIR" + else + perms "$DIR" + fi +done diff --git a/wp/restore-perms.sh.example b/wp/restore-perms.sh.example deleted file mode 100644 index af113cb..0000000 --- a/wp/restore-perms.sh.example +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -DIRS=( wp-content/plugins ) -export WEB_GID=33 -perms() { - sudo chown -R $UID:$WEB_GID "$1" - sudo chmod -R g+rwx "$1" -} -for DIR in "${DIRS[@]}"; do - perms "$DIR" -done