#!/bin/sh set -eu . /usr/share/sh/libopkbuild.shso.2 FIELDS='Package Source Version Architecture Platform Section Maintainer Essential Depends Recommends Suggests Pre-Depends Conflicts Provides Replaces Description Homepage' field_package='proquivs-dummy' field_source='proquivs-dummy' field_version='1.0' field_architecture='all' field_platform='all' field_section='' field_maintainer='"J. Random Hacker" ' field_essential='' field_depends='' field_recommends='' field_suggests='' field_pre_depends='' field_conflicts='' field_provides='' field_replaces='' field_description='Trivial package for testing This is a trivial package generated by proquivs. It should not be uploaded to the ProteanOS package archive.' field_homepage='' control() { local ctl="${1}" shift 1 local name= local value= exec 3>"${ctl}" cat 1>&3 <<-EOF ####################################################### # Fields are commented out and set to default values. # # Uncomment and edit as needed. # ####################################################### EOF for name in ${FIELDS}; do eval "value=\"\$(printf '%s' \"\${field_$(\ printf '%s' "${name}" | tr 'A-Z-' 'a-z_')}\" | \ sed 's/^/ /')\"" printf '%s:%s\n' "${name}" "${value}" | sed 's/^/# /' 1>&3 done exec 3>&- return 0 } field_cb() { local name="${1}" local value="${2}" local user_data="${3}" shift 3 case " ${FIELDS} " in *" ${name} "*) ;; *) return 0 ;; esac eval "field_$(printf '%s' "${name}" | tr 'A-Z-' 'a-z_')=\"\${value}\"" return 0 } build() { local ctl="${1}" shift 1 local name= local value= ob_parse_control "${ctl}" field_cb '' '' "${FIELDS}" if ! mkdir 'proquivs'; then printf 'proquivs: Error: Failed to create package\n' 1>&2 return 1 fi cd 'proquivs' printf '2.0\n' 1>'format' exec 3>'control' printf 'Maintainer: %s\n' "${field_maintainer}" 1>&3 if [ -n "${field_homepage}" ]; then printf 'Homepage: %s\n' "${field_homepage}" 1>&3 fi exec 3>&- cat 1>'changelog' <<-EOF ${field_source} (${field_version}) UNRELEASED * Initial release. -- ${field_maintainer} $(LC_ALL='POSIX' \ date '+%a, %d %b %Y %H:%M:%S %z') EOF cat 1>'build' <<-EOF #!/usr/bin/make -f build install: $(printf '\t')@: EOF chmod 0755 'build' mkdir -- "${field_package}.pkg" exec 3>"${field_package}.pkg/control" printf 'Architecture: %s\n' "${field_architecture}" 1>&3 printf 'Platform: %s\n' "${field_platform}" 1>&3 for name in Section Essential Depends Recommends Suggests Pre-Depends \ Conflicts Provides Replaces; do eval "value=\"\$(printf '%s' \"\${field_$(\ printf '%s' "${name}" | tr 'A-Z-' 'a-z_')}\" | \ sed 's/^/ /')\"" if [ -n "${value}" ]; then printf '%s:%s\n' "${name}" "${value}" 1>&3 fi done printf 'Description:%s\n' "$(printf '%s' "${field_description}" | \ sed 's/^/ /')" 1>&3 exec 3>&- 1>"${field_package}.pkg/docs" if ! opkbuild -b; then cd '..' rm -Rf 'proquivs' printf 'proquivs: Error: Failed to create package\n' 1>&2 return 1 fi cd '..' rm -Rf 'proquivs' # Remove .changes file. This package shouldn't be uploaded to a # pro-archman incoming queue. rm -f -- "${field_source}_${field_version}$(: \ )_$(cat /etc/proteanos_arch)_$(cat /etc/proteanos_plat).changes" printf '\nproquivs: Package "%s_%s_%s_%s.opk" built\n' \ "${field_package}" "${field_version}" \ "${field_architecture}" "${field_platform}" return 0 } usage() { printf 'Usage: %s control|build \n' "${0}" printf 'The "control" command writes a template to the specified '$(: \ )'file name.\n' printf 'The "build" command creates a package as described in the '$(: \ )'specified file.\n' return 0 } main() { local cmd= local ctl= if [ ${#} -ne 2 ]; then usage 1>&2 return 1 fi cmd="${1}" ctl="${2}" case "${cmd}" in 'control' | 'build') ;; *) return 1 ;; esac if "${cmd}" "${ctl}"; then return 0 else return ${?} fi } main "${@}"