Annotation For work_in_progress/various_tools/mmmv/mmmv_Fossil_operator_t1.bash
Not logged in

Origin for each line in work_in_progress/various_tools/mmmv/mmmv_Fossil_operator_t1.bash from check-in 84fb49b807:

20305d1054 2017-05-19    1: #!/usr/bin/env bash
20305d1054 2017-05-19    2: # Initial author: Martin.Vahi@softf1.com
20305d1054 2017-05-19    3: # This file is in the public domain.
20305d1054 2017-05-19    4: #==========================================================================
20305d1054 2017-05-19    5: S_FP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
20305d1054 2017-05-19    6: S_FP_ORIG="`pwd`"
20305d1054 2017-05-19    7: S_TIMESTAMP="`date +%Y`_`date +%m`_`date +%d`_T_`date +%H`h_`date +%M`min_`date +%S`s"
20305d1054 2017-05-19    8: 
20305d1054 2017-05-19    9: 
20305d1054 2017-05-19   10: func_assert_exists_on_path_t2 () {
20305d1054 2017-05-19   11:     local S_NAME_OF_THE_EXECUTABLE_1="$1" # first function argument
20305d1054 2017-05-19   12:     local S_NAME_OF_THE_EXECUTABLE_2="$2" # optional argument
20305d1054 2017-05-19   13:     local S_NAME_OF_THE_EXECUTABLE_3="$3" # optional argument
20305d1054 2017-05-19   14:     local S_NAME_OF_THE_EXECUTABLE_4="$4" # optional argument
20305d1054 2017-05-19   15:     #--------
20305d1054 2017-05-19   16:     # Function calls like
20305d1054 2017-05-19   17:     #
20305d1054 2017-05-19   18:     #     func_assert_exists_on_path_t2  ""    ""  "ls"
20305d1054 2017-05-19   19:     #     func_assert_exists_on_path_t2  "ls"  ""  "ps"
20305d1054 2017-05-19   20:     #
20305d1054 2017-05-19   21:     # are not allowed by the spec of this function, but it's OK to call
20305d1054 2017-05-19   22:     #
20305d1054 2017-05-19   23:     #     func_assert_exists_on_path_t2  "ls" "" 
20305d1054 2017-05-19   24:     #     func_assert_exists_on_path_t2  "ls" "ps" ""
20305d1054 2017-05-19   25:     #     func_assert_exists_on_path_t2  "ls" ""   "" ""
20305d1054 2017-05-19   26:     #
20305d1054 2017-05-19   27:     #
20305d1054 2017-05-19   28:     local SB_THROW="f"
20305d1054 2017-05-19   29:     if [ "$S_NAME_OF_THE_EXECUTABLE_1" == "" ] ; then
20305d1054 2017-05-19   30:         SB_THROW="t"
20305d1054 2017-05-19   31:     else
20305d1054 2017-05-19   32:         if [ "$S_NAME_OF_THE_EXECUTABLE_2" == "" ] ; then
20305d1054 2017-05-19   33:             if [ "$S_NAME_OF_THE_EXECUTABLE_3" != "" ] ; then
20305d1054 2017-05-19   34:                 SB_THROW="t"
20305d1054 2017-05-19   35:             fi
20305d1054 2017-05-19   36:             if [ "$S_NAME_OF_THE_EXECUTABLE_4" != "" ] ; then
20305d1054 2017-05-19   37:                 SB_THROW="t"
20305d1054 2017-05-19   38:             fi
20305d1054 2017-05-19   39:         else
20305d1054 2017-05-19   40:             if [ "$S_NAME_OF_THE_EXECUTABLE_3" == "" ] ; then
20305d1054 2017-05-19   41:                 if [ "$S_NAME_OF_THE_EXECUTABLE_4" != "" ] ; then
20305d1054 2017-05-19   42:                     SB_THROW="t"
20305d1054 2017-05-19   43:                 fi
20305d1054 2017-05-19   44:             fi
20305d1054 2017-05-19   45:         fi
20305d1054 2017-05-19   46:     fi
20305d1054 2017-05-19   47:     #----
20305d1054 2017-05-19   48:     if [ "$SB_THROW" == "t" ] ; then
20305d1054 2017-05-19   49:         echo ""
20305d1054 2017-05-19   50:         echo "The Bash function "
20305d1054 2017-05-19   51:         echo ""
20305d1054 2017-05-19   52:         echo "    func_assert_exists_on_path_t2 "
20305d1054 2017-05-19   53:         echo ""
20305d1054 2017-05-19   54:         echo "is not designed to handle series of arguments, where "
20305d1054 2017-05-19   55:         echo "empty strings preced non-empty strings."
84fb49b807 2017-05-28   56:         echo "GUID=='4db0cd83-58cb-447d-ad5d-315260c151e7'"
20305d1054 2017-05-19   57:         echo ""
20305d1054 2017-05-19   58:         #----
20305d1054 2017-05-19   59:         cd $S_FP_ORIG
20305d1054 2017-05-19   60:         exit 1 # exit with error
20305d1054 2017-05-19   61:     fi
20305d1054 2017-05-19   62:     if [ "$5" != "" ] ; then
20305d1054 2017-05-19   63:         echo ""
20305d1054 2017-05-19   64:         echo "This Bash function is designed to work with at most 4 input arguments"
84fb49b807 2017-05-28   65:         echo "GUID=='10c771f1-6b0c-44df-865d-315260c151e7'"
20305d1054 2017-05-19   66:         echo ""
20305d1054 2017-05-19   67:         #----
20305d1054 2017-05-19   68:         cd $S_FP_ORIG
20305d1054 2017-05-19   69:         exit 1 # exit with error
20305d1054 2017-05-19   70:     fi
20305d1054 2017-05-19   71:     #--------
20305d1054 2017-05-19   72:     # Function calls like
20305d1054 2017-05-19   73:     #
20305d1054 2017-05-19   74:     #     func_assert_exists_on_path_t2 " "
20305d1054 2017-05-19   75:     #     func_assert_exists_on_path_t2 "ls ps" # contains a space
20305d1054 2017-05-19   76:     #
20305d1054 2017-05-19   77:     # are not allowed.
20305d1054 2017-05-19   78:     SB_THROW="f" 
20305d1054 2017-05-19   79:     local S_TMP_0=""
20305d1054 2017-05-19   80:     local S_TMP_1=""
20305d1054 2017-05-19   81:     local S_TMP_2=""
20305d1054 2017-05-19   82:     #----
20305d1054 2017-05-19   83:     if [ "$SB_THROW" == "f" ] ; then
20305d1054 2017-05-19   84:         S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_1\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`"
20305d1054 2017-05-19   85:         if [ "$S_NAME_OF_THE_EXECUTABLE_1" != "$S_TMP_0" ] ; then
20305d1054 2017-05-19   86:             SB_THROW="t" 
20305d1054 2017-05-19   87:             S_TMP_1="$S_NAME_OF_THE_EXECUTABLE_1"
84fb49b807 2017-05-28   88:             S_TMP_2="GUID=='812f9b67-2841-4b37-a53d-315260c151e7'"
20305d1054 2017-05-19   89:         fi
20305d1054 2017-05-19   90:     fi
20305d1054 2017-05-19   91:     #----
20305d1054 2017-05-19   92:     if [ "$SB_THROW" == "f" ] ; then
20305d1054 2017-05-19   93:         S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_2\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`"
20305d1054 2017-05-19   94:         if [ "$S_NAME_OF_THE_EXECUTABLE_2" != "$S_TMP_0" ] ; then
20305d1054 2017-05-19   95:             SB_THROW="t" 
20305d1054 2017-05-19   96:             S_TMP_1="$S_NAME_OF_THE_EXECUTABLE_2"
84fb49b807 2017-05-28   97:             S_TMP_2="GUID=='104f7072-8a7f-428c-9b5c-315260c151e7'"
20305d1054 2017-05-19   98:         fi
20305d1054 2017-05-19   99:     fi
20305d1054 2017-05-19  100:     #----
20305d1054 2017-05-19  101:     if [ "$SB_THROW" == "f" ] ; then
20305d1054 2017-05-19  102:         S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_3\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`"
20305d1054 2017-05-19  103:         if [ "$S_NAME_OF_THE_EXECUTABLE_3" != "$S_TMP_0" ] ; then
20305d1054 2017-05-19  104:             SB_THROW="t" 
20305d1054 2017-05-19  105:             S_TMP_1="$S_NAME_OF_THE_EXECUTABLE_3"
84fb49b807 2017-05-28  106:             S_TMP_2="GUID=='45cc2181-f51d-41c3-961c-315260c151e7'"
20305d1054 2017-05-19  107:         fi
20305d1054 2017-05-19  108:     fi
20305d1054 2017-05-19  109:     #----
20305d1054 2017-05-19  110:     if [ "$SB_THROW" == "f" ] ; then
20305d1054 2017-05-19  111:         S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_4\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`"
20305d1054 2017-05-19  112:         if [ "$S_NAME_OF_THE_EXECUTABLE_4" != "$S_TMP_0" ] ; then
20305d1054 2017-05-19  113:             SB_THROW="t" 
20305d1054 2017-05-19  114:             S_TMP_1="$S_NAME_OF_THE_EXECUTABLE_4"
84fb49b807 2017-05-28  115:             S_TMP_2="GUID=='4548c1b5-3b70-492d-8c1c-315260c151e7'"
20305d1054 2017-05-19  116:         fi
20305d1054 2017-05-19  117:     fi
20305d1054 2017-05-19  118:     #--------
20305d1054 2017-05-19  119:     if [ "$SB_THROW" == "t" ] ; then
20305d1054 2017-05-19  120:         echo ""
20305d1054 2017-05-19  121:         echo "The Bash function "
20305d1054 2017-05-19  122:         echo ""
20305d1054 2017-05-19  123:         echo "    func_assert_exists_on_path_t2 "
20305d1054 2017-05-19  124:         echo ""
20305d1054 2017-05-19  125:         echo "is not designed to handle an argument value that contains "
20305d1054 2017-05-19  126:         echo "spaces or tabulation characters."
20305d1054 2017-05-19  127:         echo "The unaccepted value in parenthesis:($S_TMP_1)."
20305d1054 2017-05-19  128:         echo "Branch $S_TMP_2."
84fb49b807 2017-05-28  129:         echo "GUID=='4b9bcf11-9ebb-416a-965b-315260c151e7'"
20305d1054 2017-05-19  130:         echo ""
20305d1054 2017-05-19  131:         #----
20305d1054 2017-05-19  132:         cd $S_FP_ORIG
20305d1054 2017-05-19  133:         exit 1 # exit with error
20305d1054 2017-05-19  134:     fi
20305d1054 2017-05-19  135:     SB_THROW="f" # Just a reset, should I forget to reset it later.
20305d1054 2017-05-19  136:     #---------------
20305d1054 2017-05-19  137:     S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_1 2>/dev/null\`"
20305d1054 2017-05-19  138:     local S_TMP_1=""
20305d1054 2017-05-19  139:     local S_TMP_2="S_TMP_1=$S_TMP_0"
20305d1054 2017-05-19  140:     eval ${S_TMP_2}
20305d1054 2017-05-19  141:     #----
20305d1054 2017-05-19  142:     if [ "$S_TMP_1" == "" ] ; then
20305d1054 2017-05-19  143:         if [ "$S_NAME_OF_THE_EXECUTABLE_2" == "" ] ; then
20305d1054 2017-05-19  144:         if [ "$S_NAME_OF_THE_EXECUTABLE_3" == "" ] ; then
20305d1054 2017-05-19  145:         if [ "$S_NAME_OF_THE_EXECUTABLE_4" == "" ] ; then
20305d1054 2017-05-19  146:             echo ""
20305d1054 2017-05-19  147:             echo "This bash script requires the \"$S_NAME_OF_THE_EXECUTABLE_1\" to be on the PATH."
84fb49b807 2017-05-28  148:             echo "GUID=='1200880e-2e2b-4fbd-914b-315260c151e7'"
20305d1054 2017-05-19  149:             echo ""
20305d1054 2017-05-19  150:             #----
20305d1054 2017-05-19  151:             cd $S_FP_ORIG
20305d1054 2017-05-19  152:             exit 1 # exit with error
20305d1054 2017-05-19  153:         fi
20305d1054 2017-05-19  154:         fi
20305d1054 2017-05-19  155:         fi
20305d1054 2017-05-19  156:     else
20305d1054 2017-05-19  157:         return # at least one of the programs was available at the PATH
20305d1054 2017-05-19  158:     fi
20305d1054 2017-05-19  159:     #--------
20305d1054 2017-05-19  160:     S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_2 2>/dev/null\`"
20305d1054 2017-05-19  161:     S_TMP_1=""
20305d1054 2017-05-19  162:     S_TMP_2="S_TMP_1=$S_TMP_0"
20305d1054 2017-05-19  163:     eval ${S_TMP_2}
20305d1054 2017-05-19  164:     #----
20305d1054 2017-05-19  165:     if [ "$S_TMP_1" == "" ] ; then
20305d1054 2017-05-19  166:         if [ "$S_NAME_OF_THE_EXECUTABLE_3" == "" ] ; then
20305d1054 2017-05-19  167:         if [ "$S_NAME_OF_THE_EXECUTABLE_4" == "" ] ; then
20305d1054 2017-05-19  168:             echo ""
20305d1054 2017-05-19  169:             echo "This bash script requires that either \"$S_NAME_OF_THE_EXECUTABLE_1\" or "
20305d1054 2017-05-19  170:             echo " \"$S_NAME_OF_THE_EXECUTABLE_2\" is available on the PATH."
84fb49b807 2017-05-28  171:             echo "GUID=='356c3cc4-53bd-4693-885b-315260c151e7'"
20305d1054 2017-05-19  172:             echo ""
20305d1054 2017-05-19  173:             #----
20305d1054 2017-05-19  174:             cd $S_FP_ORIG
20305d1054 2017-05-19  175:             exit 1 # exit with error
20305d1054 2017-05-19  176:         fi
20305d1054 2017-05-19  177:         fi
20305d1054 2017-05-19  178:     else
20305d1054 2017-05-19  179:         return # at least one of the programs was available at the PATH
20305d1054 2017-05-19  180:     fi
20305d1054 2017-05-19  181:     #--------
20305d1054 2017-05-19  182:     S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_3 2>/dev/null\`"
20305d1054 2017-05-19  183:     S_TMP_1=""
20305d1054 2017-05-19  184:     S_TMP_2="S_TMP_1=$S_TMP_0"
20305d1054 2017-05-19  185:     eval ${S_TMP_2}
20305d1054 2017-05-19  186:     #----
20305d1054 2017-05-19  187:     if [ "$S_TMP_1" == "" ] ; then
20305d1054 2017-05-19  188:         if [ "$S_NAME_OF_THE_EXECUTABLE_4" == "" ] ; then
20305d1054 2017-05-19  189:             echo ""
20305d1054 2017-05-19  190:             echo "This bash script requires that either \"$S_NAME_OF_THE_EXECUTABLE_1\" or "
20305d1054 2017-05-19  191:             echo " \"$S_NAME_OF_THE_EXECUTABLE_2\" or \"$S_NAME_OF_THE_EXECUTABLE_3\" "
20305d1054 2017-05-19  192:             echo "is available on the PATH."
84fb49b807 2017-05-28  193:             echo "GUID=='43dbcd23-3727-452c-b12a-315260c151e7'"
20305d1054 2017-05-19  194:             echo ""
20305d1054 2017-05-19  195:             #----
20305d1054 2017-05-19  196:             cd $S_FP_ORIG
20305d1054 2017-05-19  197:             exit 1 # exit with error
20305d1054 2017-05-19  198:         fi
20305d1054 2017-05-19  199:     else
20305d1054 2017-05-19  200:         return # at least one of the programs was available at the PATH
20305d1054 2017-05-19  201:     fi
20305d1054 2017-05-19  202:     #--------
20305d1054 2017-05-19  203:     S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_4 2>/dev/null\`"
20305d1054 2017-05-19  204:     S_TMP_1=""
20305d1054 2017-05-19  205:     S_TMP_2="S_TMP_1=$S_TMP_0"
20305d1054 2017-05-19  206:     eval ${S_TMP_2}
20305d1054 2017-05-19  207:     #----
20305d1054 2017-05-19  208:     if [ "$S_TMP_1" == "" ] ; then
20305d1054 2017-05-19  209:         echo ""
20305d1054 2017-05-19  210:         echo "This bash script requires that either \"$S_NAME_OF_THE_EXECUTABLE_1\" or "
20305d1054 2017-05-19  211:         echo " \"$S_NAME_OF_THE_EXECUTABLE_2\" or \"$S_NAME_OF_THE_EXECUTABLE_3\" or "
20305d1054 2017-05-19  212:         echo " \"$S_NAME_OF_THE_EXECUTABLE_4\" is available on the PATH."
84fb49b807 2017-05-28  213:         echo "GUID=='23ce69f3-8728-4a03-9f4a-315260c151e7'"
20305d1054 2017-05-19  214:         echo ""
20305d1054 2017-05-19  215:         #----
20305d1054 2017-05-19  216:         cd $S_FP_ORIG
20305d1054 2017-05-19  217:         exit 1 # exit with error
20305d1054 2017-05-19  218:     else
20305d1054 2017-05-19  219:         return # at least one of the programs was available at the PATH
20305d1054 2017-05-19  220:     fi
20305d1054 2017-05-19  221:     #--------
20305d1054 2017-05-19  222: } # func_assert_exists_on_path_t2
20305d1054 2017-05-19  223: 
20305d1054 2017-05-19  224: 
20305d1054 2017-05-19  225: func_assert_exists_on_path_t2 "cat"
20305d1054 2017-05-19  226: func_assert_exists_on_path_t2 "file"                 # for checking MIME types
20305d1054 2017-05-19  227: func_assert_exists_on_path_t2 "find"                 # for recursing
20305d1054 2017-05-19  228: func_assert_exists_on_path_t2 "fossil"               # tested with v1.34
20305d1054 2017-05-19  229: func_assert_exists_on_path_t2 "gawk"
20305d1054 2017-05-19  230: func_assert_exists_on_path_t2 "grep"
20305d1054 2017-05-19  231: func_assert_exists_on_path_t2 "nice"
20305d1054 2017-05-19  232: func_assert_exists_on_path_t2 "ruby"                 # anything over/equal v.2.1 will probably do
20305d1054 2017-05-19  233: func_assert_exists_on_path_t2 "shred" "gshred" "rm"  # for shredding, if possible
20305d1054 2017-05-19  234: func_assert_exists_on_path_t2 "uname"                # to check the OS type
20305d1054 2017-05-19  235: func_assert_exists_on_path_t2 "uuidgen" "uuid"       # for generating tmp file names
20305d1054 2017-05-19  236: func_assert_exists_on_path_t2 "xargs"                # find . -name '*' | xargs blabla
20305d1054 2017-05-19  237: func_assert_exists_on_path_t2 "wc"  
20305d1054 2017-05-19  238: 
20305d1054 2017-05-19  239: 
20305d1054 2017-05-19  240: #--------------------------------------------------------------------------
20305d1054 2017-05-19  241: 
20305d1054 2017-05-19  242: S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT=""
20305d1054 2017-05-19  243: func_mmmv_operating_system_type_t1() {
20305d1054 2017-05-19  244:     if [ "$S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT" == "" ]; then
20305d1054 2017-05-19  245:         S_TMP_0="`uname -a | grep -E [Ll]inux`"
20305d1054 2017-05-19  246:         if [ "$S_TMP_0" != "" ]; then
20305d1054 2017-05-19  247:             S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT="Linux"
20305d1054 2017-05-19  248:         else
20305d1054 2017-05-19  249:             S_TMP_0="`uname -a | grep BSD `"
20305d1054 2017-05-19  250:             if [ "$S_TMP_0" != "" ]; then
20305d1054 2017-05-19  251:                 S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT="BSD"
20305d1054 2017-05-19  252:             else
20305d1054 2017-05-19  253:                 S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT="undetermined"
20305d1054 2017-05-19  254:             fi
20305d1054 2017-05-19  255:         fi
20305d1054 2017-05-19  256:     fi
20305d1054 2017-05-19  257: } # func_mmmv_operating_system_type_t1
20305d1054 2017-05-19  258: 
20305d1054 2017-05-19  259: func_mmmv_operating_system_type_t1
20305d1054 2017-05-19  260: 
20305d1054 2017-05-19  261: if [ "$S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT" != "Linux" ]; then
20305d1054 2017-05-19  262:     if [ "$S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT" != "BSD" ]; then
20305d1054 2017-05-19  263:         echo ""
20305d1054 2017-05-19  264:         echo "  The classical command line utilities at "
20305d1054 2017-05-19  265:         echo "  different operating systems, for example, Linux and BSD,"
20305d1054 2017-05-19  266:         echo "  differ. This script is designed to run only on "
20305d1054 2017-05-19  267:         echo "  Linux and some BSD variants."
20305d1054 2017-05-19  268:         echo "  If You are willing to risk that some of Your data "
20305d1054 2017-05-19  269:         echo "  is deleted and/or Your operating system instance"
20305d1054 2017-05-19  270:         echo "  becomes permanently flawed, to the point that "
20305d1054 2017-05-19  271:         echo "  it will not even boot, then You may edit the Bash script that "
20305d1054 2017-05-19  272:         echo "  displays this error message by modifying the test that "
20305d1054 2017-05-19  273:         echo "  checks for the operating system type."
20305d1054 2017-05-19  274:         echo ""
20305d1054 2017-05-19  275:         echo "  If You do decide to edit this Bash script, then "
20305d1054 2017-05-19  276:         echo "  a recommendation is to test Your modifications "
20305d1054 2017-05-19  277:         echo "  within a virtual machine or, if virtual machines are not"
20305d1054 2017-05-19  278:         echo "  an option, as some new operating system user that does not have "
20305d1054 2017-05-19  279:         echo "  any access to the vital data/files."
84fb49b807 2017-05-28  280:         echo "  GUID=='257de2a5-27c3-44d3-89ea-315260c151e7'"
20305d1054 2017-05-19  281:         echo ""
20305d1054 2017-05-19  282:         echo "  Aborting script without doing anything."
20305d1054 2017-05-19  283:         echo ""
20305d1054 2017-05-19  284:         exit 1 # exit with error
20305d1054 2017-05-19  285:     fi
20305d1054 2017-05-19  286: fi
20305d1054 2017-05-19  287: 
20305d1054 2017-05-19  288: 
20305d1054 2017-05-19  289: #--------------------------------------------------------------------------
20305d1054 2017-05-19  290: 
20305d1054 2017-05-19  291: SB_EXISTS_ON_PATH_T1_RESULT="f"
20305d1054 2017-05-19  292: func_sb_exists_on_path_t1 () {
20305d1054 2017-05-19  293:     local S_NAME_OF_THE_EXECUTABLE_1="$1" # first function argument
20305d1054 2017-05-19  294:     #--------
20305d1054 2017-05-19  295:     # Function calls like
20305d1054 2017-05-19  296:     #
20305d1054 2017-05-19  297:     #     func_sb_exists_on_path_t1 ""
20305d1054 2017-05-19  298:     #     func_sb_exists_on_path_t1 " "
20305d1054 2017-05-19  299:     #     func_sb_exists_on_path_t1 "ls ps" # contains a space
20305d1054 2017-05-19  300:     #
20305d1054 2017-05-19  301:     # are not allowed.
20305d1054 2017-05-19  302:     if [ "$S_NAME_OF_THE_EXECUTABLE_1" == "" ] ; then
20305d1054 2017-05-19  303:         echo ""
20305d1054 2017-05-19  304:         echo "The Bash function "
20305d1054 2017-05-19  305:         echo ""
20305d1054 2017-05-19  306:         echo "    func_sb_exists_on_path_t1 "
20305d1054 2017-05-19  307:         echo ""
20305d1054 2017-05-19  308:         echo "is not designed to handle an argument that "
20305d1054 2017-05-19  309:         echo "equals with an empty string."
84fb49b807 2017-05-28  310:         echo "GUID=='53c2aa04-0a0a-454e-9619-315260c151e7'"
20305d1054 2017-05-19  311:         echo ""
20305d1054 2017-05-19  312:         #----
20305d1054 2017-05-19  313:         cd $S_FP_ORIG
20305d1054 2017-05-19  314:         exit 1 # exit with error
20305d1054 2017-05-19  315:     fi
20305d1054 2017-05-19  316:     local S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_1\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`"
20305d1054 2017-05-19  317:     if [ "$S_NAME_OF_THE_EXECUTABLE_1" != "$S_TMP_0" ] ; then
20305d1054 2017-05-19  318:         echo ""
20305d1054 2017-05-19  319:         echo "The Bash function "
20305d1054 2017-05-19  320:         echo ""
20305d1054 2017-05-19  321:         echo "    func_sb_exists_on_path_t1 "
20305d1054 2017-05-19  322:         echo ""
20305d1054 2017-05-19  323:         echo "is not designed to handle an argument value that contains "
20305d1054 2017-05-19  324:         echo "spaces or tabulation characters."
20305d1054 2017-05-19  325:         echo "The received value in parenthesis:($S_NAME_OF_THE_EXECUTABLE_1)."
84fb49b807 2017-05-28  326:         echo "GUID=='55a67d13-2cc0-41fc-bb59-315260c151e7'"
20305d1054 2017-05-19  327:         echo ""
20305d1054 2017-05-19  328:         #----
20305d1054 2017-05-19  329:         cd $S_FP_ORIG
20305d1054 2017-05-19  330:         exit 1 # exit with error
20305d1054 2017-05-19  331:     fi
20305d1054 2017-05-19  332:     #--------
20305d1054 2017-05-19  333:     S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_1 2>/dev/null\`"
20305d1054 2017-05-19  334:     local S_TMP_1=""
20305d1054 2017-05-19  335:     local S_TMP_2="S_TMP_1=$S_TMP_0"
20305d1054 2017-05-19  336:     eval ${S_TMP_2}
20305d1054 2017-05-19  337:     #----
20305d1054 2017-05-19  338:     if [ "$S_TMP_1" == "" ] ; then
20305d1054 2017-05-19  339:         SB_EXISTS_ON_PATH_T1_RESULT="f"
20305d1054 2017-05-19  340:     else
20305d1054 2017-05-19  341:         SB_EXISTS_ON_PATH_T1_RESULT="t"
20305d1054 2017-05-19  342:     fi
20305d1054 2017-05-19  343: } # func_sb_exists_on_path_t1 
20305d1054 2017-05-19  344: 
20305d1054 2017-05-19  345: 
20305d1054 2017-05-19  346: #--------------------------------------------------------------------------
20305d1054 2017-05-19  347: 
20305d1054 2017-05-19  348: S_FUNC_MMMV_GUID_T1_RESULT="not_yet_set"
20305d1054 2017-05-19  349: S_FUNC_MMMV_GUID_T1_MODE="" # optim. to skip repeating console tool selection
20305d1054 2017-05-19  350: func_mmmv_GUID_t1() {
20305d1054 2017-05-19  351:     # Does not take any arguments.
20305d1054 2017-05-19  352:     #--------
20305d1054 2017-05-19  353:     #func_mmmv_exc_hash_function_input_verification_t1 "func_mmmv_GUID_t1" "$1"
20305d1054 2017-05-19  354:     #--------------------
20305d1054 2017-05-19  355:     local S_TMP_0="" # declaration
20305d1054 2017-05-19  356:     local S_TMP_1="" # declaration
20305d1054 2017-05-19  357:     # Mode selection:
20305d1054 2017-05-19  358:     if [ "$S_FUNC_MMMV_GUID_T1_MODE" == "" ] ; then
20305d1054 2017-05-19  359:         SB_EXISTS_ON_PATH_T1_RESULT="f"  # if-block init
20305d1054 2017-05-19  360:         #----
20305d1054 2017-05-19  361:         if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then
20305d1054 2017-05-19  362:             S_TMP_0="uuidgen" # Linux version
20305d1054 2017-05-19  363:             func_sb_exists_on_path_t1 "$S_TMP_0" 
20305d1054 2017-05-19  364:             if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then
20305d1054 2017-05-19  365:                  S_FUNC_MMMV_GUID_T1_MODE="$S_TMP_0"
20305d1054 2017-05-19  366:             fi
20305d1054 2017-05-19  367:         fi
20305d1054 2017-05-19  368:         #----
20305d1054 2017-05-19  369:         if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then
20305d1054 2017-05-19  370:             S_TMP_0="uuid"    # BSD version
20305d1054 2017-05-19  371:             func_sb_exists_on_path_t1 "$S_TMP_0" 
20305d1054 2017-05-19  372:             if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then
20305d1054 2017-05-19  373:                  S_FUNC_MMMV_GUID_T1_MODE="$S_TMP_0"
20305d1054 2017-05-19  374:             fi
20305d1054 2017-05-19  375:         fi
20305d1054 2017-05-19  376:         #--------
20305d1054 2017-05-19  377:         if [ "$S_FUNC_MMMV_GUID_T1_MODE" == "" ] ; then
20305d1054 2017-05-19  378:             echo ""
20305d1054 2017-05-19  379:             echo "All of the GUID generation implementations that this script " 
20305d1054 2017-05-19  380:             echo "is capable of using (uuidgen, uuid) "
20305d1054 2017-05-19  381:             echo "are missing from the PATH."
84fb49b807 2017-05-28  382:             echo "GUID=='1b0bea75-1ea7-454a-bf19-315260c151e7'"
20305d1054 2017-05-19  383:             echo ""
20305d1054 2017-05-19  384:             #----
20305d1054 2017-05-19  385:             cd $S_FP_ORIG
20305d1054 2017-05-19  386:             exit 1 # exit with error
20305d1054 2017-05-19  387:         fi
20305d1054 2017-05-19  388:         #--------
20305d1054 2017-05-19  389:         if [ "$?" != "0" ]; then
20305d1054 2017-05-19  390:             echo ""
20305d1054 2017-05-19  391:             echo "This script is flawed."
84fb49b807 2017-05-28  392:             echo "GUID=='1540e462-2735-47b9-8158-315260c151e7'"
20305d1054 2017-05-19  393:             echo ""
20305d1054 2017-05-19  394:             #----
20305d1054 2017-05-19  395:             cd $S_FP_ORIG
20305d1054 2017-05-19  396:             exit 1 # exit with error
20305d1054 2017-05-19  397:         fi
20305d1054 2017-05-19  398:         #--------
20305d1054 2017-05-19  399:     fi
20305d1054 2017-05-19  400:     #--------------------
20305d1054 2017-05-19  401:     S_FUNC_MMMV_GUID_T1_RESULT=""
20305d1054 2017-05-19  402:     #--------------------
20305d1054 2017-05-19  403:     if [ "$S_FUNC_MMMV_GUID_T1_MODE" == "uuidgen" ]; then
20305d1054 2017-05-19  404:         S_TMP_0="`uuidgen`"
20305d1054 2017-05-19  405:         if [ "$?" != "0" ]; then
20305d1054 2017-05-19  406:             echo ""
20305d1054 2017-05-19  407:             echo "The console application \"uuidgen\" "
20305d1054 2017-05-19  408:             echo "exited with an error."
20305d1054 2017-05-19  409:             echo ""
20305d1054 2017-05-19  410:             echo "----console--output--citation--start-----"
20305d1054 2017-05-19  411:             echo "`uuidgen`" # stdout and stderr
20305d1054 2017-05-19  412:             echo "----console--output--citation--end-------"
20305d1054 2017-05-19  413:             echo ""
84fb49b807 2017-05-28  414:             echo "GUID=='2580f6e5-20cf-4628-9548-315260c151e7'"
20305d1054 2017-05-19  415:             echo ""
20305d1054 2017-05-19  416:             #----
20305d1054 2017-05-19  417:             cd $S_FP_ORIG
20305d1054 2017-05-19  418:             exit 1 # exit with error
20305d1054 2017-05-19  419:         fi
20305d1054 2017-05-19  420:         #---- 
20305d1054 2017-05-19  421:         S_FUNC_MMMV_GUID_T1_RESULT="$S_TMP_0"
20305d1054 2017-05-19  422:     fi
20305d1054 2017-05-19  423:     #--------------------
20305d1054 2017-05-19  424:     if [ "$S_FUNC_MMMV_GUID_T1_MODE" == "uuid" ]; then
20305d1054 2017-05-19  425:         S_TMP_0="`uuid`"
20305d1054 2017-05-19  426:         if [ "$?" != "0" ]; then
20305d1054 2017-05-19  427:             echo ""
20305d1054 2017-05-19  428:             echo "The console application \"uuid\" "
20305d1054 2017-05-19  429:             echo "exited with an error."
20305d1054 2017-05-19  430:             echo ""
20305d1054 2017-05-19  431:             echo "----console--output--citation--start-----"
20305d1054 2017-05-19  432:             echo "`uuid`" # stdout and stderr
20305d1054 2017-05-19  433:             echo "----console--output--citation--end-------"
20305d1054 2017-05-19  434:             echo ""
84fb49b807 2017-05-28  435:             echo "GUID=='71ef5836-48f2-46c2-9b58-315260c151e7'"
20305d1054 2017-05-19  436:             echo ""
20305d1054 2017-05-19  437:             #----
20305d1054 2017-05-19  438:             cd $S_FP_ORIG
20305d1054 2017-05-19  439:             exit 1 # exit with error
20305d1054 2017-05-19  440:         fi
20305d1054 2017-05-19  441:         #---- 
20305d1054 2017-05-19  442:         S_FUNC_MMMV_GUID_T1_RESULT="$S_TMP_0"
20305d1054 2017-05-19  443:     fi
20305d1054 2017-05-19  444:     #--------------------
20305d1054 2017-05-19  445:     S_TMP_0="`printf \"$S_FUNC_MMMV_GUID_T1_RESULT\" | wc -m | gawk '{gsub(/\s/,"");printf "%s", $1 }'`"
20305d1054 2017-05-19  446:     S_TMP_1="36"
20305d1054 2017-05-19  447:     if [ "$S_TMP_0" != "$S_TMP_1" ]; then
20305d1054 2017-05-19  448:         echo ""
20305d1054 2017-05-19  449:         echo "According to the GUID specification, IETF RFC 4122,  "
20305d1054 2017-05-19  450:         echo "the lenght of the GUID is "
20305d1054 2017-05-19  451:         echo "$S_TMP_1 characters, but the result of the "
20305d1054 2017-05-19  452:         echo ""
20305d1054 2017-05-19  453:         echo "    func_mmmv_GUID_t1"
20305d1054 2017-05-19  454:         echo ""
20305d1054 2017-05-19  455:         echo "is something else. The flawed GUID candidate in parenthesis:"
20305d1054 2017-05-19  456:         echo "($S_FUNC_MMMV_GUID_T1_RESULT)"
20305d1054 2017-05-19  457:         echo ""
20305d1054 2017-05-19  458:         echo "The lenght candidate of the flawed GUID candidate in parenthesis:"
20305d1054 2017-05-19  459:         echo "($S_TMP_0)."
20305d1054 2017-05-19  460:         echo ""
84fb49b807 2017-05-28  461:         echo "GUID=='1efe2883-5155-4205-8918-315260c151e7'"
20305d1054 2017-05-19  462:         echo ""
20305d1054 2017-05-19  463:         #----
20305d1054 2017-05-19  464:         cd $S_FP_ORIG
20305d1054 2017-05-19  465:         exit 1 # exit with error
20305d1054 2017-05-19  466:     fi
20305d1054 2017-05-19  467:     #--------------------
20305d1054 2017-05-19  468: } # func_mmmv_GUID_t1
20305d1054 2017-05-19  469: 
20305d1054 2017-05-19  470: 
20305d1054 2017-05-19  471: #--------------------------------------------------------------------------
20305d1054 2017-05-19  472: 
20305d1054 2017-05-19  473: S_FUNC_MMMV_SHRED_T1_MODE="" # optim. to skip repeating console tool selection
20305d1054 2017-05-19  474: func_mmmv_shred_t1() {
20305d1054 2017-05-19  475:     local S_FP_IN="$1" # path to the file or folder to be shredded
20305d1054 2017-05-19  476:     # The next input parameter is a shoddy compromise,
20305d1054 2017-05-19  477:     # for the case, where shred/gshred is not installed:
20305d1054 2017-05-19  478:     local SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE="$2"  # domain: {"","f","t"}
20305d1054 2017-05-19  479:     #--------------------
20305d1054 2017-05-19  480:     if [ "$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE" != "" ] ; then
20305d1054 2017-05-19  481:         if [ "$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE" != "t" ] ; then
20305d1054 2017-05-19  482:             if [ "$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE" != "f" ] ; then
20305d1054 2017-05-19  483:                 echo ""
20305d1054 2017-05-19  484:                 echo "The second parameter of this function, the "
20305d1054 2017-05-19  485:                 echo ""
20305d1054 2017-05-19  486:                 echo "    SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE(==$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE)"
20305d1054 2017-05-19  487:                 echo ""
20305d1054 2017-05-19  488:                 echo "is optional, but its range is {\"\",\"f\",\"t\"},"
20305d1054 2017-05-19  489:                 echo "without the quotation marks."
84fb49b807 2017-05-28  490:                 echo "GUID=='1dd918b4-33fd-4416-8248-315260c151e7'"
20305d1054 2017-05-19  491:                 echo ""
20305d1054 2017-05-19  492:                 #----
20305d1054 2017-05-19  493:                 cd $S_FP_ORIG
20305d1054 2017-05-19  494:                 exit 1 # exit with error
20305d1054 2017-05-19  495:             fi
20305d1054 2017-05-19  496:         fi
20305d1054 2017-05-19  497:     else # $SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE == ""
20305d1054 2017-05-19  498:         SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE="f"
20305d1054 2017-05-19  499:     fi
20305d1054 2017-05-19  500:     #--------------------
20305d1054 2017-05-19  501:     # Declarations:
20305d1054 2017-05-19  502:     local SB_THROW=""
20305d1054 2017-05-19  503:     local SB_USE_RUBY=""
20305d1054 2017-05-19  504:     local S_CMD=""
20305d1054 2017-05-19  505:     local S_GUID=""
20305d1054 2017-05-19  506:     local S_TMP_0=""
20305d1054 2017-05-19  507:     local S_TMP_1=""
20305d1054 2017-05-19  508:     local S_TMP_2=""
20305d1054 2017-05-19  509:     local SI_0="-9999"
20305d1054 2017-05-19  510:     local SI_1="-9999"
20305d1054 2017-05-19  511:     local S_SHREDDER_APPLICATION_NAME=""
20305d1054 2017-05-19  512:     local S_FP_PWD_BEFORE_SHREDDING=""
20305d1054 2017-05-19  513:     #--------------------
20305d1054 2017-05-19  514:     # Mode selection:
20305d1054 2017-05-19  515:     if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "" ] ; then
20305d1054 2017-05-19  516:         SB_EXISTS_ON_PATH_T1_RESULT="f"  # if-block init
20305d1054 2017-05-19  517:         #----
20305d1054 2017-05-19  518:         if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then
20305d1054 2017-05-19  519:             S_TMP_0="shred" # Linux version
20305d1054 2017-05-19  520:             func_sb_exists_on_path_t1 "$S_TMP_0" 
20305d1054 2017-05-19  521:             if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then
20305d1054 2017-05-19  522:                  S_FUNC_MMMV_SHRED_T1_MODE="$S_TMP_0"
20305d1054 2017-05-19  523:             fi
20305d1054 2017-05-19  524:         fi
20305d1054 2017-05-19  525:         #----
20305d1054 2017-05-19  526:         if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then
20305d1054 2017-05-19  527:             S_TMP_0="gshred" # BSD version
20305d1054 2017-05-19  528:             func_sb_exists_on_path_t1 "$S_TMP_0" 
20305d1054 2017-05-19  529:             if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then
20305d1054 2017-05-19  530:                  S_FUNC_MMMV_SHRED_T1_MODE="$S_TMP_0"
20305d1054 2017-05-19  531:             fi
20305d1054 2017-05-19  532:         fi
20305d1054 2017-05-19  533:         #----
20305d1054 2017-05-19  534:         if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then
20305d1054 2017-05-19  535:             if [ "$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE" == "t" ] ; then
20305d1054 2017-05-19  536:                 S_TMP_0="rm" # a shoddy compromise version for exeptional cases
20305d1054 2017-05-19  537:                 func_sb_exists_on_path_t1 "$S_TMP_0" 
20305d1054 2017-05-19  538:                 if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then
20305d1054 2017-05-19  539:                     func_mmmv_operating_system_type_t1
20305d1054 2017-05-19  540:                     if [ "$S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT" != "BSD" ]; then
20305d1054 2017-05-19  541:                          S_FUNC_MMMV_SHRED_T1_MODE="rm_BSD"
20305d1054 2017-05-19  542:                     else # Linux and all the rest
20305d1054 2017-05-19  543:                          S_FUNC_MMMV_SHRED_T1_MODE="rm_plain"
20305d1054 2017-05-19  544:                     fi
20305d1054 2017-05-19  545:                 else
20305d1054 2017-05-19  546:                     echo ""
20305d1054 2017-05-19  547:                     echo "Something is wrong at the operating system "
20305d1054 2017-05-19  548:                     echo "environment setup. All UNIX-like operating systems "
20305d1054 2017-05-19  549:                     echo "and their emulators "
20305d1054 2017-05-19  550:                     echo "are expected to have the \"rm\" command."
20305d1054 2017-05-19  551:                     echo ""
20305d1054 2017-05-19  552:                     echo "    \$(which rm)==\"`which rm`\""
20305d1054 2017-05-19  553:                     echo ""
20305d1054 2017-05-19  554:                     echo "    PATH=$PATH" # will be a huge string
20305d1054 2017-05-19  555:                     echo ""
84fb49b807 2017-05-28  556:                     echo "GUID=='51771253-a74c-4c80-9b27-315260c151e7'"
20305d1054 2017-05-19  557:                     echo ""
20305d1054 2017-05-19  558:                     #----
20305d1054 2017-05-19  559:                     cd $S_FP_ORIG
20305d1054 2017-05-19  560:                     exit 1 # exit with error
20305d1054 2017-05-19  561:                 fi
20305d1054 2017-05-19  562:             fi
20305d1054 2017-05-19  563:         fi
20305d1054 2017-05-19  564:         #--------
20305d1054 2017-05-19  565:         if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "" ] ; then
20305d1054 2017-05-19  566:             echo ""
20305d1054 2017-05-19  567:             echo "All of the file shredding implementations that this script " 
20305d1054 2017-05-19  568:             echo "is capable of using (shred, gshred) "
20305d1054 2017-05-19  569:             echo "are missing from the PATH."
84fb49b807 2017-05-28  570:             echo "GUID=='26738452-9afc-4d5d-ac57-315260c151e7'"
20305d1054 2017-05-19  571:             echo ""
20305d1054 2017-05-19  572:             #----
20305d1054 2017-05-19  573:             cd $S_FP_ORIG
20305d1054 2017-05-19  574:             exit 1 # exit with error
20305d1054 2017-05-19  575:         fi
20305d1054 2017-05-19  576:         #--------
20305d1054 2017-05-19  577:         if [ "$?" != "0" ]; then
20305d1054 2017-05-19  578:             echo ""
20305d1054 2017-05-19  579:             echo "This script is flawed."
84fb49b807 2017-05-28  580:             echo "GUID=='39510271-d87c-4f0f-a217-315260c151e7'"
20305d1054 2017-05-19  581:             echo ""
20305d1054 2017-05-19  582:             #----
20305d1054 2017-05-19  583:             cd $S_FP_ORIG
20305d1054 2017-05-19  584:             exit 1 # exit with error
20305d1054 2017-05-19  585:         fi
20305d1054 2017-05-19  586:         #--------
20305d1054 2017-05-19  587:     fi
20305d1054 2017-05-19  588:     #--------------------
20305d1054 2017-05-19  589:     S_TMP_0=$(echo $S_FP_IN | gawk '{gsub(/^[\/]/,""); printf "%s",$1 }')
20305d1054 2017-05-19  590:     if [ "$S_TMP_0" == "$S_FP_IN" ]; then
20305d1054 2017-05-19  591:         echo "" 
20305d1054 2017-05-19  592:         echo "The path is expected to be an absolute path, "
20305d1054 2017-05-19  593:         echo "but currently it is not."
20305d1054 2017-05-19  594:         echo "    S_FP_IN==$S_FP_IN"
84fb49b807 2017-05-28  595:         echo "GUID=='5080ee14-8650-48f9-9c17-315260c151e7'"
20305d1054 2017-05-19  596:         echo ""
20305d1054 2017-05-19  597:         #----
20305d1054 2017-05-19  598:         cd $S_FP_ORIG
20305d1054 2017-05-19  599:         exit 1 # exit with an error
20305d1054 2017-05-19  600:     fi
20305d1054 2017-05-19  601:     #--------
20305d1054 2017-05-19  602:     if [ -h $S_FP_IN ]; then 
20305d1054 2017-05-19  603:         # The control flow is in here regardless of
20305d1054 2017-05-19  604:         # whether the symbolic link is broken or not.
20305d1054 2017-05-19  605:         # If the path is to a non-existing file/link/folder,
20305d1054 2017-05-19  606:         # then the control flow will not enter this branch.
20305d1054 2017-05-19  607:         echo ""
20305d1054 2017-05-19  608:         echo "The "
20305d1054 2017-05-19  609:         echo "    S_FP_IN=$S_FP_IN"
20305d1054 2017-05-19  610:         echo "is a symbolic link, but it is expected to "
20305d1054 2017-05-19  611:         echo "be a file or a folder."
84fb49b807 2017-05-28  612:         echo "GUID=='a3eee10a-37e6-45df-b537-315260c151e7'"
20305d1054 2017-05-19  613:         echo ""
20305d1054 2017-05-19  614:         #----
20305d1054 2017-05-19  615:         cd $S_FP_ORIG
20305d1054 2017-05-19  616:         exit 1 # exit with error
20305d1054 2017-05-19  617:     fi
20305d1054 2017-05-19  618:     if [ ! -e $S_FP_IN ]; then
20305d1054 2017-05-19  619:         echo ""
20305d1054 2017-05-19  620:         echo "The "
20305d1054 2017-05-19  621:         echo "    S_FP_IN=$S_FP_IN"
20305d1054 2017-05-19  622:         echo "does not exist."
84fb49b807 2017-05-28  623:         echo "GUID=='3ba79164-e942-4850-b427-315260c151e7'"
20305d1054 2017-05-19  624:         echo ""
20305d1054 2017-05-19  625:         #----
20305d1054 2017-05-19  626:         cd $S_FP_ORIG
20305d1054 2017-05-19  627:         exit 1 # exit with error
20305d1054 2017-05-19  628:     fi
20305d1054 2017-05-19  629:     #--------
20305d1054 2017-05-19  630:     if [ -d $S_FP_IN ]; then
20305d1054 2017-05-19  631:         #--------start--of--sub-path--check----
20305d1054 2017-05-19  632:         # If the $S_FP_IN is a folder, then the `pwd` 
20305d1054 2017-05-19  633:         # should not be a sub-path or a path of the 
20305d1054 2017-05-19  634:         # folder that is being deleted.
20305d1054 2017-05-19  635:         S_TMP_0="`cd $S_FP_IN;pwd`/"  
20305d1054 2017-05-19  636:         S_TMP_1="`pwd`/"
20305d1054 2017-05-19  637:         #----
20305d1054 2017-05-19  638:         if [ "$S_TMP_0" == "$S_TMP_1" ]; then
20305d1054 2017-05-19  639:             if [ ! -d $S_FP_IN ]; then
20305d1054 2017-05-19  640:                 echo ""
20305d1054 2017-05-19  641:                 echo "This Bash script is flawed. "
20305d1054 2017-05-19  642:                 echo "    S_FP_IN=$S_FP_IN"
84fb49b807 2017-05-28  643:                 echo "GUID=='21375937-9ca7-4339-8726-315260c151e7'"
20305d1054 2017-05-19  644:                 echo ""
20305d1054 2017-05-19  645:                 #----
20305d1054 2017-05-19  646:                 cd $S_FP_ORIG
20305d1054 2017-05-19  647:                 exit 1
20305d1054 2017-05-19  648:             fi
20305d1054 2017-05-19  649:             #----
20305d1054 2017-05-19  650:             echo ""
20305d1054 2017-05-19  651:             echo "The working directory, "
20305d1054 2017-05-19  652:             echo ""
20305d1054 2017-05-19  653:             echo "    PWD=$PWD"
20305d1054 2017-05-19  654:             echo ""
20305d1054 2017-05-19  655:             echo "equals with the folder that is being deleted."
20305d1054 2017-05-19  656:             echo ""
20305d1054 2017-05-19  657:             echo "    S_TMP_0=$S_TMP_0"
20305d1054 2017-05-19  658:             echo ""
20305d1054 2017-05-19  659:             echo "    S_FP_IN=$S_FP_IN"
20305d1054 2017-05-19  660:             echo ""
84fb49b807 2017-05-28  661:             echo "GUID=='3dc24783-ce23-4efe-ac56-315260c151e7'"
20305d1054 2017-05-19  662:             echo ""
20305d1054 2017-05-19  663:             #----
20305d1054 2017-05-19  664:             cd $S_FP_ORIG
20305d1054 2017-05-19  665:             exit 1 # exit with error
20305d1054 2017-05-19  666:         fi
20305d1054 2017-05-19  667:         #----
20305d1054 2017-05-19  668:         # If the normalized $S_FP_IN is a folder and 
20305d1054 2017-05-19  669:         # the "`pwd`/" is shorter than the normalized $S_FP_IN, then,
20305d1054 2017-05-19  670:         # with the exceptions of some symbolic links, 
20305d1054 2017-05-19  671:         # the "`pwd`/" can not be equal to the normalized $S_FP_IN, 
20305d1054 2017-05-19  672:         # nor can the "`pwd`/" be a folder that is a sub-folder 
20305d1054 2017-05-19  673:         # of the $S_FP_IN.
20305d1054 2017-05-19  674:         # 
20305d1054 2017-05-19  675:         # The paht lenght code is:
20305d1054 2017-05-19  676:         # 
20305d1054 2017-05-19  677:         #     SI_0="` echo \"$S_TMP_0\" | gawk '{i=length;printf "%s", i }' `" # S_FP_IN
20305d1054 2017-05-19  678:         #     SI_1="` echo \"$S_TMP_1\" | gawk '{i=length;printf "%s", i }' `" # pwd
20305d1054 2017-05-19  679:         #     if [ "$SI_0" -lt "$SI_1" ]; then  # $SI_0 < $SI_1
20305d1054 2017-05-19  680:         #        #echo "$SI_0 < $SI_1"
20305d1054 2017-05-19  681:         #        #
20305d1054 2017-05-19  682:         #        # In here the length of the normalized form of the $S_FP_IN
20305d1054 2017-05-19  683:         #        # is shorter than the "`pwd`/" and therefore the working directory
20305d1054 2017-05-19  684:         #        # has a greater probability to be at a sub-path of the $S_FP_IN.
20305d1054 2017-05-19  685:         #        
20305d1054 2017-05-19  686:         #        <
20305d1054 2017-05-19  687:         #         A lot of Ruby code, because 
20305d1054 2017-05-19  688:         #         the gawk code will have trouble with folders that 
20305d1054 2017-05-19  689:         #         contain spaces and other special characters
20305d1054 2017-05-19  690:         #         >
20305d1054 2017-05-19  691:         #    fi
20305d1054 2017-05-19  692:         #
20305d1054 2017-05-19  693:         # but unfortunately the Ruby code that uses 
20305d1054 2017-05-19  694:         # temporary files and the String.index would be 
20305d1054 2017-05-19  695:         # unstable due to the 
20305d1054 2017-05-19  696:         #
20305d1054 2017-05-19  697:         #     https://bugs.ruby-lang.org/issues/12710
20305d1054 2017-05-19  698:         #     https://archive.is/AJpgL
20305d1054 2017-05-19  699:         # 
20305d1054 2017-05-19  700:         # Add to that the fact that this Bash function
20305d1054 2017-05-19  701:         # would be much more appealing, if it did not launch
20305d1054 2017-05-19  702:         # any 40BiB sized interpreters like the Ruby interpreter (in 2016)
20305d1054 2017-05-19  703:         # and the temptation to just skip testing, whether the 
20305d1054 2017-05-19  704:         # working directory (`pwd`) resides at a directory that
20305d1054 2017-05-19  705:         # is a sub-path of the $S_FP_IN, grows even higher.
20305d1054 2017-05-19  706:         # So, for the time being that check is omitted from here. 
20305d1054 2017-05-19  707:         #
20305d1054 2017-05-19  708:         # TODO: If the year is at least 2020, then try to find out, 
20305d1054 2017-05-19  709:         #       whether there's some elegant way to implement that check.
20305d1054 2017-05-19  710:         #
20305d1054 2017-05-19  711:         # A code fragment for later consideration:
20305d1054 2017-05-19  712:         #     S_TMP_2="`echo \"$S_TMP_0\" | gawk '{gsub(/\s/,\"NotASpace\");printf \"%s\", \$1 }' `"
20305d1054 2017-05-19  713:         #     if [ "$S_TMP_2" != "$S_TMP_0" ]; then
20305d1054 2017-05-19  714:         #         # S_TMP_0 contains strings
20305d1054 2017-05-19  715:         #         SB_USE_RUBY="t"
20305d1054 2017-05-19  716:         #     fi
20305d1054 2017-05-19  717:         #--------end--of--sub-path--check----
20305d1054 2017-05-19  718:     fi
20305d1054 2017-05-19  719:     #--------------------
20305d1054 2017-05-19  720:     S_FP_PWD_BEFORE_SHREDDING="`pwd`"
20305d1054 2017-05-19  721:     S_CMD="" # to be sure
20305d1054 2017-05-19  722:     #--------------------
20305d1054 2017-05-19  723:     S_TMP_0="cd $S_FP_IN ; nice -n10 find . -name '*' | nice -n10 xargs "
20305d1054 2017-05-19  724:     # The space after the "cd $S_FP_IN" and before the ";" is compulsory.
20305d1054 2017-05-19  725:     #----
20305d1054 2017-05-19  726:     # The "2>/dev/null" after the shredding/deletion command
20305d1054 2017-05-19  727:     # is to hide the file permissions related error messages.
20305d1054 2017-05-19  728:     # The failure is detected by studying file existence.
20305d1054 2017-05-19  729:     #--------------------
20305d1054 2017-05-19  730:     if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "shred" ]; then
20305d1054 2017-05-19  731:         S_SHREDDER_APPLICATION_NAME="shred"
20305d1054 2017-05-19  732:         if [ -d $S_FP_IN ]; then
20305d1054 2017-05-19  733:             S_CMD="$S_TMP_0 \
20305d1054 2017-05-19  734:                    $S_SHREDDER_APPLICATION_NAME -f --remove 2>/dev/null "
20305d1054 2017-05-19  735:         else
20305d1054 2017-05-19  736:             S_CMD="nice -n10 $S_SHREDDER_APPLICATION_NAME -f --remove $S_FP_IN 2>/dev/null "
20305d1054 2017-05-19  737:         fi
20305d1054 2017-05-19  738:     fi
20305d1054 2017-05-19  739:     #----
20305d1054 2017-05-19  740:     if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "gshred" ]; then
20305d1054 2017-05-19  741:         S_SHREDDER_APPLICATION_NAME="gshred"
20305d1054 2017-05-19  742:         if [ -d $S_FP_IN ]; then
20305d1054 2017-05-19  743:             S_CMD="$S_TMP_0 \
20305d1054 2017-05-19  744:                    $S_SHREDDER_APPLICATION_NAME --force --iterations=2 --remove -z 2>/dev/null "
20305d1054 2017-05-19  745:         else
20305d1054 2017-05-19  746:             S_CMD="nice -n10 \
20305d1054 2017-05-19  747:                    $S_SHREDDER_APPLICATION_NAME --force --iterations=2 --remove -z $S_FP_IN 2>/dev/null "
20305d1054 2017-05-19  748:         fi
20305d1054 2017-05-19  749:     fi
20305d1054 2017-05-19  750:     #----
20305d1054 2017-05-19  751:     # The "rm" on Linux and BSD differ, 
20305d1054 2017-05-19  752:     # a bit like the "ps" # on Linux and BSD differ.
20305d1054 2017-05-19  753:     # The "rm -f -P foo" overwrites the file with NON-random 
20305d1054 2017-05-19  754:     # values before deleting.
20305d1054 2017-05-19  755:     # The "rm -f    foo" works, whenever the "rm" is called by the file owner.
20305d1054 2017-05-19  756:     # The "rm -f -P foo" requires write permissions even, 
20305d1054 2017-05-19  757:     # if the "rm" is called by the file owner.
20305d1054 2017-05-19  758:     if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "rm_BSD" ]; then
20305d1054 2017-05-19  759:         S_SHREDDER_APPLICATION_NAME="rm"
20305d1054 2017-05-19  760:         if [ -d $S_FP_IN ]; then
20305d1054 2017-05-19  761:             S_CMD="$S_TMP_0 \
20305d1054 2017-05-19  762:             $S_SHREDDER_APPLICATION_NAME -f -P $S_FP_IN 2>/dev/null "
20305d1054 2017-05-19  763:         else
20305d1054 2017-05-19  764:             S_CMD="nice -n10 $S_SHREDDER_APPLICATION_NAME -f -P $S_FP_IN 2>/dev/null "
20305d1054 2017-05-19  765:         fi
20305d1054 2017-05-19  766:     fi
20305d1054 2017-05-19  767:     if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "rm_plain" ]; then
20305d1054 2017-05-19  768:         # The "rm -f    foo" seems to be universally available
20305d1054 2017-05-19  769:         # at all UNIX-like environments.
20305d1054 2017-05-19  770:         S_SHREDDER_APPLICATION_NAME="rm"
20305d1054 2017-05-19  771:         if [ -d $S_FP_IN ]; then
20305d1054 2017-05-19  772:             S_CMD="$S_TMP_0 \
20305d1054 2017-05-19  773:             $S_SHREDDER_APPLICATION_NAME -f $S_FP_IN 2>/dev/null "
20305d1054 2017-05-19  774:         else
20305d1054 2017-05-19  775:             S_CMD="nice -n10 $S_SHREDDER_APPLICATION_NAME -f $S_FP_IN 2>/dev/null "
20305d1054 2017-05-19  776:         fi
20305d1054 2017-05-19  777:     fi
20305d1054 2017-05-19  778:     #--------------------
20305d1054 2017-05-19  779:     eval "$S_CMD" # the "eval" is required due to the command "find"
20305d1054 2017-05-19  780:     cd $S_FP_PWD_BEFORE_SHREDDING # required if the $S_FP_IN  was a folder
20305d1054 2017-05-19  781:     if [ -e $S_FP_IN ]; then 
20305d1054 2017-05-19  782:         # If the control flow is here, then the $S_FP_IN was 
20305d1054 2017-05-19  783:         # a folder or the deletion failed or both.
20305d1054 2017-05-19  784:         chmod -f -R 0700 $S_FP_IN  # chmod 0777 would introduce s security flaw
20305d1054 2017-05-19  785:         eval "$S_CMD" # the "eval" is required due to the command "find"
20305d1054 2017-05-19  786:         cd $S_FP_PWD_BEFORE_SHREDDING
20305d1054 2017-05-19  787:         #----
20305d1054 2017-05-19  788:         SB_THROW="f"
20305d1054 2017-05-19  789:         if [ -d $S_FP_IN ]; then 
20305d1054 2017-05-19  790:             S_TMP_0="`cd $S_FP_IN; pwd`" # "./home///foo" -> "/home/foo"
20305d1054 2017-05-19  791:             # Checks are intentionally missing to 
20305d1054 2017-05-19  792:             # allow this Bash function to be universal, without exceptions.
20305d1054 2017-05-19  793:             #----
20305d1054 2017-05-19  794:             cd $S_TMP_0
20305d1054 2017-05-19  795:             S_TMP_1="`find . -name '*' | \
20305d1054 2017-05-19  796:                       xargs file --mime-type | \
20305d1054 2017-05-19  797:                       grep -v directory | grep -v folder `"
20305d1054 2017-05-19  798:                     # The   file --mime-type foo
20305d1054 2017-05-19  799:                     # works on both, Linux and BSD. 
20305d1054 2017-05-19  800:             cd $S_FP_PWD_BEFORE_SHREDDING
20305d1054 2017-05-19  801:             #----
20305d1054 2017-05-19  802:             if [ "$S_TMP_1" == "" ]; then
20305d1054 2017-05-19  803:                 rm -fr $S_TMP_0
20305d1054 2017-05-19  804:             else
20305d1054 2017-05-19  805:                 SB_THROW="t"
84fb49b807 2017-05-28  806:                 S_GUID="'1487ddd1-a84c-4c77-9e36-315260c151e7'"
20305d1054 2017-05-19  807:             fi
20305d1054 2017-05-19  808:         fi
20305d1054 2017-05-19  809:         #----
20305d1054 2017-05-19  810:         if [ "$SB_THROW" == "f" ]; then # to avoid overwriting the S_GUID
20305d1054 2017-05-19  811:             if [ -e $S_FP_IN ]; then
20305d1054 2017-05-19  812:                 SB_THROW="t"
84fb49b807 2017-05-28  813:                 S_GUID="'31b28b97-28ac-41c2-8c16-315260c151e7'"
20305d1054 2017-05-19  814:             fi 
20305d1054 2017-05-19  815:         fi 
20305d1054 2017-05-19  816:         if [ "$SB_THROW" == "t" ]; then
20305d1054 2017-05-19  817:             echo ""
20305d1054 2017-05-19  818:             echo "The deletion failed even after the "
20305d1054 2017-05-19  819:             echo ""
20305d1054 2017-05-19  820:             echo "    chmod -f -R 0700 $S_FP_IN "
20305d1054 2017-05-19  821:             echo ""
20305d1054 2017-05-19  822:             echo "The "
20305d1054 2017-05-19  823:             echo ""
20305d1054 2017-05-19  824:             echo "    chmod 0777 "
20305d1054 2017-05-19  825:             echo ""
20305d1054 2017-05-19  826:             echo "is not done automatically in this "
20305d1054 2017-05-19  827:             echo "Bash function, because "
20305d1054 2017-05-19  828:             echo "it might introduce a security flaw."
20305d1054 2017-05-19  829:             echo ""
20305d1054 2017-05-19  830:             echo "    S_FUNC_MMMV_SHRED_T1_MODE=$S_FUNC_MMMV_SHRED_T1_MODE"
20305d1054 2017-05-19  831:             echo ""
20305d1054 2017-05-19  832:             echo "    S_CMD=$S_CMD"
20305d1054 2017-05-19  833:             echo ""
20305d1054 2017-05-19  834:             echo "GUID==$S_GUID"
84fb49b807 2017-05-28  835:             echo "GUID=='36153205-4a2f-4398-9e46-315260c151e7'"
20305d1054 2017-05-19  836:             echo ""
20305d1054 2017-05-19  837:             #----
20305d1054 2017-05-19  838:             cd $S_FP_ORIG
20305d1054 2017-05-19  839:             exit 1 # exit with error
20305d1054 2017-05-19  840:         fi
20305d1054 2017-05-19  841:     fi
84fb49b807 2017-05-28  842:     S_GUID="'63848e70-e5fa-4f4d-8836-315260c151e7'" #counters S_GUID related flaws
20305d1054 2017-05-19  843:     #--------------------
20305d1054 2017-05-19  844:     if [ -e $S_FP_IN ]; then
20305d1054 2017-05-19  845:         echo ""
20305d1054 2017-05-19  846:         echo "The deletion of the "
20305d1054 2017-05-19  847:         echo "    S_FP_IN=$S_FP_IN"
20305d1054 2017-05-19  848:         echo "failed or the file or folder was re-created by "
20305d1054 2017-05-19  849:         echo "some other process before this file existance check."
84fb49b807 2017-05-28  850:         echo "GUID=='24006e7a-ed69-4038-a955-315260c151e7'"
20305d1054 2017-05-19  851:         echo ""
20305d1054 2017-05-19  852:         #----
20305d1054 2017-05-19  853:         cd $S_FP_ORIG
20305d1054 2017-05-19  854:         exit 1 # exit with error
20305d1054 2017-05-19  855:     fi
20305d1054 2017-05-19  856:     #--------------------
20305d1054 2017-05-19  857:     cd $S_FP_PWD_BEFORE_SHREDDING
20305d1054 2017-05-19  858: } # func_mmmv_shred_t1
20305d1054 2017-05-19  859: 
84fb49b807 2017-05-28  860: 
84fb49b807 2017-05-28  861: #--------------------------------------------------------------------------
84fb49b807 2017-05-28  862: # The 
84fb49b807 2017-05-28  863: #
84fb49b807 2017-05-28  864: #     /tmp
84fb49b807 2017-05-28  865: #
84fb49b807 2017-05-28  866: # might be mounted to the same partition that contains the root folder, the "/",  
84fb49b807 2017-05-28  867: # but the root folder partition might be smaller than the data storage 
84fb49b807 2017-05-28  868: # partitions. To overcome that issue, this script should try 
84fb49b807 2017-05-28  869: # to use the same partition, where the Fossil repository file
84fb49b807 2017-05-28  870: # is stored, which is at the same folder where this script is stored. 
84fb49b807 2017-05-28  871: # The avoidance of the "/tmp", which is readable to everybody, is just
84fb49b807 2017-05-28  872: # a security bonus. 
84fb49b807 2017-05-28  873: #
84fb49b807 2017-05-28  874: # The SQLite within the Fossil uses a lot of temporary space 
84fb49b807 2017-05-28  875: # during cloning, after all of the artifacts have been downloaded.
84fb49b807 2017-05-28  876: # The default location for the temporary SQLite files is the "/tmp",
84fb49b807 2017-05-28  877: # but the folder path for the SQLite temporary files can be
84fb49b807 2017-05-28  878: # modified by setting the  SQLITE_TMPDIR environment variable.
84fb49b807 2017-05-28  879: # If the partition that contains the folder that stores the
84fb49b807 2017-05-28  880: # SQLite temporary files has less space than SQLite needs,
84fb49b807 2017-05-28  881: # the cloning fails. 
84fb49b807 2017-05-28  882: 
84fb49b807 2017-05-28  883: 
84fb49b807 2017-05-28  884: MMMV_FP_FOSSIL_OPERATOR_TMP="/tmp" # The default value.
84fb49b807 2017-05-28  885: if [ -e $S_FP_DIR/tmp_ ]; then 
84fb49b807 2017-05-28  886:     MMMV_FP_FOSSIL_OPERATOR_TMP="$S_FP_DIR/tmp_"
84fb49b807 2017-05-28  887: else
84fb49b807 2017-05-28  888:     if [ -e $S_FP_DIR/tmp ]; then 
84fb49b807 2017-05-28  889:         MMMV_FP_FOSSIL_OPERATOR_TMP="$S_FP_DIR/tmp"
84fb49b807 2017-05-28  890:     else
84fb49b807 2017-05-28  891:         if [ -e $HOME/tmp_ ]; then 
84fb49b807 2017-05-28  892:             MMMV_FP_FOSSIL_OPERATOR_TMP="$HOME/tmp_"
84fb49b807 2017-05-28  893:         else
84fb49b807 2017-05-28  894:             if [ -e $HOME/tmp ]; then 
84fb49b807 2017-05-28  895:                 MMMV_FP_FOSSIL_OPERATOR_TMP="$HOME/tmp"
84fb49b807 2017-05-28  896:             fi
84fb49b807 2017-05-28  897:         fi
84fb49b807 2017-05-28  898:     fi
84fb49b807 2017-05-28  899: fi
84fb49b807 2017-05-28  900: 
84fb49b807 2017-05-28  901: # The SQLITE_TMPDIR must be set before the Fossil
84fb49b807 2017-05-28  902: # is executed.
84fb49b807 2017-05-28  903: export SQLITE_TMPDIR="$MMMV_FP_FOSSIL_OPERATOR_TMP"
84fb49b807 2017-05-28  904: 
84fb49b807 2017-05-28  905: # TODO: Add a check here that verifies that there's enough 
84fb49b807 2017-05-28  906: #       space available at the partition that is used by the 
84fb49b807 2017-05-28  907: #       SQLite. If there's insufficient amount of free space,
84fb49b807 2017-05-28  908: #       then this script should exit without executing the 
84fb49b807 2017-05-28  909: #       fossil console application. The error message should 
84fb49b807 2017-05-28  910: #       explain the possibility to set the SQLITE_TMPDIR and/or
84fb49b807 2017-05-28  911: #       the SQLITE_TMPDIR related circumstances. 
20305d1054 2017-05-19  912: 
20305d1054 2017-05-19  913: #--------------------------------------------------------------------------
20305d1054 2017-05-19  914: S_TMP_0=""
20305d1054 2017-05-19  915: S_ACTIVITY_OF_THIS_SCRIPT=$1
20305d1054 2017-05-19  916: S_URL_REMOTE_REPOSITORY=""
20305d1054 2017-05-19  917: SB_EXIT_WITH_ERROR="f"
20305d1054 2017-05-19  918: 
20305d1054 2017-05-19  919: # needed for scriptability
20305d1054 2017-05-19  920: S_ARGNAME_ACTIVITY_SHRED_ARG_2="do_not_prompt_for_confirmation" 
20305d1054 2017-05-19  921: 
20305d1054 2017-05-19  922: fun_print_msg_t1() {
20305d1054 2017-05-19  923:     echo ""
20305d1054 2017-05-19  924:     echo "The second console argument "
20305d1054 2017-05-19  925:     echo "is expected to be the URL of the remote repository."
20305d1054 2017-05-19  926: } # fun_print_msg_t1
20305d1054 2017-05-19  927: 
20305d1054 2017-05-19  928: 
20305d1054 2017-05-19  929: fun_exit_without_any_errors_t1() {
20305d1054 2017-05-19  930:     local X_SKIP_MESSAGE="$1"
20305d1054 2017-05-19  931:     if [ "$X_SKIP_MESSAGE" == "" ]; then
20305d1054 2017-05-19  932:         echo ""
20305d1054 2017-05-19  933:         echo "Aborting script without doing anything."
20305d1054 2017-05-19  934:         echo ""
20305d1054 2017-05-19  935:     fi 
20305d1054 2017-05-19  936:     #----
20305d1054 2017-05-19  937:     cd $S_FP_ORIG
20305d1054 2017-05-19  938:     exit 0
20305d1054 2017-05-19  939: } # fun_exit_without_any_errors_t1
20305d1054 2017-05-19  940: 
20305d1054 2017-05-19  941: #--------------------------------------------------------------------------
20305d1054 2017-05-19  942: 
20305d1054 2017-05-19  943: SB_FUNC_MMMV_ASSERT_FILE_PATHS_DIFFER_T1_ASSERTION_FAILED="f"
20305d1054 2017-05-19  944: func_mmmv_assert_file_paths_differ_t1(){
20305d1054 2017-05-19  945:     local S_FP_0="$1"
20305d1054 2017-05-19  946:     local S_FP_1="$2"
20305d1054 2017-05-19  947:     local S_GUID="$3"
20305d1054 2017-05-19  948:     local SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE="$4" # domain: {"","f","t"}
20305d1054 2017-05-19  949:     #--------
20305d1054 2017-05-19  950:     if [ "$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE" != "" ] ; then
20305d1054 2017-05-19  951:         if [ "$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE" != "t" ] ; then
20305d1054 2017-05-19  952:             if [ "$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE" != "f" ] ; then
20305d1054 2017-05-19  953:                 echo ""
20305d1054 2017-05-19  954:                 echo "The fourth parameter of this function, the "
20305d1054 2017-05-19  955:                 echo ""
20305d1054 2017-05-19  956:                 echo "    SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE(==$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE)"
20305d1054 2017-05-19  957:                 echo ""
20305d1054 2017-05-19  958:                 echo "is optional, but its range is {\"\",\"f\",\"t\"},"
20305d1054 2017-05-19  959:                 echo "without the quotation marks."
84fb49b807 2017-05-28  960:                 echo "GUID=='138e10b5-accd-465c-bc15-315260c151e7'"
20305d1054 2017-05-19  961:                 echo ""
20305d1054 2017-05-19  962:                 #----
20305d1054 2017-05-19  963:                 cd $S_FP_ORIG
20305d1054 2017-05-19  964:                 exit 1 # exit with error
20305d1054 2017-05-19  965:             fi
20305d1054 2017-05-19  966:         fi
20305d1054 2017-05-19  967:     else # $SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE == ""
20305d1054 2017-05-19  968:         SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE="f"
20305d1054 2017-05-19  969:     fi
20305d1054 2017-05-19  970:     SB_FUNC_MMMV_ASSERT_FILE_PATHS_DIFFER_T1_ASSERTION_FAILED="f" # global
20305d1054 2017-05-19  971:     #--------
20305d1054 2017-05-19  972:     # The block of if-else statements for comparing the 2 paths
20305d1054 2017-05-19  973:     # is so error prone to write that this function is written 
20305d1054 2017-05-19  974:     # according to a schematic that resides at:
20305d1054 2017-05-19  975:     # http://longterm.softf1.com/documentation_fragments/2016_09_03_comparison_of_file_paths_t1/
20305d1054 2017-05-19  976:     # https://archive.is/R4yw9
20305d1054 2017-05-19  977:     #--------
20305d1054 2017-05-19  978:     # Declarations:
20305d1054 2017-05-19  979:     local S_GUID_CRAWL="S_GUID_CRAWL not set" # tree crawling at the schematic
20305d1054 2017-05-19  980:     local S_GUID_CMP="S_GUID_CMP not set"     # comparison at tree leaf
20305d1054 2017-05-19  981:                                               # Some leaves are equivalent.
20305d1054 2017-05-19  982:     local S_COMPARISON_MODE="" 
20305d1054 2017-05-19  983:     local SB_THROW="f" 
20305d1054 2017-05-19  984:     local SB_ASSERTION_FAILED="f" 
20305d1054 2017-05-19  985:     local SB_STR0="f" # whether S_FP_0 is compared purely as a string
20305d1054 2017-05-19  986:     local SB_STR1="f" # whether S_FP_1 is compared purely as a string
20305d1054 2017-05-19  987:     local S_FP_0_STR="$S_FP_0" 
20305d1054 2017-05-19  988:     local S_FP_1_STR="$S_FP_1"
20305d1054 2017-05-19  989:     local S_FP_X="" # a temporary variable for holding path value
20305d1054 2017-05-19  990:     local S_RUBY_SRC_0=""
20305d1054 2017-05-19  991:     #--------
20305d1054 2017-05-19  992:     if [ "$S_FP_0" == "$S_FP_1" ]; then 
20305d1054 2017-05-19  993:         # Covers also the case, where both are existing 
20305d1054 2017-05-19  994:         # folders, but the paths to them contains "../".
20305d1054 2017-05-19  995:         # By making the string comparison to be the first thing tried 
20305d1054 2017-05-19  996:         # a few file system accesses might be saved.
20305d1054 2017-05-19  997:         SB_ASSERTION_FAILED="t"
84fb49b807 2017-05-28  998:         S_GUID_CRAWL="4aef6e33-8b80-4cc0-874d-315260c151e7"
84fb49b807 2017-05-28  999:         S_GUID_CMP="173fec60-55e1-4fb6-8f1d-315260c151e7"
20305d1054 2017-05-19 1000:     else # the rest of the 3 comparison modes
20305d1054 2017-05-19 1001:         #--------
20305d1054 2017-05-19 1002:         if [ -e $S_FP_0 ]; then 
20305d1054 2017-05-19 1003:             if [ -d $S_FP_0 ]; then 
20305d1054 2017-05-19 1004:                 if [ -e $S_FP_1 ]; then 
20305d1054 2017-05-19 1005:                     if [ -d $S_FP_1 ]; then 
20305d1054 2017-05-19 1006:                         S_COMPARISON_MODE="cmode_cd0_cd1"
20305d1054 2017-05-19 1007:                     else 
20305d1054 2017-05-19 1008:                         S_COMPARISON_MODE="cmode_cd0_str1"
20305d1054 2017-05-19 1009:                         SB_STR1="t"
20305d1054 2017-05-19 1010:                     fi 
20305d1054 2017-05-19 1011:                 else 
20305d1054 2017-05-19 1012:                     S_COMPARISON_MODE="cmode_cd0_str1"
20305d1054 2017-05-19 1013:                     SB_STR1="t"
20305d1054 2017-05-19 1014:                 fi
20305d1054 2017-05-19 1015:             else 
20305d1054 2017-05-19 1016:                 if [ -e $S_FP_1 ]; then 
20305d1054 2017-05-19 1017:                     if [ -d $S_FP_1 ]; then 
20305d1054 2017-05-19 1018:                         S_COMPARISON_MODE="cmode_str0_cd1"
20305d1054 2017-05-19 1019:                         SB_STR0="t"
20305d1054 2017-05-19 1020:                     else 
20305d1054 2017-05-19 1021:                         S_COMPARISON_MODE="cmode_str0_str1"
20305d1054 2017-05-19 1022:                         SB_STR0="t"
20305d1054 2017-05-19 1023:                         SB_STR1="t"
20305d1054 2017-05-19 1024:                     fi 
20305d1054 2017-05-19 1025:                 else 
20305d1054 2017-05-19 1026:                     S_COMPARISON_MODE="cmode_str0_str1"
20305d1054 2017-05-19 1027:                     SB_STR0="t"
20305d1054 2017-05-19 1028:                     SB_STR1="t"
20305d1054 2017-05-19 1029:                 fi
20305d1054 2017-05-19 1030:             fi
20305d1054 2017-05-19 1031:         else # $S_FP_0 is missing or it is a broken symbolic link
20305d1054 2017-05-19 1032:             if [ -e $S_FP_1 ]; then 
20305d1054 2017-05-19 1033:                 if [ -d $S_FP_1 ]; then 
20305d1054 2017-05-19 1034:                     S_COMPARISON_MODE="cmode_str0_cd1"
20305d1054 2017-05-19 1035:                     SB_STR0="t"
20305d1054 2017-05-19 1036:                 else 
20305d1054 2017-05-19 1037:                     S_COMPARISON_MODE="cmode_str0_str1"
20305d1054 2017-05-19 1038:                     SB_STR0="t"
20305d1054 2017-05-19 1039:                     SB_STR1="t"
20305d1054 2017-05-19 1040:                 fi
20305d1054 2017-05-19 1041:             else 
20305d1054 2017-05-19 1042:                 S_COMPARISON_MODE="cmode_str0_str1"
20305d1054 2017-05-19 1043:                 SB_STR0="t"
20305d1054 2017-05-19 1044:                 SB_STR1="t"
20305d1054 2017-05-19 1045:             fi
20305d1054 2017-05-19 1046:         fi
20305d1054 2017-05-19 1047:         #----------------        
20305d1054 2017-05-19 1048:         # The "cmode_str0_str1" was tried 
20305d1054 2017-05-19 1049:         # at the first if-clause of the block, but 
20305d1054 2017-05-19 1050:         # that does not catch equivalent cases like 
20305d1054 2017-05-19 1051:         #
20305d1054 2017-05-19 1052:         #     S_FP_0="`pwd`/././////a_nonexisting_file_or_folder"
20305d1054 2017-05-19 1053:         #     S_FP_1="`pwd`/a_nonexisting_file_or_folder"
20305d1054 2017-05-19 1054:         #
20305d1054 2017-05-19 1055:         #     S_FP_0="./a_nonexisting_file_or_folder"
20305d1054 2017-05-19 1056:         #     S_FP_1="././././././a_nonexisting_file_or_folder"
20305d1054 2017-05-19 1057:         #
20305d1054 2017-05-19 1058:         #     S_FP_0="/a_nonexisting_file_or_folder"
20305d1054 2017-05-19 1059:         #     S_FP_1="/////a_nonexisting_file_or_folder"
20305d1054 2017-05-19 1060:         #
20305d1054 2017-05-19 1061:         #     S_FP_0="/a_nonexisting_file_or_folder"
20305d1054 2017-05-19 1062:         #     S_FP_1="/..///../a_nonexisting_file_or_folder"
20305d1054 2017-05-19 1063:         #
20305d1054 2017-05-19 1064:         # String normalization is required whenever at least
20305d1054 2017-05-19 1065:         # one of the paths is used at comparison 
20305d1054 2017-05-19 1066:         # purely as a string.
20305d1054 2017-05-19 1067:         #
20305d1054 2017-05-19 1068:         #----start-of-Ruby-script-header--for-copy/pasting----
20305d1054 2017-05-19 1069:         #    #!/usr/bin/env ruby
20305d1054 2017-05-19 1070:         #    
20305d1054 2017-05-19 1071:         #    s_fp_0="./a_nonexisting_file_or_folder"
20305d1054 2017-05-19 1072:         #    s_fp_1="././..//../.././a_nonexisting_file_or_folder"
20305d1054 2017-05-19 1073:         #    
20305d1054 2017-05-19 1074:         #    # The path "/../foo" is equivalent to "/foo".
20305d1054 2017-05-19 1075:         #    s_fp_2="/././..//../.././a_nonexisting_file_or_folder"
20305d1054 2017-05-19 1076:         #    
20305d1054 2017-05-19 1077:         #    # This script does not cover the case, 
20305d1054 2017-05-19 1078:         #    # where "./aa/../bb" is equivalent to "./bb"
20305d1054 2017-05-19 1079:         #----end---of-Ruby-script-header-for-copy/pasting----
20305d1054 2017-05-19 1080:         S_RUBY_SRC_0="\
20305d1054 2017-05-19 1081:             s_0='';\
20305d1054 2017-05-19 1082:             s_1=ARGV[0].to_s;\
20305d1054 2017-05-19 1083:             rgx_0=/[\\/][.][\\/]/;\
20305d1054 2017-05-19 1084:             rgx_1=/^[.][\\/]/;\
20305d1054 2017-05-19 1085:             rgx_2=/^[\\/][.][.][\\/]/;\
20305d1054 2017-05-19 1086:             i_4safety=0;\
20305d1054 2017-05-19 1087:             while s_0!=s_1 do ;\
20305d1054 2017-05-19 1088:                s_0=s_1;\
20305d1054 2017-05-19 1089:                s_1=s_0.gsub(rgx_0,'/');\
20305d1054 2017-05-19 1090:                i_4safety=i_4safety+1;\
20305d1054 2017-05-19 1091:                if 10000<i_4safety then ;\
20305d1054 2017-05-19 1092:                   raise(Exception.new('boo'));\
20305d1054 2017-05-19 1093:                end;\
20305d1054 2017-05-19 1094:             end ;\
20305d1054 2017-05-19 1095:             s_0=s_1;\
20305d1054 2017-05-19 1096:             s_1=s_0.gsub(rgx_1,'');\
20305d1054 2017-05-19 1097:             s_0=s_1;\
20305d1054 2017-05-19 1098:             s_1=s_0.gsub(/[\\/]+/,'/');\
20305d1054 2017-05-19 1099:             ;\
20305d1054 2017-05-19 1100:             ;\
20305d1054 2017-05-19 1101:             i_4safety=0;\
20305d1054 2017-05-19 1102:             while s_0!=s_1 do ;\
20305d1054 2017-05-19 1103:                s_0=s_1;\
20305d1054 2017-05-19 1104:                s_1=s_0.gsub(rgx_2,'/');\
20305d1054 2017-05-19 1105:                i_4safety=i_4safety+1;\
20305d1054 2017-05-19 1106:                if 10000<i_4safety then ;\
84fb49b807 2017-05-28 1107:                   raise(Exception.new('e8894bb5-e0bb-4ace-b135-315260c151e7'));\
20305d1054 2017-05-19 1108:                end;\
20305d1054 2017-05-19 1109:             end ;\
20305d1054 2017-05-19 1110:             s_0=s_1;\
20305d1054 2017-05-19 1111:             s_1=s_0.gsub(rgx_1,'');\
20305d1054 2017-05-19 1112:             s_0=s_1;\
20305d1054 2017-05-19 1113:             s_1=s_0.gsub(/[\\/]+/,'/');\
20305d1054 2017-05-19 1114:             ;\
20305d1054 2017-05-19 1115:             print s_1;\
20305d1054 2017-05-19 1116:             "
20305d1054 2017-05-19 1117:         #----
20305d1054 2017-05-19 1118:         if [ "$SB_STR0" == "t" ]; then 
20305d1054 2017-05-19 1119:             S_FP_0_STR="`ruby -e \"$S_RUBY_SRC_0\" $S_FP_0`"
20305d1054 2017-05-19 1120:         fi
20305d1054 2017-05-19 1121:         if [ "$SB_STR1" == "t" ]; then 
20305d1054 2017-05-19 1122:             S_FP_1_STR="`ruby -e \"$S_RUBY_SRC_0\" $S_FP_1`"
20305d1054 2017-05-19 1123:         fi
20305d1054 2017-05-19 1124:         #----------------        
20305d1054 2017-05-19 1125:         if [ "$S_COMPARISON_MODE" == "cmode_cd0_str1" ]; then 
20305d1054 2017-05-19 1126:             # 2 cases at the schematic
20305d1054 2017-05-19 1127:             S_FP_X="`cd $S_FP_0;pwd`"
20305d1054 2017-05-19 1128:             if [ "$S_FP_X" == "$S_FP_1_STR" ]; then 
20305d1054 2017-05-19 1129:                 SB_ASSERTION_FAILED="t"
84fb49b807 2017-05-28 1130:                 S_GUID_CMP="ab43a000-31d6-4c9a-9f4c-315260c151e7"
20305d1054 2017-05-19 1131:             fi
20305d1054 2017-05-19 1132:             if [ "$SB_ASSERTION_FAILED" != "t" ]; then 
20305d1054 2017-05-19 1133:                 if [ "$S_FP_X" == "$S_FP_1" ]; then # just in case
20305d1054 2017-05-19 1134:                     SB_ASSERTION_FAILED="t"
84fb49b807 2017-05-28 1135:                     S_GUID_CMP="03a258fc-5df1-423e-a88c-315260c151e7"
20305d1054 2017-05-19 1136:                 fi
20305d1054 2017-05-19 1137:             fi
20305d1054 2017-05-19 1138:         else
20305d1054 2017-05-19 1139:             if [ "$S_COMPARISON_MODE" == "cmode_str0_cd1" ]; then 
20305d1054 2017-05-19 1140:                 # 2 cases at the schematic
20305d1054 2017-05-19 1141:                 S_FP_X="`cd $S_FP_1;pwd`"
20305d1054 2017-05-19 1142:                 if [ "$S_FP_0_STR" == "$S_FP_X" ]; then 
20305d1054 2017-05-19 1143:                     SB_ASSERTION_FAILED="t"
84fb49b807 2017-05-28 1144:                     S_GUID_CMP="35827f15-b65c-4bbc-ac1c-315260c151e7"
20305d1054 2017-05-19 1145:                 fi
20305d1054 2017-05-19 1146:                 if [ "$SB_ASSERTION_FAILED" != "t" ]; then 
20305d1054 2017-05-19 1147:                     if [ "$S_FP_0" == "$S_FP_X" ]; then # just in case
20305d1054 2017-05-19 1148:                         SB_ASSERTION_FAILED="t"
84fb49b807 2017-05-28 1149:                         S_GUID_CMP="557e0b84-2224-4385-b5ab-315260c151e7"
20305d1054 2017-05-19 1150:                     fi
20305d1054 2017-05-19 1151:                 fi
20305d1054 2017-05-19 1152:             else
20305d1054 2017-05-19 1153:                 if [ "$S_COMPARISON_MODE" == "cmode_cd0_cd1" ]; then 
20305d1054 2017-05-19 1154:                     if [ "`cd $S_FP_0;pwd`" == "`cd $S_FP_1;pwd`" ]; then 
20305d1054 2017-05-19 1155:                         SB_ASSERTION_FAILED="t"
84fb49b807 2017-05-28 1156:                         S_GUID_CMP="33b3e04c-ddbc-44ea-a8eb-315260c151e7"
20305d1054 2017-05-19 1157:                     fi
20305d1054 2017-05-19 1158:                 else 
20305d1054 2017-05-19 1159:                     if [ "$S_COMPARISON_MODE" == "cmode_str0_str1" ]; then 
20305d1054 2017-05-19 1160:                         if [ "$S_FP_0_STR" == "$S_FP_1_STR" ]; then 
20305d1054 2017-05-19 1161:                             SB_ASSERTION_FAILED="t"
84fb49b807 2017-05-28 1162:                             S_GUID_CMP="33c4ceb2-c968-4890-ab1b-315260c151e7"
20305d1054 2017-05-19 1163:                         fi
20305d1054 2017-05-19 1164:                         # The if [ "$S_FP_0" == "$S_FP_1" ] ...
20305d1054 2017-05-19 1165:                         # has already been tried at the very start 
20305d1054 2017-05-19 1166:                         # of the huge if-block.
20305d1054 2017-05-19 1167:                     else
20305d1054 2017-05-19 1168:                         echo ""
20305d1054 2017-05-19 1169:                         echo "This script is flawed."
20305d1054 2017-05-19 1170:                         echo ""
20305d1054 2017-05-19 1171:                         echo "    S_FP_0=$S_FP_0"
20305d1054 2017-05-19 1172:                         echo "    S_FP_1=$S_FP_1"
20305d1054 2017-05-19 1173:                         echo "    S_GUID_CRAWL=$S_GUID_CRAWL"
20305d1054 2017-05-19 1174:                         echo "    S_GUID_CMP=$S_GUID_CMP"
20305d1054 2017-05-19 1175:                         echo "    S_COMPARISON_MODE=$S_COMPARISON_MODE"
20305d1054 2017-05-19 1176:                         echo ""
84fb49b807 2017-05-28 1177:                         echo "GUID=='4e97e325-2e0b-4cc6-8245-315260c151e7'"
20305d1054 2017-05-19 1178:                         echo ""
20305d1054 2017-05-19 1179:                         #----
20305d1054 2017-05-19 1180:                         cd $S_FP_ORIG
20305d1054 2017-05-19 1181:                         exit 1 # exit with error
20305d1054 2017-05-19 1182:                     fi
20305d1054 2017-05-19 1183:                 fi
20305d1054 2017-05-19 1184:             fi
20305d1054 2017-05-19 1185:         fi
20305d1054 2017-05-19 1186:     fi
20305d1054 2017-05-19 1187:     #--------
20305d1054 2017-05-19 1188:     SB_FUNC_MMMV_ASSERT_FILE_PATHS_DIFFER_T1_ASSERTION_FAILED="$SB_ASSERTION_FAILED" # global
20305d1054 2017-05-19 1189:     if [ "$SB_ASSERTION_FAILED" == "t" ]; then 
20305d1054 2017-05-19 1190:         if [ "$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE" != "t" ]; then
20305d1054 2017-05-19 1191:             echo ""
20305d1054 2017-05-19 1192:             echo "The file paths "
20305d1054 2017-05-19 1193:             echo ""
20305d1054 2017-05-19 1194:             echo "    S_FP_0=$S_FP_0"
20305d1054 2017-05-19 1195:             echo ""
20305d1054 2017-05-19 1196:             echo "    S_FP_1=$S_FP_1"
20305d1054 2017-05-19 1197:             echo ""
20305d1054 2017-05-19 1198:             echo "are required to differ and "
20305d1054 2017-05-19 1199:             echo "they are required to differ also after normalization."
20305d1054 2017-05-19 1200:             echo ""
84fb49b807 2017-05-28 1201:             echo "GUID=='b1a08ca1-92f4-4427-b915-315260c151e7'"
20305d1054 2017-05-19 1202:             echo "GUID=='$S_GUID_CMP'"   # comparison
20305d1054 2017-05-19 1203:             echo "GUID=='$S_GUID_CRAWL'" # tree crawling at the schematic
20305d1054 2017-05-19 1204:             if [ "$S_GUID" != "" ]; then 
20305d1054 2017-05-19 1205:                 echo "GUID=='$S_GUID'"   # GUID as an input parameter
20305d1054 2017-05-19 1206:             fi
20305d1054 2017-05-19 1207:             echo ""
20305d1054 2017-05-19 1208:             #----
20305d1054 2017-05-19 1209:             cd $S_FP_ORIG
20305d1054 2017-05-19 1210:             exit 1 # exit with error
20305d1054 2017-05-19 1211:         fi
20305d1054 2017-05-19 1212:     fi
20305d1054 2017-05-19 1213: } # func_mmmv_assert_file_paths_differ_t1
20305d1054 2017-05-19 1214: 
20305d1054 2017-05-19 1215: 
20305d1054 2017-05-19 1216: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1217: # Activity aliases for comfort.
20305d1054 2017-05-19 1218: 
20305d1054 2017-05-19 1219: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "up" ]; then
20305d1054 2017-05-19 1220:     S_ACTIVITY_OF_THIS_SCRIPT="overwrite_remote_with_local"
20305d1054 2017-05-19 1221: fi
20305d1054 2017-05-19 1222: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "upload" ]; then
20305d1054 2017-05-19 1223:     S_ACTIVITY_OF_THIS_SCRIPT="overwrite_remote_with_local"
20305d1054 2017-05-19 1224: fi
20305d1054 2017-05-19 1225: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "ci" ]; then
20305d1054 2017-05-19 1226:     S_ACTIVITY_OF_THIS_SCRIPT="overwrite_remote_with_local"
20305d1054 2017-05-19 1227: fi
20305d1054 2017-05-19 1228: #--------
20305d1054 2017-05-19 1229: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "down" ]; then
20305d1054 2017-05-19 1230:     S_ACTIVITY_OF_THIS_SCRIPT="overwrite_local_with_remote"
20305d1054 2017-05-19 1231: fi
20305d1054 2017-05-19 1232: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "download" ]; then
20305d1054 2017-05-19 1233:     S_ACTIVITY_OF_THIS_SCRIPT="overwrite_local_with_remote"
20305d1054 2017-05-19 1234: fi
20305d1054 2017-05-19 1235: #--------
20305d1054 2017-05-19 1236: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "co" ]; then
20305d1054 2017-05-19 1237:     S_ACTIVITY_OF_THIS_SCRIPT="clone_all"
20305d1054 2017-05-19 1238: fi
20305d1054 2017-05-19 1239: #--------
20305d1054 2017-05-19 1240: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "?" ]; then
20305d1054 2017-05-19 1241:     S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1242: fi
20305d1054 2017-05-19 1243: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "-?" ]; then
20305d1054 2017-05-19 1244:     S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1245: fi
20305d1054 2017-05-19 1246: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "--help" ]; then
20305d1054 2017-05-19 1247:     S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1248: fi
20305d1054 2017-05-19 1249: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "-help" ]; then
20305d1054 2017-05-19 1250:     S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1251: fi
20305d1054 2017-05-19 1252: #--------
20305d1054 2017-05-19 1253: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "rm" ]; then
20305d1054 2017-05-19 1254:     S_ACTIVITY_OF_THIS_SCRIPT="delete_local_copy"
20305d1054 2017-05-19 1255: fi
20305d1054 2017-05-19 1256: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "del" ]; then
20305d1054 2017-05-19 1257:     S_ACTIVITY_OF_THIS_SCRIPT="delete_local_copy"
20305d1054 2017-05-19 1258: fi
20305d1054 2017-05-19 1259: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "delete" ]; then
20305d1054 2017-05-19 1260:     S_ACTIVITY_OF_THIS_SCRIPT="delete_local_copy"
20305d1054 2017-05-19 1261: fi
20305d1054 2017-05-19 1262: #--------
20305d1054 2017-05-19 1263: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "info" ]; then
20305d1054 2017-05-19 1264:     S_ACTIVITY_OF_THIS_SCRIPT="about"
20305d1054 2017-05-19 1265: fi
20305d1054 2017-05-19 1266: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "--info" ]; then
20305d1054 2017-05-19 1267:     S_ACTIVITY_OF_THIS_SCRIPT="about"
20305d1054 2017-05-19 1268: fi
20305d1054 2017-05-19 1269: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "-info" ]; then
20305d1054 2017-05-19 1270:     S_ACTIVITY_OF_THIS_SCRIPT="about"
20305d1054 2017-05-19 1271: fi
20305d1054 2017-05-19 1272: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "--about" ]; then
20305d1054 2017-05-19 1273:     S_ACTIVITY_OF_THIS_SCRIPT="about"
20305d1054 2017-05-19 1274: fi
20305d1054 2017-05-19 1275: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "-about" ]; then
20305d1054 2017-05-19 1276:     S_ACTIVITY_OF_THIS_SCRIPT="about"
20305d1054 2017-05-19 1277: fi
20305d1054 2017-05-19 1278: #--------
20305d1054 2017-05-19 1279: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1280: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "about" ]; then
20305d1054 2017-05-19 1281:     echo ""
20305d1054 2017-05-19 1282:     echo "    The initial version of this script has been written by "
20305d1054 2017-05-19 1283:     echo "    Martin.Vahi@softf1.com         "
20305d1054 2017-05-19 1284:     echo "    in 2016_02. The initial version is in public domain."
20305d1054 2017-05-19 1285:     echo "    The command \"help\" offers more information. "
20305d1054 2017-05-19 1286:     echo ""
20305d1054 2017-05-19 1287:     echo "    Thank You for using this script :-)"
20305d1054 2017-05-19 1288:     echo ""
20305d1054 2017-05-19 1289:     echo ""
20305d1054 2017-05-19 1290:     fun_exit_without_any_errors_t1 "t"
20305d1054 2017-05-19 1291: fi 
20305d1054 2017-05-19 1292: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1293: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "exit" ]; then
20305d1054 2017-05-19 1294:     fun_exit_without_any_errors_t1
20305d1054 2017-05-19 1295: else
20305d1054 2017-05-19 1296:     if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "clone_all" ]; then
20305d1054 2017-05-19 1297:         if [ "$2" == "" ]; then
20305d1054 2017-05-19 1298:             fun_print_msg_t1
20305d1054 2017-05-19 1299:             S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1300:             SB_EXIT_WITH_ERROR="t"
20305d1054 2017-05-19 1301:         else
20305d1054 2017-05-19 1302:             S_URL_REMOTE_REPOSITORY="$2"
20305d1054 2017-05-19 1303:         fi
20305d1054 2017-05-19 1304:     else
20305d1054 2017-05-19 1305:         if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "clone_public" ]; then
20305d1054 2017-05-19 1306:             if [ "$2" == "" ]; then
20305d1054 2017-05-19 1307:                 fun_print_msg_t1
20305d1054 2017-05-19 1308:                 S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1309:                 SB_EXIT_WITH_ERROR="t"
20305d1054 2017-05-19 1310:             else
20305d1054 2017-05-19 1311:                 S_URL_REMOTE_REPOSITORY="$2"
20305d1054 2017-05-19 1312:             fi
20305d1054 2017-05-19 1313:         else
20305d1054 2017-05-19 1314:             if [ "$S_ACTIVITY_OF_THIS_SCRIPT" != "overwrite_local_with_remote" ]; then
20305d1054 2017-05-19 1315:                 if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "overwrite_remote_with_local" ]; then
20305d1054 2017-05-19 1316:                     if [ "$2" != "" ]; then
20305d1054 2017-05-19 1317:                         if [ "$2" == "use_autogenerated_commit_message" ]; then
20305d1054 2017-05-19 1318:                             if [ "$3" != "" ]; then
20305d1054 2017-05-19 1319:                                 echo ""
20305d1054 2017-05-19 1320:                                 echo "If the first console argument is \"overwrite_local_with_remote\" and"
20305d1054 2017-05-19 1321:                                 echo "the second console argument is \"use_autogenerated_commit_message\", "
20305d1054 2017-05-19 1322:                                 echo "then there should not be a 3. console argument."
84fb49b807 2017-05-28 1323:                                 echo "GUID=='2edc38e1-bc91-4598-8a45-315260c151e7'"
20305d1054 2017-05-19 1324:                                 S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1325:                                 SB_EXIT_WITH_ERROR="t"
20305d1054 2017-05-19 1326:                             fi
20305d1054 2017-05-19 1327:                         else
20305d1054 2017-05-19 1328:                             if [ "$2" == "read_commit_message_from_file" ]; then
20305d1054 2017-05-19 1329:                                 S_FP_MESSAGE_FILE_CANDIDATE="$3" # file path candidate
20305d1054 2017-05-19 1330:                                 if [ "$S_FP_MESSAGE_FILE_CANDIDATE" == "" ]; then
20305d1054 2017-05-19 1331:                                     echo ""
20305d1054 2017-05-19 1332:                                     echo "If the first console argument is "
20305d1054 2017-05-19 1333:                                     echo "\"overwrite_local_with_remote\" and"
20305d1054 2017-05-19 1334:                                     echo "the second console argument is "
20305d1054 2017-05-19 1335:                                     echo "\"read_commit_message_from_file\", "
20305d1054 2017-05-19 1336:                                     echo "then there should be also a 3. console argument "
20305d1054 2017-05-19 1337:                                     echo "that is expected to be a file path to a text file."
84fb49b807 2017-05-28 1338:                                     echo "GUID=='2bf02902-b474-4c68-bf24-315260c151e7'"
20305d1054 2017-05-19 1339:                                     S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1340:                                     SB_EXIT_WITH_ERROR="t"
20305d1054 2017-05-19 1341:                                 fi
20305d1054 2017-05-19 1342:                                 if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then
20305d1054 2017-05-19 1343:                                     if [ "$4" != "" ]; then
20305d1054 2017-05-19 1344:                                         echo ""
20305d1054 2017-05-19 1345:                                         echo "If the first console argument is "
20305d1054 2017-05-19 1346:                                         echo "\"overwrite_local_with_remote\" and"
20305d1054 2017-05-19 1347:                                         echo "the second console argument is "
20305d1054 2017-05-19 1348:                                         echo "\"read_commit_message_from_file\", "
20305d1054 2017-05-19 1349:                                         echo "then there should be exactly 3. console arguments, "
20305d1054 2017-05-19 1350:                                         echo "not 4 or more. Unfortunately the 4. argument is currently "
20305d1054 2017-05-19 1351:                                         echo "---citation--start---"
20305d1054 2017-05-19 1352:                                         echo "$4"
20305d1054 2017-05-19 1353:                                         echo "---citation--end-----"
84fb49b807 2017-05-28 1354:                                         echo "GUID=='304d0d85-2ca2-48aa-8154-315260c151e7'"
20305d1054 2017-05-19 1355:                                         S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1356:                                         SB_EXIT_WITH_ERROR="t"
20305d1054 2017-05-19 1357:                                     fi
20305d1054 2017-05-19 1358:                                 fi
20305d1054 2017-05-19 1359:                                 if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then
20305d1054 2017-05-19 1360:                                     if [ ! -e "$S_FP_MESSAGE_FILE_CANDIDATE" ]; then 
20305d1054 2017-05-19 1361:                                         echo ""
20305d1054 2017-05-19 1362:                                         echo "The commit message file path candidate "
20305d1054 2017-05-19 1363:                                         echo "references either a missing file or "
20305d1054 2017-05-19 1364:                                         echo "a broken symlink."
84fb49b807 2017-05-28 1365:                                         echo "GUID=='65b5592a-0561-4b74-a744-315260c151e7'"
20305d1054 2017-05-19 1366:                                         S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1367:                                         SB_EXIT_WITH_ERROR="t"
20305d1054 2017-05-19 1368:                                     fi
20305d1054 2017-05-19 1369:                                 fi 
20305d1054 2017-05-19 1370:                                 if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then
20305d1054 2017-05-19 1371:                                     if [ -d "$S_FP_MESSAGE_FILE_CANDIDATE" ]; then 
20305d1054 2017-05-19 1372:                                         echo ""
20305d1054 2017-05-19 1373:                                         echo "The commit message file path candidate "
20305d1054 2017-05-19 1374:                                         echo "references a folder, but it should "
20305d1054 2017-05-19 1375:                                         echo "reference a text file."
84fb49b807 2017-05-28 1376:                                         echo "GUID=='1c6865c3-f143-4c24-8d24-315260c151e7'"
20305d1054 2017-05-19 1377:                                         S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1378:                                         SB_EXIT_WITH_ERROR="t"
20305d1054 2017-05-19 1379:                                     fi
20305d1054 2017-05-19 1380:                                 fi
20305d1054 2017-05-19 1381:                                 if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then
20305d1054 2017-05-19 1382:                                     S_TMP_0="`filesize $S_FP_MESSAGE_FILE_CANDIDATE`"
20305d1054 2017-05-19 1383:                                     S_TMP_1="`ruby -e \"s_out='OK'; if (2000<$S_TMP_0) then s_out='too_big' end; print(s_out);\"`"
20305d1054 2017-05-19 1384:                                     if [ "$S_TMP_1" == "too_big" ]; then
20305d1054 2017-05-19 1385:                                         echo ""
20305d1054 2017-05-19 1386:                                         echo "The commit message file path "
20305d1054 2017-05-19 1387:                                         echo "references a file that has a size of $S_TMP_0 bytes."
20305d1054 2017-05-19 1388:                                         echo "The suspicion is that it is a wrong file. "
20305d1054 2017-05-19 1389:                                         echo "because a commit message is usually not that lengthy."
84fb49b807 2017-05-28 1390:                                         echo "GUID=='12bd6692-7e0d-48c6-9924-315260c151e7'"
20305d1054 2017-05-19 1391:                                         S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1392:                                         SB_EXIT_WITH_ERROR="t"
20305d1054 2017-05-19 1393:                                     else
20305d1054 2017-05-19 1394:                                         if [ "$S_TMP_0" == "0" ]; then
20305d1054 2017-05-19 1395:                                             echo ""
20305d1054 2017-05-19 1396:                                             echo "The commit message file path "
20305d1054 2017-05-19 1397:                                             echo "references a file that has a size of 0 (zero) bytes."
20305d1054 2017-05-19 1398:                                             echo ""
20305d1054 2017-05-19 1399:                                             echo "The generation of commit message files "
20305d1054 2017-05-19 1400:                                             echo "can be avoided by using the option "
20305d1054 2017-05-19 1401:                                             echo ""
20305d1054 2017-05-19 1402:                                             echo "    \"use_autogenerated_commit_message\""
20305d1054 2017-05-19 1403:                                             echo ""
20305d1054 2017-05-19 1404:                                             echo "in stead of the option "
20305d1054 2017-05-19 1405:                                             echo ""
20305d1054 2017-05-19 1406:                                             echo "    \"read_commit_message_from_file\" ."
20305d1054 2017-05-19 1407:                                             echo ""
84fb49b807 2017-05-28 1408:                                             echo "GUID=='ae242038-b226-432d-8384-315260c151e7'"
20305d1054 2017-05-19 1409:                                             S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1410:                                             SB_EXIT_WITH_ERROR="t"
20305d1054 2017-05-19 1411:                                         fi
20305d1054 2017-05-19 1412:                                     fi
20305d1054 2017-05-19 1413:                                 fi 
20305d1054 2017-05-19 1414:                                 if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then
20305d1054 2017-05-19 1415:                                     S_TMP_0="`file --mime-type $S_FP_MESSAGE_FILE_CANDIDATE | grep text `"
20305d1054 2017-05-19 1416:                                     if [ "$S_TMP_0" == "" ]; then
20305d1054 2017-05-19 1417:                                         echo ""
20305d1054 2017-05-19 1418:                                         echo "The commit message file path "
20305d1054 2017-05-19 1419:                                         echo "references a file that has a  MIME type of "
20305d1054 2017-05-19 1420:                                         echo ""
20305d1054 2017-05-19 1421:                                         echo "`file --mime-type $S_FP_MESSAGE_FILE_CANDIDATE`"
20305d1054 2017-05-19 1422:                                         echo ""
20305d1054 2017-05-19 1423:                                         echo "The commit message file must be a text file and "
20305d1054 2017-05-19 1424:                                         echo "text files have the string \"text\" in their MIME type name."
84fb49b807 2017-05-28 1425:                                         echo "GUID=='667a8634-0924-47a3-8653-315260c151e7'"
20305d1054 2017-05-19 1426:                                         S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1427:                                         SB_EXIT_WITH_ERROR="t"
20305d1054 2017-05-19 1428:                                     fi
20305d1054 2017-05-19 1429:                                 fi 
20305d1054 2017-05-19 1430:                             fi # read_commit_message_from_file
20305d1054 2017-05-19 1431:                         fi
20305d1054 2017-05-19 1432:                     fi
20305d1054 2017-05-19 1433:                 else
20305d1054 2017-05-19 1434:                     if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "delete_local_copy" ]; then
20305d1054 2017-05-19 1435:                         if [ "$2" != "" ]; then # the 2. arg is optional here
20305d1054 2017-05-19 1436:                             if [ "$2" != "$S_ARGNAME_ACTIVITY_SHRED_ARG_2" ]; then 
20305d1054 2017-05-19 1437:                                 echo ""
20305d1054 2017-05-19 1438:                                 echo "If the first console argument is \"delete_local_copy\", then"
20305d1054 2017-05-19 1439:                                 echo "the second console argument is allowed to be only "
20305d1054 2017-05-19 1440:                                 echo ""
20305d1054 2017-05-19 1441:                                 echo "    \"$S_ARGNAME_ACTIVITY_SHRED_ARG_2\", without quotation marks."
84fb49b807 2017-05-28 1442:                                 echo "GUID=='2f439d81-c08a-4eaa-9a53-315260c151e7'"
20305d1054 2017-05-19 1443:                                 S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1444:                                 SB_EXIT_WITH_ERROR="t"
20305d1054 2017-05-19 1445:                             fi
20305d1054 2017-05-19 1446:                         fi
20305d1054 2017-05-19 1447:                     else
20305d1054 2017-05-19 1448:                         if [ "$S_ACTIVITY_OF_THIS_SCRIPT" != "print_script_version" ]; then
20305d1054 2017-05-19 1449:                             if [ "$S_ACTIVITY_OF_THIS_SCRIPT" != "help" ]; then
20305d1054 2017-05-19 1450:                                 echo ""
20305d1054 2017-05-19 1451:                                 echo "The very first console argument "
20305d1054 2017-05-19 1452:                                 echo "of this script is expected to be "
20305d1054 2017-05-19 1453:                                 echo "a command that is specific to this script."
84fb49b807 2017-05-28 1454:                                 echo "GUID=='3e7ce2c5-d3cd-4c50-af13-315260c151e7'"
20305d1054 2017-05-19 1455:                                 S_ACTIVITY_OF_THIS_SCRIPT="help"
20305d1054 2017-05-19 1456:                                 SB_EXIT_WITH_ERROR="t"
20305d1054 2017-05-19 1457:                             fi
20305d1054 2017-05-19 1458:                         fi
20305d1054 2017-05-19 1459:                     fi
20305d1054 2017-05-19 1460:                 fi
20305d1054 2017-05-19 1461:             fi
20305d1054 2017-05-19 1462:         fi
20305d1054 2017-05-19 1463:     fi
20305d1054 2017-05-19 1464: fi 
20305d1054 2017-05-19 1465: 
20305d1054 2017-05-19 1466: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1467: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "help" ]; then
20305d1054 2017-05-19 1468:     echo ""
20305d1054 2017-05-19 1469:     echo "Possible console argument sets are:"
20305d1054 2017-05-19 1470:     echo ""
20305d1054 2017-05-19 1471:     echo "    clone_all    <remote repository url>"
20305d1054 2017-05-19 1472:     echo "    clone_public <remote repository url>"
20305d1054 2017-05-19 1473:     echo "    overwrite_local_with_remote"
20305d1054 2017-05-19 1474:     echo ""
20305d1054 2017-05-19 1475:     echo "    overwrite_remote_with_local (use_autogenerated_commit_message)?"
20305d1054 2017-05-19 1476:     echo "    overwrite_remote_with_local read_commit_message_from_file <path to a text file>"
20305d1054 2017-05-19 1477:     echo ""
20305d1054 2017-05-19 1478:     echo "    delete_local_copy ($S_ARGNAME_ACTIVITY_SHRED_ARG_2)?"
20305d1054 2017-05-19 1479:     echo "    help"
20305d1054 2017-05-19 1480:     echo "    print_script_version"
20305d1054 2017-05-19 1481:     echo "    exit # just for testing"
20305d1054 2017-05-19 1482:     echo ""
20305d1054 2017-05-19 1483:     #----
20305d1054 2017-05-19 1484:     cd $S_FP_ORIG
20305d1054 2017-05-19 1485:     if [ "$SB_EXIT_WITH_ERROR" == "t" ]; then
20305d1054 2017-05-19 1486:         exit 1 # To let the parent script know that 
20305d1054 2017-05-19 1487:                # the parent script calls this script with 
20305d1054 2017-05-19 1488:                # flawed console argument values.    
20305d1054 2017-05-19 1489:     else
20305d1054 2017-05-19 1490:         exit 0
20305d1054 2017-05-19 1491:     fi
20305d1054 2017-05-19 1492: fi 
20305d1054 2017-05-19 1493: 
20305d1054 2017-05-19 1494: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1495: # The script version is needed by other scripts that depend on this script.
20305d1054 2017-05-19 1496: # The script version GUID must not be surrounded by 
20305d1054 2017-05-19 1497: # any quote signs (',"), because otherwise the 
20305d1054 2017-05-19 1498: # version GUID will be overwritten by the UpGUID tool,
20305d1054 2017-05-19 1499: # but unlike error message GUID-s this GUID must stay constant. 
20305d1054 2017-05-19 1500: # To allow the version to be used as sub-part of file names and 
20305d1054 2017-05-19 1501: # folder names, the version must not contain any spaces, line breaks
20305d1054 2017-05-19 1502: # and other characters that have a special meaning in Bash.
20305d1054 2017-05-19 1503: #
20305d1054 2017-05-19 1504: # If the version ID did not match the GUID regex, then I would have to 
20305d1054 2017-05-19 1505: # write a long comment about it not being allowed to match the 
20305d1054 2017-05-19 1506: # GUID regex. :-D 
84fb49b807 2017-05-28 1507: S_VERSION_OF_THIS_SCRIPT="453710e2-11d7-4754-942a-315260c151e7"
20305d1054 2017-05-19 1508: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "print_script_version" ]; then
20305d1054 2017-05-19 1509:     echo "The version of this script is: $S_VERSION_OF_THIS_SCRIPT"
20305d1054 2017-05-19 1510:     #----
20305d1054 2017-05-19 1511:     cd $S_FP_ORIG
20305d1054 2017-05-19 1512:     exit 0
20305d1054 2017-05-19 1513: fi 
20305d1054 2017-05-19 1514: 
20305d1054 2017-05-19 1515: 
20305d1054 2017-05-19 1516: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1517: S_FP_SANDBOX_DIRECTORY_NAME="sandbox_of_the_Fossil_repository"
20305d1054 2017-05-19 1518: S_FP_SANDBOX="$S_FP_DIR/$S_FP_SANDBOX_DIRECTORY_NAME"
20305d1054 2017-05-19 1519: #----
20305d1054 2017-05-19 1520: S_FP_ARCHIVES_DIRECTORY_NAME="archival_copies_of_the_Fossil_repository_sandbox"
20305d1054 2017-05-19 1521: S_FP_ARCHIVES="$S_FP_DIR/$S_FP_ARCHIVES_DIRECTORY_NAME"
20305d1054 2017-05-19 1522: S_FP_ARCHIVES_TS="$S_FP_ARCHIVES/v$S_TIMESTAMP"
20305d1054 2017-05-19 1523: #----
20305d1054 2017-05-19 1524: S_FP_FOSSILFILE_NAME="repository_storage.fossil"
20305d1054 2017-05-19 1525: S_FP_FOSSILFILE="$S_FP_DIR/$S_FP_FOSSILFILE_NAME"
20305d1054 2017-05-19 1526: 
20305d1054 2017-05-19 1527: #--------
20305d1054 2017-05-19 1528: S_LC_NOT_DETERMINED="not determined"
20305d1054 2017-05-19 1529: SB_SANDBOX_DIR_EXISTS="$S_LC_NOT_DETERMINED"
20305d1054 2017-05-19 1530: fun_sandbox_folder_or_symlink_exists() {
20305d1054 2017-05-19 1531:     SB_SANDBOX_DIR_EXISTS="f"
20305d1054 2017-05-19 1532:     if [ ! -e $S_FP_SANDBOX ]; then
20305d1054 2017-05-19 1533:         # Does not exist or it is a broken symbolic link.
20305d1054 2017-05-19 1534:         SB_SANDBOX_DIR_EXISTS="f"
20305d1054 2017-05-19 1535:     else
20305d1054 2017-05-19 1536:         if [ -d $S_FP_SANDBOX ]; then
20305d1054 2017-05-19 1537:             SB_SANDBOX_DIR_EXISTS="t"
20305d1054 2017-05-19 1538:         fi
20305d1054 2017-05-19 1539:     fi
20305d1054 2017-05-19 1540: } # fun_sandbox_folder_or_symlink_exists
20305d1054 2017-05-19 1541: 
20305d1054 2017-05-19 1542: SB_FOSSILFILE_EXISTS="$S_LC_NOT_DETERMINED"
20305d1054 2017-05-19 1543: fun_fossil_repository_file_or_symlink_exists() {
20305d1054 2017-05-19 1544:     SB_FOSSILFILE_EXISTS="t"
20305d1054 2017-05-19 1545:     if [ ! -e $S_FP_FOSSILFILE ]; then
20305d1054 2017-05-19 1546:         # Does not exist or it is a broken symbolic link.
20305d1054 2017-05-19 1547:         SB_FOSSILFILE_EXISTS="f"
20305d1054 2017-05-19 1548:     else
20305d1054 2017-05-19 1549:         if [ -d $S_FP_FOSSILFILE ]; then
20305d1054 2017-05-19 1550:             SB_FOSSILFILE_EXISTS="f"
20305d1054 2017-05-19 1551:         fi
20305d1054 2017-05-19 1552:     fi
20305d1054 2017-05-19 1553: } # fun_fossil_repository_file_or_symlink_exists
20305d1054 2017-05-19 1554: 
20305d1054 2017-05-19 1555: S_LC_NOT_DETERMINED="not determined"
20305d1054 2017-05-19 1556: SB_ARCHIVE_DIR_EXISTS="$S_LC_NOT_DETERMINED"
20305d1054 2017-05-19 1557: fun_archives_folder_or_symlink_exists() {
20305d1054 2017-05-19 1558:     SB_ARCHIVE_DIR_EXISTS="f"
20305d1054 2017-05-19 1559:     if [ ! -e $S_FP_ARCHIVES ]; then
20305d1054 2017-05-19 1560:         # Does not exist or it is a broken symbolic link.
20305d1054 2017-05-19 1561:         SB_ARCHIVE_DIR_EXISTS="f"
20305d1054 2017-05-19 1562:     else
20305d1054 2017-05-19 1563:         if [ -d $S_FP_ARCHIVES ]; then
20305d1054 2017-05-19 1564:             SB_ARCHIVE_DIR_EXISTS="t"
20305d1054 2017-05-19 1565:         fi
20305d1054 2017-05-19 1566:     fi
20305d1054 2017-05-19 1567: } # fun_archives_folder_or_symlink_exists
20305d1054 2017-05-19 1568: 
20305d1054 2017-05-19 1569: #--------
20305d1054 2017-05-19 1570: fun_fossil_repository_file_or_symlink_exists
20305d1054 2017-05-19 1571: fun_sandbox_folder_or_symlink_exists
20305d1054 2017-05-19 1572: fun_archives_folder_or_symlink_exists
20305d1054 2017-05-19 1573: 
20305d1054 2017-05-19 1574: fun_assertion_t1() {
20305d1054 2017-05-19 1575:     local SB_CANDIDATE=$1
20305d1054 2017-05-19 1576:     local SB_THROW="t"
20305d1054 2017-05-19 1577:     #----
20305d1054 2017-05-19 1578:     if [ "$SB_CANDIDATE" == "t" ]; then
20305d1054 2017-05-19 1579:         SB_THROW="f"
20305d1054 2017-05-19 1580:     else
20305d1054 2017-05-19 1581:         if [ "$SB_CANDIDATE" == "f" ]; then
20305d1054 2017-05-19 1582:             SB_THROW="f"
20305d1054 2017-05-19 1583:         fi
20305d1054 2017-05-19 1584:     fi
20305d1054 2017-05-19 1585:     #----
20305d1054 2017-05-19 1586:     if [ "$SB_THROW" == "t" ]; then
20305d1054 2017-05-19 1587:         echo ""
20305d1054 2017-05-19 1588:         echo "This Bash script is flawed. "
20305d1054 2017-05-19 1589:         echo "fun_assertion_t1() assertion failed."
84fb49b807 2017-05-28 1590:         echo "GUID=='42e9cbd2-3c5d-4222-9b23-315260c151e7'"
20305d1054 2017-05-19 1591:         echo ""
20305d1054 2017-05-19 1592:         #----
20305d1054 2017-05-19 1593:         cd $S_FP_ORIG
20305d1054 2017-05-19 1594:         exit 1
20305d1054 2017-05-19 1595:     fi
20305d1054 2017-05-19 1596: } # fun_assertion_t1
20305d1054 2017-05-19 1597: 
20305d1054 2017-05-19 1598: fun_assertion_t1 "$SB_FOSSILFILE_EXISTS"
20305d1054 2017-05-19 1599: fun_assertion_t1 "$SB_SANDBOX_DIR_EXISTS"
20305d1054 2017-05-19 1600: fun_assertion_t1 "$SB_ARCHIVE_DIR_EXISTS"
20305d1054 2017-05-19 1601: 
20305d1054 2017-05-19 1602: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1603: 
20305d1054 2017-05-19 1604: fun_assert_repository_local_copy_existence() {
20305d1054 2017-05-19 1605:     fun_fossil_repository_file_or_symlink_exists
20305d1054 2017-05-19 1606:     if [ "$SB_FOSSILFILE_EXISTS" == "f" ]; then
20305d1054 2017-05-19 1607:         echo ""
20305d1054 2017-05-19 1608:         echo "The directory "
20305d1054 2017-05-19 1609:         echo "`pwd`"
20305d1054 2017-05-19 1610:         echo "does not contain a Fossil repository file named "
20305d1054 2017-05-19 1611:         echo ""
20305d1054 2017-05-19 1612:         echo "    $S_FP_FOSSILFILE_NAME"
20305d1054 2017-05-19 1613:         echo ""
20305d1054 2017-05-19 1614:         echo "Aborting script."
84fb49b807 2017-05-28 1615:         echo "GUID=='45a94891-a9b3-4ee4-bc23-315260c151e7'"
20305d1054 2017-05-19 1616:         echo ""
20305d1054 2017-05-19 1617:         #----
20305d1054 2017-05-19 1618:         cd $S_FP_ORIG
20305d1054 2017-05-19 1619:         exit 1
20305d1054 2017-05-19 1620:     fi
20305d1054 2017-05-19 1621:     fun_sandbox_folder_or_symlink_exists
20305d1054 2017-05-19 1622:     if [ "$SB_SANDBOX_DIR_EXISTS" == "f" ]; then
20305d1054 2017-05-19 1623:         echo ""
20305d1054 2017-05-19 1624:         echo "The directory "
20305d1054 2017-05-19 1625:         echo "`pwd`"
20305d1054 2017-05-19 1626:         echo "does not contain a directory named "
20305d1054 2017-05-19 1627:         echo ""
20305d1054 2017-05-19 1628:         echo "    $S_FP_SANDBOX_DIRECTORY_NAME"
20305d1054 2017-05-19 1629:         echo ""
20305d1054 2017-05-19 1630:         echo "Aborting script."
84fb49b807 2017-05-28 1631:         echo "GUID=='82a93b38-aea3-4429-bf13-315260c151e7'"
20305d1054 2017-05-19 1632:         echo ""
20305d1054 2017-05-19 1633:         #----
20305d1054 2017-05-19 1634:         cd $S_FP_ORIG
20305d1054 2017-05-19 1635:         exit 1
20305d1054 2017-05-19 1636:     fi
20305d1054 2017-05-19 1637: } # fun_assert_repository_local_copy_existence
20305d1054 2017-05-19 1638: 
20305d1054 2017-05-19 1639: 
20305d1054 2017-05-19 1640: fun_assert_the_lack_of_repository_local_copy_t1() {
20305d1054 2017-05-19 1641:     if [ "$SB_FOSSILFILE_EXISTS" == "t" ]; then
20305d1054 2017-05-19 1642:         echo ""
20305d1054 2017-05-19 1643:         echo "The directory "
20305d1054 2017-05-19 1644:         echo "`pwd`"
20305d1054 2017-05-19 1645:         echo "already contain a file named "
20305d1054 2017-05-19 1646:         echo ""
20305d1054 2017-05-19 1647:         echo "    $S_FP_FOSSILFILE_NAME"
20305d1054 2017-05-19 1648:         echo ""
20305d1054 2017-05-19 1649:         echo "To avoid overwriting an existing local copy, this script is aborted"
20305d1054 2017-05-19 1650:         echo "and nothing is downloaded/uploaded by this script."
84fb49b807 2017-05-28 1651:         echo "GUID=='29282811-12e7-4e08-a312-315260c151e7'"
20305d1054 2017-05-19 1652:         echo ""
20305d1054 2017-05-19 1653:         #----
20305d1054 2017-05-19 1654:         cd $S_FP_ORIG
20305d1054 2017-05-19 1655:         exit 1
20305d1054 2017-05-19 1656:     fi
20305d1054 2017-05-19 1657:     if [ "$SB_SANDBOX_DIR_EXISTS" == "t" ]; then
20305d1054 2017-05-19 1658:         echo ""
20305d1054 2017-05-19 1659:         echo "The directory "
20305d1054 2017-05-19 1660:         echo "`pwd`"
20305d1054 2017-05-19 1661:         echo "already contains a directory named "
20305d1054 2017-05-19 1662:         echo ""
20305d1054 2017-05-19 1663:         echo "    $S_FP_SANDBOX_DIRECTORY_NAME"
20305d1054 2017-05-19 1664:         echo ""
20305d1054 2017-05-19 1665:         echo "To avoid overwriting an existing local copy, this script is aborted"
20305d1054 2017-05-19 1666:         echo "and nothing is downloaded/uploaded by this script."
84fb49b807 2017-05-28 1667:         echo "GUID=='2e467a42-dbf9-4a3c-9f12-315260c151e7'"
20305d1054 2017-05-19 1668:         echo ""
20305d1054 2017-05-19 1669:         #----
20305d1054 2017-05-19 1670:         cd $S_FP_ORIG
20305d1054 2017-05-19 1671:         exit 1
20305d1054 2017-05-19 1672:     fi
20305d1054 2017-05-19 1673: } # fun_assert_the_lack_of_repository_local_copy_t1
20305d1054 2017-05-19 1674: 
20305d1054 2017-05-19 1675: 
20305d1054 2017-05-19 1676: 
20305d1054 2017-05-19 1677: fun_initialize_sandbox_t1() {
20305d1054 2017-05-19 1678:     mkdir -p $S_FP_SANDBOX
20305d1054 2017-05-19 1679:     sync;
20305d1054 2017-05-19 1680:     cd $S_FP_SANDBOX
20305d1054 2017-05-19 1681:     fossil open $S_FP_DIR/$S_FP_FOSSILFILE_NAME # full path for reliability 
20305d1054 2017-05-19 1682:     fossil settings autosync off ;
20305d1054 2017-05-19 1683:     fossil settings binary-glob on;
20305d1054 2017-05-19 1684:     fossil settings case-sensitive TRUE ;
20305d1054 2017-05-19 1685:     fossil checkout --force --latest
20305d1054 2017-05-19 1686:     fossil pull 
20305d1054 2017-05-19 1687:     fossil close
20305d1054 2017-05-19 1688:     sync;
20305d1054 2017-05-19 1689: } # fun_initialize_sandbox_t1
20305d1054 2017-05-19 1690: 
20305d1054 2017-05-19 1691: 
20305d1054 2017-05-19 1692: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1693: fun_last_minute_checks_t1() {
20305d1054 2017-05-19 1694:     # Last minute checks, just to be sure.
20305d1054 2017-05-19 1695:     local S_FP_FORBIDDEN_VALUE=$1
20305d1054 2017-05-19 1696:     if [ "$S_FP_FORBIDDEN_VALUE" == "/" ]; then
20305d1054 2017-05-19 1697:         echo ""
20305d1054 2017-05-19 1698:         echo "This Bash script is flawed."
84fb49b807 2017-05-28 1699:         echo "GUID=='1f834782-1061-4464-8842-315260c151e7'"
20305d1054 2017-05-19 1700:         echo ""
20305d1054 2017-05-19 1701:         #----
20305d1054 2017-05-19 1702:         cd $S_FP_ORIG
20305d1054 2017-05-19 1703:         exit 1
20305d1054 2017-05-19 1704:     fi
20305d1054 2017-05-19 1705:     if [ "$S_FP_FORBIDDEN_VALUE" == "$HOME" ]; then
20305d1054 2017-05-19 1706:         echo ""
20305d1054 2017-05-19 1707:         echo "This Bash script is flawed."
84fb49b807 2017-05-28 1708:         echo "GUID=='229544f2-4a15-40e5-a442-315260c151e7'"
20305d1054 2017-05-19 1709:         echo ""
20305d1054 2017-05-19 1710:         #----
20305d1054 2017-05-19 1711:         cd $S_FP_ORIG
20305d1054 2017-05-19 1712:         exit 1
20305d1054 2017-05-19 1713:     fi
20305d1054 2017-05-19 1714:     if [ "$S_FP_FORBIDDEN_VALUE" == "/home" ]; then
20305d1054 2017-05-19 1715:         echo ""
20305d1054 2017-05-19 1716:         echo "This Bash script is flawed."
84fb49b807 2017-05-28 1717:         echo "GUID=='b232f466-35d2-4442-bc82-315260c151e7'"
20305d1054 2017-05-19 1718:         echo ""
20305d1054 2017-05-19 1719:         #----
20305d1054 2017-05-19 1720:         cd $S_FP_ORIG
20305d1054 2017-05-19 1721:         exit 1
20305d1054 2017-05-19 1722:     fi
20305d1054 2017-05-19 1723:     if [ "$S_FP_FORBIDDEN_VALUE" == "/root" ]; then
20305d1054 2017-05-19 1724:         echo ""
20305d1054 2017-05-19 1725:         echo "This Bash script is flawed."
84fb49b807 2017-05-28 1726:         echo "GUID=='59c086a5-9054-495d-b022-315260c151e7'"
20305d1054 2017-05-19 1727:         echo ""
20305d1054 2017-05-19 1728:         #----
20305d1054 2017-05-19 1729:         cd $S_FP_ORIG
20305d1054 2017-05-19 1730:         exit 1
20305d1054 2017-05-19 1731:     fi
20305d1054 2017-05-19 1732:     if [ "$S_FP_FORBIDDEN_VALUE" == "/etc" ]; then
20305d1054 2017-05-19 1733:         echo ""
20305d1054 2017-05-19 1734:         echo "This Bash script is flawed."
84fb49b807 2017-05-28 1735:         echo "GUID=='ac651b62-3c43-44de-9aa1-315260c151e7'"
20305d1054 2017-05-19 1736:         echo ""
20305d1054 2017-05-19 1737:         #----
20305d1054 2017-05-19 1738:         cd $S_FP_ORIG
20305d1054 2017-05-19 1739:         exit 1
20305d1054 2017-05-19 1740:     fi
20305d1054 2017-05-19 1741:     if [ "$S_FP_FORBIDDEN_VALUE" == "/usr" ]; then
20305d1054 2017-05-19 1742:         echo ""
20305d1054 2017-05-19 1743:         echo "This Bash script is flawed."
84fb49b807 2017-05-28 1744:         echo "GUID=='40dcf201-5646-4ebb-bd11-315260c151e7'"
20305d1054 2017-05-19 1745:         echo ""
20305d1054 2017-05-19 1746:         #----
20305d1054 2017-05-19 1747:         cd $S_FP_ORIG
20305d1054 2017-05-19 1748:         exit 1
20305d1054 2017-05-19 1749:     fi
20305d1054 2017-05-19 1750: } # fun_last_minute_checks_t1
20305d1054 2017-05-19 1751: 
20305d1054 2017-05-19 1752: 
20305d1054 2017-05-19 1753: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1754: SB_FOLDER_IS_EMPTY="$S_LC_NOT_DETERMINED"
20305d1054 2017-05-19 1755: fun_folder_is_empty_t1() {
20305d1054 2017-05-19 1756:     local S_FP_FOLDER_TO_STUDY=$1
20305d1054 2017-05-19 1757:     local S_FP_ORIG_LOCAL="`pwd`"
20305d1054 2017-05-19 1758:     #--------
20305d1054 2017-05-19 1759:     SB_FOLDER_IS_EMPTY="t"
20305d1054 2017-05-19 1760:     local S_TMP_0="`cd $S_FP_FOLDER_TO_STUDY; ls -l | grep \"total 0\"`"
20305d1054 2017-05-19 1761:     if [ "$S_TMP_0" == "" ]; then
20305d1054 2017-05-19 1762:         SB_FOLDER_IS_EMPTY="f"
20305d1054 2017-05-19 1763:     fi
20305d1054 2017-05-19 1764:     #--------
20305d1054 2017-05-19 1765:     cd $S_FP_ORIG_LOCAL # just in case
20305d1054 2017-05-19 1766: } # fun_folder_is_empty_t1
20305d1054 2017-05-19 1767: 
20305d1054 2017-05-19 1768: fun_folder_is_empty_t1 "$S_FP_DIR"
20305d1054 2017-05-19 1769: fun_assertion_t1 "$SB_FOLDER_IS_EMPTY"
20305d1054 2017-05-19 1770: if [ "$SB_FOLDER_IS_EMPTY" == "t" ]; then
20305d1054 2017-05-19 1771:     echo ""
20305d1054 2017-05-19 1772:     echo "This Bash script is flawed. The "
20305d1054 2017-05-19 1773:     echo "$S_FP_DIR" 
20305d1054 2017-05-19 1774:     echo "can not possibly be empty, because it contains "
20305d1054 2017-05-19 1775:     echo "at least one file, which is "
20305d1054 2017-05-19 1776:     echo "this very same Bash script that outputs the current error message."
84fb49b807 2017-05-28 1777:     echo "GUID=='4bdcc1c4-3464-4025-8231-315260c151e7'"
20305d1054 2017-05-19 1778:     echo ""
20305d1054 2017-05-19 1779:     #----
20305d1054 2017-05-19 1780:     cd $S_FP_ORIG
20305d1054 2017-05-19 1781:     exit 1
20305d1054 2017-05-19 1782: fi
20305d1054 2017-05-19 1783: 
20305d1054 2017-05-19 1784: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1785: 
20305d1054 2017-05-19 1786: fun_activity_core_overwrite_local_with_remote() {
20305d1054 2017-05-19 1787:     fun_fossil_repository_file_or_symlink_exists
20305d1054 2017-05-19 1788:     if [ "$SB_FOSSILFILE_EXISTS" == "t" ]; then
20305d1054 2017-05-19 1789:         fun_sandbox_folder_or_symlink_exists
20305d1054 2017-05-19 1790:         if [ "$SB_SANDBOX_DIR_EXISTS" == "f" ]; then
20305d1054 2017-05-19 1791:             mkdir $S_FP_SANDBOX 
20305d1054 2017-05-19 1792:         else
20305d1054 2017-05-19 1793:             if [ "$SB_SANDBOX_DIR_EXISTS" != "t" ]; then
20305d1054 2017-05-19 1794:                 echo ""
20305d1054 2017-05-19 1795:                 echo "This Bash script is flawed."
20305d1054 2017-05-19 1796:                 echo ""
20305d1054 2017-05-19 1797:                 echo "    SB_SANDBOX_DIR_EXISTS==$SB_SANDBOX_DIR_EXISTS" 
20305d1054 2017-05-19 1798:                 echo ""
20305d1054 2017-05-19 1799:                 echo "Aborting script."
84fb49b807 2017-05-28 1800:                 echo "GUID=='177d1983-f7b0-4569-ba31-315260c151e7'"
20305d1054 2017-05-19 1801:                 echo ""
20305d1054 2017-05-19 1802:                 #----
20305d1054 2017-05-19 1803:                 cd $S_FP_ORIG
20305d1054 2017-05-19 1804:                 exit 1
20305d1054 2017-05-19 1805:             fi
20305d1054 2017-05-19 1806:         fi
20305d1054 2017-05-19 1807:     else
20305d1054 2017-05-19 1808:         if [ "$SB_FOSSILFILE_EXISTS" != "f" ]; then
20305d1054 2017-05-19 1809:             echo ""
20305d1054 2017-05-19 1810:             echo "This Bash script is flawed."
20305d1054 2017-05-19 1811:             echo ""
20305d1054 2017-05-19 1812:             echo "    SB_FOSSILFILE_EXISTS==$SB_FOSSILFILE_EXISTS" 
20305d1054 2017-05-19 1813:             echo ""
20305d1054 2017-05-19 1814:             echo "Aborting script."
84fb49b807 2017-05-28 1815:             echo "GUID=='84496d8b-1130-4cdd-ac11-315260c151e7'"
20305d1054 2017-05-19 1816:             echo ""
20305d1054 2017-05-19 1817:             #----
20305d1054 2017-05-19 1818:             cd $S_FP_ORIG
20305d1054 2017-05-19 1819:             exit 1
20305d1054 2017-05-19 1820:         fi
20305d1054 2017-05-19 1821:     fi
20305d1054 2017-05-19 1822:     fun_assert_repository_local_copy_existence
20305d1054 2017-05-19 1823:     #--------
20305d1054 2017-05-19 1824:     # The checks are party to cope with the `whoami`=="root" case.
20305d1054 2017-05-19 1825:     fun_last_minute_checks_t1 "$S_FP_SANDBOX"
20305d1054 2017-05-19 1826:     fun_last_minute_checks_t1 "$S_FP_ARCHIVES"
20305d1054 2017-05-19 1827:     fun_last_minute_checks_t1 "$S_FP_ARCHIVES_TS"
20305d1054 2017-05-19 1828:     #--------
20305d1054 2017-05-19 1829:     chmod -f -R u+rx $S_FP_SANDBOX
20305d1054 2017-05-19 1830:     fun_folder_is_empty_t1 "$S_FP_SANDBOX"
20305d1054 2017-05-19 1831:     if [ "$SB_FOLDER_IS_EMPTY" == "f" ]; then
20305d1054 2017-05-19 1832:         # This if-statement is needed because the 
20305d1054 2017-05-19 1833:         #      cp -f -R AnEmptyDirectory/* ToSomewhere/
20305d1054 2017-05-19 1834:         # gives an error.
20305d1054 2017-05-19 1835:         #----
20305d1054 2017-05-19 1836:         mkdir -p $S_FP_ARCHIVES_TS
20305d1054 2017-05-19 1837:         #----
20305d1054 2017-05-19 1838:         # The "chmod -f -R " is not used because it would
20305d1054 2017-05-19 1839:         # waste time on folders that are named by 
20305d1054 2017-05-19 1840:         # the older $S_FP_ARCHIVES_TS values.
20305d1054 2017-05-19 1841:         chmod -f 0700 $S_FP_ARCHIVES
20305d1054 2017-05-19 1842:         chmod -f 0700 $S_FP_ARCHIVES_TS 
20305d1054 2017-05-19 1843:         #----
20305d1054 2017-05-19 1844:         # The separate cp and rm of the sandbox
20305d1054 2017-05-19 1845:         # contents is to somewhat retain the original
20305d1054 2017-05-19 1846:         # file premissions of the sandbox contents.
20305d1054 2017-05-19 1847:         cp -f -R $S_FP_SANDBOX/* $S_FP_ARCHIVES_TS/
20305d1054 2017-05-19 1848:         fun_last_minute_checks_t1 "$S_FP_SANDBOX"
20305d1054 2017-05-19 1849:         chmod -f -R u+rwx $S_FP_SANDBOX
20305d1054 2017-05-19 1850:         rm -fr $S_FP_SANDBOX/*
20305d1054 2017-05-19 1851:     fi
20305d1054 2017-05-19 1852:     #--------
20305d1054 2017-05-19 1853:     cd $S_FP_SANDBOX
20305d1054 2017-05-19 1854:     fossil open $S_FP_DIR/$S_FP_FOSSILFILE_NAME # full path for reliability 
20305d1054 2017-05-19 1855:     fossil settings autosync off ;
20305d1054 2017-05-19 1856:     fossil settings binary-glob on;
20305d1054 2017-05-19 1857:     fossil settings case-sensitive TRUE ;
20305d1054 2017-05-19 1858:     fossil checkout --force --latest
20305d1054 2017-05-19 1859:     fossil pull 
20305d1054 2017-05-19 1860:     fossil close
20305d1054 2017-05-19 1861: } # fun_activity_core_overwrite_local_with_remote
20305d1054 2017-05-19 1862: 
20305d1054 2017-05-19 1863: 
20305d1054 2017-05-19 1864: 
20305d1054 2017-05-19 1865: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "overwrite_local_with_remote" ]; then
20305d1054 2017-05-19 1866:     fun_activity_core_overwrite_local_with_remote
20305d1054 2017-05-19 1867:     #----
20305d1054 2017-05-19 1868:     cd $S_FP_ORIG
20305d1054 2017-05-19 1869:     exit 0
20305d1054 2017-05-19 1870: fi # overwrite_local_with_remote
20305d1054 2017-05-19 1871: 
20305d1054 2017-05-19 1872: 
20305d1054 2017-05-19 1873: 
20305d1054 2017-05-19 1874: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1875: fossil close 2>/dev/null
20305d1054 2017-05-19 1876: 
20305d1054 2017-05-19 1877: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "clone_public" ]; then
20305d1054 2017-05-19 1878:     fun_assert_the_lack_of_repository_local_copy_t1
20305d1054 2017-05-19 1879:     cd $S_FP_DIR 
20305d1054 2017-05-19 1880:     fossil clone $S_URL_REMOTE_REPOSITORY ./$S_FP_FOSSILFILE_NAME
20305d1054 2017-05-19 1881:     fun_initialize_sandbox_t1
20305d1054 2017-05-19 1882:     cd $S_FP_ORIG
20305d1054 2017-05-19 1883:     #----
20305d1054 2017-05-19 1884:     sync
20305d1054 2017-05-19 1885:     fun_activity_core_overwrite_local_with_remote
20305d1054 2017-05-19 1886:     cd $S_FP_ORIG
20305d1054 2017-05-19 1887:     sync
20305d1054 2017-05-19 1888:     #----
20305d1054 2017-05-19 1889:     exit 0
20305d1054 2017-05-19 1890: fi # clone_public
20305d1054 2017-05-19 1891: 
20305d1054 2017-05-19 1892: 
20305d1054 2017-05-19 1893: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1894: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "clone_all" ]; then
20305d1054 2017-05-19 1895:     fun_assert_the_lack_of_repository_local_copy_t1
20305d1054 2017-05-19 1896:     cd $S_FP_DIR 
20305d1054 2017-05-19 1897:     #--------
20305d1054 2017-05-19 1898:     S_USERNAME=""
20305d1054 2017-05-19 1899:     while [ "$S_USERNAME" == "" ]
20305d1054 2017-05-19 1900:     do
20305d1054 2017-05-19 1901:         echo ""
20305d1054 2017-05-19 1902:         echo "Please enter a username: "
20305d1054 2017-05-19 1903:         S_USERNAME="`ruby -e \"s=gets.gsub(/[\n\r\s]/,'');print(s)\"`" 
20305d1054 2017-05-19 1904:         S_URL="`export S_USERNAME=\"$S_USERNAME\"; S_URL=\"$S_URL_REMOTE_REPOSITORY\" ruby -e 's_0=ENV[\"S_URL\"].sub(/^http:[\\/]+/,\"http://\").sub(/^https:[\\/]+/,\"https://\").sub(\"://\",\"://\"+ENV[\"S_USERNAME\"].to_s+\":nonsensepassword@\");print(s_0)'`"
20305d1054 2017-05-19 1905:     done
20305d1054 2017-05-19 1906:     #--------
20305d1054 2017-05-19 1907:     fossil clone --private $S_URL ./$S_FP_FOSSILFILE_NAME
20305d1054 2017-05-19 1908:     fun_initialize_sandbox_t1
20305d1054 2017-05-19 1909:     cd $S_FP_ORIG
20305d1054 2017-05-19 1910:     #----
20305d1054 2017-05-19 1911:     sync
20305d1054 2017-05-19 1912:     fun_activity_core_overwrite_local_with_remote
20305d1054 2017-05-19 1913:     cd $S_FP_ORIG
20305d1054 2017-05-19 1914:     sync
20305d1054 2017-05-19 1915:     #----
20305d1054 2017-05-19 1916:     exit 0
20305d1054 2017-05-19 1917: fi # clone_all
20305d1054 2017-05-19 1918: 
20305d1054 2017-05-19 1919: 
20305d1054 2017-05-19 1920: #--------------------------------------------------------------------------
20305d1054 2017-05-19 1921: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "overwrite_remote_with_local" ]; then
20305d1054 2017-05-19 1922:     fun_assert_repository_local_copy_existence
20305d1054 2017-05-19 1923:     #--------
20305d1054 2017-05-19 1924:     # It's important that this script will not try 
20305d1054 2017-05-19 1925:     # to recursively copy/move the content of the "/" to 
20305d1054 2017-05-19 1926:     # a subfolder of the "/", the "/tmp". 
20305d1054 2017-05-19 1927:     # The other folders that are covered by the
20305d1054 2017-05-19 1928:     # test are a bit of an overkill here, may be even an
20305d1054 2017-05-19 1929:     # annoying and unjustified restrictions, but 
20305d1054 2017-05-19 1930:     # in most cases those restrictions do not hurt either.
20305d1054 2017-05-19 1931:     fun_last_minute_checks_t1 "$S_FP_SANDBOX"
20305d1054 2017-05-19 1932:     #----
20305d1054 2017-05-19 1933:     S_TMP_0="$MMMV_FP_FOSSIL_OPERATOR_TMP/tmp_mmmv_$S_VERSION_OF_THIS_SCRIPT"
20305d1054 2017-05-19 1934:     S_TMP_1="__"
20305d1054 2017-05-19 1935:     #--
20305d1054 2017-05-19 1936:     func_mmmv_GUID_t1
20305d1054 2017-05-19 1937:     S_TMP_FOR_LOCAL="$S_TMP_0$S_TMP_1$S_FUNC_MMMV_GUID_T1_RESULT"
20305d1054 2017-05-19 1938:     #--
20305d1054 2017-05-19 1939:     func_mmmv_GUID_t1
20305d1054 2017-05-19 1940:     S_TMP_FOR_COMMIT_MESSAGE="$S_TMP_0$S_TMP_1$S_FUNC_MMMV_GUID_T1_RESULT"
20305d1054 2017-05-19 1941:     mkdir -p $S_TMP_FOR_LOCAL
20305d1054 2017-05-19 1942:     chmod -f -R u+rwx $S_FP_SANDBOX
20305d1054 2017-05-19 1943:     mv -f $S_FP_SANDBOX/* $S_TMP_FOR_LOCAL/ # the -f is for empty sandbox
20305d1054 2017-05-19 1944:     #--------
20305d1054 2017-05-19 1945:     fun_activity_core_overwrite_local_with_remote 
20305d1054 2017-05-19 1946:     fun_last_minute_checks_t1 "$S_FP_SANDBOX" # should there be flaws elsewhere
20305d1054 2017-05-19 1947:     chmod -f -R u+rwx $S_FP_SANDBOX # to be able to delete the old content
20305d1054 2017-05-19 1948:     #--------
20305d1054 2017-05-19 1949:     cd $S_FP_SANDBOX
20305d1054 2017-05-19 1950:         fossil open $S_FP_DIR/$S_FP_FOSSILFILE_NAME # full path for reliability 
20305d1054 2017-05-19 1951:         fossil settings autosync off ;
20305d1054 2017-05-19 1952:         fossil settings binary-glob on;
20305d1054 2017-05-19 1953:         fossil settings case-sensitive TRUE ;
20305d1054 2017-05-19 1954:         fun_folder_is_empty_t1 "$S_FP_SANDBOX"
20305d1054 2017-05-19 1955:         SB_SANDBOX_CONTENT_MIGHT_HAVE_BEEN_CHANGED="f"
20305d1054 2017-05-19 1956:         if [ "$SB_FOLDER_IS_EMPTY" == "f" ]; then
20305d1054 2017-05-19 1957:             fossil rm --hard --case-sensitive TRUE ./* 
20305d1054 2017-05-19 1958:             SB_SANDBOX_CONTENT_MIGHT_HAVE_BEEN_CHANGED="t"
20305d1054 2017-05-19 1959:             fun_last_minute_checks_t1 "`pwd`"
20305d1054 2017-05-19 1960:             if [ "$S_FP_SANDBOX" == "`pwd`" ]; then
20305d1054 2017-05-19 1961:                 rm -fr ./*
20305d1054 2017-05-19 1962:             else
20305d1054 2017-05-19 1963:                 echo ""
20305d1054 2017-05-19 1964:                 echo "This Bash script is flawed."
84fb49b807 2017-05-28 1965:                 echo "GUID=='26d22662-8878-4660-9120-315260c151e7'"
20305d1054 2017-05-19 1966:                 echo ""
20305d1054 2017-05-19 1967:                 #----
20305d1054 2017-05-19 1968:                 cd $S_FP_ORIG
20305d1054 2017-05-19 1969:                 exit 1
20305d1054 2017-05-19 1970:             fi
20305d1054 2017-05-19 1971:         fi
20305d1054 2017-05-19 1972:         mv -f $S_TMP_FOR_LOCAL/* $S_FP_SANDBOX/ # the -f is for empty source
20305d1054 2017-05-19 1973:         #----
20305d1054 2017-05-19 1974:         fun_last_minute_checks_t1 "$S_TMP_FOR_LOCAL"
20305d1054 2017-05-19 1975:         rm -fr $S_TMP_FOR_LOCAL
20305d1054 2017-05-19 1976:         #----
20305d1054 2017-05-19 1977:         fun_folder_is_empty_t1 "$S_FP_SANDBOX"
20305d1054 2017-05-19 1978:         if [ "$SB_FOLDER_IS_EMPTY" == "f" ]; then
20305d1054 2017-05-19 1979:             if [ "$S_FP_SANDBOX" != "`pwd`" ]; then
20305d1054 2017-05-19 1980:                 echo ""
20305d1054 2017-05-19 1981:                 echo "This Bash script is flawed."
84fb49b807 2017-05-28 1982:                 echo "GUID=='1198e2f3-6a9e-418d-b590-315260c151e7'"
20305d1054 2017-05-19 1983:                 echo ""
20305d1054 2017-05-19 1984:                 #----
20305d1054 2017-05-19 1985:                 cd $S_FP_ORIG
20305d1054 2017-05-19 1986:                 exit 1
20305d1054 2017-05-19 1987:             fi
20305d1054 2017-05-19 1988:             find . -name '*' | xargs fossil add --force --dotfiles --case-sensitive TRUE  
20305d1054 2017-05-19 1989:             SB_SANDBOX_CONTENT_MIGHT_HAVE_BEEN_CHANGED="t"
20305d1054 2017-05-19 1990:         fi
20305d1054 2017-05-19 1991:         if [ "$SB_SANDBOX_CONTENT_MIGHT_HAVE_BEEN_CHANGED" == "t" ]; then
20305d1054 2017-05-19 1992:             if [ "$2" == "" ]; then
20305d1054 2017-05-19 1993:                 echo ""
20305d1054 2017-05-19 1994:                 #echo "Please enter a one-liner commit message: "
20305d1054 2017-05-19 1995:                 #S_TMP_0="`ruby -e \"s=gets.gsub(/[\n\r\s]/,'');print(s)\"`" 
20305d1054 2017-05-19 1996:                 # TODO: improve this script so that it would not ask 
20305d1054 2017-05-19 1997:                 # for a commit message, when nothing changed. It requires
20305d1054 2017-05-19 1998:                 # some recursive analysis of files, which might be slow.
20305d1054 2017-05-19 1999:                 # This script is not optimal for speed even now and that would
20305d1054 2017-05-19 2000:                 # make it even slower. On the other hand, usually when 
20305d1054 2017-05-19 2001:                 # the upload operation is initiated, there are some changes,
20305d1054 2017-05-19 2002:                 # which means that the slow analysis would be useless in 
20305d1054 2017-05-19 2003:                 # most frequent cases. So this thing needs to be figured out 
20305d1054 2017-05-19 2004:                 # at some later time, when there is more experience with the
20305d1054 2017-05-19 2005:                 # use of this script.
20305d1054 2017-05-19 2006:                 read -p "Please enter a one-liner commit message: " S_TMP_0
20305d1054 2017-05-19 2007:                 echo $S_TMP_0 > $S_TMP_FOR_COMMIT_MESSAGE
20305d1054 2017-05-19 2008:             else
20305d1054 2017-05-19 2009:                 if [ "$2" == "use_autogenerated_commit_message" ]; then
20305d1054 2017-05-19 2010:                     echo "Autogenerated commit message timestamp: $S_TIMESTAMP" > $S_TMP_FOR_COMMIT_MESSAGE
20305d1054 2017-05-19 2011:                 else
20305d1054 2017-05-19 2012:                     if [ "$2" == "read_commit_message_from_file" ]; then
20305d1054 2017-05-19 2013:                         S_FP_MESSAGE_FILE_CANDIDATE="$3" # file path candidate
20305d1054 2017-05-19 2014:                         # Initial file existence and type checks for the 
20305d1054 2017-05-19 2015:                         # $S_FP_MESSAGE_FILE_CANDIDATE 
20305d1054 2017-05-19 2016:                         # were conducted at the start of the script.
20305d1054 2017-05-19 2017:                         # but the $S_FP_MESSAGE_FILE_CANDIDATE  might have
20305d1054 2017-05-19 2018:                         # referenced a file in the sandbox and 
20305d1054 2017-05-19 2019:                         # that file might have been just removed/deleted.
20305d1054 2017-05-19 2020:                         #
20305d1054 2017-05-19 2021:                         # There is no threat that the file got changed to a folder
20305d1054 2017-05-19 2022:                         # or a symlink switched from a file to a folder,
20305d1054 2017-05-19 2023:                         # at least that's the case for the single threaded model.
20305d1054 2017-05-19 2024:                         if [ ! -e "$S_FP_MESSAGE_FILE_CANDIDATE" ]; then 
20305d1054 2017-05-19 2025:                             # missing or a broken symlink
20305d1054 2017-05-19 2026:                             echo ""
20305d1054 2017-05-19 2027:                             echo "The commit message file is missing or "
20305d1054 2017-05-19 2028:                             echo "references a broken symlink."
20305d1054 2017-05-19 2029:                             echo "The file or symlink to it was fine at "
20305d1054 2017-05-19 2030:                             echo "the start of this script, it passed the various tests, "
20305d1054 2017-05-19 2031:                             echo "but for some reason it got deleted or its target . "
20305d1054 2017-05-19 2032:                             echo "got deleted. If the commit message file or"
20305d1054 2017-05-19 2033:                             echo "the symlink target resided within the sandbox, then "
20305d1054 2017-05-19 2034:                             echo "a recommendation is to use a file that resides "
20305d1054 2017-05-19 2035:                             echo "outside of the sandbox."
84fb49b807 2017-05-28 2036:                             echo "GUID=='d413d55a-e897-4940-b330-315260c151e7'"
20305d1054 2017-05-19 2037:                             echo ""
20305d1054 2017-05-19 2038:                             #----
20305d1054 2017-05-19 2039:                             cd $S_FP_ORIG
20305d1054 2017-05-19 2040:                             exit 1
20305d1054 2017-05-19 2041:                         fi
20305d1054 2017-05-19 2042:                         if [ -d "$S_FP_MESSAGE_FILE_CANDIDATE" ]; then 
20305d1054 2017-05-19 2043:                             # folder or a symlink to a folder
20305d1054 2017-05-19 2044:                             echo ""
20305d1054 2017-05-19 2045:                             echo "The commit message file path does not reference "
20305d1054 2017-05-19 2046:                             echo "a file. It references a folder or a symlink to a folder."
20305d1054 2017-05-19 2047:                             echo "The file or symlink to it was fine at "
20305d1054 2017-05-19 2048:                             echo "the start of this script, it passed the various tests, "
20305d1054 2017-05-19 2049:                             echo "but for some reason there were changes. "
84fb49b807 2017-05-28 2050:                             echo "GUID=='f4bd192b-71c0-42ab-99c0-315260c151e7'"
20305d1054 2017-05-19 2051:                             echo ""
20305d1054 2017-05-19 2052:                             #----
20305d1054 2017-05-19 2053:                             cd $S_FP_ORIG
20305d1054 2017-05-19 2054:                             exit 1
20305d1054 2017-05-19 2055:                         fi
20305d1054 2017-05-19 2056:                         cat $S_FP_MESSAGE_FILE_CANDIDATE > $S_TMP_FOR_COMMIT_MESSAGE
20305d1054 2017-05-19 2057:                     # else
20305d1054 2017-05-19 2058:                     #     Due to the checks at the start of the script 
20305d1054 2017-05-19 2059:                     #     this else branch is useless.
20305d1054 2017-05-19 2060:                     fi
20305d1054 2017-05-19 2061:                 fi
20305d1054 2017-05-19 2062:             fi
20305d1054 2017-05-19 2063:             #--------
20305d1054 2017-05-19 2064:             fossil commit --message-file $S_TMP_FOR_COMMIT_MESSAGE
20305d1054 2017-05-19 2065:             #----
20305d1054 2017-05-19 2066:             fun_last_minute_checks_t1 "$S_TMP_FOR_COMMIT_MESSAGE"
20305d1054 2017-05-19 2067:             rm -f $S_TMP_FOR_COMMIT_MESSAGE
20305d1054 2017-05-19 2068:             #----
20305d1054 2017-05-19 2069:         fi
20305d1054 2017-05-19 2070:     #--------
20305d1054 2017-05-19 2071:     fossil push --private
20305d1054 2017-05-19 2072:     fossil push 
20305d1054 2017-05-19 2073:     fossil pull --private
20305d1054 2017-05-19 2074:     fossil close
20305d1054 2017-05-19 2075:     #----
20305d1054 2017-05-19 2076:     cd $S_FP_ORIG
20305d1054 2017-05-19 2077:     exit 0
20305d1054 2017-05-19 2078: fi # overwrite_remote_with_local
20305d1054 2017-05-19 2079: 
20305d1054 2017-05-19 2080: 
20305d1054 2017-05-19 2081: #--------------------------------------------------------------------------
20305d1054 2017-05-19 2082: if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "delete_local_copy" ]; then
20305d1054 2017-05-19 2083:     #--------
20305d1054 2017-05-19 2084:     SB_THERE_IS_SOMETHING_TO_DELETE="f"
20305d1054 2017-05-19 2085:     if [ "$SB_FOSSILFILE_EXISTS" == "t" ]; then
20305d1054 2017-05-19 2086:         SB_THERE_IS_SOMETHING_TO_DELETE="t"
20305d1054 2017-05-19 2087:     fi
20305d1054 2017-05-19 2088:     if [ "$SB_SANDBOX_DIR_EXISTS" == "t" ]; then
20305d1054 2017-05-19 2089:         SB_THERE_IS_SOMETHING_TO_DELETE="t"
20305d1054 2017-05-19 2090:     fi
20305d1054 2017-05-19 2091:     if [ "$SB_ARCHIVE_DIR_EXISTS" == "t" ]; then
20305d1054 2017-05-19 2092:         SB_THERE_IS_SOMETHING_TO_DELETE="t"
20305d1054 2017-05-19 2093:     fi
20305d1054 2017-05-19 2094:     #--------
20305d1054 2017-05-19 2095:     if [ "$SB_THERE_IS_SOMETHING_TO_DELETE" == "t" ]; then 
20305d1054 2017-05-19 2096:         if [ "$2" != "$S_ARGNAME_ACTIVITY_SHRED_ARG_2" ]; then 
20305d1054 2017-05-19 2097:             # Includes the $2=="" case
20305d1054 2017-05-19 2098:             # id est if the control flow is in here, then there 
20305d1054 2017-05-19 2099:             # is a need to prompt for confirmation.
20305d1054 2017-05-19 2100:             # The skipping of the prompt is necessary for
20305d1054 2017-05-19 2101:             # software that use this script as its sub-component.
20305d1054 2017-05-19 2102:             #--------
20305d1054 2017-05-19 2103:             echo ""
20305d1054 2017-05-19 2104:             echo "The command \"delete_local_copy\" deletes "
20305d1054 2017-05-19 2105:             echo "the repository file, the sandbox and "
20305d1054 2017-05-19 2106:             echo "the associated automatically created archives."
20305d1054 2017-05-19 2107:             echo ""
20305d1054 2017-05-19 2108:             read -p "Proceed with deletion?  (Yes/whatever_else)  " S_TMP_0
20305d1054 2017-05-19 2109:             S_TMP_1="`echo $S_TMP_0 | gawk '{print tolower($1)}'`"
20305d1054 2017-05-19 2110:             if [ "$S_TMP_1" == "yes" ]; then
20305d1054 2017-05-19 2111:                 echo ""
20305d1054 2017-05-19 2112:                 printf "Deleting ... "
20305d1054 2017-05-19 2113:             else
20305d1054 2017-05-19 2114:                 fun_exit_without_any_errors_t1
20305d1054 2017-05-19 2115:             fi
20305d1054 2017-05-19 2116:        fi
20305d1054 2017-05-19 2117:     fi
20305d1054 2017-05-19 2118:     #--------
20305d1054 2017-05-19 2119:     cd $S_FP_ORIG # to make sure that we're not in the sandbox directory and 
20305d1054 2017-05-19 2120:                   # to make sure that we're not in the archive directory
20305d1054 2017-05-19 2121:     #----
20305d1054 2017-05-19 2122:     # The next 3 checks can bee seen to form a complete graph, 
20305d1054 2017-05-19 2123:     # in this case a triangle, with corner points  
20305d1054 2017-05-19 2124:     # S_FP_SANDBOX, S_FP_ARCHIVES, S_FP_FOSSILFILE connected
20305d1054 2017-05-19 2125:     # with lines of type "!=".
84fb49b807 2017-05-28 2126:     S_GUID="5b6a1941-e904-4f4b-881a-315260c151e7"
20305d1054 2017-05-19 2127:     func_mmmv_assert_file_paths_differ_t1 "$S_FP_FOSSILFILE" "$S_FP_SANDBOX" "$S_GUID"
20305d1054 2017-05-19 2128: 
84fb49b807 2017-05-28 2129:     S_GUID="52fba370-3714-4261-8cda-315260c151e7"
20305d1054 2017-05-19 2130:     func_mmmv_assert_file_paths_differ_t1 "$S_FP_SANDBOX" "$S_FP_ARCHIVES" "$S_GUID"
20305d1054 2017-05-19 2131: 
84fb49b807 2017-05-28 2132:     S_GUID="3819ed71-4933-4cf0-bc39-315260c151e7"
20305d1054 2017-05-19 2133:     func_mmmv_assert_file_paths_differ_t1 "$S_FP_ARCHIVES" "$S_FP_FOSSILFILE" "$S_GUID"
20305d1054 2017-05-19 2134:     #----
20305d1054 2017-05-19 2135:     # The next 3 checks turn the triangle to a tetrahedron, where  
20305d1054 2017-05-19 2136:     # the S_FP_ORIG is the "top of the pyramid".
84fb49b807 2017-05-28 2137:     S_GUID="eb5f2645-8e06-4cdc-8349-315260c151e7"
20305d1054 2017-05-19 2138:     func_mmmv_assert_file_paths_differ_t1 "$S_FP_ORIG" "$S_FP_FOSSILFILE" "$S_GUID"
20305d1054 2017-05-19 2139:     
84fb49b807 2017-05-28 2140:     S_GUID="4a3ea145-2e3a-498a-b019-315260c151e7"
20305d1054 2017-05-19 2141:     func_mmmv_assert_file_paths_differ_t1 "$S_FP_ORIG" "$S_FP_ARCHIVES" "$S_GUID"
20305d1054 2017-05-19 2142: 
84fb49b807 2017-05-28 2143:     S_GUID="72bd0a15-d08b-4bdf-9558-315260c151e7"
20305d1054 2017-05-19 2144:     func_mmmv_assert_file_paths_differ_t1 "$S_FP_ORIG" "$S_FP_SANDBOX" "$S_GUID"
20305d1054 2017-05-19 2145:     #--------
20305d1054 2017-05-19 2146:     cd $S_FP_ORIG # just in case
20305d1054 2017-05-19 2147:     SB_OK_TO_USE_RM_IN_STEAD_OF_SHRED="t" # shred is still used, if available
20305d1054 2017-05-19 2148:     if [ "$SB_FOSSILFILE_EXISTS" == "t" ]; then
20305d1054 2017-05-19 2149:         fun_last_minute_checks_t1 "`pwd`"
20305d1054 2017-05-19 2150:         func_mmmv_shred_t1 "$S_FP_FOSSILFILE" "$SB_OK_TO_USE_RM_IN_STEAD_OF_SHRED"
20305d1054 2017-05-19 2151:     fi
20305d1054 2017-05-19 2152:     if [ "$SB_SANDBOX_DIR_EXISTS" == "t" ]; then
20305d1054 2017-05-19 2153:         fun_last_minute_checks_t1 "`pwd`"
20305d1054 2017-05-19 2154:         func_mmmv_shred_t1 "$S_FP_SANDBOX" "$SB_OK_TO_USE_RM_IN_STEAD_OF_SHRED"
20305d1054 2017-05-19 2155:     fi
20305d1054 2017-05-19 2156:     if [ "$SB_ARCHIVE_DIR_EXISTS" == "t" ]; then
20305d1054 2017-05-19 2157:         fun_last_minute_checks_t1 "`pwd`"
20305d1054 2017-05-19 2158:         func_mmmv_shred_t1 "$S_FP_ARCHIVES" "$SB_OK_TO_USE_RM_IN_STEAD_OF_SHRED"
20305d1054 2017-05-19 2159:     fi
20305d1054 2017-05-19 2160:     #--------
20305d1054 2017-05-19 2161:     if [ "$SB_THERE_IS_SOMETHING_TO_DELETE" == "t" ]; then 
20305d1054 2017-05-19 2162:         if [ "$2" != "$S_ARGNAME_ACTIVITY_SHRED_ARG_2" ]; then 
20305d1054 2017-05-19 2163:             echo "✓"
20305d1054 2017-05-19 2164:             echo ""
20305d1054 2017-05-19 2165:         fi
20305d1054 2017-05-19 2166:     fi
20305d1054 2017-05-19 2167:     #--------
20305d1054 2017-05-19 2168:     cd $S_FP_ORIG
20305d1054 2017-05-19 2169:     exit 0
20305d1054 2017-05-19 2170: fi # delete_local_copy
20305d1054 2017-05-19 2171: 
20305d1054 2017-05-19 2172: 
20305d1054 2017-05-19 2173: #--------------------------------------------------------------------------
20305d1054 2017-05-19 2174: # All possible actions must have been described
20305d1054 2017-05-19 2175: # above this code block.
20305d1054 2017-05-19 2176: echo ""
20305d1054 2017-05-19 2177: echo "This Bash script is flawed."
84fb49b807 2017-05-28 2178: echo "GUID=='45ed81b3-cfda-481b-9a40-315260c151e7'"
20305d1054 2017-05-19 2179: echo ""
20305d1054 2017-05-19 2180: #----
20305d1054 2017-05-19 2181: cd $S_FP_ORIG
20305d1054 2017-05-19 2182: exit 1
20305d1054 2017-05-19 2183: 
20305d1054 2017-05-19 2184: #==========================================================================
20305d1054 2017-05-19 2185: