Compare commits

...

18 Commits

Author SHA1 Message Date
d7c8c7a43a Merge branch 'devel' 2024-08-18 17:31:00 +02:00
d56cdc78eb Use directories that require administrative privileges 2024-08-18 17:30:43 +02:00
151d89d9f0 Create $EXTRACTION_PATH 2024-08-18 17:10:10 +02:00
8d2944d00c Only delete contents of $CPOLIS_PATH 2024-08-18 17:06:49 +02:00
9ddd8198ee Use /tmp directory for downloading .tar.gz archive 2024-08-18 17:03:31 +02:00
ff6c7a66d7 Fixed a typo 2024-08-18 16:59:49 +02:00
129c85929c Small cleanup 2024-08-18 13:56:41 +02:00
b1a6359473 Exit update script if any requirement is not met 2024-08-18 13:53:37 +02:00
b5d979dbf8 Created update script and systemd service 2024-08-18 13:49:31 +02:00
1cd3edc90c Merge branch 'devel' 2024-08-18 12:06:29 +02:00
77e8edbe16 Relocated ShowHub from articles.go to sessions.go because it has even less to do with articles than with sessions 2024-08-18 11:46:23 +02:00
0e768c9f61 Merge branch 'devel' 2024-08-08 21:27:07 +02:00
1fcd775cc5 Merge branch 'devel' 2024-08-08 21:14:24 +02:00
203a1ed147 Implemented EasyMDE 2024-08-08 21:13:25 +02:00
ef1914ee5c Implemented article preview 2024-08-08 21:13:25 +02:00
084b101e31 Register f.ArticlePreviewHtmlData in init() 2024-08-08 21:13:25 +02:00
b2db128aa9 Shorten lines by referencing frontend as f and backend as b 2024-08-08 21:13:25 +02:00
081e880fb6 Change structure of code tor frontend and backend one 2024-08-08 21:13:25 +02:00
4 changed files with 68 additions and 19 deletions

View File

@ -23,25 +23,6 @@ const (
PreviewMode
)
func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session, err := getSession(w, r, c, s)
if err != nil {
return
}
session.Values["article"] = nil
if err = session.Save(r, w); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"].(int))
}
}
func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session, err := getSession(w, r, c, s)

View File

@ -107,3 +107,22 @@ func Logout(c *b.Config, s *b.CookieStore) http.HandlerFunc {
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", nil)
}
}
func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session, err := getSession(w, r, c, s)
if err != nil {
return
}
session.Values["article"] = nil
if err = session.Save(r, w); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"].(int))
}
}

9
cpolis.service Normal file
View File

@ -0,0 +1,9 @@
[Unit]
Description=cpolis
[Service]
ExecStart=/usr/local/bin/cpolis
Restart=on-failure
[Install]
WantedBy=default.target

40
update.sh Executable file
View File

@ -0,0 +1,40 @@
#! /bin/sh -
CPOLIS_REPO_URL="https://git.streifling.com/api/v1/repos/jason/cpolis/releases"
EXTRACTION_DIR=$HOME
CPOLIS_DIR=$EXTRACTION_DIR/cpolis
TAILWINDCSS_REPO_URL=https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest
TMP_DIR=/tmp
BIN_DIR=/usr/local/bin
SYSTEMD_DIR=/lib/systemd/system
! groups | grep -E 'root|wheel|sudo' && echo "You need administrative privileges for this script" && exit 1
! which curl >/dev/null 2>&1 && echo "curl needs to be installed" >&2 && exit 1
! which go >/dev/null 2>&1 && echo "go needs to be installed" >&2 && exit 1
! which jq >/dev/null 2>&1 && echo "jq needs to be installed" >&2 && exit 1
! which tar >/dev/null 2>&1 && echo "tar needs to be installed" >&2 && exit 1
! which xargs >/dev/null 2>&1 && echo "xargs needs to be installed" >&2 && exit 1
rm -fr $CPOLIS_DIR/*
latest_release=$(curl -s $CPOLIS_REPO_URL | jq -r '.[0].tag_name')
curl -Lo $TMP_DIR/cpolis.tar.gz https://git.streifling.com/jason/cpolis/archive/$latest_release.tar.gz
tar -xzf $TMP_DIR/cpolis.tar.gz -C $EXTRACTION_DIR
rm $TMP_DIR/cpolis.tar.gz
curl -s $TAILWINDCSS_REPO_URL |
grep -F browser_download_url |
grep -F linux-x64 |
cut -d'"' -f4 |
xargs -r curl -Lo $CPOLIS_DIR/tailwindcss
chmod +x $CPOLIS_DIR/tailwindcss
$CPOLIS_DIR/tailwindcss -i web/static/css/input.css -o web/static/css/style.css
go build -o $TMP_DIR/cpolis $CPOLIS_DIR/cmd/main.go
sudo mv $TMP_DIR/cpolis $BIN_DIR/cpolis
chmod +x $BIN_DIR/cpolis
[ ! -f $SYSTEMD_DIR ] && mkdir -p $SYSTEMD_DIR
sudo mv $CPOLIS_DIR/cpolis.service $SYSTEMD_DIR
sudo systemctl daemon-reload
sudo systemctl is-active --quiet cpolis.service && sudo systemctl restart cpolis.service