98 lines
2.5 KiB
Bash
Executable file
98 lines
2.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# docpp_make
|
|
# wrapper script for generating distro packages
|
|
|
|
proj="docpp"
|
|
prefix="${prefix:-/usr}"
|
|
release="${release:-Release}"
|
|
|
|
clean() {
|
|
rm -rf ./*.zst* ./*.tar* ./*.sig* *.PKGBUILD *.ebuild *.ebuild* build/ PKGBUILD
|
|
}
|
|
|
|
check_correct_dir() {
|
|
[ ! -d ".git" ] && printf "Incorrect directory.\n" && exit 1
|
|
}
|
|
|
|
gen_pkg() {
|
|
[ "$(id -u)" = "0" ] && printf "Do not run as root.\n" && exit 1
|
|
version="${version:-$(grep project CMakeLists.txt | sed "s/project(${proj} VERSION //g")}"
|
|
|
|
if [ ! -e ".git" ]; then
|
|
printf "This is not a git repository.\n"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -x "$(command -v git)" ]; then
|
|
printf "git is required for this action.\n"
|
|
exit 1
|
|
fi
|
|
|
|
rm -f ${proj} ${proj}-${version}.tar.gz ${proj}-${version}.PKGBUILD *.o *zst*
|
|
mkdir -p ${proj}-${version}
|
|
cp -rf $(git ls-files | cut -d/ -f1 | uniq) "${proj}-${version}"
|
|
tar -cf ${proj}-${version}.tar ${proj}-${version}
|
|
gzip ${proj}-${version}.tar
|
|
rm -rf ${proj}-${version}
|
|
|
|
USER="$(whoami)"
|
|
|
|
if [ "$1" = "release" ]; then
|
|
printf "Is your GPG key '$(whoami)'?\n"
|
|
select yn in "Yes" "No"; do
|
|
case $yn in
|
|
Yes) USER="$(whoami)"; break ;;
|
|
No) printf "\n> "; read -r USER; break ;;
|
|
esac
|
|
done
|
|
fi
|
|
|
|
if [ -x "$(command -v gpg)" ] && [ "$1" = "release" ]; then
|
|
gpg --detach-sign --yes --local-user "${USER}" ${proj}-${version}.tar.gz
|
|
fi
|
|
|
|
if [ -x "$(command -v md5sum)" ] && [ "$1" = "release" ]; then
|
|
md5sum *.tar.gz | cut -d ' ' -f 1 > ${proj}-${version}.tar.gz.md5
|
|
fi
|
|
|
|
if [ -x "$(command -v sha256sum)" ] && [ "$1" = "release" ]; then
|
|
sha256sum *.tar.gz | cut -d ' ' -f 1 > ${proj}-${version}.tar.gz.sha256
|
|
fi
|
|
}
|
|
|
|
help() {
|
|
cat << EOF
|
|
$0 - Wrapper script for generating distro packages
|
|
End users should not run this script directly, this is for maintainers only.
|
|
|
|
$0 clean Clean up the source tree
|
|
$0 dist Create a distro package for ${proj}
|
|
$0 help Print this help
|
|
EOF
|
|
}
|
|
|
|
main() {
|
|
case "$1" in
|
|
"clean") action="clean" ;;
|
|
"dist") action="dist" ;;
|
|
"help") action="help" ;;
|
|
"") action="help" ;;
|
|
*) [ -z "$action" ] && action="wrong" ;;
|
|
esac
|
|
|
|
check_correct_dir
|
|
|
|
case "$action" in
|
|
"wrong") printf "Invalid action: %s\n" "$1" && exit 1 ;;
|
|
"clean") clean ;;
|
|
"help") help ;;
|
|
"dist") gen_pkg ;;
|
|
"dist_release") gen_pkg "release";
|
|
esac
|
|
|
|
exit $?
|
|
}
|
|
|
|
main "$@"
|
|
|