-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild_linux.sh
More file actions
executable file
·422 lines (361 loc) · 11.8 KB
/
Copy pathbuild_linux.sh
File metadata and controls
executable file
·422 lines (361 loc) · 11.8 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#!/bin/bash
#
# Harmony Music Player - Linux Build Script
# Creates AppImage, DEB, and RPM packages
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
APP_NAME="Harmony"
APP_VERSION="${APP_VERSION:-1.0.0}"
DIST_DIR="$SCRIPT_DIR/dist"
APPDIR="AppDir"
echo "=========================================="
echo " $APP_NAME v$APP_VERSION - Linux Build"
echo "=========================================="
# Build using release.sh first
build_base() {
echo ""
echo "==> Building base application..."
if [ ! -d "$DIST_DIR/$APP_NAME" ]; then
chmod +x release.sh
./release.sh
fi
if [ ! -d "$DIST_DIR/$APP_NAME" ]; then
echo "Error: Build failed"
exit 1
fi
echo "Base build completed: $DIST_DIR/$APP_NAME"
}
# Create AppImage
create_appimage() {
echo ""
echo "==> Creating AppImage..."
# Check for appimagetool
APPIMAGETOOL="appimagetool-x86_64.AppImage"
if ! command -v appimagetool &> /dev/null; then
if [ ! -f "$APPIMAGETOOL" ]; then
echo "Downloading appimagetool..."
wget -q https://github.com/AppImage/AppImageKit/releases/download/continuous/$APPIMAGETOOL
chmod +x "$APPIMAGETOOL"
fi
APPIMAGETOOL="./$APPIMAGETOOL"
else
APPIMAGETOOL="appimagetool"
fi
# Create AppDir structure
rm -rf "$APPDIR"
mkdir -p "$APPDIR/usr/bin"
mkdir -p "$APPDIR/usr/share/applications"
mkdir -p "$APPDIR/usr/share/icons/hicolor/256x256/apps"
mkdir -p "$APPDIR/usr/share/metainfo"
# Copy application
cp -r "$DIST_DIR/$APP_NAME"/* "$APPDIR/usr/bin/"
# Create desktop file
cat > "$APPDIR/usr/share/applications/$APP_NAME.desktop" << EOF
[Desktop Entry]
Name=$APP_NAME
Comment=Modern Music Player
Exec=Harmony
Icon=$APP_NAME
Terminal=false
Type=Application
Categories=AudioVideo;Audio;Player;Qt;
MimeType=audio/mpeg;audio/flac;audio/ogg;audio/x-vorbis+ogg;audio/mp4;
StartupWMClass=$APP_NAME
EOF
# Create AppStream metadata
cat > "$APPDIR/usr/share/metainfo/$APP_NAME.metainfo.xml" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>com.harmonyplayer.$APP_NAME</id>
<name>$APP_NAME</name>
<summary>Modern Music Player with Spotify-like Interface</summary>
<metadata_license>MIT</metadata_license>
<project_license>MIT</project_license>
<description>
<p>A modern music player built with PySide6 featuring:</p>
<ul>
<li>Spotify-like interface</li>
<li>Multiple audio format support</li>
<li>Playlist management</li>
<li>Lyrics display</li>
<li>Cloud drive integration</li>
</ul>
</description>
<launchable type="desktop-id">$APP_NAME.desktop</launchable>
<content_rating type="oars-1.1"/>
</component>
EOF
# Create AppRun
cat > "$APPDIR/AppRun" << 'EOF'
#!/bin/bash
SELF=$(readlink -f "$0")
HERE=${SELF%/*}
# Debug mode - set HARMONY_DEBUG=1 to enable
if [ "$HARMONY_DEBUG" = "1" ]; then
echo "=== Harmony Debug Mode ==="
echo "AppDir: $HERE"
echo "System: $(uname -a)"
echo "glibc: $(ldd --version | head -1)"
fi
export PATH="${HERE}/usr/bin:${PATH}"
export LD_LIBRARY_PATH="${HERE}/usr/lib:${HERE}:${HERE}/usr/bin:${HERE}/usr/bin/_internal:${HERE}/usr/bin/_internal/lib:${LD_LIBRARY_PATH}"
# Qt plugins path - 输入法支持
export QT_PLUGIN_PATH="${HERE}/usr/bin/_internal/PySide6/Qt/plugins"
export QT_DEBUG_PLUGINS=0
# 平台选择 - 默认使用 XCB (更稳定),设置 HARMONY_WAYLAND=1 使用 Wayland
if [ "$HARMONY_WAYLAND" = "1" ] && [ -n "$WAYLAND_DISPLAY" ]; then
# Wayland mode
export QT_QPA_PLATFORM=wayland
else
# XCB/X11 mode (default, more stable)
export QT_QPA_PLATFORM=xcb
fi
# 输入法支持 - 可通过 HARMONY_IM=ibus/fcitx 手动指定
if [ -n "$HARMONY_IM" ]; then
# 手动指定输入法
export QT_IM_MODULE="$HARMONY_IM"
export GTK_IM_MODULE="$HARMONY_IM"
export XMODIFIERS="@im=$HARMONY_IM"
elif [ -z "$QT_IM_MODULE" ]; then
# 自动检测(仅当未设置时)
if pgrep -x "fcitx5" &>/dev/null; then
export QT_IM_MODULE=fcitx
export GTK_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
elif pgrep -x "ibus-daemon" &>/dev/null; then
export QT_IM_MODULE=ibus
export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
fi
fi
# OpenGL fallback (可通过 HARMONY_GL=1 禁用)
if [ "$HARMONY_GL" != "1" ]; then
export QT_XCB_GL_INTEGRATION=none
export LIBGL_ALWAYS_SOFTWARE=1
fi
if [ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
echo "Error: No display server found"
exit 1
fi
exec "${HERE}/usr/bin/Harmony" "$@"
EOF
chmod +x "$APPDIR/AppRun"
# Copy icon
if [ -f "$SCRIPT_DIR/icon.png" ]; then
cp "$SCRIPT_DIR/icon.png" "$APPDIR/usr/share/icons/hicolor/256x256/apps/$APP_NAME.png"
cp "$SCRIPT_DIR/icon.png" "$APPDIR/$APP_NAME.png"
fi
# Link files to AppDir root
ln -sf "$APPDIR/usr/share/applications/$APP_NAME.desktop" "$APPDIR/$APP_NAME.desktop"
# Build AppImage
ARCH=$(uname -m)
export ARCH
$APPIMAGETOOL "$APPDIR" "$DIST_DIR/${APP_NAME}-${APP_VERSION}-${ARCH}.AppImage"
echo "AppImage created: $DIST_DIR/${APP_NAME}-${APP_VERSION}-${ARCH}.AppImage"
}
# Create DEB package
create_deb() {
echo ""
echo "==> Creating DEB package..."
DEB_DIR="$DIST_DIR/deb"
rm -rf "$DEB_DIR"
mkdir -p "$DEB_DIR/DEBIAN"
mkdir -p "$DEB_DIR/usr/lib/$APP_NAME"
mkdir -p "$DEB_DIR/usr/bin"
mkdir -p "$DEB_DIR/usr/share/applications"
mkdir -p "$DEB_DIR/usr/share/icons/hicolor/256x256/apps"
mkdir -p "$DEB_DIR/usr/share/doc/$APP_NAME"
mkdir -p "$DEB_DIR/usr/share/metainfo"
# Copy application
cp -r "$DIST_DIR/$APP_NAME"/* "$DEB_DIR/usr/lib/$APP_NAME/"
# Create wrapper script
cat > "$DEB_DIR/usr/bin/$APP_NAME" << EOF
#!/bin/bash
export QT_PLUGIN_PATH="/usr/lib/$APP_NAME/_internal/PySide6/Qt/plugins"
export LD_LIBRARY_PATH="/usr/lib/$APP_NAME/_internal/lib:\$LD_LIBRARY_PATH"
exec /usr/lib/$APP_NAME/$APP_NAME "\$@"
EOF
chmod 755 "$DEB_DIR/usr/bin/$APP_NAME"
# Create control file
cat > "$DEB_DIR/DEBIAN/control" << EOF
Package: harmony
Version: $APP_VERSION
Section: sound
Priority: optional
Architecture: amd64
Depends: libc6 (>= 2.17), libgl1, libpulse0, libxcb1, libxkbcommon0, libglib2.0-0, libmpv2 | libmpv-dev
Maintainer: Harmony Player <support@harmonyplayer.com>
Description: Modern Music Player
A PySide6-based music player with a modern, Spotify-like interface.
Supports multiple audio formats including MP3, FLAC, OGG, M4A, and WAV.
Features include playlist management, lyrics display, album art,
and cloud drive integration.
EOF
# Create postinst script
cat > "$DEB_DIR/DEBIAN/postinst" << 'EOF'
#!/bin/bash
set -e
update-desktop-database /usr/share/applications 2>/dev/null || true
gtk-update-icon-cache /usr/share/icons/hicolor 2>/dev/null || true
EOF
chmod 755 "$DEB_DIR/DEBIAN/postinst"
# Create prerm script
cat > "$DEB_DIR/DEBIAN/prerm" << 'EOF'
#!/bin/bash
set -e
EOF
chmod 755 "$DEB_DIR/DEBIAN/prerm"
# Create desktop file
cat > "$DEB_DIR/usr/share/applications/$APP_NAME.desktop" << EOF
[Desktop Entry]
Name=$APP_NAME
Comment=Modern Music Player
Exec=$APP_NAME
Icon=$APP_NAME
Terminal=false
Type=Application
Categories=AudioVideo;Audio;Player;Qt;
MimeType=audio/mpeg;audio/flac;audio/ogg;audio/x-vorbis+ogg;audio/mp4;
StartupWMClass=$APP_NAME
EOF
# Copy icon
if [ -f "$SCRIPT_DIR/icon.png" ]; then
cp "$SCRIPT_DIR/icon.png" "$DEB_DIR/usr/share/icons/hicolor/256x256/apps/$APP_NAME.png"
fi
# Copy metainfo
if [ -f "$APPDIR/usr/share/metainfo/$APP_NAME.metainfo.xml" ]; then
cp "$APPDIR/usr/share/metainfo/$APP_NAME.metainfo.xml" "$DEB_DIR/usr/share/metainfo/"
fi
# Build DEB
DEB_PACKAGE="$DIST_DIR/${APP_NAME}_${APP_VERSION}_amd64.deb"
dpkg-deb --build "$DEB_DIR" "$DEB_PACKAGE"
echo "DEB package created: $DEB_PACKAGE"
}
# Create RPM package
create_rpm() {
echo ""
echo "==> Creating RPM package..."
# Check for rpmbuild
if ! command -v rpmbuild &> /dev/null; then
echo "Error: rpmbuild not found. Install with: sudo apt install rpm"
return 1
fi
RPM_DIR="$DIST_DIR/rpm"
rm -rf "$RPM_DIR"
mkdir -p "$RPM_DIR/SOURCES"
mkdir -p "$RPM_DIR/SPECS"
mkdir -p "$RPM_DIR/BUILD"
mkdir -p "$RPM_DIR/RPMS"
# Create tarball for RPM
TARBALL="$RPM_DIR/SOURCES/$APP_NAME-$APP_VERSION.tar.gz"
mkdir -p "$DIST_DIR/$APP_NAME-$APP_VERSION"
cp -r "$DIST_DIR/$APP_NAME"/* "$DIST_DIR/$APP_NAME-$APP_VERSION/"
tar -czf "$TARBALL" -C "$DIST_DIR" "$APP_NAME-$APP_VERSION"
rm -rf "$DIST_DIR/$APP_NAME-$APP_VERSION"
# Create RPM spec file
cat > "$RPM_DIR/SPECS/$APP_NAME.spec" << EOF
Name: $APP_NAME
Version: $APP_VERSION
Release: 1%{?dist}
Summary: Modern Music Player with Spotify-like Interface
License: MIT
URL: https://github.com/harmonyplayer/harmony
Source0: %{name}-%{version}.tar.gz
BuildArch: x86_64
Requires: glibc >= 2.17, libglvnd, pulseaudio-libs, libxcb, libxkbcommon
Requires: glib2, qt6-qtbase
%description
A PySide6-based music player with a modern, Spotify-like interface.
Supports multiple audio formats including MP3, FLAC, OGG, M4A, and WAV.
Features include playlist management, lyrics display, album art,
and cloud drive integration.
%prep
%setup -q
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}/usr/lib/%{name}
cp -r * %{buildroot}/usr/lib/%{name}/
mkdir -p %{buildroot}/usr/bin
cat > %{buildroot}/usr/bin/%{name} << 'WRAPPER'
#!/bin/bash
export QT_PLUGIN_PATH="/usr/lib/$APP_NAME/_internal/PySide6/Qt/plugins"
export LD_LIBRARY_PATH="/usr/lib/$APP_NAME/_internal/lib:\$LD_LIBRARY_PATH"
exec /usr/lib/$APP_NAME/$APP_NAME "\$@"
WRAPPER
chmod 755 %{buildroot}/usr/bin/%{name}
mkdir -p %{buildroot}/usr/share/applications
cat > %{buildroot}/usr/share/applications/%{name}.desktop << 'DESKTOP'
[Desktop Entry]
Name=$APP_NAME
Comment=Modern Music Player
Exec=$APP_NAME
Icon=$APP_NAME
Terminal=false
Type=Application
Categories=AudioVideo;Audio;Player;Qt;
MimeType=audio/mpeg;audio/flac;audio/ogg;audio/x-vorbis+ogg;audio/mp4;
StartupWMClass=$APP_NAME
DESKTOP
mkdir -p %{buildroot}/usr/share/icons/hicolor/256x256/apps
%if 0%{?fedora} || 0%{?rhel} >= 8
# Icon will be added separately
%endif
%files
%defattr(-,root,root,-)
/usr/lib/%{name}
/usr/bin/%{name}
/usr/share/applications/%{name}.desktop
%attr(644,root,root) /usr/share/icons/hicolor/256x256/apps/%{name}.png
%post
update-desktop-database /usr/share/applications 2>/dev/null || true
gtk-update-icon-cache /usr/share/icons/hicolor 2>/dev/null || true
%postun
update-desktop-database /usr/share/applications 2>/dev/null || true
gtk-update-icon-cache /usr/share/icons/hicolor 2>/dev/null || true
%changelog
* $(date '+%a %b %d %Y') Harmony Player <support@harmonyplayer.com> - $APP_VERSION-1
- Initial package
EOF
# Build RPM
rpmbuild --define "_topdir $RPM_DIR" -bb "$RPM_DIR/SPECS/$APP_NAME.spec"
# Copy RPM to dist
find "$RPM_DIR/RPMS" -name "*.rpm" -exec cp {} "$DIST_DIR/" \;
echo "RPM package created: $DIST_DIR/$APP_NAME-$APP_VERSION-1.x86_64.rpm"
}
# Main
case "${1:-}" in
--appimage)
build_base
create_appimage
;;
--deb)
build_base
create_appimage # Need AppDir for metainfo
create_deb
;;
--rpm)
build_base
create_rpm
;;
--all)
build_base
create_appimage
create_deb
create_rpm || echo "RPM build skipped (rpmbuild not available)"
;;
"")
build_base
create_appimage
;;
*)
echo "Usage: $0 [--appimage|--deb|--rpm|--all]"
exit 1
;;
esac
echo ""
echo "=========================================="
echo "Build complete!"
echo "=========================================="
ls -lh "$DIST_DIR"/*.{AppImage,deb,rpm} 2>/dev/null || true