diff options
-rw-r--r-- | locale/en_US.sh | 3 | ||||
-rw-r--r-- | src/oh-gencontrol.sh | 188 |
2 files changed, 16 insertions, 175 deletions
diff --git a/locale/en_US.sh b/locale/en_US.sh index bd32ab2..a0db525 100644 --- a/locale/en_US.sh +++ b/locale/en_US.sh @@ -127,3 +127,6 @@ oh_str_cant_copy_config_file='Can'\''t copy configuration file' # oh-parsechangelog oh_str_usage_oh_parsechangelog='Usage: oh-parsechangelog' + +# oh-gencontrol +oh_str_usage_oh_gencontrol='Usage: oh-gencontrol' diff --git a/src/oh-gencontrol.sh b/src/oh-gencontrol.sh index 08b09b1..89944fc 100644 --- a/src/oh-gencontrol.sh +++ b/src/oh-gencontrol.sh @@ -19,185 +19,23 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -. @@LIBDIR@@/opkhelper/controlfields -. @@LIBDIR@@/opkhelper/architecture -. @@LIBDIR@@/opkhelper/messages +. @@LIBDIR@@/locale +. @@LIBDIR@@/control -print_usage() +main() { - printf 'Usage: %s -s | pkgname...\n' "${1}" -} - -missing_field() -{ - oh_error 'Missing field "%s" in control file' "${1}" -} - -invalid_pkg_name() -{ - oh_error 'Invalid package name: "%s"' "${1}" -} - -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 -} + oh_locale_set + oh_set_source_dir .. -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 - oh_validate_pkg_name "${srcpkg}" || invalid_pkg_name "${srcpkg}" - - oh_info 'Generating control directory for package "%s"...' "${srcpkg}-src" - - control_dir="${srcpkg}-src.control" - control="${control_dir}/control" - - mkdir "${control_dir}" - chmod 755 "${control_dir}" - - printf 'Package: %s\n' "${srcpkg}-src" > ${control} - printf 'Source: %s\n' "${srcpkg}" >> ${control} - copy_required_field Version ${control} - printf 'Architecture: all\n' >> ${control} - # TODO: Calculate "Installed-Size". - copy_required_field Maintainer ${control} - copy_optional_field Homepage ${control} - - chmod 755 ${control} -} - -gen_control_bin() -{ - binpkg="${1}" - oh_validate_pkg_name "${binpkg}" || invalid_pkg_name "${binpkg}" - - oh_info 'Generating control directory for package "%s"...' "${binpkg}" - - data_dir="${binpkg}.data" - control_dir="${binpkg}.control" - control="${control_dir}/control" - - mkdir "${control_dir}" - chmod 755 "${control_dir}" - - # Binary and source package names and version. - copy_required_field ${binpkg} Package ${control} - copy_required_field Source ${control} - copy_required_field Version ${control} - - # Handle architecture. - { printf 'Architecture: ' && oh_get_package_architecture ${binpkg};} \ - >> ${control} - [ ${?} -eq 1 ] && missing_field Architecture - - # Optional fields. - 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". - copy_required_field Maintainer ${control} - copy_required_field ${binpkg} Description ${control} - copy_optional_field Homepage ${control} - - chmod 644 ${control} - - # Maintainer scripts. - for script in preinst postinst prerm postrm; do - if [ -L ../${binpkg}.pkg/${script} ]; then - target=$(ls -l "../${binpkg}.pkg/${script}" | \ - sed 's/^.* -> \(.*\)$/\1/') - ln -s ${target} ${control_dir}/${script} - elif [ -f ../${binpkg}.pkg/${script} ]; then - cp ../${binpkg}.pkg/${script} ${control_dir} - chmod 755 ${control_dir}/${script} - fi - done - - # Conffiles. - # Adapted from dh_installdeb of debhelper. - if [ -d ${data_dir}/etc ]; then - find ${data_dir}/etc -type f | sed "s@^${data_dir}@@" \ - >> ${control_dir}/conffiles - if [ -z "$(head -n 1 ${control_dir}/conffiles)" ]; then - rm -f ${control_dir}/conffiles - else - chmod 644 ${control_dir}/conffiles - fi - fi - - # MD5 checksums. - find ${data_dir} -type f | sort | xargs md5sum | sed "s@ ${data_dir}@ @" \ - > ${control_dir}/md5sums - if [ -z "$(head -n 1 ${control_dir}/md5sums)" ]; then - rm -f ${control_dir}/md5sums - else - chmod 644 ${control_dir}/md5sums - fi -} - -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 + if [ "${#}" -ne 0 ]; then + oh_usage exit 1 fi - while [ ${#} -gt 0 ]; do - gen_control_bin "${1}" - shift + for pkg in ../*.pkg/; do + pkg="${pkg#../}" + pkg="${pkg%/}" + oh_cv_load "${pkg}.control" + oh_control_gen_binary "${pkg}" done -fi +} |