+ winter restore perms quick helper

* wordpress quick script moved into subfolder
This commit is contained in:
2025-01-14 08:27:01 +03:00
parent bac03305bd
commit ed6c2ee369
19 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,44 @@
# Unnecessary files ignore
*.sql
*.gz
*.log
*.old
# wp config ignore
/wp-config.php
# wp-content uploads, backups and additional ignores
/wp-content/advanced-cache.php
/wp-content/aiowps_backups
/wp-content/backup-dup-lite
/wp-content/backupwordpress-*
/wp-content/backup*
/wp-content/cache
/wp-content/logs
/wp-content/updraft
/wp-content/wp-cache-config.php
/wp-content/webp-express
/wp-content/wp-rocket-config
# Letsencrypt dir ignore
/.well-known
# duplicator plugin wp-snapshots ignore
/wp-snapshots
/dup*.txt
# webmasters confirmation files
/yandex*.html
/google*.html
# IDE ignores
/.idea
# composer root vendor dir ignore
/vendor
# Apache htaccess ignore for resolve test/prod envs
/.htaccess
# Custom ignores

1
wordpress/quick/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.sh

View File

@ -0,0 +1,50 @@
#!/bin/bash
git fetch origin --prune
export LANG=en_US.UTF-8
LOCAL_BRANCHES_IN_DEVELOP=( $(git branch --merged develop --format "%(refname:short)") )
LOCAL_BRANCHES_WITHOUT_UPSTREAM=( $(git branch --format "%(refname:short) %(upstream) %(upstream:track)" | grep -vE "(develop|master)" | awk '{if ($3 == "[gone]" || !$2) print $1;}') )
if [ ${#LOCAL_BRANCHES_WITHOUT_UPSTREAM[@]} -eq 0 ]; then
echo "Нет веток без remote"
else
LOCAL_BRANCHES_WITHOUT_UPSTREAM_AND_MERGED_INTO_DEVELOP=()
for BRANCH_WITHOUT_UPSTREAM in "${LOCAL_BRANCHES_WITHOUT_UPSTREAM[@]}"; do
for BRANCH_MERGED_IN_DEVELOP in "${LOCAL_BRANCHES_IN_DEVELOP[@]}"; do
if [ "$BRANCH_WITHOUT_UPSTREAM" == "$BRANCH_MERGED_IN_DEVELOP" ]; then
LOCAL_BRANCHES_WITHOUT_UPSTREAM_AND_MERGED_INTO_DEVELOP+=( "$BRANCH_WITHOUT_UPSTREAM" )
fi
done
done
if [ ${#LOCAL_BRANCHES_WITHOUT_UPSTREAM_AND_MERGED_INTO_DEVELOP[@]} -ne 0 ]; then
echo "Ветки без remote и вмерженные в develop"
# echo "${LOCAL_BRANCHES_WITHOUT_UPSTREAM_AND_MERGED_INTO_DEVELOP[@]}" | tr " " "\n"
echo "${LOCAL_BRANCHES_WITHOUT_UPSTREAM_AND_MERGED_INTO_DEVELOP[@]}"
fi
LOCAL_BRANCHES_WITHOUT_UPSTREAM_AND_NOT_MERGED_INTO_DEVELOP=()
for BRANCH_WITHOUT_UPSTREAM in "${LOCAL_BRANCHES_WITHOUT_UPSTREAM[@]}"; do
BRANCH_IS_MERGED_INTO_DEVELOP=0
for BRANCH_MERGED_IN_DEVELOP in "${LOCAL_BRANCHES_IN_DEVELOP[@]}"; do
if [ "$BRANCH_WITHOUT_UPSTREAM" == "$BRANCH_MERGED_IN_DEVELOP" ] ; then
BRANCH_IS_MERGED_INTO_DEVELOP=1
fi
done
if [ $BRANCH_IS_MERGED_INTO_DEVELOP -eq 0 ]; then
LOCAL_BRANCHES_WITHOUT_UPSTREAM_AND_NOT_MERGED_INTO_DEVELOP+=( "$BRANCH_WITHOUT_UPSTREAM" )
fi
done
if [ ${#LOCAL_BRANCHES_WITHOUT_UPSTREAM_AND_NOT_MERGED_INTO_DEVELOP[@]} -ne 0 ]; then
echo "Ветки без remote, но еще не вмерженные в develop"
# echo "${LOCAL_BRANCHES_WITHOUT_UPSTREAM_AND_NOT_MERGED_INTO_DEVELOP[@]}" | tr " " "\n"
echo "${LOCAL_BRANCHES_WITHOUT_UPSTREAM_AND_NOT_MERGED_INTO_DEVELOP[@]}"
fi
fi

View File

@ -0,0 +1,24 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. $SCRIPT_DIR/settings.sh || {
echo "no settings" && exit 1
}
VER=$1
if [[ -z "$VER" ]]; then
echo "Version not defined in first argument."
exit
fi
cd "${SCRIPT_DIR}/.."
git fetch && git checkout $VER
if [[ `echo $?` -ne 0 ]]; then
echo "Unable to checkout choose tag or branch or error in submodule update command."
exit 1
fi
cd "${SCRIPT_DIR}/../wp-content/themes/$THEME/" && yarn && yarn build

View File

@ -0,0 +1,25 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "${SCRIPT_DIR}/settings.sh" || {
echo "no settings" && exit 1
}
wp core config --dbname=$PROJECT_NAME --dbuser=$PROJECT_NAME --dbpass=$PROJECT_NAME --dbhost=db --dbprefix=$TABLE_PREFIX
sed -i 's/<?php//' "${PROJECT_WEB_ROOT}/wp-config.php"
cat << \EOF | cat - "${PROJECT_WEB_ROOT}/wp-config.php" > /tmp/out && mv /tmp/out "${PROJECT_WEB_ROOT}/wp-config.php"
<?php
if (@$_SERVER['HTTP_HOST']) {
define('WP_SITEURL', 'http://'.$_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://'.$_SERVER['HTTP_HOST']);
}
//if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){
// $_SERVER['HTTPS'] = 'on';
// $_SERVER['SERVER_PORT'] = 443;
//}
define('FS_METHOD', 'direct');
EOF

View File

@ -0,0 +1,2 @@
#!/bin/bash
wp plugin deactivate really-simple-ssl

View File

@ -0,0 +1,15 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "${SCRIPT_DIR}/../settings.sh" || {
echo "no settings" && exit 1
}
TABLE_WP_OPTIONS="${TABLE_PREFIX}options"
TABLE_WP_POSTS="${TABLE_PREFIX}posts"
TABLE_WP_POSTMETA="${TABLE_PREFIX}postmeta"
wp search-replace "https://${PROD_DOMAIN}" "http://${LOCAL_DOMAIN}" ${TABLE_WP_OPTIONS} ${TABLE_WP_POSTS} ${TABLE_WP_POSTMETA} --report-changed-only=true
wp search-replace "https:\/\/${PROD_DOMAIN}" "http:\/\/${LOCAL_DOMAIN}" ${TABLE_WP_OPTIONS} ${TABLE_WP_POSTS} ${TABLE_WP_POSTMETA} --report-changed-only=true
wp search-replace "${PROD_DOMAIN}" "${LOCAL_DOMAIN}" ${TABLE_WP_OPTIONS} ${TABLE_WP_POSTS} ${TABLE_WP_POSTMETA} --report-changed-only=true

View File

@ -0,0 +1,31 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
WP_CONTENT_DIRS=(
plugins
upgrade
uploads
themes
)
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

View File

@ -0,0 +1,97 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "${SCRIPT_DIR}/settings.sh" || {
echo "no settings" && exit 1
}
WP_CONTENT_DIRS=(
plugins
languages
upgrade
uploads
themes
)
export WEB_GID=33
export DIRS_MODE=775
export FILES_MODE=664
echo -n "Check sudo permissions... "
sudo whoami
[ ! -d "$TMP_DIR" ] && {
echo "no tmp dir" && exit 1
}
perms() {
TARGET=$1
chmodFromFile() {
MODE=$1
FILE_LIST_FILE=$2
# shellcheck disable=SC2046
# shellcheck disable=SC2006
chmod "$MODE" `cat "$FILE_LIST_FILE"`
}
export -f chmodFromFile
echo -n "Set correct ownerships for $(basename ${TARGET})... "
sudo chown -R $UID:$WEB_GID "${TARGET}"
if [[ -d "${TARGET}" ]]; then
# echo -n "and fixing permissions for these directory... "
# echo "Fetching dirs without spaces"
find "${TARGET}" -type d -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep -v ' ' > $TMP_DIR/dirs-without-spaces
# echo "Splitting dirs by 10000 lines"
split -l 10000 $TMP_DIR/dirs-without-spaces $TMP_DIR/dirs-without-spaces-part-
# echo "Fetching files without spaces"
find "${TARGET}" -type f -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep -v ' ' > $TMP_DIR/files-without-spaces
# echo "Splitting files at 10000 lines"
split -l 10000 $TMP_DIR/files-without-spaces $TMP_DIR/files-without-spaces-part-
# echo "Fetching dirs with spaces"
find "${TARGET}" -type d -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep ' ' > $TMP_DIR/dirs-with-spaces
# echo "Fetching files with spaces"
find "${TARGET}" -type f -not \( -path *${THEME}/dist* -o -path */node_modules* \) | grep ' ' > $TMP_DIR/files-with-spaces
# echo "Fixing permissions for dirs"
# shellcheck disable=SC2038
# shellcheck disable=SC2016
find $TMP_DIR/ -maxdepth 1 -type f -name "dirs-without-spaces-part-*" | xargs -I {} bash -c 'chmodFromFile $DIRS_MODE {}'
# echo "Fixing permissions for files"
# shellcheck disable=SC2038
# shellcheck disable=SC2016
find $TMP_DIR/ -maxdepth 1 -type f -name "files-without-spaces-part-*" | xargs -I {} bash -c 'chmodFromFile $FILES_MODE {}'
# echo "Fixing permissions for dirs with spaces"
cat $TMP_DIR/dirs-with-spaces | xargs -I {} chmod $DIRS_MODE "{}"
# echo "Fixing permissions for files with spaces"
cat $TMP_DIR/files-with-spaces | xargs -I {} chmod $FILES_MODE "{}"
# echo "Removing temporary files"
rm $TMP_DIR/files-*
rm $TMP_DIR/dirs-*
echo "ok"
else
echo -n "and fixing permission for this file... "
# echo "Fixing permissions"
chmod $FILES_MODE "${TARGET}"
echo "ok"
fi
}
for DIR in "${WP_CONTENT_DIRS[@]}"; do
perms "$SCRIPT_DIR/../wp-content/$DIR"
done
#perms "$SCRIPT_DIR/../wp-content/index.php"

View File

@ -0,0 +1,24 @@
#!/bin/bash
SETTINGS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export TMP_DIR=$SETTINGS_SCRIPT_DIR/tmp
export PROJECT_NAME=wpstudio
export PROJECT_WEB_ROOT="${SETTINGS_SCRIPT_DIR}/.."
export TABLE_PREFIX="wp_"
export PROD_DOMAIN=wpstudio.ru
export LOCAL_DOMAIN=wpstudio.local.wpstudio.ru
export THEME=nicol
export SSH_PORT=22
export SSH_PROD_USERNAME=wpstudio
export SSH_PROD_SERVER=wpstudio.ru
export PROD_DATABASE_NAME=wpstudio
export LOCAL_DATABASE_NAME=wpstudio
export REMOTE_SITE_DIR=/var/www/html

View File

@ -0,0 +1,4 @@
# Place on remote server to home dir
[client]
user = wpstudio
password = PASSWORD

View File

@ -0,0 +1,24 @@
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
. "${SCRIPT_DIR}/../settings.sh" || {
echo "no settings" && exit 1
}
CONTAINER=$(docker ps | grep mariadb | awk '{print $1}')
if [[ -z "${CONTAINER}" ]]; then
echo "Unable to find container: db"
exit 1
fi
MYSQL_CMD="docker exec -i ${CONTAINER} mariadb -u root -p123456"
echo -n "Drop and recreate ${LOCAL_DATABASE_NAME} database... "
bash -c "${MYSQL_CMD} -e 'DROP DATABASE \`${LOCAL_DATABASE_NAME}\`'"
bash -c "${MYSQL_CMD} -e 'CREATE DATABASE \`${LOCAL_DATABASE_NAME}\`'"
echo "OK"
echo -n "Importing prod dump data from $SSH_PROD_SERVER ... "
ssh -C ${SSH_PROD_USERNAME}@${SSH_PROD_SERVER} "mariadb-dump --defaults-extra-file=/home/${SSH_PROD_USERNAME}/.my.cnf ${PROD_DATABASE_NAME} | sed '1d'" | pv | bash -c "${MYSQL_CMD} ${LOCAL_DATABASE_NAME}"
echo "OK"

View File

@ -0,0 +1,27 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "${SCRIPT_DIR}/../settings.sh" || {
echo "no settings" && exit 1
}
UPLOAD_DIR="wp-content/uploads"
SOURCE_UPLOADS_PATH="${REMOTE_SITE_DIR}/${UPLOAD_DIR}"
DESTINATION_UPLOADS_PATH=$(realpath "${SCRIPT_DIR}/../../${UPLOAD_DIR}")
if [ -z "$DESTINATION_UPLOADS_PATH" ]; then
echo "DESTINATION_UPLOADS_PATH is empty" && exit 1
fi
CMD="rsync -a --info=progress2 $SSH_PROD_USERNAME@$SSH_PROD_SERVER:$SOURCE_UPLOADS_PATH/ $DESTINATION_UPLOADS_PATH/"
# shellcheck disable=SC2145
echo "Execute: ${CMD}"
read -p "Are you sure? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
/bin/bash -c "${CMD}"
fi

2
wordpress/quick/tmp/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,2 @@
*
!.gitignore