diff --git a/make/defs.mk b/make/defs.mk index abb317fb..a977c758 100644 --- a/make/defs.mk +++ b/make/defs.mk @@ -618,6 +618,7 @@ GENERATE_FUNC_TIMERS = $(MODDIR)/YStopWatchThreadList/generate_func_timers.sh RM = rm AR = ar +LOG_INSTALL_SH = $(MOD_SCRIPT_DIR)/pkg.sh log-install ifeq ($(LOG_THREAD_NAMES), true) BUILD_CFLAGS += -DSLOG_THREAD_NAMES @@ -625,18 +626,18 @@ ifeq ($(LOG_THREAD_NAMES), true) endif ifdef INSTALL_LINK - INSTALL = sudo $(MOD_SCRIPT_DIR)/log_install.sh -LA - LINK_LIB = sudo $(MOD_SCRIPT_DIR)/log_install.sh -LA + INSTALL = sudo $(LOG_INSTALL_SH) -LA + LINK_LIB = sudo $(LOG_INSTALL_SH) -LA else ifdef INSTALL_LOG - INSTALL=$(MOD_SCRIPT_DIR)/log_install.sh -p -l $(INSTALL_LOG) - LINK_LIB=$(MOD_SCRIPT_DIR)/log_install.sh -L -l $(INSTALL_LOG) + INSTALL=$(LOG_INSTALL_SH) -p -l $(INSTALL_LOG) + LINK_LIB=$(LOG_INSTALL_SH) -L -l $(INSTALL_LOG) else ifndef INSTALL INSTALL = install endif ifndef LINK_LIB - LINK_LIB=$(MOD_SCRIPT_DIR)/log_install.sh -L + LINK_LIB=$(LOG_INSTALL_SH) -L endif endif endif diff --git a/scripts/pkg.sh b/scripts/pkg.sh index 47c07d46..e12f5673 100644 --- a/scripts/pkg.sh +++ b/scripts/pkg.sh @@ -481,6 +481,177 @@ cmd_upload() upload_pkg } +cmd_log_install() +{ + local args="$*" + + local c_format=rpm + local c_logfile=install.log + local c_mode_dir=false + local c_group=`id -gn` + local c_owner=`whoami` + local c_suffix= + local c_prefix= + local c_opmode=opmode_install + local c_absolute=0 + + set -- `getopt 'Li:a:f:l:bg:cdm:o:psS:vA' $*` + + cfgfile_macro() + { + if echo "$*" | grep -qe '/etc/\|\.conf$'; then + echo "%config(noreplace) " + fi + } + + while [ "$1" != -- ]; do + case $1 in + -f) + c_format=$2 + shift;; + -l) + c_logfile=$2 + shift;; + -a) + c_use_attr=true + ;; + -i) + c_ignore_prefix=$2 + shift + ;; + + -b) + ;; + -c) + ;; + -d) + c_mode_dir=true;; + -D) + ;; + -g) + c_group=$2 + shift;; + -m) + c_mode=$2 + shift;; + -o) + c_owner=$2 + shift;; + -p) + ;; + -s) + ;; + -S) + c_suffix=$2 + shift;; + -v) + ;; + -L) + c_opmode=opmode_link;; + -A) + c_absolute=1;; + *) + echo unknown option \"$1\". Exiting. >&2 + exit 1;; + esac + shift + done + + shift + + local args="`echo " $args" | sed -e 's/ -l *[^ ]*//g; s/ -f *[^ ]*//g; s/\b-a\b//g;'`" + + if [ -z "$c_use_attr" ]; then + #args="`echo " $args" | sed -e 's/ -g *[^ ]*//g; s/ -m *[^ ]*//g; s/ -o *[^ ]*//g;'`" + args="`echo " $args" | sed -e 's/ -g *[^ ]*//g; s/ -o *[^ ]*//g;'`" + fi + + local c_target="`echo $* | rev | cut -d' ' -f1 | rev`" + local c_source="`echo $* | rev | cut -d' ' -f2- | rev`" + + case $c_opmode in + + opmode_install) + if [ -L "$c_source" ]; then + cp -d $c_source $c_target || exit $? + else + install $args || exit $? + fi + ;; + + opmode_link) + if [ "$c_mode_dir" = true ]; then + echo "ignoring directory $c_source during link creation" + exit 0 + fi + if [ "$c_absolute" != 0 ]; then + c_logfile="" + c_source=`readlink -f $c_source` + else + c_source=`basename $c_source` + fi + cd `dirname $c_target` + ln -sf $c_source `basename $c_target` + ;; + + *) + echo "Mode \"$c_opmode\" not implemented. Exiting." >&2 + exit 1 + ;; + esac + + [ "$c_logfile" ] || { + exit 0 + } + + local file mode installd_file cfgfile dir + if [ "$c_mode_dir" = true ]; then + for file in $*; do + echo "%dir %attr($c_mode,$c_owner,$c_group) $file" >> $c_logfile + done + else + if [ -d "$c_target" ]; then + for file in $c_source; do + installed_file="$c_target/`basename $file`" + cfgfile="" + mode + if [ "$c_mode" ]; then + mode=$c_mode + cfgfile=`cfgfile_macro "$installed_file"` + else + if [ -d "$file" ]; then + dir="%dir " + mode=0755 + else + cfgfile=`cfgfile_macro "$installed_file"` + dir="" + mode=0644 + fi + fi + echo "$dir%attr($mode,$c_owner,$c_group) $cfgfile$installed_file" | + sed "s/^$c_ignore_prefix//" >> $c_logfile + done + else + installed_file="$c_target" + cfgfile="" + if [ "$c_mode" ]; then + mode=$c_mode + cfgfile=`cfgfile_macro "$installed_file"` + else + if [ -d "$c_source" ]; then + dir="%dir " + mode=0755 + else + cfgfile=`cfgfile_macro "$installed_file"` + dir="" + mode=0644 + fi + fi + echo "$dir%attr($mode,$c_owner,$c_group) $cfgfile$c_target" | sed "s/^$c_ignore_prefix//" >> $c_logfile + fi + fi +} + # ---- here we go umask 0022 trap goodbye SIGINT SIGKILL @@ -508,7 +679,22 @@ SCM=cvs [ "$CVS_RSH" ] && SSH=$CVS_RSH [ -d .git ] && SCM=git -eval set -- `getopt -- 'ht:p:m:N:R:D:P:a:F:' "$@"` + +opts='ht:p:m:N:R:D:P:a:F:' +args=("$@") +while [ "$1" ]; do + [ ${#1} = 2 -a ${1:0:1} = - ] && echo $opts | grep -q "${1:1}" && { + echo $opts | grep -q "${1:1}" && shift + shift + continue + } + break +done +cmd=$1 + +set -- "${args[@]}" +set -- "${@/$cmd/--}" + while [ "$1" != -- ] ; do case "$1" in -h) @@ -557,10 +743,9 @@ shift SRPMS_DIR=`find_path $HOME/rpmbuild/SRPMS /usr/src/packages/SRPMS` RPMS_DIR=`find_path $HOME/rpmbuild/RPMS/$RPM_ARCH /usr/src/packages/RPMS/$RPM_ARCH` -cmd=$1 -shift +# shift -[ $# -ne 0 -o ! "$cmd" ] && usage 1 +[ ! "$cmd" ] && usage 1 case $PKG_FORMAT in rpm) @@ -624,6 +809,9 @@ release) hash) calculate_hash ;; +log-install) + eval cmd_log_install "$@" + ;; *) usage 1 ;;