Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source cmsset_default.sh in the new shell to get alias and crab auto completion working #13

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions cmssw-env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -e
EXTRA_OPTS=
BASE_SCRIPT="cmssw-env"
CMD_TO_RUN=("/bin/bash")
CMD_TO_RUN=()
CMS_IMAGE=$(basename $0)
THISDIR=$(dirname $0)
IGNORE_MOUNTS=""
Expand Down Expand Up @@ -57,14 +57,19 @@ for dir in /etc/tnsnames.ora /etc/pki/ca-trust /eos /build /data /afs /pool $(/b
[ ! -e $dir ] || MOUNT_POINTS="${MOUNT_POINTS},${dir}"
done
OLD_CMSOS=$(echo ${SCRAM_ARCH} | cut -d_ -f1,2)
# necessary to preserve quotes/grouping in original CMD_TO_RUN when running multiple commands through sh -c
printf -v CMD_STR '%q ' "${CMD_TO_RUN[@]}"
# necessary to expand multi-command input given as quoted string
CMD_PREF=
if [ "${#CMD_TO_RUN[@]}" -eq 1 ]; then CMD_PREF="eval "; fi
INIT_FILE=""
RESET_SCRAM_ARCH=""
if [ -e ${THISDIR}/../cmsset_default.sh ] ; then
CMD_TO_RUN=("[ \"${OLD_CMSOS}\" != \"\$(${THISDIR}/cmsos)\" ] && export SCRAM_ARCH=""; source ${THISDIR}/../cmsset_default.sh >/dev/null 2>&1; ${CMD_PREF}${CMD_STR}")
else
INIT_FILE="--init-file ${THISDIR}/../cmsset_default.sh"
RESET_SCRAM_ARCH="[ \"${OLD_CMSOS}\" != \"\$(${THISDIR}/cmsos)\" ] && export SCRAM_ARCH= ;"
fi

if [ "${#CMD_TO_RUN[@]}" -gt 0 ] ; then
# necessary to preserve quotes/grouping in original CMD_TO_RUN when running multiple commands through sh -c
printf -v CMD_STR '%q ' "${CMD_TO_RUN[@]}"
# necessary to expand multi-command input given as quoted string
CMD_PREF=
if [ "${#CMD_TO_RUN[@]}" -eq 1 ]; then CMD_PREF="eval "; fi
CMD_TO_RUN=("${CMD_PREF}${CMD_STR}")
fi

Expand Down Expand Up @@ -111,4 +116,8 @@ if [ -e $UNPACKED_IMAGE ] ; then
done
export ${BINDPATH_ENV}=$(echo ${VALID_MOUNT_POINTS} | sed 's|^,||')
fi
${CONTAINER_CMD} -s exec ${EXTRA_OPTS} $UNPACKED_IMAGE sh -c "${CMD_TO_RUN[@]}"
if [ "${#CMD_TO_RUN[@]}" -eq 0 ] ; then
${CONTAINER_CMD} -s exec ${EXTRA_OPTS} $UNPACKED_IMAGE sh -c "${RESET_SCRAM_ARCH} /bin/bash ${INIT_FILE} -i "
else
${CONTAINER_CMD} -s exec ${EXTRA_OPTS} $UNPACKED_IMAGE sh -c "${RESET_SCRAM_ARCH} /bin/bash ${INIT_FILE} -i -c '${CMD_TO_RUN[@]}'"
fi