#!/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_COMMONLIB="/usr/share/lliurex/llxcfg-common/llxcfg-common.sh" [ -f "${LLX_COMMONLIB}" ] || exit 1 . ${LLX_COMMONLIB} error_msg() { say_msg "Error: " "$@" >&2 } warn_msg() { say_msg "Warning: " "$@" >&2 } say_msg() { if [ $# -gt 1 ] ; then PRE_MSG="$1" PRE_BLANK="" j=0 while [ ${j} -lt ${#PRE_MSG} ] ;do PRE_BLANK="${PRE_BLANK} " j=$(($j + 1 )) done shift else PRE_MSG="" PRE_BLANK="" fi while [ "$1" ] ; do echo -e "${PRE_MSG}${1}" PRE_MSG="${PRE_BLANK}" shift done return 0 } enable_pkg(){ pkg_exists "$1" || return 1 if ! is_pkg_enabled "$1" 2> /dev/null ; then pkg="$1" run_directory_sync "$pkg" ln -s "$(cpkg_reldir "$pkg")" "$(cpkg_endir "$pkg" "$2")" # create required dirs # for d in ${CPKG_DIRS} ; do # mkdir -p "${d}/${pkg}" # done else warn_msg "Skipping already enabled config package \"$1\"" return 1 fi return 0 } disable_pkg(){ pkg="$1" pkg_exists "$1" || return 1 is_pkg_enabled "$1" || return 1 find "${CPKG_ENABLED}" -lname "$(cpkg_reldir "$1")" 2>/dev/null |while read FILE_NAME ; do rm -f "${FILE_NAME}" done # removed 'deconfigure' at disable time # restore files if active # if is_pkg_allowed "${1}" ; then # # TODO: if reset_pkg returns true , may be we need to restart some services ... # reset_pkg "${1}" || true # fi # remove required dirs rm -fr "$(cpkg_dir "$pkg")" # for d in ${CPKG_DIRS} ; do # [ -d "${d}/${pkg}" ] && rmdir --ignore-fail-on-non-empty "${d}/${pkg}" &> /dev/null # done # remove log # rm -f "${CPKG_INFO}/${pkg}.log" return 0 } pkg_exists(){ [ -d "${CPKG_ORIGINAL}/${1}" ] && return 0 warn_msg "Skipping unavailable config package \"$1\"" return 1 } is_pkg_enabled(){ [ "$(find "${CPKG_ENABLED}" -lname "$(cpkg_reldir "$1")" 2>/dev/null)" ] && return 0 warn_msg "Skipping disabled config package \"$1\"" return ${RC_NOTFOUND} } is_pkg_allowed(){ if rgrep -q "^${1}$" "${CPKG_DENIED}" 2>/dev/null ; then warn_msg "Skipping denied config package \"$1\"" return ${RC_DISABLED} fi return 0 } test_pkg(){ pkg_exists "$1" || return $? is_pkg_enabled "$1" || return $? is_pkg_allowed "$1" || return $? return 0 } deny_pkg(){ pkg_exists "$1" || return 1 if [ ! -f "${DEFAULT_DENYFILE}" ] ; then touch "${DEFAULT_DENYFILE}" fi # removed 'deconfigure' at deny time # if pkg is active, undo changes # if is_pkg_allowed "${1}" ; then # # TODO: if reset_pkg returns true , may be we need to restart some services ... # reset_pkg "${1}" || true # fi if ! grep -q "^${1}$" "${DEFAULT_DENYFILE}" ; then ( cat "${DEFAULT_DENYFILE}"; echo "$1" ) | llxcfg-install - "${DEFAULT_DENYFILE}" fi return 0 } allow_pkg(){ pkg_exists "$1" || return 1 if [ -f "${DEFAULT_DENYFILE}" ] ; then is_pkg_enabled "$1" || return $? cat "${DEFAULT_DENYFILE}" |grep -v "^${1}$" | llxcfg-install - "${DEFAULT_DENYFILE}" fi return 0 } get_all_pkg(){ PLIST="" find "${CPKG_ENABLED}" -type l |sort |while read line; do PNAME="$(basename $(readlink -f ${line}))" if ! echo " $PLIST " | grep -q " ${PNAME} " ; then echo "${PNAME}" PLIST="$PLIST $PNAME" fi done return 0 } get_pkg_list(){ # build package list from (optional) parameters # or from full package list (default) but # remove disabled packages if [ "$@" ] ; then # verify required pkgs and sort them in correct order REQUIRED_PKG=" $@ " ALL_PKG=($(get_all_pkg)) i=0 n=0 while [ $i -lt ${#ALL_PKG[@]} ] ; do if echo "$REQUIRED_PKG" |grep -q " ${ALL_PKG[$i]} " ; then PKG_LIST[$n]="${ALL_PKG[$i]}" n=$(( $n + 1 )) fi i=$(( $i +1 )) done else PKG_LIST=($(get_all_pkg)) fi if [ ${#PKG_LIST[@]} -eq 0 ] ; then warn_msg "There are not config packages selected" return 1 fi return 0 } restart_pkg_services(){ p="$1" SERVICES="$(cat "$(cpkg_dir "$p")/${CPKG_SERVICES_FILE}")" rcs=0 for srv in $SERVICES ; do if [ -x "/etc/init.d/${srv}" ] ; then invoke-rc.d "${srv}" restart || rcs=$? fi done return $rcs } run_pkg_scripts(){ local CURPWD s i rc i=0 pkg_suffix="$1" CTL_ACTION="$2" CURPWD="$(pwd)" while [ $i -lt ${#PKG_LIST[@]} ] ; do p="${PKG_LIST[$i]}" rc=0 if test_pkg "$p" && [ -d "$(cpkg_dir "$p")" ]; then EXEC_COMMAND="" s="$(cpkg_dir "$p")/${pkg_suffix}" case "$1" in preconfig) upgrade_test "$p" || true ;; postconfig) [ -s "$(cpkg_dir "$p")/${CPKG_SERVICES_FILE}" ] && EXEC_COMMAND="restart_pkg_services" ;; esac if [ "${EXEC_COMMAND}" -o -x "${s}" ] ; then [ "$CTL_ACTION" = "test" ] && rc=${PKG_RC[${i}]} if [ "$rc" = "0" ] ; then cd "$(cpkg_dir "$p")" if [ -x "$s" ] ; then ${s} || rc=$? fi if [ "${EXEC_COMMAND}" ] ; then if [ $rc -eq 0 ] ; then ${EXEC_COMMAND} $p || rc=$? fi fi if [ $rc -eq 0 ] ; then say_pkg_msg "$p" "[OK]" else say_pkg_msg "$p" "*FAILED*" fi else say_pkg_msg "$p" "*not required* (no files updated)" fi fi fi [ "$CTL_ACTION" = "set" ] && PKG_RC[${i}]=$rc i=$(($i + 1)) done cd "${CURPWD}" return 0 } say_pkg_msg(){ local j j=0 PRE=" Package $1:" while [ $j -lt $PKG_MSG_LEN ] ; do PRE="$PRE " j=$(($j + 1)) done PRE="${PRE:0:$PKG_MSG_LEN}" say_msg "$PRE" "$2" } run_preconfig(){ say_msg "llxcfg-cpkg: Running pre-cpkg scripts ..." ${SCRTOOL} "cpkg" run "pre-cpkg" || true say_msg "llxcfg-cpkg: BEGIN pre-configuration" run_pkg_scripts "preconfig" "$1" say_msg "llxcfg-cpkg: END pre-configuration" } run_postconfig(){ say_msg "llxcfg-cpkg: BEGIN post-configuration" run_pkg_scripts "postconfig" "$1" say_msg "llxcfg-cpkg: END post-configuration" say_msg "llxcfg-cpkg: Running post-cpkg scripts ..." ${SCRTOOL} "cpkg" run "post-cpkg" || true } read_parameter(){ # check line [ $# -ne 3 ] && return 0 par_num=$1 shift $1 echo "$1" } read_pkg_template(){ pkg_name="${1}" install_file="${CPKG_TEMPLATES_FILE}" if [ ! -f ${install_file} -a -d "${DEFAULT_TEMPLATE}" ] ; then TEMPLATES_SOURCE=("${DEFAULT_TEMPLATE}") TEMPLATES_TARGET=("${DEFAULT_TARGET}") return 0 else return 1 fi TEMPLATES_SOURCE=() TEMPLATES_TARGET=() n=0 exec 3< ${install_file} while read line <&3 ; do source_path="$(eval "read_parameter 1 ${line}")" target_path="$(eval "read_parameter 2 ${line}")" if [ "$source_path" -a "$target_path" ] ; then TEMPLATES_SOURCE[$n]="$source_path" TEMPLATES_TARGET[$n]="$target_path" n=$(($n + 1)) fi done exec 3>&- return 0 } read_pkg_install(){ pkg_name="${1}" install_file="${CPKG_INSTALL_FILE}" if [ ! -f ${install_file} -a -d "${DEFAULT_SOURCE}" ] ; then INSTALL_SOURCES=("${DEFAULT_SOURCE}") INSTALL_TARGETS=("${DEFAULT_TARGET}") return 0 else return 1 fi INSTALL_SOURCES=() INSTALL_TARGETS=() n=0 exec 3< ${install_file} while read line <&3 ; do source_path="$(eval "read_parameter 1 ${line}")" target_path="$(eval "read_parameter 2 ${line}")" if [ "$source_path" -a "$target_path" ] ; then INSTALL_SOURCES[$n]="$source_path" INSTALL_TARGETS[$n]="$target_path" n=$(($n + 1)) fi done exec 3>&- return 0 } escape_string(){ echo "$1" |sed -e "s%\.%\\\.%g;s%/%\\\/%g" } write_pkg_log(){ INSTALL_LOG="${CPKG_INFO}/$1.log" [ ! -f "${INSTALL_LOG}" ] && touch "${INSTALL_LOG}" TMPFILE="$(tempfile)" # exclude from log files in config dirs sed -e "/^$(escape_string "${LCFG_ADMIN_DIR}")/d;/^$(escape_string "${LCFG_PROGS_DIR}")/d;/^$(escape_string "${LCFG_STATIC_DIR}")/d" "$2" > "$TMPFILE" sort -u "${INSTALL_LOG}" "$TMPFILE" |llxcfg-install - "${INSTALL_LOG}" rm -f "$TMPFILE" return 0 } install_undo(){ if [ -s "$1" ] ; then rsync -qpc --files-from="$1" "${CPKG_LAST_BACKUP}/" / &> /dev/null || true fi } test_dpkg_dist(){ INSTALL_LOG="${CPKG_INFO}/$1.log" DPKG_EXT=".dpkg-dist" if [ -s "$INSTALL_LOG" ] ; then cat "$INSTALL_LOG" |while read f; do if [ -f "${f}.${DPKG_EXT}" ] ; then rsync -qp --checksum "${f}.${DPKG_EXT}" "${CPKG_FIRST_BACKUP}/$f" &> /dev/null || true rm -f "${f}.${DPKG_EXT}" fi done fi return 0 } delete_from_file(){ diff "$1" "$2" |sed -ne "/^< /s%^< %%p" } reset_pkg(){ INSTALL_LOG="${CPKG_INFO}/$1.log" test_dpkg_dist "$1" ignore_list="" if [ "$2" = "upgrade" ] ; then [ -s "$(cpkg_dir "$1")/${CPKG_CONF_FILE}" ] && ignore_list="$(cpkg_dir "$1")/${CPKG_CONF_FILE}" fi res_files=0 del_files=0 if [ -s "$INSTALL_LOG" ] ; then if [ "$ignore_list" ] ; then RESTORE_LIST="$(tempfile -p "LIS")" delete_from_file "$INSTALL_LOG" "$ignore_list" > "$RESTORE_LIST" else RESTORE_LIST="$INSTALL_LOG" fi # first, restore as files as posible TMP_FILE="$(tempfile -p "RES")" rsync -qp --checksum --files-from="$RESTORE_LIST" --log-file="${TMP_FILE}" --log-file-format="%o %f" "${CPKG_FIRST_BACKUP}/" / &> /dev/null || true res_files=$(wc -l "${TMP_FILE}" |cut -f 1 -d " " ) if [ ${res_files} -gt 0 ] ; then echo "Restored files:" log2files "${TMP_FILE}" else echo "No files to restore" fi :> "${TMP_FILE}" # last, remove non pre-existing files # (TODO: rewrite using exec to avoid potential subshell problems) cat "$RESTORE_LIST" |while read line; do [ ! -f "${CPKG_FIRST_BACKUP}/${line}" ] && rm -vf "${line}" > "${TMP_FILE}" done del_files=$(wc -l "${TMP_FILE}" |cut -f 1 -d " " ) if [ ${del_files} -gt 0 ] ; then echo "Deleted files:" sed -ne "s%.*\`\(.*\)'.*%\1%p" "${TMP_FILE}" else echo "No files to remove" fi rm -f "$TMP_FILE" fi num_files=$(($res_files + $del_files)) if [ "$ignore_list" ] ; then cat "$ignore_list" |sort -u |llxcfg-install - "$INSTALL_LOG" else rm -f "$INSTALL_LOG" fi return ${num_files} } log2files(){ sed -ne "/^.* recv /s%^.* recv %/%p" "$1" } cpkg_readfield(){ [ -f "$2" ] && sed -ne "/^${1}:/{s%,[[:space:]]\+%,%g;s%^${1}:[[:space:]]*%%p}" "$2" } run_directory_sync(){ p="$1" rc=0 mkdir -p "$(cpkg_dir $p)" # rsync -a --delete "${CPKG_ORIGINAL}/$p/" "$(cpkg_dir $p)/" &>/dev/null || rc=$? rsync -a --delete "${CPKG_ORIGINAL}/$p/" "$(cpkg_dir $p)/" || rc=$? return $rc } upgrade_test(){ local CURPWD p rc s s0 CURPWD="$(pwd)" p="$1" rc=0 if test_pkg "$p" &>/dev/null ; then # first, purge and update run-directory run_directory_sync "$p" || true s="$(cpkg_dir $p)/${CPKG_CONTROL_FILE}" s0="${CPKG_INFO}/${p}.control" if [ -f "$s" ] ; then if [ ! -f "$s0" ] ; then # new package (first run) cp "$s" "$s0" elif [ "$(cpkg_readfield "Version" "$s")" != "$(cpkg_readfield "Version" "$s0")" ] ; then # ok, it's not a new package and has been upgraded if [ -x "$(cpkg_dir $p)/upgrade" ] ; then cd "$(cpkg_dir $p)" say_pkg_msg "$p" "Version upgrade: Running upgrade script ..." ${s} || rc=$? fi if [ $rc -eq 0 ] ; then if echo ",$(cpkg_readfield "Upgrade-actions" "$s")," |grep -q ",deconfigure," ; then say_pkg_msg "$p" "Version upgrade: Deconfiguring cpkg ..." reset_pkg "$p" "upgrade" &>/dev/null || true fi fi cp "$s" "$s0" fi fi else rc=1 fi cd "$CURPWD" return $rc } garbage_removal(){ CP_FAILED="$(find "$CPKG_TMP" -type f -name "${CPKG_CP_PREFIX}*")" INSTALLED_FILES=$(tempfile -p "INS") for LOG_FILE in ${CP_FAILED} ; do log2files "${LOG_FILE}" > "${INSTALLED_FILES}" install_undo "${INSTALLED_FILES}" rm -f "${LOG_FILE}" done rm -f "${INSTALLED_FILES}" DELETED_FILES=$(tempfile -p "DEL") RM_FAILED="$(find "$CPKG_TMP" -type f -name "${CPKG_RM_PREFIX}*")" for LOG_FILE in ${RM_FAILED} ; do sed -e "s%.*\`\(.*\)'.*%\1%" "${LOG_FILE}" > "${DELETED_FILES}" install_undo "${DELETED_FILES}" rm -f "${LOG_FILE}" done rm -f "${DELETED_FILES}" } install_files(){ SOURCE_DIR="$1" TARGET_DIR="$2" LOG_FILE=$(tempfile -p "$CPKG_CP_PREFIX" -d "$CPKG_TMP") INSTALLED_FILES=$(tempfile -p "INS") rc=0 [ -d "${SOURCE_DIR}" ] && SOURCE_DIR="${SOURCE_DIR}/" rsync -qrl --no-p --backup --backup-dir="${CPKG_LAST_BACKUP}/" --checksum --log-file="${LOG_FILE}" --log-file-format="%o %f" "${SOURCE_DIR}" "${TARGET_DIR}" &> /dev/null || rc=$? log2files "${LOG_FILE}" > "${INSTALLED_FILES}" if [ $rc -ne 0 ] ; then install_undo "${INSTALLED_FILES}" else NEW_FILES=$(wc -l "${INSTALLED_FILES}" |cut -f 1 -d " " ) PKG_UPDATED_FILES=$(($PKG_UPDATED_FILES + $NEW_FILES)) # test first backup rsync -qp --files-from="${INSTALLED_FILES}" --ignore-existing "${CPKG_LAST_BACKUP}/" "${CPKG_FIRST_BACKUP}/" &> /dev/null || true write_pkg_log "$pkg_name" "${INSTALLED_FILES}" fi rm -f "${LOG_FILE}" rm -f "${INSTALLED_FILES}" return 0 } install_pkg_skel(){ local i pkg_name="${1}" pdir="$(cpkg_dir $pkg_name)" if [ -d "$pdir" ] ; then cd "$pdir" if read_pkg_install "${pkg_name}" ; then i=0 while [ $i -lt ${#INSTALL_SOURCES[@]} ] ; do install_files "${INSTALL_SOURCES[i]}" "${INSTALL_TARGETS[i]}" i=$(($i +1)) done fi # templates if read_pkg_template "${pkg_name}" ; then TMP_DIR="$(mktemp -d)" i=0 while [ $i -lt ${#TEMPLATES_SOURCE[@]} ] ; do rc=0 if [ -d "${TEMPLATES_SOURCE[i]}" -a -d "${TEMPLATES_TARGET[i]}" ] ; then (cd "${TEMPLATES_SOURCE[i]}"; find ./ -xtype f )|while read TMP_FILE ; do TMP_FILE="${TMP_FILE#\.\/}" llxcfg-install --cmd="llxcfg-template" "${TEMPLATES_SOURCE[i]}/${TMP_FILE}" "${TMP_DIR}/${TMP_FILE}" &>/dev/null || rc=$? [ $rc -ne 0 ] && rm -f "${TMP_DIR}/${TMP_FILE}" done install_files "${TMP_DIR}" "${TEMPLATES_TARGET[i]}" fi i=$(($i +1)) done rm -fr "${TMP_DIR}" fi # delete remove_file="remove.list" if [ -f "$remove_file" ] ; then LOG_FILE=$(tempfile -p "$CPKG_RM_PREFIX" -d "$CPKG_TMP") rsync -qp --files-from="$remove_file" / "${CPKG_LAST_BACKUP}/" &> /dev/null || true # test first backup rsync -qp --files-from="${remove_file}" --ignore-existing "${CPKG_LAST_BACKUP}/" "${CPKG_FIRST_BACKUP}/" &> /dev/null || true rm -fv $(cat "$remove_file") > "${LOG_FILE}" || true NEW_FILES=$(wc -l "${LOG_FILE}" |cut -f 1 -d " " ) PKG_UPDATED_FILES=$(($PKG_UPDATED_FILES + $NEW_FILES)) write_pkg_log "$pkg_name" "${remove_file}" rm -f "${LOG_FILE}" fi fi test_dpkg_dist "$pkg_name" } install_skel(){ local n CURPWD say_msg "llxcfg-cpkg: BEGIN skel-installation" n=0 CURPWD="$(pwd)" while [ $n -lt ${#PKG_LIST[@]} ] ; do p="${PKG_LIST[$n]}" if test_pkg "$p" ; then rc=${PKG_RC[${n}]} if [ "$rc" = "0" ] ; then PKG_UPDATED_FILES=0 # cd "${CPKG_INFO}/${p}" install_pkg_skel "$p" || true if [ ${PKG_UPDATED_FILES} -eq 0 ] ; then say_pkg_msg "$p" "(No update needed)" PKG_RC[${n}]=100 else say_pkg_msg "$p" "[${PKG_UPDATED_FILES} file(s) updated]" fi else say_pkg_msg "$p" "*skipped* (preconfigure error)" fi fi n=$(($n + 1)) done cd "${CURPWD}" say_msg "llxcfg-cpkg: END skel-installation" return 0 } run_reset(){ i=0 while [ $i -lt ${#PKG_LIST[@]} ] ; do rc=0 reset_pkg "${PKG_LIST[$i]}" || rc=$? PKG_RC[${i}]=$rc i=$(($i + 1)) done return 0 } pkg_info(){ # control file p="$1" CTL_FILE="${CPKG_ORIGINAL}/${p}/${CPKG_CONTROL_FILE}" [ -r "$CTL_FILE" ] && sed -e "s%^%${p}:%" "$CTL_FILE" # services SRV_FILE="${CPKG_ORIGINAL}/${p}/${CPKG_SERVICES_FILE}" [ -s "$SRV_FILE" ] && SERVICES="$(cat "$SRV_FILE"|tr "\n" ,)" [ "$SERVICES" ] && echo "${p}:Services: ${SERVICES}" |sed -e "s%,%, %g;s%,[[:space:]]*$%%g" return 0 } usage() { CMD_NAME="$(basename "$0")" say_msg "Usage: " "$CMD_NAME {pre-dpkg|post-dpkg|update|revert} [PKG_1 [... PKG_N]]" \ "$CMD_NAME {configure|deconfigure|postconfigure} [PKG_1 [... PKG_N]]" \ "$CMD_NAME {listfiles|info} [PKG_1 [... PKG_N]]" \ "$CMD_NAME {grepinfo} FIELD_NAME [PKG_1 [... PKG_N]]" \ "$CMD_NAME {enable|disable} PACKAGE [RUN_ORDER]" \ "$CMD_NAME {allow|deny} PKG_1 [... PKG_N]" \ "$CMD_NAME {list|list-allow|list-deny}" \ "$CMD_NAME search FILE_PATTERN" \ "$CMD_NAME plainview FILE" >&2 } # ---- # main # ---- PKG_UPDATED_FILES=0 declare -a PKG_LIST PKG_RC SCRTOOL="/usr/sbin/llxcfg-script" if [ -z "$1" ] ; then usage exit 1 fi CPKG_ACTION="$1" export CPKG_ACTION shift PKG_LIST0="$@" case "$CPKG_ACTION" in pre-dpkg) # nothing to do on pre-dpkg exit 0 ;; post-dpkg|update) get_pkg_list "$PKG_LIST0" || exit 0 garbage_removal run_preconfig "set" install_skel "test" run_postconfig "test" ;; revert) get_pkg_list "$PKG_LIST0" || exit 0 garbage_removal run_reset run_postconfig "test" ;; deconfigure) get_pkg_list "$PKG_LIST0" || exit 0 garbage_removal run_reset ;; 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 ;; configure) get_pkg_list $PKG_LIST0 || exit 0 garbage_removal run_preconfig "set" install_skel "test" ;; postconfigure) get_pkg_list $PKG_LIST0 || exit 0 garbage_removal run_postconfig ;; allow) if [ -z "$1" ] ; then usage exit 1 fi get_pkg_list $PKG_LIST0 || exit $? garbage_removal i=0 while [ $i -lt ${#PKG_LIST[@]} ] ; do allow_pkg "${PKG_LIST[$i]}" || true i=$(($i + 1)) done ;; deny) if [ -z "$1" ] ; then usage exit 1 fi get_pkg_list $PKG_LIST0 || exit $? garbage_removal i=0 while [ $i -lt ${#PKG_LIST[@]} ] ; do deny_pkg "${PKG_LIST[$i]}" || true i=$(($i + 1)) done ;; enable) if [ -z "$1" ] ; then usage exit 1 fi garbage_removal enable_pkg "$1" "$2" || exit 0 ;; disable) if [ -z "$1" ] ; then usage exit 1 fi garbage_removal disable_pkg "$1" "$2" || exit 0 ;; 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