Jekyll is a cool way to quickly produce web content. You can view your site locally running this command from the root of your jekyll site:

jekyll serve

It also automatically updates when files change.

Now I needed an efficient way to upload the website to my host.

Difficulty: no rsync or ssh keys.

My new hosting service didn’t provide rsync or the ability to use SSH keys to upload changes to my website without entering a password every time.

I wanted to keep things fairly secure so no password could be stored in a file (it could be made public in a git repository), passed as a parameter to a script (it could be seen in a call to ps), or shown on the screen (it could be seen by another person).

I created two scripts. One calls Jekyll to compile the website and get just the files I need into a directory structure. The other is an expect script that manages the upload using scp.

Here is a line by line break-down of what the scripts do:

3. I use Oh-my-zsh which provides some nice out-of-the-box colouring and macros.
4. This method doesn’t delete files you don’t want anymore. You have to delete these manually at present.
5. Jekyll compiles your site.
6. Remove the staging directory that we will use to upload with scp.
7. Create the staging directory fresh.
8. Recursively copy the generated Jekyll site.
9. Delete all the files that are older than 2 weeks.
10. Call the Expect script to do the upload.

13. This is a script in the Expect language.
14. Hide the user output so that our password is not visible.
15. Calls a command that displays the password as saved previously in Keychain Access under the name xxxxx.
16. Matches anything that is returned that has at least one character.
17. Set the returned password to a variable whose name doesn’t sound like “password”.
18. Run SCP to connect to my website and copy the changed files. Note that you have to run a shell that can expand your * wildcard in the copy command. Expect can’t do it on its own. 19. Wait for the prompt to enter the password.
20. Send the password to the prompt.
21. Turn on user output.
22. Makes the output of the SCP command visible.