repo/pkgfile2puke

69 lines
1.5 KiB
Plaintext
Raw Normal View History

2019-05-18 09:21:03 -06:00
#!/bin/sh
# shellcheck source=/dev/null disable=2154,2016
#
# Convert a crux pkgfile to puke's format.
die() {
printf '\033[31mERROR>\033[m %s\n' "$@" >&2
exit 1
}
repo_setup() {
cd repo >/dev/null || die "Not in kiss repository."
mkdir "$name" || die "$name already exists."
cd "$name" >/dev/null || die "Can't cd to $name"
}
pkgfile_read() {
[ -n "$1" ] || die "Need a pkgfile as input."
[ -f "$1" ] || die "File not found '$1'"
. "$1" || die "Syntax error in pkgfile."
[ -n "$name" ] || die "Field 'name' missing from pkgfile."
[ -n "$version" ] || die "Field 'version' missing from pkgfile."
[ -n "$release" ] || die "Field 'release' missing from pkgfile."
[ -n "$source" ] || die "Field 'source' missing from pkgfile."
}
pkgfile_version() {
printf '%s\n' "$version $release" > version
}
pkgfile_source() {
2019-05-18 09:58:12 -06:00
printf '%s\n' "$source" | sed 's/ /\n/g' > sources
2019-05-18 09:21:03 -06:00
}
2019-05-18 09:34:25 -06:00
pkgfile_depends() {
[ "$depends" ] || return
2019-05-18 09:58:12 -06:00
printf '%s\n' "$depends" | sed 's/ /\n/g' > depends
2019-05-18 09:34:25 -06:00
}
2019-05-18 09:21:03 -06:00
pkgfile_build() {
2019-05-18 09:42:33 -06:00
sed 's/$\(BUILD\|PKG\)/$1/g' "$1" | while read -r line; do
2019-05-18 09:21:03 -06:00
[ "$line" = "}" ] && code=
[ "$code" ] && printf '%s\n' "$line"
[ "$line" = "build() {" ] && {
printf '%s\n\n' "#!/bin/sh -e"
code=1
}
done > build
2019-05-18 09:42:33 -06:00
chmod +x build
2019-05-18 09:21:03 -06:00
}
main() {
pkgfile_read "$1"
repo_setup
pkgfile_version
pkgfile_source
2019-05-18 09:34:25 -06:00
pkgfile_depends
2019-05-18 09:21:03 -06:00
pkgfile_build "$1"
}
main "$@"