-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage_app.sh
More file actions
executable file
·132 lines (109 loc) · 3.73 KB
/
package_app.sh
File metadata and controls
executable file
·132 lines (109 loc) · 3.73 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
#!/bin/bash
# Configuration
# ---------------------------------------------------------
# PACKAGE_NAME: Must be lowercase, no spaces
PACKAGE_NAME="wiretray"
# MENU_NAME: What you see in the App Launcher
MENU_NAME="WireTray"
# Use the first argument as version, default to "1.0" if not provided
VERSION="${1:-1.0}"
SOURCE_SCRIPT="wiretray.py"
MAINTAINER="Jack Macqueen"
DESCRIPTION="System tray utility to manage WireGuard connections."
# Detect System Architecture (amd64, arm64, etc.)
ARCH=$(dpkg --print-architecture)
# ---------------------------------------------------------
# Check for PyInstaller
if ! command -v pyinstaller &> /dev/null; then
echo "Error: PyInstaller is not installed."
echo "Please run: pip install pyinstaller"
exit 1
fi
echo "Building standalone binary with PyInstaller..."
# UPDATED: Added --add-data to bundle the SVG icon inside the binary
pyinstaller --noconfirm --onefile --windowed --clean \
--add-data "icon.svg:." \
--name "$PACKAGE_NAME" "$SOURCE_SCRIPT"
# Verify build succeeded
if [ ! -f "dist/$PACKAGE_NAME" ]; then
echo "Error: PyInstaller build failed."
exit 1
fi
# Create a temporary directory for building .deb
rm -rf build
BUILD_DIR="build/${PACKAGE_NAME}_${VERSION}_${ARCH}"
mkdir -p "$BUILD_DIR/DEBIAN"
mkdir -p "$BUILD_DIR/usr/local/bin"
mkdir -p "$BUILD_DIR/usr/share/applications"
# UPDATED: Create pixmaps directory for the system icon
mkdir -p "$BUILD_DIR/usr/share/pixmaps"
echo "Creating directory structure for $MENU_NAME (v$VERSION) [$ARCH]..."
# 1. Copy the Compiled Binary
cp "dist/$PACKAGE_NAME" "$BUILD_DIR/usr/local/bin/$PACKAGE_NAME"
chmod 755 "$BUILD_DIR/usr/local/bin/$PACKAGE_NAME"
# 2. UPDATED: Copy the Icon for the System Menu
# We rename it to match the PACKAGE_NAME so the .desktop file finds it easily
cp "icon.svg" "$BUILD_DIR/usr/share/pixmaps/$PACKAGE_NAME.svg"
# 3. Create the Control file (Metadata)
cat <<EOF > "$BUILD_DIR/DEBIAN/control"
Package: $PACKAGE_NAME
Version: $VERSION
Section: utils
Priority: optional
Architecture: $ARCH
Depends: wireguard-tools, libxcb-cursor0
Maintainer: $MAINTAINER
Description: $DESCRIPTION
A system tray application to toggle WireGuard interfaces.
EOF
# 4. Create the Post-Installation Script
cat <<EOF > "$BUILD_DIR/DEBIAN/postinst"
#!/bin/bash
set -e
# Define the sudoers file path
SUDOERS_FILE="/etc/sudoers.d/$PACKAGE_NAME"
# Allow the 'sudo' group to run wg-quick without password
echo "%sudo ALL=(ALL) NOPASSWD: /usr/bin/wg-quick" > "\$SUDOERS_FILE"
chmod 0440 "\$SUDOERS_FILE"
# --- NEW: Fix WireGuard Directory Permissions ---
# This allows the GUI app (running as user) to list the .conf files
if [ -d "/etc/wireguard" ]; then
echo "Updating /etc/wireguard permissions to allow listing configs..."
chmod o+rx /etc/wireguard
fi
exit 0
EOF
chmod 755 "$BUILD_DIR/DEBIAN/postinst"
# 5. Create the Post-Removal Script
cat <<EOF > "$BUILD_DIR/DEBIAN/postrm"
#!/bin/bash
set -e
SUDOERS_FILE="/etc/sudoers.d/$PACKAGE_NAME"
if [ "\$1" = "remove" ]; then
if [ -f "\$SUDOERS_FILE" ]; then
rm "\$SUDOERS_FILE"
fi
fi
exit 0
EOF
chmod 755 "$BUILD_DIR/DEBIAN/postrm"
# 6. Create the .desktop file
cat <<EOF > "$BUILD_DIR/usr/share/applications/$PACKAGE_NAME.desktop"
[Desktop Entry]
Name=$MENU_NAME
Comment=$DESCRIPTION
Exec=/usr/local/bin/$PACKAGE_NAME
# UPDATED: Use the package name (which maps to the file in /usr/share/pixmaps)
Icon=$PACKAGE_NAME
Terminal=false
Type=Application
Categories=Network;Utility;
EOF
# 7. Build the .deb package
DEB_FILE="${PACKAGE_NAME}_${VERSION}_${ARCH}.deb"
dpkg-deb --build "$BUILD_DIR" "$DEB_FILE"
rm -rf build dist "$PACKAGE_NAME.spec"
echo "Success! Package created at: $DEB_FILE"
echo "Run these commands to install:"
echo "sudo dpkg -i ./$DEB_FILE"
echo "sudo apt-get install -f"