summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/oh-gencontrol69
1 files changed, 39 insertions, 30 deletions
diff --git a/src/oh-gencontrol b/src/oh-gencontrol
index 066200b..088e0f5 100644
--- a/src/oh-gencontrol
+++ b/src/oh-gencontrol
@@ -38,6 +38,28 @@ invalid_pkg_name()
exit 2
}
+copy_required_field()
+{
+ if [ ${#} -eq 2 ]; then
+ { printf '%s: ' "${1}" && oh_get_field "${1}";} >> "${2}"
+ [ ${?} -eq 1 ] && missing_field "${1}"
+ else
+ { printf '%s: ' "${2}" && oh_get_field "${1}" "${2}";} >> "${3}"
+ [ ${?} -eq 1 ] && missing_field "${2}"
+ fi
+}
+
+copy_optional_field()
+{
+ if [ ${#} -eq 2 ]; then
+ field=$(printf '%s: ' "${1}" && oh_get_field "${1}")
+ [ ${?} -eq 0 ] && printf '%s\n' "${field}" >> "${2}"
+ else
+ field=$(printf '%s: ' "${2}" && oh_get_field "${1}" "${2}")
+ [ ${?} -eq 0 ] && printf '%s\n' "${field}" >> "${3}"
+ fi
+}
+
gen_control_src()
{
srcpkg=$(oh_get_field Source) || missing_field Source
@@ -53,13 +75,11 @@ gen_control_src()
printf 'Package: %s\n' "${srcpkg}-src" > ${control}
printf 'Source: %s\n' "${srcpkg}" >> ${control}
- { printf 'Version: ' && oh_get_field Version;} >> ${control}
- [ ${?} -eq 1 ] && missing_field Version
+ copy_required_field Version ${control}
printf 'Architecture: all\n' >> ${control}
# TODO: Calculate "Installed-Size".
- { printf 'Maintainer: ' && oh_get_field Maintainer;} >> ${control}
- [ ${?} -eq 1 ] && missing_field Maintainer
- { printf 'Homepage: ' && oh_get_field Homepage;} >> ${control}
+ copy_required_field Maintainer ${control}
+ copy_optional_field Homepage ${control}
}
gen_control_bin()
@@ -76,40 +96,29 @@ gen_control_bin()
mkdir "${control_dir}"
# Binary and source package names and version.
- { printf 'Package: ' && oh_get_field ${binpkg} Package;} > ${control}
- [ ${?} -eq 1 ] && missing_field Package
- { printf 'Source: ' && oh_get_field Source;} >> ${control}
- [ ${?} -eq 1 ] && missing_field Source
- { printf 'Version: ' && oh_get_field Version;} >> ${control}
- [ ${?} -eq 1 ] && missing_field Version
+ copy_required_field ${binpkg} Package ${control}
+ copy_required_field Source ${control}
+ copy_required_field Version ${control}
# TODO: Handle architecture.
{ printf 'Architecture: ' && oh_get_field ${binpkg} Architecture;} \
>> ${control}
[ ${?} -eq 1 ] && missing_field Architecture
- # XXX: If an optional field is omitted, its name is still written out.
- # Fields should be handled by wrapper functions, e.g.:
- # copy_required_field Maintainer
- # copy_required_field ${binpkg} Description
- # copy_optional_field Homepage
-
# Optional fields.
- { printf 'Essential: ' && oh_get_field ${binpkg} Essential;} >> ${control}
- { printf 'Depends: ' && oh_get_field ${binpkg} Depends;} >> ${control}
- { printf 'Recommends: ' && oh_get_field ${binpkg} Recommends;} >> ${control}
- { printf 'Suggests: ' && oh_get_field ${binpkg} Suggests;} >> ${control}
- { printf 'Pre-Depends: ' && oh_get_field ${binpkg} Pre-Depends;} >> ${control}
- { printf 'Conflicts: ' && oh_get_field ${binpkg} Conflicts;} >> ${control}
- { printf 'Provides: ' && oh_get_field ${binpkg} Provides;} >> ${control}
- { printf 'Replaces: ' && oh_get_field ${binpkg} Replaces;} >> ${control}
+ copy_optional_field ${binpkg} Essential ${control}
+ copy_optional_field ${binpkg} Depends ${control}
+ copy_optional_field ${binpkg} Recommends ${control}
+ copy_optional_field ${binpkg} Suggests ${control}
+ copy_optional_field ${binpkg} Pre-Depends ${control}
+ copy_optional_field ${binpkg} Conflicts ${control}
+ copy_optional_field ${binpkg} Provides ${control}
+ copy_optional_field ${binpkg} Replaces ${control}
# TODO: Calculate "Installed-Size".
- { printf 'Maintainer: ' && oh_get_field Maintainer;} >> ${control}
- [ ${?} -eq 1 ] && missing_field Maintainer
- { printf 'Description: ' && oh_get_field ${binpkg} Description;} >> ${control}
- [ ${?} -eq 1 ] && missing_field Description
- { printf 'Homepage: ' && oh_get_field Homepage;} >> ${control}
+ copy_required_field Maintainer ${control}
+ copy_required_field ${binpkg} Description ${control}
+ copy_optional_field Homepage ${control}
for script in preinst postinst prerm postrm; do
if [ -f ../${binpkg}.pkg/${script} ]; then