Skip to content

Commit

Permalink
added build script for .deb
Browse files Browse the repository at this point in the history
  • Loading branch information
padaliyajay committed Dec 23, 2024
1 parent 8c0b41f commit be9a382
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
Binary file added asynchook_1.0.0_amd64.deb
Binary file not shown.
68 changes: 68 additions & 0 deletions build-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

# Exit on error
set -e

# Variables
APP_NAME="asynchook" # Name of your application
VERSION="1.0.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"

0 comments on commit be9a382

Please sign in to comment.