From 6b0aad508a7aa2c4274cca3b4a6b2f4444d714a5 Mon Sep 17 00:00:00 2001 From: Priyank Upadhyay Date: Wed, 11 Dec 2024 20:15:09 +0530 Subject: [PATCH] feat(): Add binary builders Signed-off-by: Priyank Upadhyay --- install.sh | 25 +++++++++++++++++++++++ make_binary.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 install.sh create mode 100755 make_binary.sh diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..d014c62 --- /dev/null +++ b/install.sh @@ -0,0 +1,25 @@ + +#!/bin/bash + +# Installation paths +INSTALL_DIR="/usr/local/bin" +SCRIPT_NAME="egs-installer" + +echo "🚀 Installing EGS Installer..." + +# Check if running with sudo/root +if [ "$EUID" -ne 0 ]; then + echo "❌ Please run as root or with sudo" + exit 1 +fi + +# Create binary using make_binary.sh +./make_binary.sh + +# Copy binary to installation directory +cp "./$SCRIPT_NAME" "$INSTALL_DIR/" + +# Make executable +chmod +x "$INSTALL_DIR/$SCRIPT_NAME" + +echo "✅ Installation complete. Run 'egs-installer --help' to get started." \ No newline at end of file diff --git a/make_binary.sh b/make_binary.sh new file mode 100755 index 0000000..df27b7c --- /dev/null +++ b/make_binary.sh @@ -0,0 +1,54 @@ + +#!/bin/bash + +# Set script name and version +SCRIPT_NAME="egs-installer" +VERSION="1.0.0" + +# Create temporary build directory +BUILD_DIR="build" +mkdir -p $BUILD_DIR + +echo "🔨 Creating binary package for $SCRIPT_NAME v$VERSION..." + +# Create the binary structure +cat > $BUILD_DIR/binary.sh << 'EOF' +#!/bin/bash +############ Binary Header ############ + +# Embedded base64 data will be appended here +PAYLOAD_START=$(awk '/^__PAYLOAD_BELOW__/ {print NR + 1; exit 0; }' $0) + +# Extract to temporary directory +TEMP_DIR=$(mktemp -d) +EXTRACT_DIR="$TEMP_DIR/egs-installer" +mkdir -p "$EXTRACT_DIR" + +# Extract payload +tail -n +$PAYLOAD_START $0 | base64 --decode | tar xz -C "$EXTRACT_DIR" + +# Execute the main script with all arguments +"$EXTRACT_DIR/egs-installer.sh" "$@" + +# Cleanup +rm -rf "$TEMP_DIR" + +exit 0 + +__PAYLOAD_BELOW__ +EOF + +# Package the installer and dependencies +echo "📦 Packaging installer and dependencies..." +tar czf - egs-installer.sh | base64 >> $BUILD_DIR/binary.sh + +# Make binary executable +chmod +x $BUILD_DIR/binary.sh + +# Move to final location +mv $BUILD_DIR/binary.sh "./$SCRIPT_NAME" + +# Cleanup +rm -rf $BUILD_DIR + +echo "✅ Binary created successfully: ./$SCRIPT_NAME" \ No newline at end of file