summaryrefslogtreecommitdiffstats
path: root/remote
diff options
context:
space:
mode:
authorJonathan Bauer2014-03-24 09:48:50 +0100
committerJonathan Bauer2014-03-24 09:48:50 +0100
commitd0ab838d0cf6cb0ecd741873c436a1954aca2da9 (patch)
tree6ebaec351fe4332380f5f7437e20fd117d2bceee /remote
parent[setup_target] clean_modules fix (diff)
downloadtm-scripts-d0ab838d0cf6cb0ecd741873c436a1954aca2da9.tar.gz
tm-scripts-d0ab838d0cf6cb0ecd741873c436a1954aca2da9.tar.xz
tm-scripts-d0ab838d0cf6cb0ecd741873c436a1954aca2da9.zip
[packagemanager] improve list_content_packages function
added "--files" and "--dirs" switches to list only files or dirs respectively. added support for external "EXTRA_PACKAGES" bash variables with which the content of additional packages can be listed without them beeing in the REQUIRED_CONTENT_PACKAGES vairable of the config file
Diffstat (limited to 'remote')
-rw-r--r--remote/includes/packagemanager.inc102
1 files changed, 71 insertions, 31 deletions
diff --git a/remote/includes/packagemanager.inc b/remote/includes/packagemanager.inc
index 358dd8b1..66013807 100644
--- a/remote/includes/packagemanager.inc
+++ b/remote/includes/packagemanager.inc
@@ -1,44 +1,84 @@
#
# get all files of required packages by a module
#
-list_packet_files() {
+# Usage:
+# list_content_packages
+# - lists all files/directories in REQUIRED_CONTENT_PACKAGES
+# list_content_packages --files
+# - lists all files in REQUIRED_CONTENT_PACKAGES
+# list_content_packages --dirs
+# - lists all dirs in REQUIRED_CONTENT_PACKAGES
+#
+# NOTE: additional packages needed to be listed can be given
+# through the environment variable EXTRA_PACKAGES
+
+list_content_packages() {
[ -z "$REQUIRED_CONTENT_PACKAGES" ] && pinfo "No required packages for $TOOL" && return 1
+ [ $# -gt 2 ] && perror "'list_content_packages' accepts only 1 or no args. $# given."
local PACKAGE=""
- for PACKAGE in $REQUIRED_CONTENT_PACKAGES; do
- local OPTIONAL="$(echo "$PACKAGE" | cut -c 1)"
- [ "x$OPTIONAL" = "x@" ] && PACKAGE="$(echo "$PACKAGE" | cut -c 2-)"
- local FILES=""
- if [ "$PACKET_HANDLER" = "dpkg" ]; then
- PACKAGECOMMAND="dpkg -L"
- elif [ "$PACKET_HANDLER" = "rpm" ]; then
- PACKAGECOMMAND="rpm -ql"
- fi
+ for PACKAGE in $REQUIRED_CONTENT_PACKAGES $EXTRA_PACKAGES; do
+ list_content_package $1 $PACKAGE
+ done
- if [ -n "$REQUIRED_PACKET_FILES_BLACKLIST" ]; then
- FILES="$($PACKAGECOMMAND "$PACKAGE" | grep "^/" | \
- grep -v "$REQUIRED_PACKET_FILES_BLACKLIST" | \
- grep -v -E 'share/(man|doc)|/var/run|/var/log|/etc/init\.d'; \
- echo ":###:${PIPESTATUS[0]}")"
- else
- FILES="$($PACKAGECOMMAND "$PACKAGE" | grep "^/" | grep -v -E 'share/(man|doc)|/var/run|/var/log|/etc/init\.d'; echo ":###:${PIPESTATUS[0]}")"
- fi
+}
+list_content_package(){
+ #[ -z "$EXTRA_PACKAGES" ] || pinfo "Listing additional packages: $EXTRA_PACKAGES"
+ [ $# -gt 2 ] && perror "'list_content_package' accepts max 2 args. $# given."
+ local OP="-e"
+ case "$1" in
+ --files)
+ OP="-f"
+ ;;
+ --dirs)
+ OP="-d"
+ ;;
+ "")
+ OP="-e"
+ ;;
+ *)
+ perror "'list_content_packages' invalid argument: $1"
+ ;;
+ esac
+ local PACKAGE="$2"
+ local OPTIONAL="$(echo "$PACKAGE" | cut -c 1)"
+ [ "x$OPTIONAL" = "x@" ] && PACKAGE="$(echo "$PACKAGE" | cut -c 2-)"
+ local FILES=""
+ if [ "$PACKET_HANDLER" = "dpkg" ]; then
+ PACKAGECOMMAND="dpkg -L"
+ elif [ "$PACKET_HANDLER" = "rpm" ]; then
+ PACKAGECOMMAND="rpm -ql"
+ fi
+
+ if [ -n "$REQUIRED_PACKET_FILES_BLACKLIST" ]; then
+ FILES="$($PACKAGECOMMAND "$PACKAGE" | grep "^/" | \
+ grep -v "$REQUIRED_PACKET_FILES_BLACKLIST" | \
+ grep -v -E 'share/(man|doc)|/var/run|/var/log|/etc/init\.d'; \
+ echo ":###:${PIPESTATUS[0]}")"
+ else
+ FILES="$($PACKAGECOMMAND "$PACKAGE" | grep "^/" | grep -v -E 'share/(man|doc)|/var/run|/var/log|/etc/init\.d'; echo ":###:${PIPESTATUS[0]}")"
+ fi
# FILES="$(rpm -ql "$PACKAGE" | grep "^/" | grep -v -E 'share/(man|doc)|/var/run|/var/log'; echo ":###:${PIPESTATUS[0]}")"
- # ugly hack to get our return value
- local LPRET=$(echo "$FILES" | awk -F ':###:' '{printf $2}')
- FILES=$(echo "$FILES" | awk -F ':###:' '{print $1}')
- if [ "x$LPRET" != "x0" -a "x$OPTIONAL" != "x@" ]; then
- pdebug "FILES: '$FILES'"
- perror "dpkg/rpm exited with code '$LPRET' for required package ${PACKAGE}."
- fi
- [ "x$LPRET" != "x0" ] && pwarning "dpkg/rpm exited with code '$LPRET' for optional package ${PACKAGE}." && continue
- [ -z "$FILES" ] && pwarning "list_packet_files empty for packet ${PACKAGE}." && continue
- pdebug "Packet $PACKAGE has $(echo $FILES | wc -w) files..."
- for FILE in $FILES; do
- [ ! -d "$FILE" ] && echo "$FILE"
- done
+ # ugly hack to get our return value
+ local LPRET=$(echo "$FILES" | awk -F ':###:' '{printf $2}')
+ FILES=$(echo "$FILES" | awk -F ':###:' '{print $1}')
+ if [ "x$LPRET" != "x0" -a "x$OPTIONAL" != "x@" ]; then
+ pdebug "FILES: '$FILES'"
+ perror "dpkg/rpm exited with code '$LPRET' for required package ${PACKAGE}."
+ fi
+ [ "x$LPRET" != "x0" ] && pwarning "dpkg/rpm exited with code '$LPRET' for optional package ${PACKAGE}." && continue
+ [ -z "$FILES" ] && pwarning "list_packet_files empty for packet ${PACKAGE}." && continue
+ pdebug "Packet $PACKAGE has $(echo $FILES | wc -w) files..."
+ for FILE in $FILES; do
+ [ "$OP" "$FILE" ] && echo "$FILE"
done
}
+#
+# Convenience function
+#
+list_packet_files() {
+ list_content_packages --files
+}
#
# Convenience function