summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2020-08-01 18:39:42 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2020-08-01 18:39:42 (EDT)
commit34e300c3829678b4cfd42ab06900772087971736 (patch)
tree089685f1012e6a696580e2073c2e14bfe985342b /src
parent822276704a60be901f191054685cffeaae99824e (diff)
src/proquivs: New script
Diffstat (limited to 'src')
-rwxr-xr-xsrc/proquivs196
-rw-r--r--src/template.ctl19
2 files changed, 196 insertions, 19 deletions
diff --git a/src/proquivs b/src/proquivs
new file mode 100755
index 0000000..693d92b
--- /dev/null
+++ b/src/proquivs
@@ -0,0 +1,196 @@
+#!/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='share'
+field_maintainer='"J. Random Hacker" <jrandom@example.com>'
+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_package}_${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 <control-file>\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 "${@}"
diff --git a/src/template.ctl b/src/template.ctl
deleted file mode 100644
index 6811dec..0000000
--- a/src/template.ctl
+++ /dev/null
@@ -1,19 +0,0 @@
-Package: proquivs-dummy
-# Source: <defaults to package name>
-Version: 1.0
-# Architecture: all
-# Platform: all
-# Section: share
-Maintainer: "J. Random Hacker" <jrandom@example.com>
-# Essential: no
-# Depends:
-# Recommends:
-# Suggests:
-# Pre-Depends:
-# Conflicts:
-# Provides:
-# Replaces:
-Description: Trivial package for testing
- This is a trivial package generated by proquivs. It should not be uploaded to
- the ProteanOS package archive.
-# Homepage: