mirror of
https://github.com/garethgeorge/backrest.git
synced 2025-12-16 02:25:37 +00:00
fix: install scripts and improved asset compression
This commit is contained in:
@@ -12,7 +12,7 @@ before:
|
||||
hooks:
|
||||
- go mod tidy
|
||||
- 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:
|
||||
- main: .
|
||||
|
||||
20
backrest.go
20
backrest.go
@@ -80,7 +80,25 @@ func main() {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
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 {
|
||||
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
|
||||
|
||||
require (
|
||||
connectrpc.com/connect v1.14.0
|
||||
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/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/mattn/go-colorable v0.1.13
|
||||
github.com/natefinch/atomic v1.0.1
|
||||
go.etcd.io/bbolt v1.3.8
|
||||
go.uber.org/zap v1.26.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/grpc v1.60.1
|
||||
google.golang.org/protobuf v1.32.0
|
||||
)
|
||||
|
||||
require (
|
||||
connectrpc.com/connect v1.14.0 // indirect
|
||||
github.com/daaku/go.zipexe v1.0.2 // 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/mattn/go-isatty v0.0.20 // 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/text v0.14.0 // 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.rice v1.0.3 h1:k5viR+xGtIhF61125vCE1cmJ5957RQGXG6dmbaWZSmI=
|
||||
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/daaku/go.zipexe v1.0.2 h1:Zg55YLYTr7M9wjKn8SY/WcpuuEi+kR2u4E8RhvpyXmk=
|
||||
github.com/daaku/go.zipexe v1.0.2/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8=
|
||||
|
||||
36
install.sh
36
install.sh
@@ -1,14 +1,10 @@
|
||||
#! /bin/bash
|
||||
|
||||
if [ "$EUID" -ne "0" ]; then
|
||||
echo "Please run as root e.g. sudo ./install.sh"
|
||||
exit
|
||||
fi
|
||||
|
||||
install_unix() {
|
||||
echo "Installing backrest to /usr/local/bin"
|
||||
mkdir -p /usr/local/bin
|
||||
cp $(ls -1 backrest | head -n 1) /usr/local/bin
|
||||
sudo mkdir -p /usr/local/bin
|
||||
sudo cp $(ls -1 backrest | head -n 1) /usr/local/bin
|
||||
}
|
||||
|
||||
create_systemd_service() {
|
||||
@@ -19,7 +15,7 @@ create_systemd_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]
|
||||
Description=Backrest Service
|
||||
After=network.target
|
||||
@@ -35,28 +31,30 @@ WantedBy=multi-user.target
|
||||
EOM
|
||||
|
||||
echo "Reloading systemd daemon"
|
||||
systemctl daemon-reload
|
||||
sudo systemctl daemon-reload
|
||||
}
|
||||
|
||||
create_launchd_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"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.backrest</string>
|
||||
<key>Program</key>
|
||||
<string>/usr/local/bin/backrest</string>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.backrest</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/usr/local/bin/backrest</string>
|
||||
</array>
|
||||
<key>KeepAlive</key>
|
||||
<true/>
|
||||
<key>StandardOutPath</key>
|
||||
<string>/tmp/backrest.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/tmp/backrest.log</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
EOM
|
||||
}
|
||||
@@ -78,8 +76,8 @@ elif [ "$OS" = "Linux" ]; then
|
||||
install_unix
|
||||
create_systemd_service
|
||||
echo "Enabling systemd service backrest.service"
|
||||
systemctl enable backrest
|
||||
systemctl start backrest
|
||||
sudo systemctl enable backrest
|
||||
sudo systemctl start backrest
|
||||
else
|
||||
echo "Unknown OS: $OS. This script only supports Darwin and Linux."
|
||||
exit 1
|
||||
|
||||
17
uninstall.sh
17
uninstall.sh
@@ -1,13 +1,8 @@
|
||||
#! /bin/bash
|
||||
|
||||
if [ "$EUID" -ne "0" ]; then
|
||||
echo "Please run as root e.g. sudo ./install.sh"
|
||||
exit
|
||||
fi
|
||||
|
||||
uninstall_unix() {
|
||||
echo "Uninstalling backrest from /usr/local/bin/backrest"
|
||||
rm -f /usr/local/bin/backrest
|
||||
sudo rm -f /usr/local/bin/backrest
|
||||
}
|
||||
|
||||
remove_systemd_service() {
|
||||
@@ -17,19 +12,19 @@ remove_systemd_service() {
|
||||
fi
|
||||
|
||||
echo "Removing systemd service at /etc/systemd/system/backrest.service"
|
||||
systemctl stop backrest
|
||||
systemctl disable backrest
|
||||
rm -f /etc/systemd/system/backrest.service
|
||||
sudo systemctl stop backrest
|
||||
sudo systemctl disable backrest
|
||||
sudo rm -f /etc/systemd/system/backrest.service
|
||||
|
||||
echo "Reloading systemd daemon"
|
||||
systemctl daemon-reload
|
||||
sudo systemctl daemon-reload
|
||||
}
|
||||
|
||||
remove_launchd_plist() {
|
||||
echo "Removing launchd plist at /Library/LaunchAgents/com.backrest.plist"
|
||||
|
||||
launchctl unload /Library/LaunchAgents/com.backrest.plist || true
|
||||
rm /Library/LaunchAgents/com.backrest.plist
|
||||
sudo rm /Library/LaunchAgents/com.backrest.plist
|
||||
}
|
||||
|
||||
OS=$(uname -s)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"/api": {
|
||||
"/v1.Backrest": {
|
||||
"target": "http://localhost:9898",
|
||||
"secure": false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user