Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3241429e98 | ||
|
|
8165b2d843 | ||
|
|
e480141e89 | ||
|
|
e1ae34a336 |
3
.env
3
.env
@@ -1,5 +1,6 @@
|
|||||||
ENV= #empty|development
|
ENV= #empty|development|debug
|
||||||
PHOTO_DIR=images
|
PHOTO_DIR=images
|
||||||
HOST=0.0.0.0
|
HOST=0.0.0.0
|
||||||
PORT=8080
|
PORT=8080
|
||||||
INTERVAL_DEFAULT=10
|
INTERVAL_DEFAULT=10
|
||||||
|
LOG_PATH= #path for logger files default .
|
||||||
@@ -79,7 +79,7 @@ jobs:
|
|||||||
export GOARM=${{ matrix.arm_version }}
|
export GOARM=${{ matrix.arm_version }}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OUTPUT="${OUTPUT}"
|
OUTPUT="${OUTPUT}${{ matrix.ext }}"
|
||||||
echo "Building $OUTPUT"
|
echo "Building $OUTPUT"
|
||||||
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -trimpath -o "$OUTPUT"
|
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -ldflags="-s -w" -trimpath -o "$OUTPUT"
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -98,6 +98,7 @@ jobs:
|
|||||||
# 2. Create Directory Structure
|
# 2. Create Directory Structure
|
||||||
mkdir -p $BUILD_DIR/usr/bin
|
mkdir -p $BUILD_DIR/usr/bin
|
||||||
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME
|
mkdir -p $BUILD_DIR/usr/share/$PKG_NAME
|
||||||
|
mkdir -p $BUILD_DIR/etc/systemd/system
|
||||||
mkdir -p $BUILD_DIR/DEBIAN
|
mkdir -p $BUILD_DIR/DEBIAN
|
||||||
|
|
||||||
# 3. Copy Files
|
# 3. Copy Files
|
||||||
@@ -105,7 +106,33 @@ jobs:
|
|||||||
cp -r ./web $BUILD_DIR/usr/share/$PKG_NAME/
|
cp -r ./web $BUILD_DIR/usr/share/$PKG_NAME/
|
||||||
chmod +x $BUILD_DIR/usr/bin/$PKG_NAME
|
chmod +x $BUILD_DIR/usr/bin/$PKG_NAME
|
||||||
|
|
||||||
# 4. Create Control File
|
# 4. Handle .env (Copy as a .template so it doesn't overwrite existing ones)
|
||||||
|
if [ -f ".env" ]; then
|
||||||
|
cp .env $BUILD_DIR/usr/share/$PKG_NAME/.env.template
|
||||||
|
else
|
||||||
|
echo "PORT=8080" > $BUILD_DIR/usr/share/$PKG_NAME/.env.template
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 5. Create the systemd Service File
|
||||||
|
cat <<EOF > $BUILD_DIR/etc/systemd/system/$PKG_NAME.service
|
||||||
|
[Unit]
|
||||||
|
Description=Slideshow Application Service
|
||||||
|
After=graphical.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Environment=DISPLAY=:0
|
||||||
|
Environment=XAUTHORITY=/home/youruser/.Xauthority
|
||||||
|
ExecStart=/usr/bin/$PKG_NAME
|
||||||
|
WorkingDirectory=/usr/share/$PKG_NAME
|
||||||
|
Restart=always
|
||||||
|
User=root
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# 6. Create Control File
|
||||||
cat <<EOF > $BUILD_DIR/DEBIAN/control
|
cat <<EOF > $BUILD_DIR/DEBIAN/control
|
||||||
Package: $PKG_NAME
|
Package: $PKG_NAME
|
||||||
Version: $VERSION
|
Version: $VERSION
|
||||||
@@ -116,7 +143,28 @@ jobs:
|
|||||||
Description: Slideshow Application
|
Description: Slideshow Application
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# 5. Build .deb
|
# 7. Optional: Add post-install script to enable service automatically
|
||||||
|
echo "create service"
|
||||||
|
cat <<EOF > $BUILD_DIR/DEBIAN/postinst
|
||||||
|
#!/bin/sh
|
||||||
|
# Check if .env exists in the target share folder
|
||||||
|
if [ ! -f "/usr/share/$PKG_NAME/.env" ]; then
|
||||||
|
echo "Creating new .env from template..."
|
||||||
|
cp /usr/share/$PKG_NAME/.env.template /usr/share/$PKG_NAME/.env
|
||||||
|
else
|
||||||
|
echo ".env already exists, skipping template copy to preserve settings."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "reload"
|
||||||
|
systemctl daemon-reload
|
||||||
|
echo "enable service"
|
||||||
|
systemctl enable $PKG_NAME.service
|
||||||
|
echo "start service"
|
||||||
|
systemctl start $PKG_NAME.service
|
||||||
|
EOF
|
||||||
|
chmod 555 $BUILD_DIR/DEBIAN/postinst
|
||||||
|
|
||||||
|
# 8. Build .deb
|
||||||
dpkg-deb --build $BUILD_DIR
|
dpkg-deb --build $BUILD_DIR
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
|
|||||||
1
env/enviroment.go
vendored
1
env/enviroment.go
vendored
@@ -13,6 +13,7 @@ const (
|
|||||||
Host EnvKey = "HOST"
|
Host EnvKey = "HOST"
|
||||||
Port EnvKey = "PORT"
|
Port EnvKey = "PORT"
|
||||||
IntervalDefault EnvKey = "INTERVAL_DEFAULT"
|
IntervalDefault EnvKey = "INTERVAL_DEFAULT"
|
||||||
|
LogPath EnvKey = "LOG_PATH"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EnvKey string
|
type EnvKey string
|
||||||
|
|||||||
7
go.mod
7
go.mod
@@ -3,7 +3,14 @@ module slideshowApp
|
|||||||
go 1.25.4
|
go 1.25.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
gitea.tecamino.com/paadi/tecamino-logger v1.0.0
|
||||||
github.com/gorilla/mux v1.8.1
|
github.com/gorilla/mux v1.8.1
|
||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
go.uber.org/multierr v1.10.0 // indirect
|
||||||
|
go.uber.org/zap v1.27.0 // indirect
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||||
|
)
|
||||||
|
|||||||
18
go.sum
18
go.sum
@@ -1,6 +1,24 @@
|
|||||||
|
gitea.tecamino.com/paadi/tecamino-logger v1.0.0 h1:Quk0UJerOCy7xbHWYOuBXk0FQIgx4arjVDMt2ahvaO0=
|
||||||
|
gitea.tecamino.com/paadi/tecamino-logger v1.0.0/go.mod h1:FkzRTldUBBOd/iy2upycArDftSZ5trbsX5Ira5OzJgM=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||||
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
|
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||||
|
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
|
||||||
|
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||||
|
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||||
|
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
23
main.go
23
main.go
@@ -10,6 +10,7 @@ import (
|
|||||||
"slideshowApp/utils"
|
"slideshowApp/utils"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gitea.tecamino.com/paadi/tecamino-logger/logging"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,16 +18,28 @@ var staticFolder = "./web/static/"
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
logConfig := logging.DefaultConfig()
|
||||||
|
logConfig.Debug = env.Env.GetValue() == "debug"
|
||||||
|
|
||||||
|
logger, err := logging.NewLogger(env.LogPath.GetValue(), logConfig)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Debug("main", "load enviroment variable")
|
||||||
env.Load(".env")
|
env.Load(".env")
|
||||||
|
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
|
|
||||||
uploadFolder := env.PhotoDir.GetValue()
|
uploadFolder := env.PhotoDir.GetValue()
|
||||||
|
logger.Debug("main", "uploadfolder: "+uploadFolder)
|
||||||
|
|
||||||
if _, err := os.Stat(uploadFolder); err != nil {
|
if _, err := os.Stat(uploadFolder); err != nil {
|
||||||
fmt.Println("upload folder for images not found: ", uploadFolder)
|
fmt.Println("upload folder for images not found: ", uploadFolder)
|
||||||
|
logger.Error("main", "upload folder for images not found: "+uploadFolder)
|
||||||
fmt.Println("use fallback folder")
|
fmt.Println("use fallback folder")
|
||||||
uploadFolder = "./images"
|
uploadFolder = "./images"
|
||||||
|
logger.Info("main", "use fallback uploadfolder: "+uploadFolder)
|
||||||
env.PhotoDir.SetValue(uploadFolder)
|
env.PhotoDir.SetValue(uploadFolder)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -60,11 +73,15 @@ func main() {
|
|||||||
port := env.Port.GetValue()
|
port := env.Port.GetValue()
|
||||||
url := fmt.Sprintf("%s:%s", host, port)
|
url := fmt.Sprintf("%s:%s", host, port)
|
||||||
go func() {
|
go func() {
|
||||||
|
logger.Debug("main", "start go routine with a 3 second wait")
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
if err := utils.OpenBrowser(fmt.Sprintf("%s:%s/slideshow", handlers.GetLocalIP(), port)); err != nil {
|
if err := utils.OpenBrowser(logger, fmt.Sprintf("%s:%s/slideshow", handlers.GetLocalIP(), port)); err != nil {
|
||||||
fmt.Println(err)
|
logger.Error("main", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
fmt.Println("Server running at", url)
|
fmt.Println("Server running at", url)
|
||||||
log.Fatal(http.ListenAndServe(url, r))
|
logger.Info("main", "Server running at: "+url)
|
||||||
|
if err := http.ListenAndServe(url, r); err != nil {
|
||||||
|
logger.Error("main", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,17 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gitea.tecamino.com/paadi/tecamino-logger/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OpenBrowser(url string) error {
|
func OpenBrowser(logger *logging.Logger, url string) error {
|
||||||
var commands [][]string
|
var commands [][]string
|
||||||
|
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "windows":
|
case "windows":
|
||||||
|
logger.Debug("OpenBrowser", "os: windows")
|
||||||
commands = [][]string{
|
commands = [][]string{
|
||||||
// Chrome (most common)
|
// Chrome (most common)
|
||||||
{`C:\Program Files\Google\Chrome\Application\chrome.exe`, "--kiosk", url},
|
{`C:\Program Files\Google\Chrome\Application\chrome.exe`, "--kiosk", url},
|
||||||
@@ -30,6 +34,7 @@ func OpenBrowser(url string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "darwin":
|
case "darwin":
|
||||||
|
logger.Debug("OpenBrowser", "os: windows")
|
||||||
commands = [][]string{
|
commands = [][]string{
|
||||||
// Chrome
|
// Chrome
|
||||||
{"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "--kiosk", url},
|
{"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "--kiosk", url},
|
||||||
@@ -48,6 +53,7 @@ func OpenBrowser(url string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default: // Linux
|
default: // Linux
|
||||||
|
logger.Debug("OpenBrowser", "os: linux")
|
||||||
if os.Getenv("DISPLAY") == "" &&
|
if os.Getenv("DISPLAY") == "" &&
|
||||||
os.Getenv("WAYLAND_DISPLAY") == "" &&
|
os.Getenv("WAYLAND_DISPLAY") == "" &&
|
||||||
os.Getenv("XDG_SESSION_TYPE") != "wayland" {
|
os.Getenv("XDG_SESSION_TYPE") != "wayland" {
|
||||||
@@ -71,6 +77,7 @@ func OpenBrowser(url string) error {
|
|||||||
for _, cmd := range commands {
|
for _, cmd := range commands {
|
||||||
execCmd := exec.Command(cmd[0], cmd[1:]...)
|
execCmd := exec.Command(cmd[0], cmd[1:]...)
|
||||||
if err := execCmd.Start(); err == nil {
|
if err := execCmd.Start(); err == nil {
|
||||||
|
logger.Debug("OpenBrowser", "browser started with command: "+strings.Join(cmd, ", "))
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user