From 67a57f56fb9ad41d085153f717364b801ea01881 Mon Sep 17 00:00:00 2001 From: Dave Cole <42361141+Dave9111@users.noreply.github.com> Date: Tue, 4 Feb 2020 23:24:47 -0500 Subject: [PATCH 1/4] Update oref0-log-shortcuts.sh Rewrite to get rid of dependency on detection of "source" or "non source" invocation of this script, which is not necessary. Tested on a new install. --- bin/oref0-log-shortcuts.sh | 215 ++++++++++++++++++------------------- 1 file changed, 105 insertions(+), 110 deletions(-) diff --git a/bin/oref0-log-shortcuts.sh b/bin/oref0-log-shortcuts.sh index 5de69ac94..e7d7f4759 100755 --- a/bin/oref0-log-shortcuts.sh +++ b/bin/oref0-log-shortcuts.sh @@ -1,63 +1,24 @@ #!/usr/bin/env bash -# Because this script is meant to be "source"d, not just run normally, it -# doesn't include oref0-bash-common-functions.sh like most others do. +#Maintain a standard list of convenience aliases in the ~/.bash_profile file. -myopenaps=${OPENAPS_DIR:-"$HOME/myopenaps"} -self="${BASH_SOURCE[0]}" -function usage () -{ - cat <>"$PROFILE_PATH" - fi + remove_obsolete_aliases + + #if they exist, remove current aliases to avoid multiple identical aliases in .bash_profile file on a repeat setup + remove_current_aliases + + #add in the current aliases + add_current_aliases + # source default /etc/profile as well if ! grep -q /etc/skel/.profile "$PROFILE_PATH"; then echo "source /etc/skel/.profile" >> "$PROFILE_PATH" @@ -65,38 +26,34 @@ function add_aliases_to_profile () } # In versions prior to 0.7.0, we individually added a bunch of aliases to the -# user's .bash_profile; in 0.7.0, we instead make the .bash_profile source a -# file that includes those aliases. For upgrading purposes, we want to remove +# user's .bash_profile; For upgrading purposes, we want to remove # aliases that exactly match the ones that earlier versions added, but not # aliases that have been modified. + function remove_obsolete_aliases () { - local PROFILE_PATH="$1" - - # List of aliases that may have been added by previous versions of oref0. - # Some have multiple variants. OBSOLETE_ALIASES=$(cat <"$PROFILE_PATH".new$$ && + mv -f "$PROFILE_PATH".new$$ "$PROFILE_PATH" + done) +} + +function add_current_aliases () { + CURRENT_ALIASES1=$(cat <> "$PROFILE_PATH" +} -# Script was loaded with "source" (rather than regular execution)? -if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then - # Don't parse arguments, because the arguments in $@ belong to the parent - # script, not to us. - do_aliases -else - if [[ $# == 0 ]]; then - usage - exit 0 - fi - for i in "$@"; do - case "$i" in - --add-to-profile) - test -f "$HOME/.bash_profile" && add_aliases_to_profile "$HOME/.bash_profile" - ;; - --add-to-profile=*) - test -f "${i#*=}" && add_aliases_to_profile "${i#*=}" - ;; - *) - echo "Unrecognized argument: $i" - exit 1 - ;; - esac - done -fi +# Do it! + +update_aliases_in_profile + +exit 0 From bcd1e8004057bc1ace1027a6ca796b33b165244c Mon Sep 17 00:00:00 2001 From: Dave Cole <42361141+Dave9111@users.noreply.github.com> Date: Tue, 4 Feb 2020 23:30:30 -0500 Subject: [PATCH 2/4] Update oref0-setup.sh Remove arguments from oref0-log-shortcuts function, which is no longer needed after rewrite of that script. --- bin/oref0-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/oref0-setup.sh b/bin/oref0-setup.sh index 1a28fac00..17e5c0cd6 100755 --- a/bin/oref0-setup.sh +++ b/bin/oref0-setup.sh @@ -1051,7 +1051,7 @@ if prompt_yn "" N; then do_openaps_import $HOME/src/oref0/lib/oref0-setup/supermicrobolus.json echo "Adding OpenAPS log shortcuts" - oref0-log-shortcuts --add-to-profile="$HOME/.bash_profile" + oref0-log-shortcuts # Append NIGHTSCOUT_HOST and API_SECRET to $HOME/.bash_profile so that openaps commands can be executed from the command line #echo Add NIGHTSCOUT_HOST and API_SECRET to $HOME/.bash_profile From 6b5777394970af10dbdacc50b48f7e91a76e51a3 Mon Sep 17 00:00:00 2001 From: Dave Cole <42361141+Dave9111@users.noreply.github.com> Date: Sat, 8 Feb 2020 12:10:06 -0500 Subject: [PATCH 3/4] Update oref0-log-shortcuts.sh Fixed typos on "alias edison-battery=" lines --- bin/oref0-log-shortcuts.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/oref0-log-shortcuts.sh b/bin/oref0-log-shortcuts.sh index e7d7f4759..57acb1f88 100755 --- a/bin/oref0-log-shortcuts.sh +++ b/bin/oref0-log-shortcuts.sh @@ -84,7 +84,7 @@ alias edit-runagain="cd ${myopenaps} && nano oref0-runagain.sh" alias cat-autotune="cd ${myopenaps}/autotune && cat autotune_recommendations.log" alias git-branch="cd $HOME/src/oref0 && git branch" alias runagain="bash ${myopenaps}/oref0-runagain.sh" -alias edison-battery="cd=${myopenaps}/monitor && cat edison-battery.json" +alias edison-battery="cd ${myopenaps}/monitor && cat edison-battery.json" alias cat-reservoir="cd ${myopenaps}/monitor && cat reservoir.json" alias stop-cron="cd ${myopenaps} && /etc/init.d/cron stop && killall -g oref0-pump-loop" alias start-cron="/etc/init.d/cron start" @@ -117,7 +117,7 @@ alias edit-runagain="cd ${myopenaps} && nano oref0-runagain.sh" alias cat-autotune="cd ${myopenaps}/autotune && cat autotune_recommendations.log" alias git-branch="cd $HOME/src/oref0 && git branch" alias runagain="bash ${myopenaps}/oref0-runagain.sh" -alias edison-battery="cd=${myopenaps}/monitor && cat edison-battery.json" +alias edison-battery="cd ${myopenaps}/monitor && cat edison-battery.json" alias cat-reservoir="cd ${myopenaps}/monitor && cat reservoir.json" alias stop-cron="cd ${myopenaps} && /etc/init.d/cron stop && killall -g oref0-pump-loop" alias start-cron="/etc/init.d/cron start" From d49f26cd53e7360e87285fa93b4d62fdbeb43605 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Thu, 13 Feb 2020 19:18:50 -0800 Subject: [PATCH 4/4] remove broken bash_profile tests --- tests/bash-util-functions.test.sh | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/tests/bash-util-functions.test.sh b/tests/bash-util-functions.test.sh index 8c15018b9..ba5580ec2 100755 --- a/tests/bash-util-functions.test.sh +++ b/tests/bash-util-functions.test.sh @@ -189,32 +189,7 @@ EOT if [[ "$(source ./test_script_is_sourced.sh)" != "sourced" ]]; then fail_test "script_is_sourced on sourced script" fi - - # Test oref0-log-shortcuts - cat >test_bash_profile <