-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c0b41f
commit be9a382
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |