#! /bin/sh # # opkhelper # src/oh-gencontrol # Generates a control directory with a control file and scripts. # # Copyright (C) 2012 Patrick "P. J." McDermott # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . . @@LIBDIR@@/opkhelper/controlfields print_usage() { printf 'Usage: %s -s | pkgname...\n' "$1" } missing_field() { printf 'oh-gencontrol: ERROR: Missing field "%s" in control file.\n' "${1}" >&2 exit 2 } invalid_pkg_name() { printf 'oh-gencontrol: Error: Invalid package name: "%s"\n' "${1}" >&2 exit 2 } gen_control_src() { srcpkg=$(oh_get_field Source) || missing_field Source oh_validate_pkg_name "${srcpkg}" || invalid_pkg_name "${srcpkg}" printf 'oh-gencontrol: Generating control directory for package "%s"...\n' \ "${srcpkg}-src" control_dir="${srcpkg}-src.control" control="${control_dir}/control" mkdir "${control_dir}" 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 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} } gen_control_bin() { binpkg="${1}" oh_validate_pkg_name "${binpkg}" || invalid_pkg_name "${binpkg}" printf 'oh-gencontrol: Generating control directory for package "%s"...\n' \ "${binpkg}" control_dir="${binpkg}.control" control="${control_dir}/control" 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 # 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} # 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} for script in preinst postinst prerm postrm; do if [ -f ../${binpkg}.pkg/${script} ]; then cp ../${binpkg}.pkg/${script} ${control_dir} # TODO: Set mode? # TODO: Handle links? fi done } if [ ${#} -eq 0 ]; then print_usage ${0} >&2 exit 1 fi is_src=false opts=$(getopt -n "${0}" -o 's' -- "${@}") if [ ${?} -ne 0 ]; then print_usage "${0}" >&2 exit 1; fi eval set -- "${opts}" while true; do case "${1}" in -s) is_src=true shift ;; --) shift break ;; *) print_usage "${0}" >&2 exit 1 ;; esac done if ${is_src}; then gen_control_src else if [ ${#} -eq 0 ]; then print_usage "${0}" >&2 exit 1 fi while [ ${#} -gt 0 ]; do gen_control_bin "${1}" shift done fi