#!/bin/sh ## pkgin package method for cfengine ## Copyright 2015 Brian Bennett ## ## Licensed under the terms of the GNU GPL version 3. ## https://www.gnu.org/licenses/gpl-3.0.txt # /opt/local supports SmartOS # /usr/pkg supports standard pkgsrc # This should be sufficient to support all platforms supported by pgksrc. PATH=/opt/local/bin:/opt/local/sbin:/usr/pkg/bin:/usr/pkg/sbin:$PATH export MACHINE_ARCH=`pkg_info -X pkg_install | grep MACHINE_ARCH | cut -d = -f 2` fatal () { echo "$@" >&2 exit 2 } warn () { echo "$@" >&2 } supports_api_version () { warn 1 echo 1 } repo_install () { warn "Requested to install $1" [ -n $2 ] && warn "Version $2" warn "pkgsrc module currently declines to install packages." false } file_install () { false } remove () { false } list_installed () { warn "Output too large. Number of lines returned by package module:" warn "`pkgin list | parse_pkg_data | wc -l`" pkgin list | parse_pkg_data } list_updates () { warn "`pkgin -pl '<' ls | parse_pkg_data`" pkgin -pl '<' ls | parse_pkg_data } list_updates_local () { list_updates "$@" } get_package_data () { #warn "pkgin -pP search nginx | grep \; | sort -n | tail -1 | parse_pkg_data" warn "PackageType=repo" warn "`pkgin -pP search nginx | grep \; | sort -n | tail -1 | parse_pkg_data`" echo "PackageType=repo" pkgin -pP search nginx | grep \; | sort -n | tail -1 | parse_pkg_data } parse_pkg_data () { awk -F';' ' { sp="-" sa="=" l=split($1,p,sp) v=p[l] printf("Name=") for (i=1;i1) { printf("-") } printf("%s",p[i]) } printf("\nVersion=%s\n",v) printf("Architecture=%s\n",ENVIRON["MACHINE_ARCH"]) }' } warn "############################ pkgsrc module START ############################" #warn $PATH #warn `type pkgin` warn "method called: $1" warn "===== INPUT DATA =====" while IFS= read -r -u 0 line; do printf '%s\n' "$line" >&2 eval "$line" done warn "===== OUTPUT DATA =====" case "$1" in supports-api-version) supports_api_version;; repo-install) repo_install "$Name" "$Version";; file-install) file_install "$@";; remove) remove "$@";; list-installed) list_installed "$@";; list-updates) list_updates "$@";; list-updates-local) list_updates_local "$@";; get-package-data) get_package_data "$File";; *) fatal "Invalid operation";; esac warn "############################ pkgsrc module END ############################"