Skip to content

Instantly share code, notes, and snippets.

@zAbuQasem
Created April 12, 2024 02:58
Show Gist options
  • Save zAbuQasem/70671fba2810b8b4a71a5652ba4b1be3 to your computer and use it in GitHub Desktop.
Save zAbuQasem/70671fba2810b8b4a71a5652ba4b1be3 to your computer and use it in GitHub Desktop.
Create apt package and serve it
#!/bin/bash
# Create necessary directory structure
mkdir -p package/package_1.0.0-1_amd64
cd package/package_1.0.0-1_amd64
# Create directory for binary
mkdir -p usr/bin
cd usr/bin
# Create C source file for the program
cat <<EOF > package.c
#include <stdio.h>
int main() {
printf("\033[1;32m[!] Hello World!\033[0m\\n");
return 0;
}
EOF
# Compile the C source file to produce the binary and remove the source file
gcc package.c -o package && rm package.c
cd ../..
# Create DEBIAN directory and control file with package metadata
mkdir DEBIAN
cat <<EOF > DEBIAN/control
Package: package
Version: 1.0.0
Maintainer: zabuqasem <[email protected]>
Depends: libc6
Architecture: amd64
Homepage: https://example.com/
Description: A program that does something'
EOF
# Move back to the parent directory and build the Debian package
cd ..
dpkg --build package_1.0.0-1_amd64
#!/bin/bash
mkdir -p apt-repo/conf
cat <<EOF > apt-repo/conf/distributions
Origin: Package Repository
Label: Package
Suite: stable
Codename: stable
Version: 1.0
Architectures: amd64
Components: main
Description: Package Repository
Pull: stable
EOF
sudo apt install reprepro -y
reprepro -V --basedir apt-repo -S utils -P optional includedeb stable package/package_1.0.0-1_amd64.deb
# For a POC, in Production enviroments, serve it with nginx or apache2..
echo '[+] Now server it with: python3 -m http.server'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment