Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:59

0001 #!/bin/sh
0002 #CMSSDT_DAS_CLIENT_SIGN:12345678901234567890ABCDEFABCDEF
0003 #Do not change the above magic line. It is signature for the cmssw ibs das_client wrapper
0004 function get_parent_cmds ()
0005 {
0006   local DEPTH=$2
0007   let DEPTH=$DEPTH+1
0008   [ $DEPTH -gt 2 ] && return 0
0009   local XPID=$(ps -p $1 -o ppid= | sed 's| ||g;')
0010   [ "$XPID" = "" -o "$XPID" = "1" ] && return 0
0011   cat "/proc/$XPID/cmdline"
0012   echo ""
0013   cat "/proc/$XPID/cmdline" >> ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.info
0014   echo "" >> ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.info
0015   get_parent_cmds "$XPID" "$DEPTH"
0016 }
0017 
0018 CMD_NAME=$(basename $0)
0019 LIMIT_RESULTS="NO"
0020 QUERY=
0021 FORMAT="plain"
0022 HELP=
0023 for ((i=1; i<=$#; i++)); do
0024   next=$((i+1))
0025   case  ${!i} in
0026     --query=*  ) QUERY=$(echo ${!i} | sed 's|.*=||') ;;
0027     --query    ) QUERY=${!next} ;;
0028     --format=* ) FORMAT=$(echo ${!i} | sed 's|.*=||') ;;
0029     --format   ) FORMAT=${!next} ;;
0030     -h|--help  ) HELP=YES ;;
0031   esac
0032 done
0033 
0034 ORIG_DAS_CLIENT=""
0035 for DAS_CLIENT in $(echo $PATH | tr ':' '\n' | sed "s|\$|/${CMD_NAME}|") ; do
0036  [ -e ${DAS_CLIENT} ] || continue
0037  if [ $(head -2 ${DAS_CLIENT} | grep 'CMSSDT_DAS_CLIENT_SIGN' | wc -l) -eq 0 ] ; then ORIG_DAS_CLIENT=${DAS_CLIENT}; break; fi
0038 done
0039 
0040 if [ "X${ORIG_DAS_CLIENT}" = "X" ] ; then
0041   echo "${CMD_NAME}: Command not found." 1>&2
0042   exit 1
0043 fi
0044 
0045 if [ "${QUERY}" = "" -o "${HELP}" != "" ] ; then
0046   ${ORIG_DAS_CLIENT} "$@"
0047   exit $?
0048 fi
0049 
0050 QUERY=$(echo "${QUERY}" | sed 's|^ *||;s| *$||;s|  *| |g;s| =|=|g;s|= |=|g;')
0051 QUERY_SHA_HASH=$(echo -n "${QUERY}" | sha256sum | sed 's| .*$||;s| *||')
0052 QUERY_SHA=$(echo "${QUERY_SHA_HASH}" | sed 's|^\(..\)|\1/\1|')
0053 QUERY_URL="https://raw.githubusercontent.com/cms-sw/cms-sw.github.io/master/das_queries/${QUERY_SHA}"
0054 DAS_QUERY_DIR=das_query/$$
0055 if [ "X${LOCALRT}" != "X" ] ; then DAS_QUERY_DIR="${LOCALRT}/${DAS_QUERY_DIR}" ; fi
0056 rm -rf ${DAS_QUERY_DIR}
0057 mkdir -p ${DAS_QUERY_DIR}
0058 echo "${QUERY}" > ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.query
0059 touch ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.info
0060 if [ "${FORMAT}" = "json" ]  ; then
0061   QUERY_RESULTS=$(curl -f -L -s "${QUERY_URL}.json" || true)
0062   if [ "${QUERY_RESULTS}" = "" ] ; then
0063     ${ORIG_DAS_CLIENT} "$@" > ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.out
0064   else
0065     echo "${QUERY_RESULTS}" > ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.out
0066   fi
0067 else
0068   QUERY_RESULTS=$((curl -f -L -s "${QUERY_URL}" || true) | grep /store/ | sed 's| ||g;s|"||g;s|,||g')
0069   [ $((get_parent_cmds $$ 0 2>&1 || true) | grep '/cmsDriver.py' | wc -l) -gt 0 ] && LIMIT_RESULTS="YES"
0070   if [ "${QUERY_RESULTS}" = "" ] ; then
0071     ${ORIG_DAS_CLIENT} "$@" > ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.out
0072   else
0073     echo "${QUERY_RESULTS}" > ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.out
0074   fi
0075 fi
0076 echo $LIMIT_RESULTS >> ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.info
0077 if [ "$LIMIT_RESULTS" = "YES" ] ; then
0078   cat ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.out | ibeos-lfn-sort > ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.selected
0079   cat ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.selected
0080 else
0081   cat ${DAS_QUERY_DIR}/${QUERY_SHA_HASH}.out
0082 fi