104 lines
1.7 KiB
Bash
Executable File
104 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/bash
|
|
|
|
# Init variables
|
|
APTPKG_VERSION="0.1.0-dev"
|
|
|
|
# Show help
|
|
show_help(){
|
|
cat > /dev/stdout <<EOF
|
|
|
|
aptpkg v$APTPKG_VERSION
|
|
|
|
Easily create debian packages.
|
|
|
|
Documentation: https://man.sr.ht/~earnestma/aptpkg
|
|
|
|
Usage:
|
|
aptpkg [directory]
|
|
aptpkg -h, --help Show help
|
|
|
|
EOF
|
|
}
|
|
|
|
# Incorrect aptpkg usage: explain, show help, and exit
|
|
error_usage_die(){
|
|
echo "ERROR: " "$1"
|
|
show_help
|
|
exit 1
|
|
}
|
|
|
|
# Check that "build" file exists in directory
|
|
check(){
|
|
if ! [ -f "$1/build" ]; then
|
|
echo "No package of that name exists."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Generate the debian control file
|
|
gen_control_file(){
|
|
mkdir -p "$builddir"/DEBIAN
|
|
echo "Package: $name
|
|
Version: $version-$rev
|
|
Architecture: amd64
|
|
Maintainer: $(grep -am 1 -hr "Maintainer: " build | sed 's/# Maintainer: //')
|
|
Homepage: $url
|
|
Description: $description
|
|
$customcontrol
|
|
" > "$builddir"/DEBIAN/control
|
|
}
|
|
|
|
# Download a debian package
|
|
build_deb(){
|
|
echo "Getting $source"
|
|
wget "$source" -qO dist/"$name"_"$version"-"$rev"-amd64.deb
|
|
}
|
|
|
|
# Download and build using files
|
|
build_file(){
|
|
builddir=${name}_${version}-${rev}_amd64
|
|
|
|
cd "$1"
|
|
mkdir -p "$builddir"
|
|
|
|
download "$@"
|
|
steps "$@"
|
|
|
|
gen_control_file "$@"
|
|
|
|
[ -f preinst ] && cp preinst "$builddir"/debian/
|
|
[ -f postinst ] && cp postinst "$builddir"/debian/
|
|
|
|
cd -
|
|
|
|
dpkg-deb --build --root-owner-group "$1"/"$builddir" dist/
|
|
}
|
|
|
|
# Determine which function to run
|
|
load_build(){
|
|
mkdir -p dist
|
|
|
|
# shellcheck disable=SC1090
|
|
source "$1/build"
|
|
|
|
case "$type" in
|
|
deb)
|
|
build_deb ;;
|
|
file)
|
|
build_file "$@" ;;
|
|
esac
|
|
}
|
|
|
|
# Run!
|
|
case $1 in
|
|
-h|--help)
|
|
show_help ;;
|
|
*)
|
|
if [ $# -ne 1 ]; then
|
|
error_usage_die "You must provide one directory"
|
|
fi
|
|
|
|
check "$1"
|
|
load_build "$1" ;;
|
|
esac
|