I edit my blog using a desktop Mac, a Macbook, and an iPad. Now I use ssh and TextWrangler on the Macs and Textastic on the iPad. But if I'm not connected, I'm out of luck. In addition, I am actually editing the live site, which has the potential for disaster. I wanted to have the ability to edit and post to the site while offline, have some degree of version control to roll back mistakes and as well as have backups if the webserver crashes or I screw up by deleting some file.
I decided to use git to manage the blog so I can have multiple machines editing and some degree of distributed backup. There are a number of articles on the web regarding this (for example, here), but my system is a little bit different.
For the server running OpenBSD with httpd as the web server, the workflow is this:
Here, the git repo "devel.repo.git" acts as the central repository. The remote repos on the client machines are clones of the devel.repo.git. After edits, commits are pushed to the devel.repo.git master. A post-receive hook checks out the files to the web server www document root (see below).
So to set up the OpenBSD box:
1. Set up passwordless ssh using shared keys: This is well-described in multiple sources. For the iPad, there are some quirks (see below).
2. Install git: By the usual package system:
pkg_add -v git
3. Create git repos:
First, create the shared development repo that the remote users will clone and push to. This should be a bare repository. This will have a post-receive script to checkout the HTML and other files to the web document root. Another non-bare repository is also created to act as a backup repo and initial source of the files in the central shared bare repo.
cd ~/blog/git-repos/ mkdir live.blog devel.blog.git cd devel.blog.git git init --bare touch hooks/post-receive chmod 755 hooks/post-receive cd ../live.blog git init cp -R /var/www/htdocs/vhosts/blog/* . git add -A git commit -a -m "Initial commit" git add remote devel /home/user/blog/git-repos/devel.blog.git git push devel master
4. Post-receive script:
#!/bin/sh GIT_WORK_TREE=/path/to/webroot/of/website git checkout -f --
The "--" in git-checkout acts to only checkout the changed files.
First, git (part of the xcode command line tools) is installed. Then, be sure passwordless ssh access with private/public keys to your server works. A key passphrase should be used. Next, the devel repository is cloned and TextWrangler is set as the editor. To do this, be sure the command line tools for TextWrangler need are installed. (You can check by seeing if /usr/local/bin/edit exists.):
cd ~ mkdir git-repos cd git-repo git clone ssh://email@example.com:/home/user/blog/git-repos/devel.blog.git git config --global core.editor /usr/local/bin/edit
Now, the terminal can be used to manage the repo with TextWrangler as the editor as before. To edit a file if you'e working in the repo directory, simply enter in the terminal:
TextWrangler pops up with the file open, edit it, and save. Now, go back to the terminal and check "git status" and you will see the new file or modified file. Then, it's a matter of "git add new_filename.html" or "git add -a" followed by "git commit." Finally, when all your work is done, "git push." The commit to the devel.repo.git on the web server updates the web site.
First, set up passwordless ssh access to the webserver. Working Copy (WC) tends to be very fastidious about the private key for the server. It says it must be in OpenSSH format yet rejects keys made with "keygen -o" on both the Mac and OpenBSD. The best approach is just to use or generate keys in WC and export the public key to the server.
Once you have this set up, clone the devel repo. When you select a file to edit, simply select "Open in Textastic" from the Share menu on the top right and the file opens in the Textastic editor. As you edit (the actual file in the WC silo), the changes appear in WC. No need to save or share back - pretty slick.
Then it's the usual git commit and git push in WC. The web site updates seamlessly. With this set up, it's now easier to manage the blog from the iPad than the desktop!
Important: Remember, when you're editing from multiple device or locations, to "git pull" to get the current master before you start up on a new edit!
Posted by Gordon, No Hair Blog, Apr 15, 2018
© nohair.net and the author