Skip to content

Commit 96b1b3a

Browse files
committed
Create .deb package
1 parent 5472ec5 commit 96b1b3a

File tree

6 files changed

+65
-35
lines changed

6 files changed

+65
-35
lines changed

.goreleaser.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# This is an example goreleaser.yaml file with some sane defaults.
2-
# Make sure to check the documentation at http://goreleaser.com
31
before:
42
hooks:
53
builds:
@@ -12,7 +10,7 @@ builds:
1210
- amd64
1311
- arm
1412
goarm:
15-
- 5
13+
- 7
1614
ignore:
1715
- goos: windows
1816
goarch: arm
@@ -28,6 +26,25 @@ archive:
2826
format: zip
2927
files:
3028
- LICENSE
29+
nfpm:
30+
name_template: '{{ .ProjectName }}_{{ .Arch }}'
31+
homepage: https://github.com/axxelG/loxwebhook
32+
description: Make selected Loxone inputs and outputs securely available on the internet
33+
maintainer: Axel Gluth <[email protected]>
34+
vendor: Axel Gluth
35+
license: LGPL-3.0
36+
formats:
37+
- deb
38+
bindir: "/usr/local/bin/loxwebhook/"
39+
config_files:
40+
"./config.example.toml": "/etc/loxwebhook/config.toml"
41+
empty_folders:
42+
- "/etc/loxwebhook/controls.d"
43+
files:
44+
"./install/systemd_loxwebhook.service": "/etc/systemd/system/loxwebhook.service"
45+
scripts:
46+
preinstall: "./install/deb_preinstall.sh"
47+
postinstall: "./install/deb_postinstall.sh"
3148
checksum:
3249
name_template: 'checksums.txt'
3350
snapshot:

config.example.toml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
logfile = ''
2-
ListenPort = 80
3-
PublicURI = 'example.example.com'
4-
LetsencryptCache = './cache/letsencrypt/example'
5-
ControlsFiles = './controls_example.d'
6-
MiniserverURL = 'http://192.168.1.2:80'
7-
MiniserverUser = 'user'
8-
MiniserverPassword = 'SecretPassword'
9-
MiniserverTimeout = 2 # Seconds
1+
PublicURI = 'loxwebhook.example.com'
2+
ListenPort = 4443
3+
MiniserverURL = 'http://192.168.1.1:80'
4+
MiniserverUser = 'loxwebhook'
5+
MiniserverPassword = 'YourSecretPassword'
6+
MiniserverTimeout = 2 # Seconds
7+
LetsencryptCache = '~/.loxwebhook/cache/letsencrypt'
8+
logfileMain = '/var/log/loxwebhook/loxwebhook.log'
9+
logfileHTTPError = '/var/log/loxwebhook/error.log'
10+
logfileHTTPAccess = '/var/log/loxwebhook/access.log'
11+
controlsFiles = '/etc/loxwebhook/controls.d'

config/config.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ func newFlagConfig(versionStr string) *basicTypeConfig {
163163
miniserverTimeout := flags.Int("miniserverTimeout", 0, "Timeout for requests to the Miniserver")
164164
flags.Parse(os.Args[1:])
165165
if *versionFlag {
166-
fmt.Printf("Version: %s", versionStr)
166+
fmt.Printf("Version : %s\n", versionStr)
167+
fmt.Printf("Build for: %s\n", buildForOS)
167168
os.Exit(0)
168169
}
169170
cfg := newDefaultConfig()
@@ -206,32 +207,20 @@ func newFlagConfig(versionStr string) *basicTypeConfig {
206207
return cfg
207208
}
208209

209-
// readConfigFiles tries to read a config file specified by filename.
210-
// On success a slize of bytes containing the file content is returned.
211-
// If filename is empty readConfigFile tries to read all default files.
212-
// On success a byte string containing the content of the first file found is returned.
213-
// On failure an empty slize of bytes is returned. Errors are ignored.
214210
func readConfigFile(filename string) (name string, f []byte, err error) {
215-
defaultConfigFiles := []string{
216-
"/etc/loxwebhook/config.toml",
217-
"./config.toml",
218-
}
219-
if filename != "" {
220-
f, err = ioutil.ReadFile(filename)
221-
if err != nil {
222-
err = errors.Wrap(err, "Error reading config file")
223-
return
224-
}
225-
name = filename
226-
return
227-
}
228-
for _, fn := range defaultConfigFiles {
229-
f, err = ioutil.ReadFile(fn)
211+
if filename == "" {
212+
f, err = ioutil.ReadFile(defaultConfigFile)
230213
if err == nil {
231-
name = fn
232-
break
214+
name = defaultConfigFile
233215
}
216+
// Ignore errors because we might get all nedded parameters
217+
// from flags and/or environment variables
234218
err = nil
219+
return
220+
}
221+
f, err = ioutil.ReadFile(filename)
222+
if err == nil {
223+
name = filename
235224
}
236225
return
237226
}

install/deb_postinstall.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
chmod +x /usr/local/bin/loxwebhook/loxwebhook
2+
systemctl daemon-reload
3+
chown loxwebhook /etc/loxwebhook/config.toml
4+
chmod 0660 /etc/loxwebhook/config.toml

install/deb_preinstall.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
adduser --system loxwebhook
2+
mkdir /var/log/loxwebhook
3+
chown loxwebhook /var/log/loxwebhook
4+
chmod 750 /var/log/loxwebhook

install/systemd_loxwebhook.service

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=Loxwebhook
3+
After=network-online.target
4+
5+
[Service]
6+
Type=notify
7+
Restart=always
8+
RestartSec=5s
9+
User=loxwebhook
10+
WorkingDirectory=/usr/local/bin/loxwebhook/
11+
ExecStart=/usr/local/bin/loxwebhook/loxwebhook
12+
13+
[Install]
14+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)