Skip to content

Instantly share code, notes, and snippets.

View lsemenenko's full-sized avatar

Leo Semenenko lsemenenko

View GitHub Profile
@lsemenenko
lsemenenko / gist:8282e34ef722e9e75843396ea3d13607
Created January 21, 2021 03:49
Change all users with specific role to another role across MU network with WP-CLI
for i in $(sudo -u www-data wp site list --field=url); \
do
echo ${i}; \
a="$(sudo -u www-data wp user list --url=${i} --role=SuperUser --field=user_login)"; \
if [[ ! -z "${a}" ]]; then \
sudo -u www-data wp user --url="${i}" update "${a}" --role "administrator"; \
echo "User ${a} updated for site ${i}."; \
fi; \
done
@lsemenenko
lsemenenko / gist:b080ea195de92869449cd3f241b5ae7e
Created March 22, 2020 09:12
Resize filesystem on live instance
sudo file -s /dev/xvd*
/dev/xvda: DOS/MBR boot sector
/dev/xvda1: Linux rev 1.0 ext4 filesystem data, UUID=651cda91-e465-4685-b697-67aa07181279, volume name "cloudimg-rootfs" (needs journal recovery) (extents) (64bit) (large files) (huge files)
sudo growpart /dev/xvda 1
sudo resize2fs /dev/xvda1
@lsemenenko
lsemenenko / gist:f47b93184afed83fd7c5589b4ff109f4
Last active July 17, 2020 02:04
Format PDF text export from BOA for Tiller Import
#!/bin/bash
pat='([0-9]{2}/[0-9]{2}/[0-9]{2}).(.*)\ (-?[0-9,]+\.[0-9]{2})'
while IFS= read -r line; do
[[ $line =~ $pat ]] &&
echo "${BASH_REMATCH[1]}|${BASH_REMATCH[2]}|${BASH_REMATCH[3]}"
done <file.txt
@lsemenenko
lsemenenko / main.sh
Created February 22, 2020 06:18
Trigger Github Actions repository_dispatch with curl
#!/bin/bash
TOKEN=""
REPO="" # format: username/repository
EVENT_TYPE=""
curl -H "Accept: application/vnd.github.everest-preview+json" \
-H "Authorization: token ${TOKEN}" \
--request POST \
--data '{"event_type": "${EVENT_TYPE}"}' \
@lsemenenko
lsemenenko / main.sh
Last active February 21, 2020 07:11
Quick find for WordPress malware
#!/bin/bash
# Find includes that start with escape character
grep -R '@include \"\\'
# Find files that end with ico and have a random 8 character filename.
find . | egrep "\.[0-9a-z]{8}.ico"
# Find files with ico code include injected at the top.
@lsemenenko
lsemenenko / main.sh
Created February 15, 2020 10:18
Interate through plugin folders, rename, and pause; used for troubleshooting plugin issues
for i in $(find ./wp-content/plugins -maxdepth 1 ! -path . -type d)
do
sudo mv ${i} ${i}.old
echo "Disabled ${i}"
read -p "Press enter to continue"
done
@lsemenenko
lsemenenko / main.sh
Created February 14, 2020 06:05
Pull entrypoint/cmd from running containers
docker inspect -f "{{.Path}} {{.Args}} ({{.Id}})" $(docker ps -a -q)
Source: https://stackoverflow.com/questions/30441035/how-to-find-the-cmd-command-of-a-docker-image
@lsemenenko
lsemenenko / watch.sh
Last active February 15, 2020 10:19 — forked from fago/watch.sh
Inotify script to trigger a command on file changes, e.g. rsync
#!/bin/bash
# (c) Wolfgang Ziegler // fago
#
# Inotify script to trigger a command on file changes.
#
# The script triggers the command as soon as a file event occurs. Events
# occurring during command execution are aggregated and trigger a single command
# execution only.
#
# Usage example: Trigger rsync for synchronizing file changes.
@lsemenenko
lsemenenko / main.sh
Last active February 13, 2020 06:56
Remove linkojager.org injected js from WordPress posts
#!/bin/bash
wp search-replace '\<img style="width: 0; height: 0; display: none; visibility: hidden;" src="(https?:)?\/\/linkojager\.org\/.+\/\>' '' --regex
wp search-replace '\<script.+src="(https?:)?\/\/linkojager\.org\/.+\<\/script\>' '' --regex
@lsemenenko
lsemenenko / main.sh
Created January 29, 2020 05:59
WordPress: Merge existing single site into existing multisite installation
#!/usr/bin/env bash
#
# This is a rudimentary script to merge wordpress single site into existing multisite
#
site1_directory="" # path to single site installation. example: /sites/google.com/public
site2_directory="" # path to new multisite installation.
new_blog_id="" # the new blog id
cd ${site1_directory} && \