aptpkg/aptpkg

129 lines
1.9 KiB
Plaintext
Raw Normal View History

#! /usr/bin/env bash
2021-07-26 13:41:48 -04:00
# Init variables
2021-07-27 18:50:38 -04:00
APTPKG_VERSION="0.1.0"
2021-07-26 13:41:48 -04:00
# Show help
show_help(){
cat > /dev/stdout <<EOF
aptpkg v$APTPKG_VERSION
Easily create debian packages.
2021-07-26 17:26:29 -04:00
Documentation: https://man.sr.ht/~earnestma/aptpkg
2021-07-26 13:41:48 -04:00
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
}
# Verify sha512sums
verify(){
echo "$sha512sums" | sha512sum -c
}
# Copy/ install wrapper for files
cin-bin(){
install -Dm755 "$@"
}
cin-file(){
install -Dm644 "$@"
}
2021-07-26 13:41:48 -04:00
# Check that "build" file exists in directory
check(){
if ! [ -f "$1/build" ]; then
echo "No package of that name exists."
exit 1
fi
}
2021-07-26 17:33:50 -04:00
# 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: //')
Section:
Priority:
2021-07-26 17:33:50 -04:00
Homepage: $url
Description: $description
$customcontrol
" > "$builddir"/DEBIAN/control
}
2021-07-26 13:41:48 -04:00
# Download a debian package
build_deb(){
echo "Getting $source"
wget "$source" -qP dist/
( cd dist ; verify )
2021-07-26 13:41:48 -04:00
}
2021-07-26 17:33:50 -04:00
# Download and build using files
build_file(){
builddir=${name}_${version}-${rev}_amd64
cd "$1"
mkdir -p "$builddir"
for url in $source; do
echo "Getting $source"
wget -q "$url"
done
verify
# Run
2021-07-26 17:33:50 -04:00
steps "$@"
gen_control_file "$@"
2021-07-26 23:14:32 -04:00
for maintfile in preinst postinst prerm postrm; do
2021-07-27 18:47:30 -04:00
[ -f $maintfile ] && cin-bin $maintfile "$builddir"/DEBIAN/$maintfile
2021-07-26 23:14:32 -04:00
done
2021-07-26 17:33:50 -04:00
cd -
dpkg-deb --build --root-owner-group "$1"/"$builddir" dist/
}
2021-07-26 13:41:48 -04:00
# Determine which function to run
load_build(){
2021-07-26 17:26:29 -04:00
mkdir -p dist
2021-07-26 13:41:48 -04:00
# shellcheck disable=SC1090
source "$1/build"
case "$type" in
deb)
build_deb ;;
2021-07-26 17:33:50 -04:00
file)
build_file "$@" ;;
2021-07-26 13:41:48 -04:00
esac
}
# Run!
case $1 in
-h|--help)
show_help ;;
*)
2021-07-26 17:26:29 -04:00
if [ $# -ne 1 ]; then
error_usage_die "You must provide one directory"
fi
2021-07-26 13:41:48 -04:00
check "$1"
load_build "$1" ;;
esac