Response to Issue #2198: loadup and medley scripts can now store/retrieve loadup files to/from named subdirectories of MEDLEYDIR/loadups (#2200)
* Add to loadup and medley scripts a --branch argument whereby which loadup outputs are stored in MEDLEYDIR/loadups/branches/BRANCH, where BRANCH is the name of the currently active git branch of MEDLEYDIR (for loadup) or the name of a BRANCH whereby which a loadup had been run with the --branch option (for medley). Man pages updated accordingly. * Removed --git-branch synonym for --branch from both medley and loadup scripts. Added optional BRANCH argument to --branch in loadup script. If BRANCH is specified iot is used as the (pseudo)branch name instead of the current active git branch of MEDLEYDIR. If BRANCH is "-", the current git branch name is used. * When doing loadups, a file called gitinfo is created in the LOADUP_OUTDIR that contains the git commit, git branch and git status of MEDLEYDIR at the time of the loadup. Branch names in loadup and medley scripts now contain only alphanumerics, dahes, underscores, periods. Any other character is coerced to underscore. The branch name is now included in the window title. * Incorporate changes from PR#2208: Use the loadup step script names as the --id string. * Add loadups/gitinfo and loadups/branches to .gitignore
This commit is contained in:
@@ -3,9 +3,6 @@
|
||||
|
||||
main() {
|
||||
|
||||
# shellcheck source=./loadup-setup.sh
|
||||
. "${LOADUP_SCRIPTDIR}/loadup-setup.sh"
|
||||
|
||||
# process args
|
||||
start=""
|
||||
start_s=""
|
||||
@@ -20,6 +17,9 @@ main() {
|
||||
override_lock=false
|
||||
ignore_lock=false
|
||||
export LOADUP_USE_VNC="-"
|
||||
man_flg=false
|
||||
use_branch=""
|
||||
branch_requested=false
|
||||
|
||||
while [ "$#" -ne 0 ];
|
||||
do
|
||||
@@ -123,6 +123,22 @@ main() {
|
||||
end=1
|
||||
end_s=init
|
||||
;;
|
||||
-br | -branch | --branch)
|
||||
branch_requested=true
|
||||
if [ "$2" = "-" ]
|
||||
then
|
||||
use_branch="-"
|
||||
shift
|
||||
else
|
||||
if check_for_no_arg "$2"
|
||||
then
|
||||
use_branch="-"
|
||||
else
|
||||
use_branch="$2"
|
||||
shift
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
-nc | -nocopy | --nocopy)
|
||||
nocopy=true
|
||||
;;
|
||||
@@ -168,13 +184,7 @@ main() {
|
||||
force_vnc="+"
|
||||
;;
|
||||
-z | -man | --man )
|
||||
if [ "$(uname)" = "Darwin" ]
|
||||
then
|
||||
/usr/bin/man "${LOADUP_SOURCEDIR}/man-page/loadup.1.gz"
|
||||
else
|
||||
/usr/bin/man -l "${LOADUP_SOURCEDIR}/man-page/loadup.1.gz"
|
||||
fi
|
||||
exit 0
|
||||
man_flg=true
|
||||
;;
|
||||
*)
|
||||
output_error_msg "Error: unknown flag: $1${EOL}Exiting"
|
||||
@@ -184,6 +194,27 @@ main() {
|
||||
shift
|
||||
done
|
||||
|
||||
#
|
||||
# Source loadup-setup.sh script to set all the standard loadup env variables
|
||||
#
|
||||
|
||||
# shellcheck source=./loadup-setup.sh
|
||||
. "${LOADUP_SCRIPTDIR}/loadup-setup.sh"
|
||||
|
||||
#
|
||||
# if --man flag is set, then show man page and exit
|
||||
#
|
||||
if [ "${man_flg}" = true ]
|
||||
then
|
||||
if [ "$(uname)" = "Darwin" ]
|
||||
then
|
||||
/usr/bin/man "${LOADUP_SOURCEDIR}/man-page/loadup.1.gz"
|
||||
else
|
||||
/usr/bin/man -l "${LOADUP_SOURCEDIR}/man-page/loadup.1.gz"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#
|
||||
#
|
||||
# check arguments
|
||||
@@ -192,6 +223,12 @@ main() {
|
||||
|
||||
no_loadups=false
|
||||
|
||||
# check --branch is used correctly
|
||||
if [ "${branch_requested}" = true ] && [ -z "${use_branch}" ]
|
||||
then
|
||||
output_warn_msg "The --branch (-br) flag was used. But either git is not installed on this system or \"${LOADUP_SOURCEDIR}\" is not a git directory.${EOL}The --branch flag will be ignored"
|
||||
fi
|
||||
|
||||
#
|
||||
# check for no args or only maikodir arg and set defaults appropriately
|
||||
#
|
||||
@@ -299,6 +336,16 @@ main() {
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# Save git informatiom into LOADUP_OUTDIR
|
||||
#
|
||||
|
||||
if [ -n "${LOADUP_COMMIT_ID}" ]
|
||||
then
|
||||
echo "Commit: ${LOADUP_COMMIT_ID}" > "${LOADUP_OUTDIR}"/gitinfo
|
||||
git status >> "${LOADUP_OUTDIR}"/gitinfo
|
||||
fi
|
||||
|
||||
#
|
||||
# Do individual "stage" loadups as requested
|
||||
#
|
||||
@@ -433,7 +480,6 @@ main() {
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# OK we're done, exit cleanly
|
||||
#
|
||||
@@ -443,6 +489,43 @@ main() {
|
||||
|
||||
}
|
||||
|
||||
is_tput="$(command -v tput)"
|
||||
if [ -z "${is_tput}" ]
|
||||
then
|
||||
is_tput="$(command -v true)"
|
||||
fi
|
||||
|
||||
|
||||
EOL="
|
||||
"
|
||||
|
||||
output_error_msg() {
|
||||
local_oem_file="${TMPDIR:-/tmp}"/oem_$$
|
||||
echo "$1" >"${local_oem_file}"
|
||||
while read -r line
|
||||
do
|
||||
echo "$(${is_tput} setab 1)$(${is_tput} setaf 7)${line}$(${is_tput} sgr0)"
|
||||
done <"${local_oem_file}"
|
||||
rm -f "${local_oem_file}"
|
||||
}
|
||||
|
||||
check_for_no_arg() {
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
return 0
|
||||
else
|
||||
case "$1" in
|
||||
-*)
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
# shellcheck disable=SC2164,SC2034
|
||||
if [ -z "${LOADUP_SCRIPTDIR}" ]
|
||||
|
||||
@@ -32,10 +32,20 @@ main() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git_commit_ID "${NOTECARDSDIR}"
|
||||
git_commit_info "${NOTECARDSDIR}"
|
||||
NOTECARDS_COMMIT_ID="${COMMIT_ID}"
|
||||
export NOTECARDS_COMMIT_ID
|
||||
|
||||
if [ -n "${NOTECARDS_COMMIT_ID}" ]
|
||||
then
|
||||
{
|
||||
echo ;
|
||||
echo "--------------------------------------------" ;
|
||||
echo "Notecards Commit: ${NOTECARDS_COMMIT_ID}" ;
|
||||
git -C "${NOTECARDSDIR}" status ;
|
||||
} >> "${LOADUP_OUTDIR}/gitinfo"
|
||||
fi
|
||||
|
||||
initfile="-"
|
||||
cat >"${cmfile}" <<-EOF
|
||||
"
|
||||
|
||||
@@ -12,10 +12,38 @@ then
|
||||
export LOADUP_SOURCEDIR
|
||||
fi
|
||||
|
||||
git_commit_info () {
|
||||
if [ -f "$(command -v git)" ] && [ -x "$(command -v git)" ]
|
||||
then
|
||||
if git -C "$1" rev-parse >/dev/null 2>/dev/null
|
||||
then
|
||||
# This does NOT indicate if there are any modified files!
|
||||
COMMIT_ID="$(git -C "$1" rev-parse --short HEAD)"
|
||||
BRANCH="$(git -C "$1" rev-parse --abbrev-ref HEAD)"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
git_commit_info "${LOADUP_SOURCEDIR}"
|
||||
export LOADUP_COMMIT_ID="${COMMIT_ID}"
|
||||
export LOADUP_BRANCH="${BRANCH}"
|
||||
|
||||
if [ "${use_branch}" = "-" ]
|
||||
then
|
||||
use_branch="${LOADUP_BRANCH}"
|
||||
fi
|
||||
|
||||
slash_branch=""
|
||||
if [ -n "${use_branch}" ]
|
||||
then
|
||||
use_branch="$(printf %s "${use_branch}" | sed "s/[^a-zA-Z0-9_.-]/_/g")"
|
||||
slash_branch="/branches/${use_branch}"
|
||||
fi
|
||||
|
||||
|
||||
if [ -z "${LOADUP_OUTDIR}" ]
|
||||
then
|
||||
LOADUP_OUTDIR="${MEDLEYDIR}/loadups"
|
||||
export LOADUP_OUTDIR
|
||||
export LOADUP_OUTDIR="${MEDLEYDIR}/loadups${slash_branch}"
|
||||
fi
|
||||
|
||||
if [ ! -d "${LOADUP_OUTDIR}" ];
|
||||
@@ -63,43 +91,13 @@ then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f "$(command -v git)" ] && [ -x "$(command -v git)" ]
|
||||
then
|
||||
export HAS_GIT=true
|
||||
else
|
||||
export HAS_GIT=false
|
||||
fi
|
||||
|
||||
is_git_dir () {
|
||||
if [ "${HAS_GIT}" = true ]
|
||||
then
|
||||
return "$(git -C "$1" rev-parse >/dev/null 2>/dev/null; echo $?)"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
git_commit_ID () {
|
||||
if [ "${HAS_GIT}" = true ]
|
||||
then
|
||||
if is_git_dir "$1"
|
||||
then
|
||||
# This does NOT indicate if there are any modified files!
|
||||
COMMIT_ID="$(git -C "$1" rev-parse --short HEAD)"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
git_commit_ID "${LOADUP_SOURCEDIR}"
|
||||
LOADUP_COMMIT_ID="${COMMIT_ID}"
|
||||
export LOADUP_COMMIT_ID
|
||||
|
||||
# obsolete? scr="-sc 1024x768 -g 1042x790"
|
||||
geometry=1024x768
|
||||
|
||||
touch "${LOADUP_WORKDIR}"/loadup.timestamp
|
||||
|
||||
script_name=$(basename "$0" ".sh")
|
||||
script_name_for_id=$(echo "${script_name}" | sed -e "s/-/_/g")
|
||||
cmfile="${LOADUP_WORKDIR}/${script_name}.cm"
|
||||
initfile="${LOADUP_WORKDIR}/${script_name}.init"
|
||||
|
||||
@@ -165,7 +163,7 @@ force_vnc="-"
|
||||
run_medley () {
|
||||
/bin/sh "${MEDLEYDIR}/scripts/medley/medley.command" \
|
||||
--config - \
|
||||
--id loadup_+ \
|
||||
--id "${script_name_for_id}_+" \
|
||||
--geometry "${geometry}" \
|
||||
--noscroll \
|
||||
--logindir "${LOADUP_LOGINDIR}" \
|
||||
@@ -187,6 +185,7 @@ fi
|
||||
|
||||
EOL="
|
||||
"
|
||||
|
||||
output_error_msg() {
|
||||
local_oem_file="${TMPDIR:-/tmp}"/oem_$$
|
||||
echo "$1" >"${local_oem_file}"
|
||||
|
||||
Reference in New Issue
Block a user