-
-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·231 lines (193 loc) · 5.68 KB
/
install.sh
File metadata and controls
executable file
·231 lines (193 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#! /bin/bash
cd "$(dirname "$0")" # cd to the directory of this script
# Parse command line arguments
ALLOW_REMOTE_ACCESS=false
FROM_SOURCE=false
for arg in "$@"; do
case $arg in
--allow-remote-access)
ALLOW_REMOTE_ACCESS=true
shift
;;
--from-source)
FROM_SOURCE=true
shift
;;
*)
echo "Unknown option: $arg"
echo "Usage: $0 [--allow-remote-access] [--from-source]"
echo " --allow-remote-access: Allow remote access by binding to 0.0.0.0:9898 instead of 127.0.0.1:9898"
echo " --from-source: Build binary from source"
exit 1
;;
esac
done
# Set the appropriate port based on the flag
if [ "$ALLOW_REMOTE_ACCESS" = true ]; then
BACKREST_PORT="0.0.0.0:9898"
echo "Remote access enabled: Backrest will bind to 0.0.0.0:9898"
else
BACKREST_PORT="127.0.0.1:9898"
echo "Local access only: Backrest will bind to 127.0.0.1:9898, run ./install.sh --allow-remote-access to enable remote access"
fi
if [ "$FROM_SOURCE" = true ]; then
if ! command -v go &> /dev/null; then
echo "Error: go is not installed or not in PATH."
exit 1
fi
if ! command -v npm &> /dev/null; then
echo "Error: npm is not installed or not in PATH."
exit 1
fi
echo "Building from source..."
echo "Installing webui dependencies..."
pushd webui > /dev/null || exit 1
if command -v pnpm &> /dev/null; then
echo "Using pnpm..."
pnpm install
else
echo "Using npm..."
npm install
fi
popd > /dev/null || exit 1
go generate ./...
go build -o backrest ./cmd/backrest
fi
stop_systemd_service() {
if systemctl is-active --quiet backrest; then
sudo systemctl stop backrest
echo "Paused backrest for update"
fi
}
stop_openrc_service() {
sudo rc-service backrest --ifstarted stop
echo "Paused backrest for update (if started)"
}
install_unix() {
echo "Installing backrest to /usr/local/bin"
sudo mkdir -p /usr/local/bin
sudo cp $(ls -1 backrest | head -n 1) /usr/local/bin
}
create_systemd_service() {
if [ -f /etc/systemd/system/backrest.service ]; then
echo "Systemd unit already exists. Skipping creation."
return 0
fi
echo "Creating systemd service at /etc/systemd/system/backrest.service"
sudo tee /etc/systemd/system/backrest.service > /dev/null <<- EOM
[Unit]
Description=Backrest Service
After=network.target
[Service]
Type=simple
User=$(whoami)
Group=$(whoami)
ExecStart=/usr/local/bin/backrest
Restart=on-failure
Environment="BACKREST_PORT=$BACKREST_PORT"
[Install]
WantedBy=multi-user.target
EOM
echo "Reloading systemd daemon"
sudo systemctl daemon-reload
}
create_openrc_service() {
if [ -f /etc/init.d/backrest ]; then
echo "Openrc service already exists. Skipping creation."
return 0
fi
echo "Creating openrc service at /etc/init.d/backrest"
sudo tee /etc/init.d/backrest > /dev/null <<- EOM
#!/sbin/openrc-run
description="Backrest Service"
depend() {
need loopback
use net logger
}
: \${BACKREST_PORT:=${BACKREST_PORT}}
command=/usr/local/bin/backrest
command_background=true
command_args="-bind-address \${BACKREST_PORT}"
pidfile="/run/\${RC_SVCNAME}.pid"
command_user="$(whoami):$(whoami)"
supervisor=supervise-daemon
EOM
sudo chmod 755 /etc/init.d/backrest
}
create_launchd_plist() {
echo "Creating launchd plist at /Library/LaunchAgents/com.backrest.plist"
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>ProgramArguments</key>
<array>
<string>/usr/local/bin/backrest</string>
</array>
<key>KeepAlive</key>
<true/>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
<key>BACKREST_PORT</key>
<string>$BACKREST_PORT</string>
</dict>
</dict>
</plist>
EOM
}
enable_launchd_plist() {
echo "Trying to unload any previous version of com.backrest.plist"
launchctl unload /Library/LaunchAgents/com.backrest.plist || true
echo "Loading com.backrest.plist"
launchctl load -w /Library/LaunchAgents/com.backrest.plist
}
OS=$(uname -s)
if [ "$OS" = "Darwin" ]; then
echo "Installing on Darwin"
install_unix
create_launchd_plist
enable_launchd_plist
sudo xattr -d com.apple.quarantine /usr/local/bin/backrest # remove quarantine flag
elif [ "$OS" = "Linux" ]; then
echo "Installing on Linux"
systemctl --version
systemd_=$?
rc-status --version
openrc_=$?
if [ $systemd_ -eq 0 ]; then
echo "Systemd found."
stop_systemd_service
install_unix
create_systemd_service
echo "Enabling systemd service backrest.service"
sudo systemctl enable backrest
echo "Reloading systemd service"
sudo systemctl start backrest
elif [ $openrc_ -eq 0 ]; then
echo "Openrc found."
stop_openrc_service
install_unix
create_openrc_service
echo "Adding backrest to runlevel default"
sudo rc-update add backrest default
echo "Reloading openrc service"
sudo rc-service backrest start
else
echo "neither systemd nor openrc were found"
fi
else
echo "Unknown OS: $OS. This script only supports Darwin and Linux."
exit 1
fi
echo "Logs are available at ~/.local/share/backrest/processlogs/backrest.log"
if [ "$ALLOW_REMOTE_ACCESS" = true ]; then
echo "Access backrest WebUI at http://0.0.0.0:9898 (remote access enabled)"
echo "Note: Remote access allows connections from any IP address. Ensure proper firewall configuration or that authentication is set up."
else
echo "Access backrest WebUI at http://localhost:9898"
fi