Skip to content

Commit

Permalink
even more
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Jul 17, 2024
1 parent a0a89e0 commit a785043
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 33 deletions.
10 changes: 7 additions & 3 deletions examples/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ services:
# Get the user:group correct so unpackerr can read and write to your files.
user: ${PUID}:${PGID}
#user: 1000:100
# What you see below are defaults for this compose. You only need to modify things specific to your environment.
# Remove apps and feature configs you do not use or need.
# ie. Remove all lines that begin with UN_CMDHOOK, UN_WEBHOOK, UN_FOLDER, UN_WEBSERVER, and other apps you do not use.
# What you see below are defaults mixed with examples where examples make more sense than the default.
# You only need to modify things specific to your environment.
# Remove apps and feature configs you do not use or need.
# ie. Remove all lines that begin with UN_CMDHOOK, UN_WEBHOOK,
# UN_FOLDER, UN_WEBSERVER, and other apps you do not use.
environment:
- TZ=${TZ}
## Global Settings
Expand Down Expand Up @@ -132,3 +134,5 @@ services:
- UN_CMDHOOK_0_EXCLUDE_0=readarr
- UN_CMDHOOK_0_EXCLUDE_1=lidarr
- UN_CMDHOOK_0_TIMEOUT=10s

## => Content Auto Generated, 17 JUL 2024 08:35 UTC
1 change: 1 addition & 0 deletions examples/unpackerr.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,4 @@ dir_mode = "0755"
## You can adjust how long to wait for the command to run.
# timeout = "10s"

## => Content Auto Generated, 17 JUL 2024 08:35 UTC
21 changes: 6 additions & 15 deletions init/config/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import (
"bytes"
"fmt"
"log"
"os"
"path/filepath"
"strings"
"time"
)

/* This file creates an example compose file: docker-compose.yml */
Expand All @@ -33,10 +30,10 @@ services:
user: ${PUID}:${PGID}
#user: 1000:100
# What you see below are defaults mixed with examples where examples make more sense than the default.
# You only need to modify things specific to your environment.
# Remove apps and feature configs you do not use or need.
# ie. Remove all lines that begin with UN_CMDHOOK, UN_WEBHOOK,
# UN_FOLDER, UN_WEBSERVER, and other apps you do not use.
# You only need to modify things specific to your environment.
# Remove apps and feature configs you do not use or need.
# ie. Remove all lines that begin with UN_CMDHOOK, UN_WEBHOOK,
# UN_FOLDER, UN_WEBSERVER, and other apps you do not use.
environment:
- TZ=${TZ}`
)
Expand All @@ -60,14 +57,8 @@ func createCompose(config *Config, output, dir string) {
}
}

_ = os.Mkdir(dir, dirMode)
filePath := filepath.Join(dir, output)
log.Printf("Writing: %s, size: %d", filePath, buf.Len())
buf.WriteString("\n# Generated: " + time.Now().Round(time.Second).String() + "\n")

if err := os.WriteFile(filePath, buf.Bytes(), fileMode); err != nil {
log.Fatalln(err)
}
buf.WriteString("\n")
writeFile(dir, output, &buf)
}

func (h *Header) makeCompose(prefix string, bare bool) string {
Expand Down
10 changes: 1 addition & 9 deletions init/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"bytes"
"fmt"
"log"
"os"
"path/filepath"
"strings"

"github.com/BurntSushi/toml"
Expand All @@ -30,13 +28,7 @@ func createConfFile(config *Config, output, dir string) {
}
}

_ = os.Mkdir(dir, dirMode)
filePath := filepath.Join(dir, output)
log.Printf("Writing: %s, size: %d", filePath, buf.Len())

if err := os.WriteFile(filePath, buf.Bytes(), fileMode); err != nil {
log.Fatalln(err)
}
writeFile(dir, output, &buf)
}

// Not all sections have defs, and it may be nil. Defs only work on 'list' sections.
Expand Down
13 changes: 11 additions & 2 deletions init/config/docusaurus.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func createDocusaurus(config *Config, output string) {

func writeDocusaurus(dir, file, content string) error {
_ = os.Mkdir(dir, dirMode)
date := "---\n# Generated: " + time.Now().Round(time.Second).String() + "\n---\n\n"
date := "---\n## => Content Auto Generated, " +
strings.ToUpper(time.Now().UTC().Round(time.Second).Format("02 Jan 2006 15:04 UTC")) + "\n---\n\n"
filePath := filepath.Join(dir, file+".md")
log.Printf("Writing: %s, size: %d", filePath, len(content))
//nolint:wrapcheck
Expand All @@ -67,7 +68,15 @@ func makeGenerated(config *Config, output string) error {
}
}

return writeDocusaurus(output, "index", first.String()+"\n"+second.String())
err := writeDocusaurus(output, "index", first.String()+"\n"+second.String())
if err != nil {
return err
}

date := strings.ToUpper(time.Now().UTC().Round(time.Second).Format("02 Jan 2006 15:04 UTC"))
// Create a footer file that can be imported.
return writeDocusaurus(output, "footer", `<font color="gray" style={{'float': 'right', 'font-style': 'italic'}}>`+
"This page was [generated automatically](https://github.com/Unpackerr/unpackerr/tree/main/init/config), "+date+"</font>\n")
}

func (h *Header) makeDocs(prefix string, section section) string {
Expand Down
14 changes: 14 additions & 0 deletions init/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"net/http"
"os"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -182,3 +183,16 @@ func createDefinedSection(def *Def, section *Header) *Header {

return newSection
}

// This is used only by compose and config. docs has it's own.
func writeFile(dir, output string, buf *bytes.Buffer) {
_ = os.Mkdir(dir, dirMode)
filePath := filepath.Join(dir, output)
log.Printf("Writing: %s, size: %d", filePath, buf.Len())
buf.WriteString("## => Content Auto Generated, " +
strings.ToUpper(time.Now().UTC().Round(time.Second).Format("02 Jan 2006 15:04 UTC")+"\n"))

if err := os.WriteFile(filePath, buf.Bytes(), fileMode); err != nil {
log.Fatalln(err)
}
}
Loading

0 comments on commit a785043

Please sign in to comment.