1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#+TITLE: How This Blog Is Set Up
#+DATE: 2020-06-17T21:03:26-04:00
#+DRAFT: true
#+DESCRIPTION:
#+TAGS[]: hugo openbsd emacs
#+KEYWORDS[]:
#+SLUG:
#+SUMMARY:
When I was thinking about making this blog, there were a couple of
factors I kept in mind when I was trying to figure out how I was going
to set it up. Here's a simplified list of that:
- Simple
- Version controlled
- Runs on OpenBSD
- Minimal maintenance
- Good integration with Emacs
That's how I came up with what I currently use. Let me walk you
through how I run by blog.
* Framework
The blog engine is [[https://gohugo.io/][hugo]], a static site generator. I chose this over
something dynamic like wordpress for several reasons.
First of all, it's very easy to manage, blog posts are just simple
files written in one of the markup languages hugo supports. Being
statically generated is also a massive advantage in terms of
maintenance. With something like wordpress, you have to be careful to
keep your site and plugins up to date.
Since there's no dynamic content generation or database involved with
hugo, the attack surface is dramatically decreased. No possibility for
SQL injection, PHP RATs, accidental shell access, or hacked
credentials. The entire site is generated using a single command after
a new post is created, and then moved to the web server's root
directory.
Being all flat files also means the entire thing can very easily be
tracked using =git= (or maybe [[https://gameoftrees.org/][got]], eventually), in fact that's the
recommended way to use hugo. There's no fear I'll accidentally delete
something, as I can always go back to a previous commit and restore
it.
Since hugo is written in go, it's trivial to compile on OpenBSD, and
is actually available directly from the OpenBSD package manager right
out of the gate.
Maybe the most important thing to be however, is that hugo natively
supports org-mode markup. I write all my notes, both personal and work
related, in org-mode. It makes converting my notes into blog posts
really easy. It also lets me leverage my existing Emacs setup, which
comes in handy often. While it's not very well documented, since
org-mode markup is a bit of a second class citizen in the hugo world,
it's pretty easy to figure out.
* Prerequisites
The only thing that's required on the host server is =git=, although
you could even get away without that if you chose to host your git
repository elsewhere, like on github.
#+BEGIN_SRC shell
pkg_add git
#+END_SRC
* Version Control
I wanted to try to keep things as simple as possible for this. The
"origin" for the blog is simply a bare git repository in the =blog=
user's home directory. This blog user was also made the owner of the
blog document root directory.
** Setting up the blog user
First I set up the blog user
#+BEGIN_SRC shell
useradd -m blog
#+END_SRC
I then placed my public SSH key in its =authorized_keys= file
#+BEGIN_SRC shell
mkdir -m 700 /home/blog/.ssh
cp /root/.ssh/authorized_keys /home/blog/.ssh/
chown -R blog:blog /home/blog
#+END_SRC
I then logged in as the blog user and initialize the bare git
repository.
#+BEGIN_SRC shell
su blog
cd # cd with no arguments goes to home directory
git init --bare blog.git
#+END_SRC
** Cloning the repository
Cloning the repository onto my local machine is very easy at this
point. As long as my private keys are in the =blog= user's
=authorized_keys=, git will take care of the rest.
#+BEGIN_SRC shell
# on my local machine
git clone blog@lambda.cx:blog.git
#+END_SRC
|