diff --git a/elements/package-installs/README.rst b/elements/package-installs/README.rst index e988a71d..3e05a6fd 100644 --- a/elements/package-installs/README.rst +++ b/elements/package-installs/README.rst @@ -1,8 +1,8 @@ The package-installs element allows for a declarative method of installing and uninstalling packages for an image build. Adding a file under your elements -install.d directory called package-installs- will cause the list -of packages in that file to be installed at the beginning of the install.d -phase. +pre-install.d, install.d, or post-install.d directories called +package-installs- will cause the list of packages in that file to +be installed at the beginning of the respective phase. If the package name in the file starts with a "-", then that package will be removed at the end of the install.d phase. diff --git a/elements/package-installs/bin/package-installs b/elements/package-installs/bin/package-installs new file mode 100755 index 00000000..b1dc1604 --- /dev/null +++ b/elements/package-installs/bin/package-installs @@ -0,0 +1,60 @@ +#!/bin/bash + +set -eux +set -o pipefail + +SCRIPTNAME=$(basename $0) +function show_options () { + echo "Usage: $SCRIPTNAME -d " + echo + echo "Options:" + echo " -d -- directory to search for package-installs-* files" + exit 1 +} + +TEMP=$(getopt -o hd: -n $SCRIPTNAME -- "$@") +if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi +eval set -- "$TEMP" + +WORKDIR= + +while true ; do + case "$1" in + -d) WORKDIR=$2; shift 2;; + -h) show_options;; + --) shift ; break ;; + *) echo "Error: unsupported option $1."; exit 1;; + esac +done + +if [ -z "$WORKDIR" ]; then + show_options +fi + +PACKAGES= + +for PACKAGEFILE in $(find $WORKDIR -maxdepth 1 -name "package-installs-*" ); do + basefile=$(basename $PACKAGEFILE) + element_name=${basefile#"package-installs-"} + while read pkg; do + if [ -z "$pkg" ]; then + continue + fi + # Ignore comments + if [ ${pkg:0:1} = "#" ]; then + continue + fi + if [ ${pkg:0:1} = "-" ]; then + pkg=${pkg:1} + fi + + if [ -e /usr/share/pkg-map/$element_name ]; then + # map the package to its true name + pkg=$(pkg-map --element $element_name $pkg) + fi + + PACKAGES="$PACKAGES $pkg" + done < $PACKAGEFILE +done + +install-packages $PACKAGES diff --git a/elements/package-installs/bin/package-uninstalls b/elements/package-installs/bin/package-uninstalls new file mode 100755 index 00000000..2ca474d8 --- /dev/null +++ b/elements/package-installs/bin/package-uninstalls @@ -0,0 +1,61 @@ +#!/bin/bash + +set -eux +set -o pipefail + +SCRIPTNAME=$(basename $0) +function show_options () { + echo "Usage: $SCRIPTNAME -d " + echo + echo "Options:" + echo " -d -- directory to search for package-uninstalls-* files" + exit 1 +} + +TEMP=$(getopt -o hd: -n $SCRIPTNAME -- "$@") +if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi +eval set -- "$TEMP" + +WORKDIR= + +while true ; do + case "$1" in + -d) WORKDIR=$2; shift 2;; + -h) show_options;; + --) shift ; break ;; + *) echo "Error: unsupported option $1."; exit 1;; + esac +done + +if [ -z "$WORKDIR" ]; then + show_options +fi + +PACKAGES= + +for PACKAGEFILE in $(find $WORKDIR -maxdepth 1 -name "package-installs-*" ); do + basefile=$(basename $PACKAGEFILE) + element_name=${basefile#"package-installs-"} + while read pkg; do + if [ -z "$pkg" ]; then + continue + fi + # Ignore comments + if [ ${pkg:0:1} = "#" ]; then + continue + fi + if [ ! ${pkg:0:1} = "-" ]; then + continue + fi + + if [ -e /usr/share/pkg-map/$element_name ]; then + # map the package to its true name + pkg=$(pkg-map --element $element_name $pkg) + fi + + pkg=${pkg:1} + PACKAGES="$PACKAGES $pkg" + done < $PACKAGEFILE +done + +install-packages -e $PACKAGES diff --git a/elements/package-installs/element-deps b/elements/package-installs/element-deps new file mode 100644 index 00000000..ef25eec6 --- /dev/null +++ b/elements/package-installs/element-deps @@ -0,0 +1 @@ +pkg-map diff --git a/elements/package-installs/install.d/00-package-installs b/elements/package-installs/install.d/00-package-installs index 043a2a81..22de5a59 100755 --- a/elements/package-installs/install.d/00-package-installs +++ b/elements/package-installs/install.d/00-package-installs @@ -3,15 +3,4 @@ set -eux set -o pipefail -PACKAGES= - -for PACKAGEFILE in $(find $(dirname $0) -maxdepth 1 -name "package-installs-*" ); do - while read pkg; do - if [ ${pkg:0:1} = "-" ]; then - pkg=${pkg:1} - fi - PACKAGES="$PACKAGES $pkg" - done < $PACKAGEFILE -done - -install-packages $PACKAGES +package-installs -d $(dirname $0) diff --git a/elements/package-installs/install.d/99-package-uninstalls b/elements/package-installs/install.d/99-package-uninstalls index dff2845e..bf8336ee 100755 --- a/elements/package-installs/install.d/99-package-uninstalls +++ b/elements/package-installs/install.d/99-package-uninstalls @@ -3,16 +3,4 @@ set -eux set -o pipefail -PACKAGES= - -for PACKAGEFILE in $(find $(dirname $0) -maxdepth 1 -name "package-installs-*" ); do - while read pkg; do - if [ ! ${pkg:0:1} = "-" ]; then - continue - fi - pkg=${pkg:1} - PACKAGES="$PACKAGES $pkg" - done < $PACKAGEFILE -done - -install-packages -e $PACKAGES +package-uninstalls -d $(dirname $0) diff --git a/elements/package-installs/post-install.d/00-package-installs b/elements/package-installs/post-install.d/00-package-installs new file mode 100755 index 00000000..22de5a59 --- /dev/null +++ b/elements/package-installs/post-install.d/00-package-installs @@ -0,0 +1,6 @@ +#!/bin/bash + +set -eux +set -o pipefail + +package-installs -d $(dirname $0) diff --git a/elements/package-installs/post-install.d/99-package-uninstalls b/elements/package-installs/post-install.d/99-package-uninstalls new file mode 100755 index 00000000..bf8336ee --- /dev/null +++ b/elements/package-installs/post-install.d/99-package-uninstalls @@ -0,0 +1,6 @@ +#!/bin/bash + +set -eux +set -o pipefail + +package-uninstalls -d $(dirname $0) diff --git a/elements/package-installs/pre-install.d/02-package-installs b/elements/package-installs/pre-install.d/02-package-installs new file mode 100755 index 00000000..22de5a59 --- /dev/null +++ b/elements/package-installs/pre-install.d/02-package-installs @@ -0,0 +1,6 @@ +#!/bin/bash + +set -eux +set -o pipefail + +package-installs -d $(dirname $0) diff --git a/elements/package-installs/pre-install.d/99-package-uninstalls b/elements/package-installs/pre-install.d/99-package-uninstalls new file mode 100755 index 00000000..bf8336ee --- /dev/null +++ b/elements/package-installs/pre-install.d/99-package-uninstalls @@ -0,0 +1,6 @@ +#!/bin/bash + +set -eux +set -o pipefail + +package-uninstalls -d $(dirname $0)