-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_deb.sh
More file actions
89 lines (74 loc) · 2.3 KB
/
Copy pathcreate_deb.sh
File metadata and controls
89 lines (74 loc) · 2.3 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
#!/bin/bash
set -e
# Configuration
VERSION="1.1.0"
ARCH="amd64"
create_package() {
local PKG_NAME=$1
local PROJECT_PATH=$2
local BINARY_NAME=$3
local DIR="pkg_${PKG_NAME}"
echo "Building Package: ${PKG_NAME}..."
# 1. Clean and Create structure
rm -rf "$DIR"
mkdir -p "$DIR/DEBIAN"
mkdir -p "$DIR/usr/bin"
mkdir -p "$DIR/etc/${PKG_NAME}"
mkdir -p "$DIR/lib/systemd/system"
# 2. Build the .NET App (Self-Contained)
dotnet publish "$PROJECT_PATH" -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=true -o "publish_temp"
# 3. Copy files
cp "publish_temp/$BINARY_NAME" "$DIR/usr/bin/${PKG_NAME}"
cp "publish_temp/appsettings.json" "$DIR/etc/${PKG_NAME}/appsettings.json"
rm -rf "publish_temp"
# 4. Create Control file
cat > "$DIR/DEBIAN/control" <<EOF
Package: ${PKG_NAME}
Version: ${VERSION}
Section: utils
Priority: optional
Architecture: ${ARCH}
Maintainer: SystemMonitor Team
Description: Standalone System Monitoring Suite
EOF
# 5. Create Systemd Service
if [ "$PKG_NAME" == "system-monitor-server" ]; then
SERVICE_DESC="System Monitor Collector"
EXEC="/usr/bin/system-monitor-server"
else
SERVICE_DESC="System Monitor Agent"
EXEC="/usr/bin/system-monitor-agent"
fi
cat > "$DIR/lib/systemd/system/${PKG_NAME}.service" <<EOF
[Unit]
Description=${SERVICE_DESC}
After=network.target
[Service]
Type=simple
ExecStart=${EXEC}
WorkingDirectory=/etc/${PKG_NAME}
Restart=always
RestartSec=10
User=root
[Install]
WantedBy=multi-user.target
EOF
# 6. Create Post-Install script (to start service automatically)
cat > "$DIR/DEBIAN/postinst" <<EOF
#!/bin/bash
systemctl daemon-reload
systemctl enable ${PKG_NAME}
systemctl start ${PKG_NAME}
echo "${PKG_NAME} installed and started successfully."
EOF
chmod 755 "$DIR/DEBIAN/postinst"
# 7. Build the .deb
dpkg-deb --build "$DIR" "${PKG_NAME}_${VERSION}_${ARCH}.deb"
rm -rf "$DIR"
echo "Created: ${PKG_NAME}_${VERSION}_${ARCH}.deb"
}
# Run the packaging
create_package "system-monitor-server" "SystemCollectorService/SystemCollectorService.csproj" "SystemCollectorService"
create_package "system-monitor-agent" "SystemMonitorService/SystemMonitorService.csproj" "SystemMonitorService"
echo -e "
Successfully created .deb packages!"