mirror of
https://github.com/garethgeorge/backrest.git
synced 2025-12-15 10:05:42 +00:00
fix: install scripts and improved asset compression
This commit is contained in:
@@ -12,7 +12,7 @@ before:
|
|||||||
hooks:
|
hooks:
|
||||||
- go mod tidy
|
- go mod tidy
|
||||||
- go generate ./...
|
- go generate ./...
|
||||||
- sh -c "ls && cd ./webui && npm i && npm run build"
|
- sh -c "ls && cd ./webui && npm i && npm run build && gzip ./dist/*"
|
||||||
|
|
||||||
builds:
|
builds:
|
||||||
- main: .
|
- main: .
|
||||||
|
|||||||
20
backrest.go
20
backrest.go
@@ -80,7 +80,25 @@ func main() {
|
|||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
if box, err := rice.FindBox("webui/dist"); err == nil {
|
if box, err := rice.FindBox("webui/dist"); err == nil {
|
||||||
mux.Handle("/", http.FileServer(box.HTTPBox()))
|
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if strings.HasSuffix(r.URL.Path, "/") {
|
||||||
|
r.URL.Path += "index.html"
|
||||||
|
}
|
||||||
|
f, err := box.Open(r.URL.Path + ".gz")
|
||||||
|
if err == nil {
|
||||||
|
defer f.Close()
|
||||||
|
w.Header().Set("Content-Encoding", "gzip")
|
||||||
|
http.ServeContent(w, r, r.URL.Path, box.Time(), f)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
f, err = box.Open(r.URL.Path)
|
||||||
|
if err == nil {
|
||||||
|
defer f.Close()
|
||||||
|
http.ServeContent(w, r, r.URL.Path, box.Time(), f)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
http.Error(w, "Not found", http.StatusNotFound)
|
||||||
|
}))
|
||||||
} else {
|
} else {
|
||||||
zap.S().Warnf("Error loading static assets, not serving UI: %v", err)
|
zap.S().Warnf("Error loading static assets, not serving UI: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
9
go.mod
9
go.mod
@@ -3,29 +3,30 @@ module github.com/garethgeorge/backrest
|
|||||||
go 1.21
|
go 1.21
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
connectrpc.com/connect v1.14.0
|
||||||
github.com/GeertJohan/go.rice v1.0.3
|
github.com/GeertJohan/go.rice v1.0.3
|
||||||
|
github.com/NYTimes/gziphandler v1.1.1
|
||||||
github.com/gitploy-io/cronexpr v0.2.2
|
github.com/gitploy-io/cronexpr v0.2.2
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.1
|
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1
|
|
||||||
github.com/hashicorp/go-multierror v1.1.1
|
github.com/hashicorp/go-multierror v1.1.1
|
||||||
github.com/mattn/go-colorable v0.1.13
|
github.com/mattn/go-colorable v0.1.13
|
||||||
github.com/natefinch/atomic v1.0.1
|
github.com/natefinch/atomic v1.0.1
|
||||||
go.etcd.io/bbolt v1.3.8
|
go.etcd.io/bbolt v1.3.8
|
||||||
go.uber.org/zap v1.26.0
|
go.uber.org/zap v1.26.0
|
||||||
golang.org/x/crypto v0.17.0
|
golang.org/x/crypto v0.17.0
|
||||||
|
golang.org/x/net v0.19.0
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0
|
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0
|
||||||
google.golang.org/grpc v1.60.1
|
google.golang.org/grpc v1.60.1
|
||||||
google.golang.org/protobuf v1.32.0
|
google.golang.org/protobuf v1.32.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
connectrpc.com/connect v1.14.0 // indirect
|
|
||||||
github.com/daaku/go.zipexe v1.0.2 // indirect
|
github.com/daaku/go.zipexe v1.0.2 // indirect
|
||||||
github.com/golang/protobuf v1.5.3 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
|
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.1 // indirect
|
||||||
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1 // indirect
|
||||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
golang.org/x/net v0.19.0 // indirect
|
|
||||||
golang.org/x/sys v0.15.0 // indirect
|
golang.org/x/sys v0.15.0 // indirect
|
||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 // indirect
|
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 // indirect
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -3,6 +3,8 @@ connectrpc.com/connect v1.14.0/go.mod h1:uoAq5bmhhn43TwhaKdGKN/bZcGtzPW1v+ngDTn5
|
|||||||
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
|
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
|
||||||
github.com/GeertJohan/go.rice v1.0.3 h1:k5viR+xGtIhF61125vCE1cmJ5957RQGXG6dmbaWZSmI=
|
github.com/GeertJohan/go.rice v1.0.3 h1:k5viR+xGtIhF61125vCE1cmJ5957RQGXG6dmbaWZSmI=
|
||||||
github.com/GeertJohan/go.rice v1.0.3/go.mod h1:XVdrU4pW00M4ikZed5q56tPf1v2KwnIKeIdc9CBYNt4=
|
github.com/GeertJohan/go.rice v1.0.3/go.mod h1:XVdrU4pW00M4ikZed5q56tPf1v2KwnIKeIdc9CBYNt4=
|
||||||
|
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
|
||||||
|
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
|
||||||
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
|
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
|
||||||
github.com/daaku/go.zipexe v1.0.2 h1:Zg55YLYTr7M9wjKn8SY/WcpuuEi+kR2u4E8RhvpyXmk=
|
github.com/daaku/go.zipexe v1.0.2 h1:Zg55YLYTr7M9wjKn8SY/WcpuuEi+kR2u4E8RhvpyXmk=
|
||||||
github.com/daaku/go.zipexe v1.0.2/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8=
|
github.com/daaku/go.zipexe v1.0.2/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8=
|
||||||
|
|||||||
40
install.sh
40
install.sh
@@ -1,14 +1,10 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
if [ "$EUID" -ne "0" ]; then
|
|
||||||
echo "Please run as root e.g. sudo ./install.sh"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
install_unix() {
|
install_unix() {
|
||||||
echo "Installing backrest to /usr/local/bin"
|
echo "Installing backrest to /usr/local/bin"
|
||||||
mkdir -p /usr/local/bin
|
sudo mkdir -p /usr/local/bin
|
||||||
cp $(ls -1 backrest | head -n 1) /usr/local/bin
|
sudo cp $(ls -1 backrest | head -n 1) /usr/local/bin
|
||||||
}
|
}
|
||||||
|
|
||||||
create_systemd_service() {
|
create_systemd_service() {
|
||||||
@@ -19,7 +15,7 @@ create_systemd_service() {
|
|||||||
|
|
||||||
echo "Creating systemd service at /etc/systemd/system/backrest.service"
|
echo "Creating systemd service at /etc/systemd/system/backrest.service"
|
||||||
|
|
||||||
cat > /etc/systemd/system/backrest.service <<- EOM
|
sudo cat > /etc/systemd/system/backrest.service <<- EOM
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Backrest Service
|
Description=Backrest Service
|
||||||
After=network.target
|
After=network.target
|
||||||
@@ -33,30 +29,32 @@ ExecStart=/usr/local/bin/backrest
|
|||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOM
|
EOM
|
||||||
|
|
||||||
echo "Reloading systemd daemon"
|
echo "Reloading systemd daemon"
|
||||||
systemctl daemon-reload
|
sudo systemctl daemon-reload
|
||||||
}
|
}
|
||||||
|
|
||||||
create_launchd_plist() {
|
create_launchd_plist() {
|
||||||
echo "Creating launchd plist at /Library/LaunchAgents/com.backrest.plist"
|
echo "Creating launchd plist at /Library/LaunchAgents/com.backrest.plist"
|
||||||
|
|
||||||
cat > /Library/LaunchAgents/com.backrest.plist <<- EOM
|
sudo tee /Library/LaunchAgents/com.backrest.plist > /dev/null <<- EOM
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>Label</key>
|
<key>Label</key>
|
||||||
<string>com.backrest</string>
|
<string>com.backrest</string>
|
||||||
<key>Program</key>
|
<key>ProgramArguments</key>
|
||||||
<string>/usr/local/bin/backrest</string>
|
<array>
|
||||||
<key>RunAtLoad</key>
|
<string>/usr/local/bin/backrest</string>
|
||||||
<true/>
|
</array>
|
||||||
|
<key>KeepAlive</key>
|
||||||
|
<true/>
|
||||||
<key>StandardOutPath</key>
|
<key>StandardOutPath</key>
|
||||||
<string>/tmp/backrest.log</string>
|
<string>/tmp/backrest.log</string>
|
||||||
<key>StandardErrorPath</key>
|
<key>StandardErrorPath</key>
|
||||||
<string>/tmp/backrest.log</string>
|
<string>/tmp/backrest.log</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
EOM
|
EOM
|
||||||
}
|
}
|
||||||
@@ -78,9 +76,9 @@ elif [ "$OS" = "Linux" ]; then
|
|||||||
install_unix
|
install_unix
|
||||||
create_systemd_service
|
create_systemd_service
|
||||||
echo "Enabling systemd service backrest.service"
|
echo "Enabling systemd service backrest.service"
|
||||||
systemctl enable backrest
|
sudo systemctl enable backrest
|
||||||
systemctl start backrest
|
sudo systemctl start backrest
|
||||||
else
|
else
|
||||||
echo "Unknown OS: $OS. This script only supports Darwin and Linux."
|
echo "Unknown OS: $OS. This script only supports Darwin and Linux."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
17
uninstall.sh
17
uninstall.sh
@@ -1,13 +1,8 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
if [ "$EUID" -ne "0" ]; then
|
|
||||||
echo "Please run as root e.g. sudo ./install.sh"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
uninstall_unix() {
|
uninstall_unix() {
|
||||||
echo "Uninstalling backrest from /usr/local/bin/backrest"
|
echo "Uninstalling backrest from /usr/local/bin/backrest"
|
||||||
rm -f /usr/local/bin/backrest
|
sudo rm -f /usr/local/bin/backrest
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_systemd_service() {
|
remove_systemd_service() {
|
||||||
@@ -17,19 +12,19 @@ remove_systemd_service() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Removing systemd service at /etc/systemd/system/backrest.service"
|
echo "Removing systemd service at /etc/systemd/system/backrest.service"
|
||||||
systemctl stop backrest
|
sudo systemctl stop backrest
|
||||||
systemctl disable backrest
|
sudo systemctl disable backrest
|
||||||
rm -f /etc/systemd/system/backrest.service
|
sudo rm -f /etc/systemd/system/backrest.service
|
||||||
|
|
||||||
echo "Reloading systemd daemon"
|
echo "Reloading systemd daemon"
|
||||||
systemctl daemon-reload
|
sudo systemctl daemon-reload
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_launchd_plist() {
|
remove_launchd_plist() {
|
||||||
echo "Removing launchd plist at /Library/LaunchAgents/com.backrest.plist"
|
echo "Removing launchd plist at /Library/LaunchAgents/com.backrest.plist"
|
||||||
|
|
||||||
launchctl unload /Library/LaunchAgents/com.backrest.plist || true
|
launchctl unload /Library/LaunchAgents/com.backrest.plist || true
|
||||||
rm /Library/LaunchAgents/com.backrest.plist
|
sudo rm /Library/LaunchAgents/com.backrest.plist
|
||||||
}
|
}
|
||||||
|
|
||||||
OS=$(uname -s)
|
OS=$(uname -s)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"/api": {
|
"/v1.Backrest": {
|
||||||
"target": "http://localhost:9898",
|
"target": "http://localhost:9898",
|
||||||
"secure": false
|
"secure": false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user