#!/bin/bash

# Exit on any error
set -e

# Install build dependencies
sudo apt-get update
sudo apt-get install -y checkinstall build-essential wget tar gzip

# Create temporary directory for building
WORKDIR=$(mktemp -d)
cd "$WORKDIR"

# Download and extract source
wget https://sourceforge.net/projects/atinout/files/latest/download -O atinout.tar.gz
tar xfz atinout.tar.gz
cd "$(ls -d */)"

# Modify Makefile to remove -Werror flag
sed -i 's/-Werror//g' Makefile

# Create package using checkinstall
sudo checkinstall --pkgname=atinout \
                 --pkgversion=$(date +%Y%m%d) \
                 --pkgrelease=1 \
                 --maintainer="your@email.com" \
                 --nodoc \
                 --strip=no \
                 --backup=no \
                 --reset-uids=yes \
                 --fstrans=no \
                 --default \
                 make install

# Clean up temporary files
cd ..
rm -rf "$WORKDIR"

echo "Package created successfully!"
