summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/control.sh59
1 files changed, 57 insertions, 2 deletions
diff --git a/lib/control.sh b/lib/control.sh
index ca11999..e193d86 100644
--- a/lib/control.sh
+++ b/lib/control.sh
@@ -58,6 +58,25 @@ oh_control_parse_binary()
_control_parse "${OH_SOURCE_DIR}/${1}.pkg/control" 'BINARY'
}
+oh_control_gen_source()
+{
+ _old_arch="${OH_CONTROL_BINARY_FIELD_ARCHITECTURE}"
+ _old_desc="${OH_CONTROL_BINARY_FIELD_DESCRIPTION}"
+
+ OH_CONTROL_BINARY_FIELD_ARCHITECTURE='all'
+ OH_CONTROL_BINARY_FIELD_DESCRIPTION="${OH_SOURCE} source package"
+
+ _control_gen 'SOURCE' "src:${OH_SOURCE}.control/control"
+
+ OH_CONTROL_BINARY_FIELD_ARCHITECTURE="${_old_arch}"
+ OH_CONTROL_BINARY_FIELD_DESCRIPTION="${_old_desc}"
+}
+
+oh_control_gen_binary()
+{
+ _control_gen 'BINARY' "${1}.control/control"
+}
+
_control_parse()
{
_control="${1}"
@@ -105,8 +124,8 @@ _control_parse()
else
_got="${_got}${_field} "
fi
- _param="OH_CONTROL_${_type}_FIELD_$(LC_CTYPE=C \
- tr '[:lower:]-' '[:upper:]_')"
+ _param="OH_CONTROL_${_type}_FIELD_$(echo "${_name}" | \
+ LC_CTYPE=C tr '[:lower:]-' '[:upper:]_')"
eval "${_param}=\"${_value}\""
else
# Continuation line.
@@ -146,3 +165,39 @@ _control_parse_error()
fi
oh_warn "${_file_info} ${_error}" "${@}"
}
+
+_control_gen()
+{
+ _type="${1}"
+ _control="${2}"
+
+ # TODO: Handle platforms and architectures like "any" and "any-linux-any".
+ # TODO: Calculate installed size.
+
+ cat >"${_control}" <<EOF
+Package: ${OH_CONTROL_BINARY_FIELD_PACKAGE}
+Source: ${OH_SOURCE}
+Version: ${OH_BINARY_VERSION}
+Architecture: ${_arch}
+EOF
+
+ for _name in Essential Depends Recommends Suggests Pre-Depends Conflicts \
+ Provides Replaces; do
+ _param="OH_CONTROL_BINARY_FIELD_$(echo "${_name}" | \
+ LC_CTYPE=C tr '[:lower:]-' '[:upper:]_')"
+ _value="$(eval echo \$\{"${param}"\})"
+ if [ -n "${_value}" ]; then
+ printf '%s: %s\n' "${_name}" "${_value}" >"${_control}"
+ fi
+ done
+
+ cat >"${_control}" <<EOF
+Installed-Size: ${_inst_size}
+Description:$(echo "${OH_CONTROL_BINARY_FIELD_DESCRIPTION}" | sed 's/^/ /')
+EOF
+
+ if [ -n "${OH_CONTROL_SOURCE_FIELD_HOMEPAGE}" ]; then
+ printf '%s: %s\n' 'Homepage' "${OH_CONTROL_SOURCE_FIELD_HOMEPAGE}" \
+ >"${_control}"
+ fi
+}