From a3f4fe5c53c41ee92bc8f60c0b8b83550111d33d Mon Sep 17 00:00:00 2001 From: David Phillips Date: Thu, 7 Mar 2019 20:53:52 +1300 Subject: Draft support for Arch Linux/pacman packages --- Functions/Arch | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ bin/ThirdPartyInstaller | 23 ++++++++-- 2 files changed, 133 insertions(+), 3 deletions(-) create mode 100755 Functions/Arch diff --git a/Functions/Arch b/Functions/Arch new file mode 100755 index 0000000..f4c50d5 --- /dev/null +++ b/Functions/Arch @@ -0,0 +1,113 @@ +#!/bin/bash (source) + +# ThirdPartyInstallers Arch backend + +function get_pkginfo_field() { + local file="$1" + local field="$2" + tar --to-stdout -xf "$file" .PKGINFO | grep '^'"$field"'' | awk -F' = ' '{print $2}' | sed -e 's/\([^><]\)=.*/\1/g' +} + +function thirdparty_backend() { + echo "Arch" +} + +function thirdparty_arch() { + local file="$1" + local arch=$(get_pkginfo_field "$file" arch) + if [ "$arch" = "all" ] + then echo "noarch" + else echo "$arch" + fi +} + +function thirdparty_distribution() { + # This isn't given by .PKGINFO. Closest we get is the packager field + echo "Unknown" +} + +function thirdparty_distribution_name() { + # This isn't given by .PKGINFO + echo "Unknown" +} + +function thirdparty_distribution_code() { + # This isn't given by .PKGINFO + echo "Unknown" +} + +function thirdparty_dependencies() { + local file="$1" + local deps=$(get_pkginfo_field "$file" depend) + + # The Depends fields contains a comma-separated list of dependencies. The range with the required + # versions, when available, is output between parenthesis. To make the Dependencies output match the + # format used by GoboLinux, we use a newline separator and remove all parenthesis characters found. + + echo "$deps" | sed 's/, /\n/g' | tr -d "()" +} + +function thirdparty_description() { + local file="$1" + get_pkginfo_field "$file" pkgdesc +} + +function thirdparty_filenames() { + local file="$1" + local contents=$(tar -tf "$file" | grep -Ev '^(\.MTREE|\.BUILDINFO|\.PKGINFO)' 2>/dev/null) + + echo "$contents" +} + +function thirdparty_license() { + local file="$1" + get_pkginfo_field "$file" license +} + +function thirdparty_name() { + local file="$1" + get_pkginfo_field "$file" pkgname +} + +function thirdparty_version() { + local file="$1" + local version=$(get_pkginfo_field "$file" pkgver) + # The format is: [epoch:]upstream_version[-arch_revision] + # We want to output the [epoch:]upstream_version part + echo "$version" | cut -d: -f1-2 | rev | cut -d- -f2- | rev +} + +function thirdparty_release() { + local file="$1" + local version=$(get_pkginfo_field "$file" pkgver) + # The format is: [epoch:]upstream_version[-arch_revision] + # We want to output the [-debian_revision] part + # Let's make the absence of a arch_revision is equivalent to a arch_revision of 0. + if echo "$version" | grep -q -- "-" + then echo "$version" | rev | cut -d- -f1 | rev + else echo "0" + fi +} + +function thirdparty_summary() { + local file="$1" + get_pkginfo_field "$file" pkgdesc +} + +function thirdparty_url() { + local file="$1" + get_pkginfo_field "$file" url +} + +function thirdparty_search_remotedb() { + local path="$1" + local arch="$2" + local distro="$3" + false +} + +function thirdparty_uncompress() { + local file="$1" + Log_Normal "Extracting Arch payload from $file." + tar -x --exclude={.MTREE,.BUILDINFO,.PKGINFO} -f "$file" 2>/dev/null +} diff --git a/bin/ThirdPartyInstaller b/bin/ThirdPartyInstaller index 122df20..158d4db 100755 --- a/bin/ThirdPartyInstaller +++ b/bin/ThirdPartyInstaller @@ -491,6 +491,21 @@ function prepare_program_entry() { target="$goboPrograms/$programname/$programversion" } +function has_mixed_packages() { + grep -vq "\.pkg.tar" <<< "$@" + local has_arch=$? + + grep -vq "\.deb" <<< "$@" + local has_deb=$? + + grep -vq "\.rpm" <<< "$@" + local has_rpm=$? + + # only one of these should be 1 for mutual exclusivity + [ "$(( $has_arch + $has_deb + $has_rpm ))" != "1" ] +} + + ### Operation ################################################################# Is_Writable "${goboPrograms}" || Verify_Superuser @@ -501,13 +516,15 @@ else verbose= fi # Sanity checks, then import the backend to handle the input package(s) -if echo "$@" | grep -q "\.rpm" && echo "$@" | grep -q "\.deb" -then Die "Error: cannot handle both RPM and DEB files in one shot." +if has_mixed_packages $@ +then Die "Error: cannot handle package archives of more than one format in one shot." elif echo "$@" | grep -q "\.rpm" then Import RPM elif echo "$@" | grep -q "\.deb" then Import DEB -else Die "Error: this tool can only handle RPM and DEB archives." +elif echo "$@" | grep -q "\.pkg.tar" +then Import Arch +else Die "Error: this tool can only handle RPM, DEB, and Arch Linux archives." fi # The inputfiles array holds the full path of all RPM/DEB input files -- cgit v1.1