-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-deb.sh
executable file
·68 lines (57 loc) · 1.75 KB
/
build-deb.sh
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
#!/bin/bash
# Exit on error
set -e
# Variables
APP_NAME="asynchook" # Name of your application
VERSION="1.1.0" # Version of your application
ARCH="amd64" # Architecture (amd64, arm64, all, etc.)
BUILD_DIR="./build" # Temporary build directory
PACKAGE_DIR="./package" # Package structure directory
DEB_FILE="./${APP_NAME}_${VERSION}_${ARCH}.deb" # Output .deb file
# Step 1: Build the Go application
echo "Building Go application..."
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
GOOS=linux GOARCH=$ARCH go build -o "$BUILD_DIR/$APP_NAME" .
# Step 2: Set up the package structure
echo "Setting up package structure..."
rm -rf "$PACKAGE_DIR"
mkdir -p "$PACKAGE_DIR/DEBIAN"
mkdir -p "$PACKAGE_DIR/usr/bin"
mkdir -p "$PACKAGE_DIR/lib/systemd/system"
# Step 3: Create control file
echo "Creating control file..."
cat <<EOF > "$PACKAGE_DIR/DEBIAN/control"
Package: $APP_NAME
Version: $VERSION
Section: utils
Priority: optional
Architecture: $ARCH
Maintainer: Jay padaliya <[email protected]>
Description: $APP_NAME
EOF
# Step 4: Copy application binary and service file
echo "Copying application binary..."
cp "$BUILD_DIR/$APP_NAME" "$PACKAGE_DIR/usr/bin/"
echo "Copying service file..."
cat <<EOF > "$PACKAGE_DIR/lib/systemd/system/$APP_NAME.service"
[Unit]
Description=$APP_NAME Service
After=network.target
[Service]
ExecStart=/usr/bin/$APP_NAME --config=/etc/$APP_NAME/config.yaml
Restart=on-failure
User=root
Group=root
[Install]
WantedBy=multi-user.target
EOF
# Step 5: Build the .deb package
echo "Building .deb package..."
dpkg-deb --build "$PACKAGE_DIR" "$DEB_FILE"
# Step 6: Clean up
echo "Cleaning up..."
rm -rf "$BUILD_DIR"
rm -rf "$PACKAGE_DIR"
# Step 7: Output result
echo "Debian package created successfully: $DEB_FILE"