summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Whited2019-01-18 23:07:23 -0600
committerSam Whited2019-01-18 23:07:23 -0600
commitc6d13de1ebe622309f86c1a2dac9a1ca513bcb36 (patch)
tree43be4425a8c4703aee47a8156dc44fe8db45dff0
parent5c303e3de0fcd2ebd3a4fea581ea5e2b6e62e33b (diff)
downloadaur-c6d13de1ebe622309f86c1a2dac9a1ca513bcb36.tar.gz
Rework file layouts, fix permissions, etc.
-rw-r--r--69.patch277
-rw-r--r--PKGBUILD45
-rw-r--r--config.ini19
-rw-r--r--writefreely.install13
-rw-r--r--writefreely.service4
5 files changed, 316 insertions, 42 deletions
diff --git a/69.patch b/69.patch
new file mode 100644
index 00000000000..a6bae88763a
--- /dev/null
+++ b/69.patch
@@ -0,0 +1,277 @@
+From 53a51be578458960f23c62711740d97ba1043237 Mon Sep 17 00:00:00 2001
+From: Matt Baer <matt@write.as>
+Date: Fri, 18 Jan 2019 18:57:04 -0500
+Subject: [PATCH 1/2] Support configuring resource directories
+
+This adds new configuration values that specify the parent directory of
+application resources:
+
+- templates_parent_dir
+- static_parent_dir
+- pages_parent_dir
+- keys_parent_dir
+
+For any values not specified, the application will default to the
+current directory.
+
+This closes T560
+---
+ app.go | 7 +++---
+ config/config.go | 5 +++++
+ keys.go | 12 +++++++++++
+ templates.go | 56 ++++++++++++++++++++++++------------------------
+ 4 files changed, 49 insertions(+), 31 deletions(-)
+
+diff --git a/app.go b/app.go
+index 9fc04a9..af7fa72 100644
+--- a/app.go
++++ b/app.go
+@@ -19,6 +19,7 @@ import (
+ "net/url"
+ "os"
+ "os/signal"
++ "path/filepath"
+ "regexp"
+ "strings"
+ "syscall"
+@@ -41,7 +42,7 @@ import (
+ )
+
+ const (
+- staticDir = "static/"
++ staticDir = "static"
+ assumedTitleLen = 80
+ postsPerPage = 10
+
+@@ -336,7 +337,7 @@ func Serve() {
+ isSingleUser = app.cfg.App.SingleUser
+ app.cfg.Server.Dev = *debugPtr
+
+- initTemplates()
++ initTemplates(app.cfg)
+
+ // Load keys
+ log.Info("Loading encryption keys...")
+@@ -395,7 +396,7 @@ func Serve() {
+ }
+
+ // Handle static files
+- fs := http.FileServer(http.Dir(staticDir))
++ fs := http.FileServer(http.Dir(filepath.Join(app.cfg.Server.StaticParentDir, staticDir)))
+ shttp.Handle("/", fs)
+ r.PathPrefix("/").Handler(fs)
+
+diff --git a/config/config.go b/config/config.go
+index 2acf763..ffecc72 100644
+--- a/config/config.go
++++ b/config/config.go
+@@ -30,6 +30,11 @@ type (
+ TLSCertPath string `ini:"tls_cert_path"`
+ TLSKeyPath string `ini:"tls_key_path"`
+
++ TemplatesParentDir string `ini:"templates_parent_dir"`
++ StaticParentDir string `ini:"static_parent_dir"`
++ PagesParentDir string `ini:"pages_parent_dir"`
++ KeysParentDir string `ini:"keys_parent_dir"`
++
+ Dev bool `ini:"-"`
+ }
+
+diff --git a/keys.go b/keys.go
+index 92a9ad5..ccc872e 100644
+--- a/keys.go
++++ b/keys.go
+@@ -38,16 +38,28 @@ func initKeys(app *app) error {
+ var err error
+ app.keys = &keychain{}
+
++ emailKeyPath = filepath.Join(app.cfg.Server.KeysParentDir, emailKeyPath)
++ if debugging {
++ log.Info(" %s", emailKeyPath)
++ }
+ app.keys.emailKey, err = ioutil.ReadFile(emailKeyPath)
+ if err != nil {
+ return err
+ }
+
++ cookieAuthKeyPath = filepath.Join(app.cfg.Server.KeysParentDir, cookieAuthKeyPath)
++ if debugging {
++ log.Info(" %s", cookieAuthKeyPath)
++ }
+ app.keys.cookieAuthKey, err = ioutil.ReadFile(cookieAuthKeyPath)
+ if err != nil {
+ return err
+ }
+
++ cookieKeyPath = filepath.Join(app.cfg.Server.KeysParentDir, cookieKeyPath)
++ if debugging {
++ log.Info(" %s", cookieKeyPath)
++ }
+ app.keys.cookieKey, err = ioutil.ReadFile(cookieKeyPath)
+ if err != nil {
+ return err
+diff --git a/templates.go b/templates.go
+index d03fb0d..802856f 100644
+--- a/templates.go
++++ b/templates.go
+@@ -11,10 +11,10 @@
+ package writefreely
+
+ import (
+- "fmt"
+ "github.com/dustin/go-humanize"
+ "github.com/writeas/web-core/l10n"
+ "github.com/writeas/web-core/log"
++ "github.com/writeas/writefreely/config"
+ "html/template"
+ "io"
+ "io/ioutil"
+@@ -54,53 +54,53 @@ func showUserPage(w http.ResponseWriter, name string, obj interface{}) {
+ }
+ }
+
+-func initTemplate(name string) {
++func initTemplate(parentDir, name string) {
+ if debugging {
+- log.Info(" %s%s%s.tmpl", templatesDir, string(filepath.Separator), name)
++ log.Info(" " + filepath.Join(parentDir, templatesDir, name+".tmpl"))
+ }
+
+ files := []string{
+- filepath.Join(templatesDir, name+".tmpl"),
+- filepath.Join(templatesDir, "include", "footer.tmpl"),
+- filepath.Join(templatesDir, "base.tmpl"),
++ filepath.Join(parentDir, templatesDir, name+".tmpl"),
++ filepath.Join(parentDir, templatesDir, "include", "footer.tmpl"),
++ filepath.Join(parentDir, templatesDir, "base.tmpl"),
+ }
+ if name == "collection" || name == "collection-tags" {
+ // These pages list out collection posts, so we also parse templatesDir + "include/posts.tmpl"
+- files = append(files, filepath.Join(templatesDir, "include", "posts.tmpl"))
++ files = append(files, filepath.Join(parentDir, templatesDir, "include", "posts.tmpl"))
+ }
+ if name == "collection" || name == "collection-tags" || name == "collection-post" || name == "post" {
+- files = append(files, filepath.Join(templatesDir, "include", "post-render.tmpl"))
++ files = append(files, filepath.Join(parentDir, templatesDir, "include", "post-render.tmpl"))
+ }
+ templates[name] = template.Must(template.New("").Funcs(funcMap).ParseFiles(files...))
+ }
+
+-func initPage(path, key string) {
++func initPage(parentDir, path, key string) {
+ if debugging {
+- log.Info(" %s", key)
++ log.Info(" [%s] %s", key, path)
+ }
+
+ pages[key] = template.Must(template.New("").Funcs(funcMap).ParseFiles(
+ path,
+- filepath.Join(templatesDir, "include", "footer.tmpl"),
+- filepath.Join(templatesDir, "base.tmpl"),
++ filepath.Join(parentDir, templatesDir, "include", "footer.tmpl"),
++ filepath.Join(parentDir, templatesDir, "base.tmpl"),
+ ))
+ }
+
+-func initUserPage(path, key string) {
++func initUserPage(parentDir, path, key string) {
+ if debugging {
+- log.Info(" %s", key)
++ log.Info(" [%s] %s", key, path)
+ }
+
+ userPages[key] = template.Must(template.New(key).Funcs(funcMap).ParseFiles(
+ path,
+- filepath.Join(templatesDir, "user", "include", "header.tmpl"),
+- filepath.Join(templatesDir, "user", "include", "footer.tmpl"),
++ filepath.Join(parentDir, templatesDir, "user", "include", "header.tmpl"),
++ filepath.Join(parentDir, templatesDir, "user", "include", "footer.tmpl"),
+ ))
+ }
+
+-func initTemplates() error {
++func initTemplates(cfg *config.Config) error {
+ log.Info("Loading templates...")
+- tmplFiles, err := ioutil.ReadDir(templatesDir)
++ tmplFiles, err := ioutil.ReadDir(filepath.Join(cfg.Server.TemplatesParentDir, templatesDir))
+ if err != nil {
+ return err
+ }
+@@ -109,20 +109,16 @@ func initTemplates() error {
+ if !f.IsDir() && !strings.HasPrefix(f.Name(), ".") {
+ parts := strings.Split(f.Name(), ".")
+ key := parts[0]
+- initTemplate(key)
++ initTemplate(cfg.Server.TemplatesParentDir, key)
+ }
+ }
+
+ log.Info("Loading pages...")
+ // Initialize all static pages that use the base template
+- filepath.Walk(pagesDir, func(path string, i os.FileInfo, err error) error {
++ filepath.Walk(filepath.Join(cfg.Server.PagesParentDir, pagesDir), func(path string, i os.FileInfo, err error) error {
+ if !i.IsDir() && !strings.HasPrefix(i.Name(), ".") {
+- parts := strings.Split(path, string(filepath.Separator))
+ key := i.Name()
+- if len(parts) > 2 {
+- key = fmt.Sprintf("%s%s%s", parts[1], string(filepath.Separator), i.Name())
+- }
+- initPage(path, key)
++ initPage(cfg.Server.PagesParentDir, path, key)
+ }
+
+ return nil
+@@ -130,14 +126,18 @@ func initTemplates() error {
+
+ log.Info("Loading user pages...")
+ // Initialize all user pages that use base templates
+- filepath.Walk(filepath.Join(templatesDir, "user"), func(path string, f os.FileInfo, err error) error {
++ filepath.Walk(filepath.Join(cfg.Server.TemplatesParentDir, templatesDir, "user"), func(path string, f os.FileInfo, err error) error {
+ if !f.IsDir() && !strings.HasPrefix(f.Name(), ".") {
+- parts := strings.Split(path, string(filepath.Separator))
++ corePath := path
++ if cfg.Server.TemplatesParentDir != "" {
++ corePath = corePath[len(cfg.Server.TemplatesParentDir)+1:]
++ }
++ parts := strings.Split(corePath, string(filepath.Separator))
+ key := f.Name()
+ if len(parts) > 2 {
+ key = filepath.Join(parts[1], f.Name())
+ }
+- initUserPage(path, key)
++ initUserPage(cfg.Server.TemplatesParentDir, path, key)
+ }
+
+ return nil
+
+From 5c19d249b67a3d550cf58e5263a46af553f60d0e Mon Sep 17 00:00:00 2001
+From: Matt Baer <matt@write.as>
+Date: Fri, 18 Jan 2019 19:17:10 -0500
+Subject: [PATCH 2/2] Log and exit when templates init fails
+
+---
+ app.go | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/app.go b/app.go
+index af7fa72..ddb6e20 100644
+--- a/app.go
++++ b/app.go
+@@ -337,11 +337,15 @@ func Serve() {
+ isSingleUser = app.cfg.App.SingleUser
+ app.cfg.Server.Dev = *debugPtr
+
+- initTemplates(app.cfg)
++ err := initTemplates(app.cfg)
++ if err != nil {
++ log.Error("load templates: %s", err)
++ os.Exit(1)
++ }
+
+ // Load keys
+ log.Info("Loading encryption keys...")
+- err := initKeys(app)
++ err = initKeys(app)
+ if err != nil {
+ log.Error("\n%s\n", err)
+ }
diff --git a/PKGBUILD b/PKGBUILD
index b125e6fa91c..ddf87e98a32 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -2,7 +2,7 @@
pkgname=writefreely
pkgver=0.7.1
-pkgrel=1
+pkgrel=2
pkgdesc='Federated blogging from write.as'
arch=('x86_64')
url='https://writefreely.org/'
@@ -12,17 +12,20 @@ makedepends=('go>=1.11'
'sqlite')
optdepends=('sqlite: For SQLite support',
'mariadb: For MariaDB support')
-backup=('var/lib/writefreely/config.ini')
+backup=('var/lib/writefreely/config.ini'
+ 'etc/writefreely/config.ini')
install=writefreely.install
-source=('writefreely-sysusers.conf'
- 'writefreely.service'
- 'config.ini'
- '64.patch'
+source=(writefreely-sysusers.conf
+ writefreely.service
+ config.ini
+ 64.patch
+ 69.patch
"https://github.com/writeas/writefreely/archive/v${pkgver}.tar.gz")
sha256sums=('6c74c81e27165851daf20d4bcf958227342f063aa3ec53b1cb86a56dac565f10'
- '142fcf18320a418b73ed0678acea58ae69287e47760d6abb5283376c21092dec'
- '6946f0211b25743451954d2c155222df2aeaf7f49c3fafcb9183c6fc62a95ef9'
+ '60d4b49872523a2aed3e0e6a55513dfefe5ae6cbec43f2fcc65db894fb3bd2a3'
+ 'e357b687bd0eab95996711276216b6f2dc534ba9214ae094172d6d7a6b1fdae5'
'009c083488511d92b489337f7feb8bd17631a104907959d21b1f9b5df3ce0a70'
+ '3a8adb0c6c559801e5ffcea89c06a787fdff5e8d0b7ffd4d5ff4261f168912fa'
'e9700e751d7d2a71a19ed9313be93247e4f865e193de5b3d3d9d81bea2148be4')
prepare() {
@@ -30,6 +33,7 @@ prepare() {
cd "${srcdir}/${pkgname}-${pkgver}/"
patch -p1 <../64.patch
+ patch -p1 <../69.patch
rm -rf go.mod
go mod init github.com/writeas/writefreely
@@ -37,6 +41,7 @@ prepare() {
# Temporary manual override:
# Go picks v2 by default, which writefreely doesn't seem to support yet.
go get -u github.com/ikeikeikeike/go-sitemap-generator@v1.0.1
+ go get -u github.com/writeas/monday@v0.0.0-20181024143321-54a7dd579219
go mod tidy
}
@@ -46,22 +51,20 @@ build() {
}
package() {
- install -dm750 "${pkgdir}"/var/lib/writefreely/data
- install -dm750 "${pkgdir}"/var/lib/writefreely/keys
- install -dm750 "${pkgdir}"/var/lib/writefreely/pages
- install -dm750 "${pkgdir}"/var/lib/writefreely/static
- install -dm750 "${pkgdir}"/var/lib/writefreely/templates
+ install -dm750 "${pkgdir}"/var/lib/${pkgname}/data
+ install -dm750 "${pkgdir}"/var/lib/${pkgname}/keys
+ install -dm750 "${pkgdir}"/usr/share/${pkgname}/pages
+ install -dm750 "${pkgdir}"/usr/share/${pkgname}/static
+ install -dm750 "${pkgdir}"/usr/share/${pkgname}/templates
+
+ install -Dm644 config.ini "${pkgdir}"/etc/writefreely/config.ini
install -Dm644 writefreely.service -t "${pkgdir}"/usr/lib/systemd/system/
- install -Dm755 "${pkgname}-${pkgver}"/cmd/writefreely/writefreely "${pkgdir}"/usr/bin/writefreely
install -Dm644 writefreely-sysusers.conf "${pkgdir}"/usr/lib/sysusers.d/writefreely.conf
+ install -Dm755 "${pkgname}-${pkgver}"/cmd/writefreely/writefreely "${pkgdir}"/usr/bin/writefreely
- # These files should probably be in /usr/share and /etc but writefreely
- # expects everything in the same directory.
- # See: https://github.com/writeas/writefreely/issues/63
- install -Dm644 config.ini "${pkgdir}"/var/lib/writefreely/config.ini
- cp -r "${pkgname}-${pkgver}"/pages/* "${pkgdir}"/var/lib/writefreely/pages
- cp -r "${pkgname}-${pkgver}"/static/* "${pkgdir}"/var/lib/writefreely/static
- cp -r "${pkgname}-${pkgver}"/templates/* "${pkgdir}"/var/lib/writefreely/templates
+ cp -r "${pkgname}-${pkgver}"/pages/* "${pkgdir}"/usr/share/writefreely/pages
+ cp -r "${pkgname}-${pkgver}"/static/* "${pkgdir}"/usr/share/writefreely/static
+ cp -r "${pkgname}-${pkgver}"/templates/* "${pkgdir}"/usr/share/writefreely/templates
}
# vim: ts=2 sw=2 et:
diff --git a/config.ini b/config.ini
index 1c3eed2f60c..c0177d33196 100644
--- a/config.ini
+++ b/config.ini
@@ -5,14 +5,19 @@ bind = localhost
tls_cert_path =
tls_key_path =
+keys_parent_dir = "/var/lib/writefreely"
+pages_parent_dir = "/usr/share/writefreely"
+static_parent_dir = "/usr/share/writefreely"
+templates_parent_dir = "/usr/share/writefreely"
+
[database]
-type = mysql
-filename =
-username =
-password =
-database =
-host = localhost
-port = 3306
+type = sqlite3
+filename = /var/lib/writefreely/data/data.db
+username =
+password =
+database =
+host =
+port =
[app]
site_name =
diff --git a/writefreely.install b/writefreely.install
index 9c82d27ce31..d2550c32512 100644
--- a/writefreely.install
+++ b/writefreely.install
@@ -1,14 +1,5 @@
-post_upgrade() {
- echo "---"
- echo "To begin, configure your blog using 'writefreely --configure'."
- echo "If using mariadb, create a database called 'writefreely'"
- echo "then initialize the database with 'writefreely --init-db'."
- echo "---"
-}
-
post_install() {
cd /var/lib/writefreely
- sudo -u writefreely writefreely -gen-keys
-
- post_upgrade
+ sudo -u writefreely /usr/bin/writefreely -c /etc/writefreely/config.ini -gen-keys
+ sudo -u writefreely /usr/bin/writefreely -c /etc/writefreely/config.ini -init-db
}
diff --git a/writefreely.service b/writefreely.service
index 548a2ec1d00..659a81944b6 100644
--- a/writefreely.service
+++ b/writefreely.service
@@ -10,7 +10,7 @@ User=writefreely
Group=writefreely
Type=simple
WorkingDirectory=/var/lib/writefreely
-ExecStart=/usr/bin/writefreely
+ExecStart=/usr/bin/writefreely -c config.ini
Restart=always
RestartSec=2s
CapabilityBoundingSet=
@@ -29,8 +29,6 @@ MemoryDenyWriteExecute=true
RestrictRealtime=true
SystemCallArchitectures=native
SystemCallFilter=@system-service
-StandardOutput=syslog
-StandardError=syslog
[Install]
WantedBy=multi-user.target