#!/bin/bash # ------- # File: llxcfg-cpkg # Description: LliureX Config Packages Script to stop and start llxcfg apt scripts # Author: Luis Garcia Gisbert # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # -------- set -e PATH="/usr/sbin:/usr/bin:/sbin:/bin" # library LLX_CPKGLIB="/usr/share/lliurex/llxcfg-cpkg/llxcfg-cpkg.sh" [ -f "${LLX_CPKGLIB}" ] || exit 1 . ${LLX_CPKGLIB} if [ -r "/etc/default/llxcfg-cpkg" ] ; then . /etc/default/llxcfg-cpkg fi # functions usage() { VERBOSE="Y" CMD_NAME="$(basename "$0")" say_msg "Usage: " "$CMD_NAME [options] {pre-dpkg|post-dpkg|update|revert} [PKG_1 [... PKG_N]]" \ "$CMD_NAME [options] {configure|deconfigure|postconfigure} [PKG_1 [... PKG_N]]" \ "$CMD_NAME [options] {enable|disable} PACKAGE [RUN_ORDER]" \ "$CMD_NAME [options] {allow|deny} PKG_1 [... PKG_N]" \ "$CMD_NAME [options] invoke ACTION [PKG_1 [... PKG_N]]" \ "$CMD_NAME [options] {listfiles|info} [PKG_1 [... PKG_N]]" \ "$CMD_NAME [options] {list|list-allow|list-deny}" \ "$CMD_NAME [options] grepinfo FIELD_NAME [PKG_1 [... PKG_N]]" \ "$CMD_NAME [options] search FILE_PATTERN" \ "$CMD_NAME [options] plainview FILE" \ "options: -q|--quiet" >&2 } # ---- # main # ---- VERBOSE="Y" # check option(s) case $1 in -q|--quiet) VERBOSE="" shift ;; esac if [ -z "$1" ] ; then usage exit 1 fi CPKG_ACTION="$1" if is_backend_option "$CPKG_ACTION" ; then if [ $(id -u) -ne 0 ] ; then if ! echo " $(groups) " |grep -q " llxcfg " ; then error_msg "Only root and llxcfg group members are allowed to run backend action \"$CPKG_ACTION\"" exit 1 fi fi LLX_BACKEND_LIB="/usr/share/lliurex/llxcfg-backend/llxcfg-backend-common.sh" if [ -f "$LLX_BACKEND_LIB" -a -z "$CPKG_DO_NOT_USE_SOCKET" ] ; then . "$LLX_BACKEND_LIB" CPKG_BACKEND_CMD="$LBACK_SEND $LBACK_CMD_CPKG" else CPKG_BACKEND_CMD="$CPKG_BACKEND" fi [ -z "$VERBOSE" ] || CPKG_BACKEND_CMD="$CPKG_BACKEND_CMD --verbose" rc=0 $CPKG_BACKEND_CMD "$@" || rc=$? if [ $rc -eq $CPKG_RC_NOTRUNNINGDAEMON ] ; then error_msg "cpkg-daemon is not running" elif [ $rc -ne 0 ] ; then usage fi exit $rc fi shift PKG_LIST0="$@" case "$CPKG_ACTION" in list|list-allow|list-deny) if [ "$1" ] ; then usage exit 1 fi get_pkg_list || exit 0 i=0 while [ $i -lt ${#PKG_LIST[@]} ] ; do p="${PKG_LIST[$i]}" if is_pkg_allowed "$p" &>/dev/null ; then [ "$CPKG_ACTION" != "list-deny" ] && echo "$p" else [ "$CPKG_ACTION" != "list-allow" ] && echo "$p" fi i=$(($i + 1)) done ;; listfiles|info) get_pkg_list "$PKG_LIST0" || exit 0 i=0 while [ $i -lt ${#PKG_LIST[@]} ] ; do p="${PKG_LIST[$i]}" if [ "$CPKG_ACTION" = "listfiles" ] ; then rgrep --include="${p}.log" ".*" "${CPKG_INFO}" |sed -e "s%^${CPKG_INFO}/\(.*\)\.log:%\1:%" else pkg_info "$p" fi i=$(( $i + 1 )) done ;; grepinfo) if [ -z "$1" ] ; then usage exit 1 fi FIELDNAME="$1" shift PKG_LIST0="$@" get_pkg_list "$PKG_LIST0" || exit 0 i=0 REGEXP="^[^:]\+:${FIELDNAME}:" while [ $i -lt ${#PKG_LIST[@]} ] ; do p="${PKG_LIST[$i]}" pkg_info "$p" |sed -ne "/${REGEXP}/s%${REGEXP}[[:blank:]]*%%p" i=$(( $i + 1 )) done ;; plainview) if [ -z "$1" ] ; then usage exit 1 fi DUMP_FILE="${CPKG_FIRST_BACKUP}/$1" [ -f "${DUMP_FILE}" ] || DUMP_FILE="$1" if [ -f "${DUMP_FILE}" ] ; then cat "${DUMP_FILE}" else exit 1 fi ;; search) if [ -z "$1" ] ; then usage exit 1 fi rgrep --include="*.log" "$1" "${CPKG_INFO}" |sed -e "s%^${CPKG_INFO}/\(.*\)\.log:%\1:%" ;; *) usage exit 1 ;; esac exit 0