Forgor to push 💀
This commit is contained in:
88
util.go
88
util.go
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.nevets.tech/Steven/ezconf"
|
||||
"github.com/google/go-github/v55/github"
|
||||
@@ -16,30 +17,47 @@ type Domain struct {
|
||||
gtClient *gitea.Client
|
||||
}
|
||||
|
||||
func createFile(fileName string, data []byte) {
|
||||
type GlobalConfig struct {
|
||||
Git struct {
|
||||
Host string
|
||||
Endpoint string
|
||||
Username string
|
||||
Password string
|
||||
ApiToken string
|
||||
}
|
||||
}
|
||||
|
||||
type DomainConfig struct {
|
||||
}
|
||||
|
||||
func createFile(fileName string, filePermission os.FileMode, data []byte) {
|
||||
fileInfo, err := os.Stat(fileName)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
file, err := os.Create(fileName)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating configuration file:", err)
|
||||
fmt.Println("Error creating configuration file: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
_, err = file.Write(data)
|
||||
if err != nil {
|
||||
fmt.Println("Error writing to file;", err)
|
||||
fmt.Println("Error writing to file: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = file.Chmod(filePermission)
|
||||
if err != nil {
|
||||
fmt.Println("Error changing file permission: ", err)
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Error opening configuration file:", err)
|
||||
fmt.Println("Error opening configuration file: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
if fileInfo.Size() == 0 {
|
||||
file, err := os.Create(fileName)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating configuration file:", err)
|
||||
fmt.Println("Error creating configuration file: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@@ -51,3 +69,63 @@ func createFile(fileName string, data []byte) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fileExists(filePath string) bool {
|
||||
if _, err := os.Stat(filePath); err == nil {
|
||||
return true
|
||||
} else if errors.Is(err, os.ErrNotExist) {
|
||||
return false
|
||||
} else {
|
||||
fmt.Println("Error checking file existence: ", err)
|
||||
os.Exit(1)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func contains(slice []string, value string) (sliceHas bool, index int) {
|
||||
for i, entry := range slice {
|
||||
if entry == value {
|
||||
return true, i
|
||||
}
|
||||
}
|
||||
return false, -1
|
||||
}
|
||||
|
||||
func insert(a []string, index int, value string) []string {
|
||||
last := len(a) - 1
|
||||
a = append(a, a[last])
|
||||
copy(a[index+1:], a[index:last])
|
||||
a[index] = value
|
||||
return a
|
||||
}
|
||||
|
||||
const defaultConfig = `[Git]
|
||||
host = gitea
|
||||
server = https://gitea.instance.com
|
||||
username = user
|
||||
org_name = org
|
||||
template_name = template
|
||||
|
||||
[Certificates]
|
||||
email = user@example.com
|
||||
data_root = /var/local/certman
|
||||
request_method = dns
|
||||
|
||||
[Cloudflare]
|
||||
cf_email = email@example.com
|
||||
|
||||
`
|
||||
|
||||
const defaultDomainConfig = `[Domain]
|
||||
domain_name = {domain}
|
||||
; default (use system dns) or IPv4 Address (1.1.1.1)
|
||||
dns_server = default
|
||||
|
||||
[Certificates]
|
||||
subdomains =
|
||||
expiry = 90
|
||||
|
||||
; Don't change setting below here unless you know what you're doing!
|
||||
[Internal]
|
||||
last_issued = never
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user