Browsed by
Tag: BASH/Shell

Automatic WordPress Update Script

Automatic WordPress Update Script

Instal WP CLI on the server the WordPress is hosted on : https://wp-cli.org/#installing

Setup an update script using WP CLI commands:

#! /usr/bin/env bash
# Update all WordPress Plugins
wp plugin update --all
# Update all WordPress Translations
wp language core update
# Update WordPress Core
wp core update
# Update WordPress Database
wp core update-db
# Check no plugins need to be updated after core wordpress update. 
wp plugin update --all

Setup a scheduled task in linux crontab to run the script

0 4 * * *      user    /path/to/task/wpupdates.sh >> /path/to/logs/wordpress-$(date +\%d-\%m-\%Y).log 2>&1

Troubleshooting

Make sure that the user is the same as the folder owner

Make sure that the script is executable.

New Useful Shell Script

New Useful Shell Script

I’ve modified my SCSS Breakpoints Shell Script a tiny bit to now add @import <<viewport size>> for each of the module viewport breakpoints to my main theme.scss file. I’ve set this up to work with my own setup, but if it’s useful to anyone else I’ve added it to github.

View on Github

Previous Posts:

http://www.dgmyspace.dumgal.ac.uk/eportfolios/rumbler/useful-shell-scripts/
Useful Shell Scripts

Useful Shell Scripts

I wrote a couple of Shell Scripts to save time when splitting SCSS into breakpoint files.

https://github.com/dgrumbler/useful_shell_scripts

$ sh sassBreakpoints.sh

This creates a named folder based on the name of the module you type in.
It then creates all the breakpoints :

  • _base.scss
  • _481up.scss
  • _768down.scss
  • _768up.scss
  • _899down.scss
  • _900up.scss
  • _1029down.scss
  • _1030up.scss
  • _1240up.scss
  • _1400up.scss
  • _1600up.scss
  • _1900up.scss

Then for each breakpoint it adds the following:

/****************************************************************
	Theme: << Module Name >>
	Viewport: << Viewport Size >>
	Author: << Author >>
****************************************************************/

Replacing Module name, viewport size and author with the user input and filename.

e.g.

/****************************************************************
	Theme: Carousel
	Viewport: 768 up
	Author: Rebecca Rumble
****************************************************************/

This one does the same as the above except it doesn’t create a folder and runs in the current directory.

$ sh sassBreakpointsNoFolder.sh
https://www.dgmyspace.dumgal.ac.uk/eportfolios/rumbler/new-useful-shell-script/
Removing OSX “This resource fork intentionally left blank” message

Removing OSX “This resource fork intentionally left blank” message

Had an odd problem when editing a file locally where the following text started appearing everywhere:

Mac OS X  2ATTR com.apple.lastuseddate#PS&|o^6This resource fork intentionally left blank

After a bit of searching via Google I found out that this is caused by the finder of Mac OS creating an ._ file.

I tried to view these via CMD + SHIFT + . 

But nothing showed up. 

In terminal however if I used

$ ls -la 

It listed the ._ files

All I had to do then was run

$ rm ._tabs.php 

This solved the issue. 

WordPress Cli

WordPress Cli

WP-Cli is the WordPress command line tool. It can be used for updating WordPress, plugins and translations via the terminal.

$ cd /folder/example/
$ wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info
https://make.wordpress.org/cli/handbook/installing/
https://make.wordpress.org/cli/handbook/quick-start/

Updating Translations

$ cd /wp/folder/
$ wp language core update
$ wp language plugin update -all

Updating Plugins

$ cd /wp/folder/
$ wp plugin update --all
Learning to Use Node.js NPM and WebPack

Learning to Use Node.js NPM and WebPack

As part of my XD Plugin project I needed to use Node.js, npm and WebPack.js . I’m documenting this for my future reference.

Installing Node.js also installs a copy of npm. According to npm the copy of npm that Node.js installs is often out of date so I followed their instructions to install.

npm install npm@latest -g

Permissions Error

Note: If like me you get a permissions error just add sudo to the start. Only ever do this if you know what you are installing however!

Once that was installed I then installed Webpack.js using their instructions here : https://webpack.js.org/guides/installation/

Once I had finished that I went through the webpack basic tutorial in Terminal to get an idea what it was for.

The XD Plugin React tutorial I was following also uses Yarn so installed that as well. Yarn uses homebrew to install which I already have installed (it’s very useful).

The basic steps when creating a project that will be using a package library seems to be:

  1. Create a Project folder (mkdir)
  2. Navigate to above folder (cd)
  3. Create a package.json file (init) without asking questions ( -y )
  4. Install webpack locally and install webpack-cli this is used to run webpack on the command line
mkdir xdpluginreact
cd xdpluginreact
npm init -y
npm install webpack webpack-cli --save-dev

This creates the following files:

Screenshot of created folder structure

It is a good idea to seperate your plugin out into Dev and Distribution since we won’t need all the extra node_modules etc.

To create the initial plugin I followed the XD react tutorial: https://adobexdplatform.com/plugin-docs/tutorials/quick-start-react/

But when you finish that you end up with the main.js file located inside your development folder. You won’t want to copy the entire thing into Adobe XD because you don’t need all of it.

Adding a Distribution Folder

We want to end up with this instead:

A Screenshot of an example XD file

The example-plugin folder in the dist (distribution) folder is the one that gets copied to Adobe XD.

$ mkdir dist
$ mkdir dist/example-plugin
$ mv manifest.json dist/example-plugin
$ rm main.js

This creates the dist folder
Then Creates the example-plugin folder inside the dist folder
Moves the manifest.json (a file which Adobe XD needs) to dist/example-plugin
Deletes the currently compiled main.js

Then we need to change a couple of things. Open package.json and change the following line :

"main": "dist/example-plugin/main.js",

Open webpack.config.js and change the following line in the output section:

filename: "dist/example-plugin/main.js",
Screenshot of my webpack.config.js file.
This is what it should look like.

If I run yarn now this will create the main.js in the desired location

$ yarn build
Search for string in files

Search for string in files

$ grep -r -i "string" /your/directory/path/

-r (search recursively)

-i (case insensitive)

-l (list only file names)

--include=\*.${file_extension} – search files that match the extension(s) or file pattern only

grep -r -i -l --include \*.jpg --include \*.png --include \*.gif "Mouse" /your/directory/path/
Copy a File to a Remote Server

Copy a File to a Remote Server

Make sure you are on your local machine and not logged in to the remote server in terminal

Tip: drag and drop file into Terminal to get file address

$ scp /Users/username/Desktop/file.txt username@www.example.com:/path/public_html/foldername

Translation: SecureCoPy file on local machine to remote server at this directory path.

SSH Keyless Login

SSH Keyless Login

Useful Guide

$ ssh -keygen -t rsa

Accept default file name and don’t set a pass phrase if you don’t need one.

$ ls .ssh
$ cat .ssh/id_rsa.pub

Then Login via ssh

$ ssh user@www.example.com
$ nano .ssh/authorized_keys

Add the key copied from id_rsa.pub to authorised_keys on a new line.

CTRL + O to save

CTRL + X to exit nano

$ logout

Then try going to ssh again to login and it should auto login without asking for a password

$ ssh www.example.com