Compare commits

...

12 Commits

Author SHA1 Message Date
1bd264478c * ignore sh files in winter quick 2025-01-15 11:07:56 +03:00
ed6c2ee369 + winter restore perms quick helper
* wordpress quick script moved into subfolder
2025-01-14 08:27:01 +03:00
bac03305bd + example content for --defaults-extra-file option on remote server mariadb dump 2024-06-18 09:33:17 +03:00
e5f35243e4 + import prod to local database script with ssh native compression
+ lighten restore perms script because on small count of files - that is better speed
2024-06-18 09:24:24 +03:00
0b25140481 - remove execute file bit from example bash files 2024-06-04 12:13:59 +03:00
51c4dc0b8b + sync script for wp uploads 2024-06-04 12:01:38 +03:00
2d56599c73 + quick sync from old prod server scripts 2024-04-20 11:37:59 +03:00
9c0d583c8d + optimize restore perms for any project and grav perms set 2024-04-12 13:37:50 +03:00
bc7443dc86 * refactoring use cat {} in subcommand with xargs
+ tmp dir for restore-perms script
2023-10-24 16:54:44 +03:00
b187f6d342 + show branches merged to develop and without upstream 2023-10-16 19:18:35 +03:00
2c9b6efedc * fix DIRS_MODE - add execute bit for other users 2023-09-08 09:09:48 +03:00
15a30eaa78 + smart restore perms - for files set 664 mode (u: rw, g: rw, o: r) and for directories 774 mode (u: rwx, g: rwx, o: rx) 2023-09-06 17:48:13 +03:00
29 changed files with 450 additions and 15 deletions

View File

@ -0,0 +1,18 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export TMP_DIR=$SCRIPT_DIR/tmp
DIRS=(
cache
logs
user/config
user/data
user/accounts
user/pages
user/themes/quark/images
tmp
backup
images
assets
)

View File

@ -0,0 +1,87 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "${SCRIPT_DIR}/_settings.sh" || {
echo "no settings" && exit 1
}
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 "${DIRS[@]}"; do
perms "$SCRIPT_DIR/../$DIR"
done

View File

@ -1,12 +0,0 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PROJECT_NAME=wpstudio
export PROJECT_WEB_ROOT="${SCRIPT_DIR}/.."
export TABLE_PREFIX="wp_"
export PROD_DOMAIN=wpstudio.ru
export LOCAL_DOMAIN=wpstudio.local.wpstudio.ru
export THEME=nicol

1
server/quick/sync-old-prod/.gitignore vendored Normal file
View File

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

View File

@ -0,0 +1,4 @@
#!/bin/bash
REMOTE_SSH_USER=site_name
REMOTE_SSH_HOST=host_name
REMOTE_SSH_PORT=22

View File

@ -0,0 +1,41 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. $SCRIPT_DIR/_settings.sh || {
echo "no settings" && exit 1
}
REMOTE_FROM_DATABASE_USERNAME=some_username
REMOTE_FROM_DATABASE_PASSWORD=some_password
REMOTE_FROM_DATABASE_NAME=some_database
DATABASE_USERNAME=site_name
DATABASE_PASSWORD='password'
DATABASE_NAME=site_name
echo -n "SSH connection verify... "
ssh $REMOTE_SSH_USER@$REMOTE_SSH_HOST -p $REMOTE_SSH_PORT "whoami"
if [[ "$?" -ne 0 ]]; then
echo "That is not ok... Abort program!"
exit 1
fi
WITHOUT_DROP_LOCAL_DB=0
if [[ ! -z "$1" ]]; then
WITHOUT_DROP_LOCAL_DB=1
fi
if [[ $WITHOUT_MAKE_DUMP -ne 1 ]]; then
echo -n "Drop and recreate local database... "
mariadb -e "DROP DATABASE \`${DATABASE_NAME}\`"
mariadb -e "CREATE DATABASE \`${DATABASE_NAME}\`"
fi
echo -n "Loading database from remote server... "
ssh $REMOTE_SSH_USER@$REMOTE_SSH_HOST -p $REMOTE_SSH_PORT \
"mysqldump -u $REMOTE_FROM_DATABASE_USERNAME -p$REMOTE_FROM_DATABASE_PASSWORD $REMOTE_FROM_DATABASE_NAME | bzip2 -c" \
| pv | bzip2 -cd | mariadb -u $DATABASE_USERNAME -p''"$DATABASE_PASSWORD"'' ${DATABASE_NAME}
echo "OK"

View File

@ -0,0 +1,14 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. $SCRIPT_DIR/_settings.sh || {
echo "no settings" && exit 1
}
REMOTE_FROM_DIR_PATH=some_absolute_path_without_end_slash
DESTINATION_DIR_PATH=/var/www/html/wp-content/uploads
echo -n "Upload... "
rsync -a --info=progress2 -e "ssh -p ${REMOTE_SSH_PORT}" $REMOTE_SSH_USER@$REMOTE_SSH_HOST:$REMOTE_FROM_DIR_PATH/ $DESTINATION_DIR_PATH/
echo "OK"

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

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

View File

@ -0,0 +1,8 @@
#!/bin/bash
SETTINGS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# exporting variables dot not effect to visibility for other scripts - all variables is visible
export TMP_DIR=$SETTINGS_SCRIPT_DIR/tmp
export THEME=demo

View File

@ -0,0 +1,29 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "$SCRIPT_DIR/_settings.sh" || {
echo "no settings" && exit 1
}
APP_DIR="${SCRIPT_DIR}/.."
PLUGINS=(winter)
THEME_DIRS=(layouts pages partials)
export WEB_GID=33
perms() {
sudo chown -R $UID:$WEB_GID "$1"
sudo chmod -R g+rwx "$1"
}
perms "${APP_DIR}/storage"
perms "${APP_DIR}/bootstrap/cache"
for DIR in "${THEME_DIRS[@]}"; do
perms "${APP_DIR}/themes/$THEME/$DIR"
done
for DIR in "${PLUGINS[@]}"; do
perms "${APP_DIR}/plugins/$DIR"
done

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

@ -5,16 +5,27 @@ WP_CONTENT_DIRS=(
plugins
upgrade
uploads
themes
)
export WEB_GID=33
perms() {
sudo chown -R $UID:$WEB_GID "$1"
find "$1" -type d -exec chmod g+rwx '{}' \;
find "$1" -type f -exec chmod g+rw '{}' \;
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
perms "$SCRIPT_DIR/../wp-content/$DIR"
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