Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·254 lines (219 loc) · 7.12 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·254 lines (219 loc) · 7.12 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/env bash
set -u
APP_NAME="dback"
DIST_DIR="dist"
ICON_PATH="logo.png"
APP_VERSION="${APP_VERSION:-3.8.3}"
NFPM_VERSION="${NFPM_VERSION:-v2.44.1}"
export PATH="$PATH:$(go env GOPATH 2>/dev/null)/bin"
ensure_dist_dir() {
mkdir -p "$DIST_DIR"
}
ensure_icon() {
if [ ! -f "$ICON_PATH" ]; then
print_error "Icon not found: $ICON_PATH"
return 1
fi
}
print_success() {
echo "OK: $1"
}
print_error() {
echo "ERROR: $1"
}
sudo_cmd() {
if [ "$(id -u)" -eq 0 ]; then
"$@"
else
sudo "$@"
fi
}
install_apt_packages() {
if ! command -v apt-get >/dev/null 2>&1; then
print_error "Automatic system package installation currently supports apt-based Linux distributions."
echo "Missing packages: $*"
return 1
fi
echo "Installing system packages: $*"
sudo_cmd apt-get update
sudo_cmd env DEBIAN_FRONTEND=noninteractive apt-get install -y "$@"
}
ensure_linux_deps() {
local missing=()
command -v gcc >/dev/null 2>&1 || missing+=(build-essential)
command -v pkg-config >/dev/null 2>&1 || missing+=(pkg-config)
[ -f "/usr/include/vulkan/vulkan.h" ] || missing+=(libvulkan-dev)
[ -f "/usr/include/X11/Xlib.h" ] || missing+=(xorg-dev)
local gio_pkg_modules=(
egl wayland-egl wayland-client wayland-cursor
x11 xkbcommon xkbcommon-x11 x11-xcb xcursor xfixes
)
if command -v pkg-config >/dev/null 2>&1; then
for pkg in "${gio_pkg_modules[@]}"; do
if ! pkg-config --exists "$pkg" 2>/dev/null; then
case "$pkg" in
xkbcommon-x11) missing+=(libxkbcommon-x11-dev) ;;
x11-xcb) missing+=(libx11-xcb-dev) ;;
wayland-*) missing+=(libwayland-dev) ;;
xkbcommon) missing+=(libxkbcommon-dev) ;;
egl|wayland-egl) missing+=(libegl-dev) ;;
xcursor) missing+=(libxcursor-dev) ;;
xfixes) missing+=(libxfixes-dev) ;;
x11) missing+=(xorg-dev) ;;
esac
fi
done
fi
if [ ${#missing[@]} -gt 0 ]; then
local unique_missing=()
for pkg in "${missing[@]}"; do
local seen=false
for existing in "${unique_missing[@]}"; do
if [ "$existing" = "$pkg" ]; then
seen=true
break
fi
done
if [ "$seen" = false ]; then
unique_missing+=("$pkg")
fi
done
install_apt_packages "${unique_missing[@]}" || return 1
fi
}
ensure_nfpm() {
if command -v nfpm >/dev/null 2>&1; then
return 0
fi
local nfpm_version="$NFPM_VERSION"
local nfpm_arch
case "$(uname -m)" in
x86_64|amd64) nfpm_arch="x86_64" ;;
aarch64|arm64) nfpm_arch="arm64" ;;
*)
print_error "Unsupported architecture for nfpm bootstrap: $(uname -m)"
return 1
;;
esac
local nfpm_url="https://github.com/goreleaser/nfpm/releases/download/${nfpm_version}/nfpm_${nfpm_version#v}_Linux_${nfpm_arch}.tar.gz"
local tmp_dir
tmp_dir="$(mktemp -d)"
echo "Installing nfpm ${nfpm_version} (${nfpm_arch})..."
if ! curl -fsSL "$nfpm_url" | tar -xz -C "$tmp_dir" nfpm; then
print_error "Failed to download nfpm from ${nfpm_url}"
rm -rf "$tmp_dir"
return 1
fi
mkdir -p "${HOME}/.local/bin"
mv "$tmp_dir/nfpm" "${HOME}/.local/bin/nfpm"
chmod +x "${HOME}/.local/bin/nfpm"
export PATH="${HOME}/.local/bin:${PATH}"
rm -rf "$tmp_dir"
if ! command -v nfpm >/dev/null 2>&1; then
print_error "nfpm install failed."
return 1
fi
}
prepare_packaging_icons() {
ensure_icon || return 1
mkdir -p packaging/icons/hicolor/256x256/apps packaging/icons/hicolor/48x48/apps
cp "$ICON_PATH" packaging/icons/hicolor/256x256/apps/dback.png
cp "$ICON_PATH" packaging/icons/hicolor/48x48/apps/dback.png
}
pack_deb() {
if [ ! -f "$DIST_DIR/${APP_NAME}-linux" ]; then
print_error "Missing Linux binary; build it first."
return 1
fi
prepare_packaging_icons || return 1
ensure_nfpm || return 1
echo ""
echo "Building Debian package..."
rm -f "$DIST_DIR"/dback_*_amd64.deb
export APP_VERSION
if APP_VERSION="$APP_VERSION" nfpm package -f packaging/nfpm.yaml -p deb --target "$DIST_DIR"; then
local deb_file="$DIST_DIR/dback_${APP_VERSION}_amd64.deb"
if [ -f "$deb_file" ]; then
print_success "Debian package: ./$deb_file"
return 0
fi
local found
found="$(find "$DIST_DIR" -maxdepth 1 -name 'dback_*_amd64.deb' | head -n 1)"
if [ -n "$found" ]; then
print_success "Debian package: ./$found"
return 0
fi
fi
print_error "Debian package build failed."
return 1
}
print_release_hint() {
echo ""
echo "Release tag for GitHub (version ${APP_VERSION}):"
echo " git tag v${APP_VERSION}"
echo " git push origin v${APP_VERSION}"
echo ""
echo "CI will publish: dback-linux, dback-windows.exe, dback_${APP_VERSION}_amd64.deb"
}
build_linux() {
echo ""
echo "Building for Linux..."
ensure_dist_dir
ensure_icon || return 1
ensure_linux_deps || return 1
ldflags="-X main.appVersion=${APP_VERSION}"
if CGO_ENABLED=1 go build -ldflags "$ldflags" -o "$DIST_DIR/${APP_NAME}-linux" .; then
print_success "Linux build: ./$DIST_DIR/${APP_NAME}-linux"
# Create a launcher wrapper that handles EGL/GPU driver issues automatically.
local launcher="$DIST_DIR/${APP_NAME}"
cat > "$launcher" << 'LAUNCHER_EOF'
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BINARY="$SCRIPT_DIR/dback-linux"
# Detect NVIDIA driver/library version mismatch (common after updates without reboot).
# If detected, force Mesa EGL to avoid eglInitialize failures.
if [ -z "${__EGL_VENDOR_LIBRARY_FILENAMES}" ]; then
if [ -f "/usr/share/glvnd/egl_vendor.d/10_nvidia.json" ]; then
if ! nvidia-smi >/dev/null 2>&1; then
MESA_VENDOR="/usr/share/glvnd/egl_vendor.d/50_mesa.json"
if [ -f "$MESA_VENDOR" ]; then
echo "WARNING: NVIDIA driver mismatch — using Mesa EGL. Reboot for full GPU acceleration." >&2
export __EGL_VENDOR_LIBRARY_FILENAMES="$MESA_VENDOR"
fi
fi
fi
fi
exec "$BINARY" "$@"
LAUNCHER_EOF
chmod +x "$launcher"
print_success "Launcher script: ./$DIST_DIR/${APP_NAME}"
echo " Run the app with: ./$DIST_DIR/${APP_NAME}"
pack_deb || return 1
print_release_hint
return 0
fi
print_error "Linux build failed."
return 1
}
run_choice() {
case "$1" in
1|linux|Linux|"")
build_linux
;;
q|Q|quit|exit)
echo "Canceled."
return 0
;;
*)
print_error "Unknown option: $1 (Linux-only build)"
return 1
;;
esac
}
if [ $# -gt 0 ]; then
run_choice "$1"
exit $?
fi
echo "DBack Linux build"
echo ""
run_choice linux