Comment: | mmmv_microbot_crypto_t1 template |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
76fba73212ef36b45e56f6dac0cca5c3 |
User & Date: | martin_vahi on 2017-01-01 22:09:03 |
Other Links: | manifest | tags |
2017-01-07 16:36 | mmmv_silkexec attic check-in: 7c010a3f80 user: martin_vahi tags: trunk | |
2017-01-01 22:09 | mmmv_microbot_crypto_t1 template check-in: 76fba73212 user: martin_vahi tags: trunk | |
2016-10-29 18:21 | bugfix check-in: 2b3fc88e27 user: martin_vahi tags: trunk | |
Deleted work_in_progress/COMMENTS.txt version [625ecc2027].
1 - 2 -This folder might one day 3 -contain the Silktorrent "development trunk". 4 -
Deleted work_in_progress/download_Silkotrrent_repository_and_run_local_web_server.bash version [0d05147f51].
1 -#!/usr/bin/env bash 2 -# Initial author: martin.vahi@softf1.com 3 -# This file is in public domain. 4 -# For further information please see 5 -# 6 -# http://www.silktorrent.ch 7 -# 8 -#========================================================================= 9 -S_FP_ORIG="`pwd`" 10 -#------------------------------------------------------------------------- 11 - 12 -func_mmmv_exit_if_not_on_path_t2() { # S_COMMAND_NAME 13 - local S_COMMAND_NAME=$1 14 - local S_LOCAL_VARIABLE="`which $S_COMMAND_NAME 2>/dev/null`" 15 - if [ "$S_LOCAL_VARIABLE" == "" ]; then 16 - echo "" 17 - echo "Command \"$S_COMMAND_NAME\" could not be found from the PATH. " 18 - echo "The Fossil source code might be available from a link at " 19 - echo "http://www.softf1.com/cgi-bin/tree1/technology/flaws/silktorrent.bash/wiki?name=Fossil+Repository+Related+Links+and+Comments" 20 - echo "" 21 - echo "The execution of the Bash script is aborted." 22 - echo "GUID=='3f7ad84e-e0f2-45c8-94e7-217051d1a0e7'" 23 - echo "" 24 - #-------- 25 - cd $S_FP_ORIG 26 - exit 1; # exit with an error 27 - fi 28 -} # func_mmmv_exit_if_not_on_path_t2 29 - 30 -func_mmmv_exit_if_not_on_path_t2 "fossil" 31 - 32 -#------------------------------------------------------------------------- 33 - 34 - mkdir ./stuff 35 - cd ./stuff 36 - wget http://www.softf1.com/cgi-bin/tree1/technology/flaws/silktorrent.bash/raw/work_in_progress/mmmv_Fossil_operator_t1.bash?name=ebb536fdad89b21bd6180652275b3571b3ab4cef --output-document=`pwd`/mmmv_Fossil_operator_t1.bash 37 - echo "" 38 - echo "Now it will probably take a while, because it needs to dowload ~500MiB of files." 39 - echo "" 40 - bash ./mmmv_Fossil_operator_t1.bash clone_public http://www.softf1.com/cgi-bin/tree1/technology/flaws/silktorrent.bash/ 41 - fossil ui `pwd`/repository_storage.fossil # Runs a Fossil web server at localhost 42 - # and opens the default web browser. 43 - 44 -#------------------------------------------------------------------------- 45 -cd $S_FP_ORIG 46 -#========================================================================= 47 -
Added work_in_progress/experiments/mmmv_microbot_crypto_t1/README.md version [f034d7f8ef].
1 + 2 +mmmv_microbot_crypto_t1 3 +=========================================================================== 4 + 5 +The mmmv_microbot_crypto_t1 is a microcontroller C library. 6 +The aim of the mmmv_microbot_crypto_t1 is to maximize 7 +cryptographic strength and availability at as many microcontrollers 8 +as possible, while minimizing electrical power consumption and 9 +computational power requirements. It is up to the client code 10 +developers to decide, what their minimum acceptable cryptographic 11 +strength is, how much electrical power and computational 12 +power, RAM, execution time, etc. they are willing to sacrifice 13 +for cryptographic strength. This project is a sub-project of 14 +[Silktorrent](http://www.silktorrent.ch). Project theory related 15 +documentation and references reside at the Silktorrent Fossil repository. 16 + 17 + 18 +The current version is optimized for 8-bit microcontrollers, but 19 +it has been written so that the same code can run and process 20 +the sime kind of data streams also on 32-bit microcontrollers 21 +and on desktop computers. CPU-specific bit endianness could be 22 +determined during runtime, but due to efficiency it is expected 23 +to be given to a buld script as a parameter. 24 +The mmmv_microbot_crypto_t1 build and test system is written in 25 +[Ruby](https://www.ruby-lang.org/). The main entry to the 26 +build and test system is the 27 + 28 + 29 + ./src/dev_tools/Rakefile 30 + 31 + 32 +--------------------------------------------------------------------------- 33 + 34 +## W A R N I N G 35 + 36 +There is absolutely no code in this project yet. 37 + 38 + 39 +--------------------------------------------------------------------------- 40 + 41 +## Implementation Overview 42 + 43 +Source resides at 44 + 45 + ./src/devel 46 + 47 +Build results are placed to an autogenerated folder 48 + 49 + ./src/deployment_deliverables 50 + 51 +which includes, depending on build parameters, both, 52 +the patched source and compiled binaries. Formal 53 +verification tools are expected to work on the code 54 +that resides at the 55 + 56 + ./src/deployment_deliverables 57 + 58 +because that allows the original C source, the one at 59 + 60 + ./src/devel 61 + 62 +to be kept free from verification tool specific 63 +comments, making it easier to use multiple formal 64 +verification tools for analyzing the same source. 65 +The build output includes a verification tool specific patch. 66 +As the mmmv_microbot_crypto_t1 is meant to be a 67 +sub-component of a collaborative scheduling based 68 +control software, error conditions are not allowed 69 +and data dependent maximum execution time is not allowed. 70 +If error conditions never occur, then exceptions are useless. 71 +Data is processed in blocks and control flow is 72 +collaboratively yielded to another thread at the end of the 73 +processing of a single block. Processing result is 74 +an instance of a C structure that has a flag, whether processing 75 +failed or succeeded. Flawed input data is discarded. 76 + 77 + 78 +Error correction and bitstream dissection are 79 +done before there is an attempt to decrypt the 80 +series of blocks. All blocks that are received 81 +by the decryption function, can be decrypted, 82 +except that when the block content has been corrupted, 83 +the decryption result is also flawed. There 84 +has to be a separate checksum calculation 85 +step after decryption. The processing pipeline for decryption: 86 + 87 + 88 +* Error correction, Viterbi demodulation, etc. 89 +* Blockstream creation from error-corrected bitstream. 90 +* Decryption. Outputs a blockstream. 91 +* Decryption result blockstream checksum calculations 92 + and new blockstream creation. 93 + 94 + 95 +The processing pipeline for encryption: 96 + 97 + 98 +* Checksummed blockstream creation from cleartext. 99 +* Encryption. 100 +* Encrypted blockstream to data transmission bitstream conversion. 101 + 102 + 103 +The names of all of the mmmv_microbot_crypto_t1 104 +functions start with **mmmv_0001_func_**. 105 +The names of all of the mmmv_microbot_crypto_t1 106 +structures start with **mmmv_0001_st_**. 107 +The mmmv_microbot_crypto_t1 library code does not 108 +have any global variables. 109 + 110 +A general design pattern is that functions are given a pointer 111 +to a structure. All functions that return anything other than *void* 112 +are side-effect free. The ones that return *void* place 113 +their output to the structures that are referenced by 114 +their call parameters. 115 + 116 + 117 +--------------------------------------------------------------------------- 118 + 119 +## Building and Testing 120 + 121 +The default Rake task at 122 + 123 + ./src/dev_tools/Rakefile 124 + 125 +displays the list of available tasks. The folder 126 + 127 + ./src/deployment_deliverables 128 + 129 +can be deleted safely, because it is autogenerated and overwritten. 130 + 131 + 132 + 133 +--------------------------------------------------------------------------- 134 + 135 +
Added work_in_progress/experiments/mmmv_microbot_crypto_t1/src/dev_tools/Rakefile version [acf603805c].
1 +#!/usr/bin/env ruby 2 + 3 +require "rubygems" 4 +require "rake" 5 + 6 + 7 +task :build_devel_deliverables do 8 + raise(Exception.new("subject to completion")) 9 +end 10 + 11 +task :build_deployment_deliverables do 12 + raise(Exception.new("subject to completion")) 13 +end 14 + 15 +task :build_for_testing do 16 + raise(Exception.new("subject to completion")) 17 +end 18 + 19 +task :deploy_for_testing do 20 + raise(Exception.new("subject to completion")) 21 +end 22 + 23 +task :r => [:build_for_testing, :deploy_for_testing] do 24 + # For convenience only. The "r" is derived from the word "run". 25 +end 26 + 27 +task :default do 28 + ar_task_names=Array.new 29 + Rake.application.tasks.each {|x_task| ar_task_names<<x_task.to_s} 30 + ar_task_names.sort! 31 + puts "\n\nAvailable Rake functions:\n\n" 32 + s_1=" " 33 + ar_task_names.each do |s_task_name| 34 + puts s_1+s_task_name.to_s 35 + end # loop 36 + puts "\n\n" 37 +end 38 +
Added work_in_progress/experiments/mmmv_microbot_crypto_t1/src/devel/mmmv_microbot_crypto_t1_crypto_t1.c version [672cf30b48].
1 + 2 + 3 + 4 +/* encrypted blockstream -> decryption -> decrypted blockstream checksum -> cleartext blockstream 5 + and vice versa for encryption. 6 +*/
Added work_in_progress/experiments/mmmv_microbot_crypto_t1/src/devel/mmmv_microbot_crypto_t1_transmission_H_blockstream.c version [0fbc300aa7].
1 + 2 + 3 + 4 +/* Conversion functions between transmission bitstream and blockstream. */
Deleted work_in_progress/mmmv_Fossil_operator_t1.bash version [ebb536fdad].
1 -#!/usr/bin/env bash 2 -# Initial author: Martin.Vahi@softf1.com 3 -# This file is in the public domain. 4 -#========================================================================== 5 -S_FP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 6 -S_FP_ORIG="`pwd`" 7 -S_TIMESTAMP="`date +%Y`_`date +%m`_`date +%d`_T_`date +%H`h_`date +%M`min_`date +%S`s" 8 - 9 - 10 -func_assert_exists_on_path_t2 () { 11 - local S_NAME_OF_THE_EXECUTABLE_1="$1" # first function argument 12 - local S_NAME_OF_THE_EXECUTABLE_2="$2" # optional argument 13 - local S_NAME_OF_THE_EXECUTABLE_3="$3" # optional argument 14 - local S_NAME_OF_THE_EXECUTABLE_4="$4" # optional argument 15 - #-------- 16 - # Function calls like 17 - # 18 - # func_assert_exists_on_path_t2 "" "" "ls" 19 - # func_assert_exists_on_path_t2 "ls" "" "ps" 20 - # 21 - # are not allowed by the spec of this function, but it's OK to call 22 - # 23 - # func_assert_exists_on_path_t2 "ls" "" 24 - # func_assert_exists_on_path_t2 "ls" "ps" "" 25 - # func_assert_exists_on_path_t2 "ls" "" "" "" 26 - # 27 - # 28 - local SB_THROW="f" 29 - if [ "$S_NAME_OF_THE_EXECUTABLE_1" == "" ] ; then 30 - SB_THROW="t" 31 - else 32 - if [ "$S_NAME_OF_THE_EXECUTABLE_2" == "" ] ; then 33 - if [ "$S_NAME_OF_THE_EXECUTABLE_3" != "" ] ; then 34 - SB_THROW="t" 35 - fi 36 - if [ "$S_NAME_OF_THE_EXECUTABLE_4" != "" ] ; then 37 - SB_THROW="t" 38 - fi 39 - else 40 - if [ "$S_NAME_OF_THE_EXECUTABLE_3" == "" ] ; then 41 - if [ "$S_NAME_OF_THE_EXECUTABLE_4" != "" ] ; then 42 - SB_THROW="t" 43 - fi 44 - fi 45 - fi 46 - fi 47 - #---- 48 - if [ "$SB_THROW" == "t" ] ; then 49 - echo "" 50 - echo "The Bash function " 51 - echo "" 52 - echo " func_assert_exists_on_path_t2 " 53 - echo "" 54 - echo "is not designed to handle series of arguments, where " 55 - echo "empty strings preced non-empty strings." 56 - echo "GUID=='0541255e-4633-4cd9-b55c-f1e0305090e7'" 57 - echo "" 58 - #---- 59 - cd $S_FP_ORIG 60 - exit 1 # exit with error 61 - fi 62 - if [ "$5" != "" ] ; then 63 - echo "" 64 - echo "This Bash function is designed to work with at most 4 input arguments" 65 - echo "GUID=='41001a45-42a8-4dd3-824c-f1e0305090e7'" 66 - echo "" 67 - #---- 68 - cd $S_FP_ORIG 69 - exit 1 # exit with error 70 - fi 71 - #-------- 72 - # Function calls like 73 - # 74 - # func_assert_exists_on_path_t2 " " 75 - # func_assert_exists_on_path_t2 "ls ps" # contains a space 76 - # 77 - # are not allowed. 78 - SB_THROW="f" 79 - local S_TMP_0="" 80 - local S_TMP_1="" 81 - local S_TMP_2="" 82 - #---- 83 - if [ "$SB_THROW" == "f" ] ; then 84 - S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_1\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`" 85 - if [ "$S_NAME_OF_THE_EXECUTABLE_1" != "$S_TMP_0" ] ; then 86 - SB_THROW="t" 87 - S_TMP_1="$S_NAME_OF_THE_EXECUTABLE_1" 88 - S_TMP_2="GUID=='2a1fd3d0-3841-4e87-854c-f1e0305090e7'" 89 - fi 90 - fi 91 - #---- 92 - if [ "$SB_THROW" == "f" ] ; then 93 - S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_2\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`" 94 - if [ "$S_NAME_OF_THE_EXECUTABLE_2" != "$S_TMP_0" ] ; then 95 - SB_THROW="t" 96 - S_TMP_1="$S_NAME_OF_THE_EXECUTABLE_2" 97 - S_TMP_2="GUID=='d23cd2de-f38c-43f2-894c-f1e0305090e7'" 98 - fi 99 - fi 100 - #---- 101 - if [ "$SB_THROW" == "f" ] ; then 102 - S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_3\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`" 103 - if [ "$S_NAME_OF_THE_EXECUTABLE_3" != "$S_TMP_0" ] ; then 104 - SB_THROW="t" 105 - S_TMP_1="$S_NAME_OF_THE_EXECUTABLE_3" 106 - S_TMP_2="GUID=='7bf6f543-26c4-400e-a33c-f1e0305090e7'" 107 - fi 108 - fi 109 - #---- 110 - if [ "$SB_THROW" == "f" ] ; then 111 - S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_4\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`" 112 - if [ "$S_NAME_OF_THE_EXECUTABLE_4" != "$S_TMP_0" ] ; then 113 - SB_THROW="t" 114 - S_TMP_1="$S_NAME_OF_THE_EXECUTABLE_4" 115 - S_TMP_2="GUID=='a8746d54-43bc-4958-923c-f1e0305090e7'" 116 - fi 117 - fi 118 - #-------- 119 - if [ "$SB_THROW" == "t" ] ; then 120 - echo "" 121 - echo "The Bash function " 122 - echo "" 123 - echo " func_assert_exists_on_path_t2 " 124 - echo "" 125 - echo "is not designed to handle an argument value that contains " 126 - echo "spaces or tabulation characters." 127 - echo "The unaccepted value in parenthesis:($S_TMP_1)." 128 - echo "Branch $S_TMP_2." 129 - echo "GUID=='c3948131-401e-470a-a53c-f1e0305090e7'" 130 - echo "" 131 - #---- 132 - cd $S_FP_ORIG 133 - exit 1 # exit with error 134 - fi 135 - SB_THROW="f" # Just a reset, should I forget to reset it later. 136 - #--------------- 137 - S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_1 2>/dev/null\`" 138 - local S_TMP_1="" 139 - local S_TMP_2="S_TMP_1=$S_TMP_0" 140 - eval ${S_TMP_2} 141 - #---- 142 - if [ "$S_TMP_1" == "" ] ; then 143 - if [ "$S_NAME_OF_THE_EXECUTABLE_2" == "" ] ; then 144 - if [ "$S_NAME_OF_THE_EXECUTABLE_3" == "" ] ; then 145 - if [ "$S_NAME_OF_THE_EXECUTABLE_4" == "" ] ; then 146 - echo "" 147 - echo "This bash script requires the \"$S_NAME_OF_THE_EXECUTABLE_1\" to be on the PATH." 148 - echo "GUID=='f284925c-b40f-4549-b22c-f1e0305090e7'" 149 - echo "" 150 - #---- 151 - cd $S_FP_ORIG 152 - exit 1 # exit with error 153 - fi 154 - fi 155 - fi 156 - else 157 - return # at least one of the programs was available at the PATH 158 - fi 159 - #-------- 160 - S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_2 2>/dev/null\`" 161 - S_TMP_1="" 162 - S_TMP_2="S_TMP_1=$S_TMP_0" 163 - eval ${S_TMP_2} 164 - #---- 165 - if [ "$S_TMP_1" == "" ] ; then 166 - if [ "$S_NAME_OF_THE_EXECUTABLE_3" == "" ] ; then 167 - if [ "$S_NAME_OF_THE_EXECUTABLE_4" == "" ] ; then 168 - echo "" 169 - echo "This bash script requires that either \"$S_NAME_OF_THE_EXECUTABLE_1\" or " 170 - echo " \"$S_NAME_OF_THE_EXECUTABLE_2\" is available on the PATH." 171 - echo "GUID=='7f92b447-d805-460e-912c-f1e0305090e7'" 172 - echo "" 173 - #---- 174 - cd $S_FP_ORIG 175 - exit 1 # exit with error 176 - fi 177 - fi 178 - else 179 - return # at least one of the programs was available at the PATH 180 - fi 181 - #-------- 182 - S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_3 2>/dev/null\`" 183 - S_TMP_1="" 184 - S_TMP_2="S_TMP_1=$S_TMP_0" 185 - eval ${S_TMP_2} 186 - #---- 187 - if [ "$S_TMP_1" == "" ] ; then 188 - if [ "$S_NAME_OF_THE_EXECUTABLE_4" == "" ] ; then 189 - echo "" 190 - echo "This bash script requires that either \"$S_NAME_OF_THE_EXECUTABLE_1\" or " 191 - echo " \"$S_NAME_OF_THE_EXECUTABLE_2\" or \"$S_NAME_OF_THE_EXECUTABLE_3\" " 192 - echo "is available on the PATH." 193 - echo "GUID=='39c63c1f-eec1-450d-b12c-f1e0305090e7'" 194 - echo "" 195 - #---- 196 - cd $S_FP_ORIG 197 - exit 1 # exit with error 198 - fi 199 - else 200 - return # at least one of the programs was available at the PATH 201 - fi 202 - #-------- 203 - S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_4 2>/dev/null\`" 204 - S_TMP_1="" 205 - S_TMP_2="S_TMP_1=$S_TMP_0" 206 - eval ${S_TMP_2} 207 - #---- 208 - if [ "$S_TMP_1" == "" ] ; then 209 - echo "" 210 - echo "This bash script requires that either \"$S_NAME_OF_THE_EXECUTABLE_1\" or " 211 - echo " \"$S_NAME_OF_THE_EXECUTABLE_2\" or \"$S_NAME_OF_THE_EXECUTABLE_3\" or " 212 - echo " \"$S_NAME_OF_THE_EXECUTABLE_4\" is available on the PATH." 213 - echo "GUID=='71c5f5de-2801-47fc-841c-f1e0305090e7'" 214 - echo "" 215 - #---- 216 - cd $S_FP_ORIG 217 - exit 1 # exit with error 218 - else 219 - return # at least one of the programs was available at the PATH 220 - fi 221 - #-------- 222 -} # func_assert_exists_on_path_t2 223 - 224 - 225 -func_assert_exists_on_path_t2 "cat" 226 -func_assert_exists_on_path_t2 "file" # for checking MIME types 227 -func_assert_exists_on_path_t2 "find" # for recursing 228 -func_assert_exists_on_path_t2 "fossil" # tested with v1.34 229 -func_assert_exists_on_path_t2 "gawk" 230 -func_assert_exists_on_path_t2 "grep" 231 -func_assert_exists_on_path_t2 "nice" 232 -func_assert_exists_on_path_t2 "ruby" # anything over/equal v.2.1 will probably do 233 -func_assert_exists_on_path_t2 "shred" "gshred" "rm" # for shredding, if possible 234 -func_assert_exists_on_path_t2 "uname" # to check the OS type 235 -func_assert_exists_on_path_t2 "uuidgen" "uuid" # for generating tmp file names 236 -func_assert_exists_on_path_t2 "xargs" # find . -name '*' | xargs blabla 237 -func_assert_exists_on_path_t2 "wc" 238 - 239 - 240 -#-------------------------------------------------------------------------- 241 - 242 -S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT="" 243 -func_mmmv_operating_system_type_t1() { 244 - if [ "$S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT" == "" ]; then 245 - S_TMP_0="`uname -a | grep -E [Ll]inux`" 246 - if [ "$S_TMP_0" != "" ]; then 247 - S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT="Linux" 248 - else 249 - S_TMP_0="`uname -a | grep BSD `" 250 - if [ "$S_TMP_0" != "" ]; then 251 - S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT="BSD" 252 - else 253 - S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT="undetermined" 254 - fi 255 - fi 256 - fi 257 -} # func_mmmv_operating_system_type_t1 258 - 259 -func_mmmv_operating_system_type_t1 260 - 261 -if [ "$S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT" != "Linux" ]; then 262 - if [ "$S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT" != "BSD" ]; then 263 - echo "" 264 - echo " The classical command line utilities at " 265 - echo " different operating systems, for example, Linux and BSD," 266 - echo " differ. This script is designed to run only on " 267 - echo " Linux and some BSD variants." 268 - echo " If You are willing to risk that some of Your data " 269 - echo " is deleted and/or Your operating system instance" 270 - echo " becomes permanently flawed, to the point that " 271 - echo " it will not even boot, then You may edit the Bash script that " 272 - echo " displays this error message by modifying the test that " 273 - echo " checks for the operating system type." 274 - echo "" 275 - echo " If You do decide to edit this Bash script, then " 276 - echo " a recommendation is to test Your modifications " 277 - echo " within a virtual machine or, if virtual machines are not" 278 - echo " an option, as some new operating system user that does not have " 279 - echo " any access to the vital data/files." 280 - echo " GUID=='52460304-7c62-4f4e-b51c-f1e0305090e7'" 281 - echo "" 282 - echo " Aborting script without doing anything." 283 - echo "" 284 - exit 1 # exit with error 285 - fi 286 -fi 287 - 288 - 289 -#-------------------------------------------------------------------------- 290 - 291 -SB_EXISTS_ON_PATH_T1_RESULT="f" 292 -func_sb_exists_on_path_t1 () { 293 - local S_NAME_OF_THE_EXECUTABLE_1="$1" # first function argument 294 - #-------- 295 - # Function calls like 296 - # 297 - # func_sb_exists_on_path_t1 "" 298 - # func_sb_exists_on_path_t1 " " 299 - # func_sb_exists_on_path_t1 "ls ps" # contains a space 300 - # 301 - # are not allowed. 302 - if [ "$S_NAME_OF_THE_EXECUTABLE_1" == "" ] ; then 303 - echo "" 304 - echo "The Bash function " 305 - echo "" 306 - echo " func_sb_exists_on_path_t1 " 307 - echo "" 308 - echo "is not designed to handle an argument that " 309 - echo "equals with an empty string." 310 - echo "GUID=='31ed2a21-41ac-4368-831c-f1e0305090e7'" 311 - echo "" 312 - #---- 313 - cd $S_FP_ORIG 314 - exit 1 # exit with error 315 - fi 316 - local S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_1\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`" 317 - if [ "$S_NAME_OF_THE_EXECUTABLE_1" != "$S_TMP_0" ] ; then 318 - echo "" 319 - echo "The Bash function " 320 - echo "" 321 - echo " func_sb_exists_on_path_t1 " 322 - echo "" 323 - echo "is not designed to handle an argument value that contains " 324 - echo "spaces or tabulation characters." 325 - echo "The received value in parenthesis:($S_NAME_OF_THE_EXECUTABLE_1)." 326 - echo "GUID=='40cb1b02-90f3-404e-8a0c-f1e0305090e7'" 327 - echo "" 328 - #---- 329 - cd $S_FP_ORIG 330 - exit 1 # exit with error 331 - fi 332 - #-------- 333 - S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_1 2>/dev/null\`" 334 - local S_TMP_1="" 335 - local S_TMP_2="S_TMP_1=$S_TMP_0" 336 - eval ${S_TMP_2} 337 - #---- 338 - if [ "$S_TMP_1" == "" ] ; then 339 - SB_EXISTS_ON_PATH_T1_RESULT="f" 340 - else 341 - SB_EXISTS_ON_PATH_T1_RESULT="t" 342 - fi 343 -} # func_sb_exists_on_path_t1 344 - 345 - 346 -#-------------------------------------------------------------------------- 347 - 348 -S_FUNC_MMMV_GUID_T1_RESULT="not_yet_set" 349 -S_FUNC_MMMV_GUID_T1_MODE="" # optim. to skip repeating console tool selection 350 -func_mmmv_GUID_t1() { 351 - # Does not take any arguments. 352 - #-------- 353 - #func_mmmv_exc_hash_function_input_verification_t1 "func_mmmv_GUID_t1" "$1" 354 - #-------------------- 355 - local S_TMP_0="" # declaration 356 - local S_TMP_1="" # declaration 357 - # Mode selection: 358 - if [ "$S_FUNC_MMMV_GUID_T1_MODE" == "" ] ; then 359 - SB_EXISTS_ON_PATH_T1_RESULT="f" # if-block init 360 - #---- 361 - if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then 362 - S_TMP_0="uuidgen" # Linux version 363 - func_sb_exists_on_path_t1 "$S_TMP_0" 364 - if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then 365 - S_FUNC_MMMV_GUID_T1_MODE="$S_TMP_0" 366 - fi 367 - fi 368 - #---- 369 - if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then 370 - S_TMP_0="uuid" # BSD version 371 - func_sb_exists_on_path_t1 "$S_TMP_0" 372 - if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then 373 - S_FUNC_MMMV_GUID_T1_MODE="$S_TMP_0" 374 - fi 375 - fi 376 - #-------- 377 - if [ "$S_FUNC_MMMV_GUID_T1_MODE" == "" ] ; then 378 - echo "" 379 - echo "All of the GUID generation implementations that this script " 380 - echo "is capable of using (uuidgen, uuid) " 381 - echo "are missing from the PATH." 382 - echo "GUID=='3094c835-5f40-4884-b40c-f1e0305090e7'" 383 - echo "" 384 - #---- 385 - cd $S_FP_ORIG 386 - exit 1 # exit with error 387 - fi 388 - #-------- 389 - if [ "$?" != "0" ]; then 390 - echo "" 391 - echo "This script is flawed." 392 - echo "GUID=='817cc031-3315-4771-a3fb-f1e0305090e7'" 393 - echo "" 394 - #---- 395 - cd $S_FP_ORIG 396 - exit 1 # exit with error 397 - fi 398 - #-------- 399 - fi 400 - #-------------------- 401 - S_FUNC_MMMV_GUID_T1_RESULT="" 402 - #-------------------- 403 - if [ "$S_FUNC_MMMV_GUID_T1_MODE" == "uuidgen" ]; then 404 - S_TMP_0="`uuidgen`" 405 - if [ "$?" != "0" ]; then 406 - echo "" 407 - echo "The console application \"uuidgen\" " 408 - echo "exited with an error." 409 - echo "" 410 - echo "----console--output--citation--start-----" 411 - echo "`uuidgen`" # stdout and stderr 412 - echo "----console--output--citation--end-------" 413 - echo "" 414 - echo "GUID=='46b00d44-8784-489e-a5fb-f1e0305090e7'" 415 - echo "" 416 - #---- 417 - cd $S_FP_ORIG 418 - exit 1 # exit with error 419 - fi 420 - #---- 421 - S_FUNC_MMMV_GUID_T1_RESULT="$S_TMP_0" 422 - fi 423 - #-------------------- 424 - if [ "$S_FUNC_MMMV_GUID_T1_MODE" == "uuid" ]; then 425 - S_TMP_0="`uuid`" 426 - if [ "$?" != "0" ]; then 427 - echo "" 428 - echo "The console application \"uuid\" " 429 - echo "exited with an error." 430 - echo "" 431 - echo "----console--output--citation--start-----" 432 - echo "`uuid`" # stdout and stderr 433 - echo "----console--output--citation--end-------" 434 - echo "" 435 - echo "GUID=='c3d42e43-1f05-4355-93fb-f1e0305090e7'" 436 - echo "" 437 - #---- 438 - cd $S_FP_ORIG 439 - exit 1 # exit with error 440 - fi 441 - #---- 442 - S_FUNC_MMMV_GUID_T1_RESULT="$S_TMP_0" 443 - fi 444 - #-------------------- 445 - S_TMP_0="`printf \"$S_FUNC_MMMV_GUID_T1_RESULT\" | wc -m | gawk '{gsub(/\s/,"");printf "%s", $1 }'`" 446 - S_TMP_1="36" 447 - if [ "$S_TMP_0" != "$S_TMP_1" ]; then 448 - echo "" 449 - echo "According to the GUID specification, IETF RFC 4122, " 450 - echo "the lenght of the GUID is " 451 - echo "$S_TMP_1 characters, but the result of the " 452 - echo "" 453 - echo " func_mmmv_GUID_t1" 454 - echo "" 455 - echo "is something else. The flawed GUID candidate in parenthesis:" 456 - echo "($S_FUNC_MMMV_GUID_T1_RESULT)" 457 - echo "" 458 - echo "The lenght candidate of the flawed GUID candidate in parenthesis:" 459 - echo "($S_TMP_0)." 460 - echo "" 461 - echo "GUID=='4bba14f5-f666-40a4-9efb-f1e0305090e7'" 462 - echo "" 463 - #---- 464 - cd $S_FP_ORIG 465 - exit 1 # exit with error 466 - fi 467 - #-------------------- 468 -} # func_mmmv_GUID_t1 469 - 470 - 471 -#-------------------------------------------------------------------------- 472 - 473 -S_FUNC_MMMV_SHRED_T1_MODE="" # optim. to skip repeating console tool selection 474 -func_mmmv_shred_t1() { 475 - local S_FP_IN="$1" # path to the file or folder to be shredded 476 - # The next input parameter is a shoddy compromise, 477 - # for the case, where shred/gshred is not installed: 478 - local SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE="$2" # domain: {"","f","t"} 479 - #-------------------- 480 - if [ "$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE" != "" ] ; then 481 - if [ "$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE" != "t" ] ; then 482 - if [ "$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE" != "f" ] ; then 483 - echo "" 484 - echo "The second parameter of this function, the " 485 - echo "" 486 - echo " SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE(==$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE)" 487 - echo "" 488 - echo "is optional, but its range is {\"\",\"f\",\"t\"}," 489 - echo "without the quotation marks." 490 - echo "GUID=='502df336-4c86-4286-83fb-f1e0305090e7'" 491 - echo "" 492 - #---- 493 - cd $S_FP_ORIG 494 - exit 1 # exit with error 495 - fi 496 - fi 497 - else # $SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE == "" 498 - SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE="f" 499 - fi 500 - #-------------------- 501 - # Declarations: 502 - local SB_THROW="" 503 - local SB_USE_RUBY="" 504 - local S_CMD="" 505 - local S_GUID="" 506 - local S_TMP_0="" 507 - local S_TMP_1="" 508 - local S_TMP_2="" 509 - local SI_0="-9999" 510 - local SI_1="-9999" 511 - local S_SHREDDER_APPLICATION_NAME="" 512 - local S_FP_PWD_BEFORE_SHREDDING="" 513 - #-------------------- 514 - # Mode selection: 515 - if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "" ] ; then 516 - SB_EXISTS_ON_PATH_T1_RESULT="f" # if-block init 517 - #---- 518 - if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then 519 - S_TMP_0="shred" # Linux version 520 - func_sb_exists_on_path_t1 "$S_TMP_0" 521 - if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then 522 - S_FUNC_MMMV_SHRED_T1_MODE="$S_TMP_0" 523 - fi 524 - fi 525 - #---- 526 - if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then 527 - S_TMP_0="gshred" # BSD version 528 - func_sb_exists_on_path_t1 "$S_TMP_0" 529 - if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then 530 - S_FUNC_MMMV_SHRED_T1_MODE="$S_TMP_0" 531 - fi 532 - fi 533 - #---- 534 - if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then 535 - if [ "$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE" == "t" ] ; then 536 - S_TMP_0="rm" # a shoddy compromise version for exeptional cases 537 - func_sb_exists_on_path_t1 "$S_TMP_0" 538 - if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then 539 - func_mmmv_operating_system_type_t1 540 - if [ "$S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT" != "BSD" ]; then 541 - S_FUNC_MMMV_SHRED_T1_MODE="rm_BSD" 542 - else # Linux and all the rest 543 - S_FUNC_MMMV_SHRED_T1_MODE="rm_plain" 544 - fi 545 - else 546 - echo "" 547 - echo "Something is wrong at the operating system " 548 - echo "environment setup. All UNIX-like operating systems " 549 - echo "and their emulators " 550 - echo "are expected to have the \"rm\" command." 551 - echo "" 552 - echo " \$(which rm)==\"`which rm`\"" 553 - echo "" 554 - echo " PATH=$PATH" # will be a huge string 555 - echo "" 556 - echo "GUID=='a6e67041-a70f-4e87-92fb-f1e0305090e7'" 557 - echo "" 558 - #---- 559 - cd $S_FP_ORIG 560 - exit 1 # exit with error 561 - fi 562 - fi 563 - fi 564 - #-------- 565 - if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "" ] ; then 566 - echo "" 567 - echo "All of the file shredding implementations that this script " 568 - echo "is capable of using (shred, gshred) " 569 - echo "are missing from the PATH." 570 - echo "GUID=='2db9ac59-a8f0-4852-a1eb-f1e0305090e7'" 571 - echo "" 572 - #---- 573 - cd $S_FP_ORIG 574 - exit 1 # exit with error 575 - fi 576 - #-------- 577 - if [ "$?" != "0" ]; then 578 - echo "" 579 - echo "This script is flawed." 580 - echo "GUID=='4a9e0e43-a179-434b-81eb-f1e0305090e7'" 581 - echo "" 582 - #---- 583 - cd $S_FP_ORIG 584 - exit 1 # exit with error 585 - fi 586 - #-------- 587 - fi 588 - #-------------------- 589 - S_TMP_0=$(echo $S_FP_IN | gawk '{gsub(/^[\/]/,""); printf "%s",$1 }') 590 - if [ "$S_TMP_0" == "$S_FP_IN" ]; then 591 - echo "" 592 - echo "The path is expected to be an absolute path, " 593 - echo "but currently it is not." 594 - echo " S_FP_IN==$S_FP_IN" 595 - echo "GUID=='b72d3528-b829-43dd-b4eb-f1e0305090e7'" 596 - echo "" 597 - #---- 598 - cd $S_FP_ORIG 599 - exit 1 # exit with an error 600 - fi 601 - #-------- 602 - if [ -h $S_FP_IN ]; then 603 - # The control flow is in here regardless of 604 - # whether the symbolic link is broken or not. 605 - # If the path is to a non-existing file/link/folder, 606 - # then the control flow will not enter this branch. 607 - echo "" 608 - echo "The " 609 - echo " S_FP_IN=$S_FP_IN" 610 - echo "is a symbolic link, but it is expected to " 611 - echo "be a file or a folder." 612 - echo "GUID=='2ff01c25-3734-48c8-a9eb-f1e0305090e7'" 613 - echo "" 614 - #---- 615 - cd $S_FP_ORIG 616 - exit 1 # exit with error 617 - fi 618 - if [ ! -e $S_FP_IN ]; then 619 - echo "" 620 - echo "The " 621 - echo " S_FP_IN=$S_FP_IN" 622 - echo "does not exist." 623 - echo "GUID=='2b88f713-2945-4752-a4eb-f1e0305090e7'" 624 - echo "" 625 - #---- 626 - cd $S_FP_ORIG 627 - exit 1 # exit with error 628 - fi 629 - #-------- 630 - if [ -d $S_FP_IN ]; then 631 - #--------start--of--sub-path--check---- 632 - # If the $S_FP_IN is a folder, then the `pwd` 633 - # should not be a sub-path or a path of the 634 - # folder that is being deleted. 635 - S_TMP_0="`cd $S_FP_IN;pwd`/" 636 - S_TMP_1="`pwd`/" 637 - #---- 638 - if [ "$S_TMP_0" == "$S_TMP_1" ]; then 639 - if [ ! -d $S_FP_IN ]; then 640 - echo "" 641 - echo "This Bash script is flawed. " 642 - echo " S_FP_IN=$S_FP_IN" 643 - echo "GUID=='5b46db54-09a9-41ab-b5eb-f1e0305090e7'" 644 - echo "" 645 - #---- 646 - cd $S_FP_ORIG 647 - exit 1 648 - fi 649 - #---- 650 - echo "" 651 - echo "The working directory, " 652 - echo "" 653 - echo " PWD=$PWD" 654 - echo "" 655 - echo "equals with the folder that is being deleted." 656 - echo "" 657 - echo " S_TMP_0=$S_TMP_0" 658 - echo "" 659 - echo " S_FP_IN=$S_FP_IN" 660 - echo "" 661 - echo "GUID=='167f9421-0412-433c-91db-f1e0305090e7'" 662 - echo "" 663 - #---- 664 - cd $S_FP_ORIG 665 - exit 1 # exit with error 666 - fi 667 - #---- 668 - # If the normalized $S_FP_IN is a folder and 669 - # the "`pwd`/" is shorter than the normalized $S_FP_IN, then, 670 - # with the exceptions of some symbolic links, 671 - # the "`pwd`/" can not be equal to the normalized $S_FP_IN, 672 - # nor can the "`pwd`/" be a folder that is a sub-folder 673 - # of the $S_FP_IN. 674 - # 675 - # The paht lenght code is: 676 - # 677 - # SI_0="` echo \"$S_TMP_0\" | gawk '{i=length;printf "%s", i }' `" # S_FP_IN 678 - # SI_1="` echo \"$S_TMP_1\" | gawk '{i=length;printf "%s", i }' `" # pwd 679 - # if [ "$SI_0" -lt "$SI_1" ]; then # $SI_0 < $SI_1 680 - # #echo "$SI_0 < $SI_1" 681 - # # 682 - # # In here the length of the normalized form of the $S_FP_IN 683 - # # is shorter than the "`pwd`/" and therefore the working directory 684 - # # has a greater probability to be at a sub-path of the $S_FP_IN. 685 - # 686 - # < 687 - # A lot of Ruby code, because 688 - # the gawk code will have trouble with folders that 689 - # contain spaces and other special characters 690 - # > 691 - # fi 692 - # 693 - # but unfortunately the Ruby code that uses 694 - # temporary files and the String.index would be 695 - # unstable due to the 696 - # 697 - # https://bugs.ruby-lang.org/issues/12710 698 - # https://archive.is/AJpgL 699 - # 700 - # Add to that the fact that this Bash function 701 - # would be much more appealing, if it did not launch 702 - # any 40BiB sized interpreters like the Ruby interpreter (in 2016) 703 - # and the temptation to just skip testing, whether the 704 - # working directory (`pwd`) resides at a directory that 705 - # is a sub-path of the $S_FP_IN, grows even higher. 706 - # So, for the time being that check is omitted from here. 707 - # 708 - # TODO: If the year is at least 2020, then try to find out, 709 - # whether there's some elegant way to implement that check. 710 - # 711 - # A code fragment for later consideration: 712 - # S_TMP_2="`echo \"$S_TMP_0\" | gawk '{gsub(/\s/,\"NotASpace\");printf \"%s\", \$1 }' `" 713 - # if [ "$S_TMP_2" != "$S_TMP_0" ]; then 714 - # # S_TMP_0 contains strings 715 - # SB_USE_RUBY="t" 716 - # fi 717 - #--------end--of--sub-path--check---- 718 - fi 719 - #-------------------- 720 - S_FP_PWD_BEFORE_SHREDDING="`pwd`" 721 - S_CMD="" # to be sure 722 - #-------------------- 723 - S_TMP_0="cd $S_FP_IN ; nice -n10 find . -name '*' | nice -n10 xargs " 724 - # The space after the "cd $S_FP_IN" and before the ";" is compulsory. 725 - #---- 726 - # The "2>/dev/null" after the shredding/deletion command 727 - # is to hide the file permissions related error messages. 728 - # The failure is detected by studying file existence. 729 - #-------------------- 730 - if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "shred" ]; then 731 - S_SHREDDER_APPLICATION_NAME="shred" 732 - if [ -d $S_FP_IN ]; then 733 - S_CMD="$S_TMP_0 \ 734 - $S_SHREDDER_APPLICATION_NAME -f --remove 2>/dev/null " 735 - else 736 - S_CMD="nice -n10 $S_SHREDDER_APPLICATION_NAME -f --remove $S_FP_IN 2>/dev/null " 737 - fi 738 - fi 739 - #---- 740 - if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "gshred" ]; then 741 - S_SHREDDER_APPLICATION_NAME="gshred" 742 - if [ -d $S_FP_IN ]; then 743 - S_CMD="$S_TMP_0 \ 744 - $S_SHREDDER_APPLICATION_NAME --force --iterations=2 --remove -z 2>/dev/null " 745 - else 746 - S_CMD="nice -n10 \ 747 - $S_SHREDDER_APPLICATION_NAME --force --iterations=2 --remove -z $S_FP_IN 2>/dev/null " 748 - fi 749 - fi 750 - #---- 751 - # The "rm" on Linux and BSD differ, 752 - # a bit like the "ps" # on Linux and BSD differ. 753 - # The "rm -f -P foo" overwrites the file with NON-random 754 - # values before deleting. 755 - # The "rm -f foo" works, whenever the "rm" is called by the file owner. 756 - # The "rm -f -P foo" requires write permissions even, 757 - # if the "rm" is called by the file owner. 758 - if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "rm_BSD" ]; then 759 - S_SHREDDER_APPLICATION_NAME="rm" 760 - if [ -d $S_FP_IN ]; then 761 - S_CMD="$S_TMP_0 \ 762 - $S_SHREDDER_APPLICATION_NAME -f -P $S_FP_IN 2>/dev/null " 763 - else 764 - S_CMD="nice -n10 $S_SHREDDER_APPLICATION_NAME -f -P $S_FP_IN 2>/dev/null " 765 - fi 766 - fi 767 - if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "rm_plain" ]; then 768 - # The "rm -f foo" seems to be universally available 769 - # at all UNIX-like environments. 770 - S_SHREDDER_APPLICATION_NAME="rm" 771 - if [ -d $S_FP_IN ]; then 772 - S_CMD="$S_TMP_0 \ 773 - $S_SHREDDER_APPLICATION_NAME -f $S_FP_IN 2>/dev/null " 774 - else 775 - S_CMD="nice -n10 $S_SHREDDER_APPLICATION_NAME -f $S_FP_IN 2>/dev/null " 776 - fi 777 - fi 778 - #-------------------- 779 - eval "$S_CMD" # the "eval" is required due to the command "find" 780 - cd $S_FP_PWD_BEFORE_SHREDDING # required if the $S_FP_IN was a folder 781 - if [ -e $S_FP_IN ]; then 782 - # If the control flow is here, then the $S_FP_IN was 783 - # a folder or the deletion failed or both. 784 - chmod -f -R 0700 $S_FP_IN # chmod 0777 would introduce s security flaw 785 - eval "$S_CMD" # the "eval" is required due to the command "find" 786 - cd $S_FP_PWD_BEFORE_SHREDDING 787 - #---- 788 - SB_THROW="f" 789 - if [ -d $S_FP_IN ]; then 790 - S_TMP_0="`cd $S_FP_IN; pwd`" # "./home///foo" -> "/home/foo" 791 - # Checks are intentionally missing to 792 - # allow this Bash function to be universal, without exceptions. 793 - #---- 794 - cd $S_TMP_0 795 - S_TMP_1="`find . -name '*' | \ 796 - xargs file --mime-type | \ 797 - grep -v directory | grep -v folder `" 798 - # The file --mime-type foo 799 - # works on both, Linux and BSD. 800 - cd $S_FP_PWD_BEFORE_SHREDDING 801 - #---- 802 - if [ "$S_TMP_1" == "" ]; then 803 - rm -fr $S_TMP_0 804 - else 805 - SB_THROW="t" 806 - S_GUID="'23c2b1e5-3972-4dc6-a2db-f1e0305090e7'" 807 - fi 808 - fi 809 - #---- 810 - if [ "$SB_THROW" == "f" ]; then # to avoid overwriting the S_GUID 811 - if [ -e $S_FP_IN ]; then 812 - SB_THROW="t" 813 - S_GUID="'ca0b9b36-4ea9-4be6-92db-f1e0305090e7'" 814 - fi 815 - fi 816 - if [ "$SB_THROW" == "t" ]; then 817 - echo "" 818 - echo "The deletion failed even after the " 819 - echo "" 820 - echo " chmod -f -R 0700 $S_FP_IN " 821 - echo "" 822 - echo "The " 823 - echo "" 824 - echo " chmod 0777 " 825 - echo "" 826 - echo "is not done automatically in this " 827 - echo "Bash function, because " 828 - echo "it might introduce a security flaw." 829 - echo "" 830 - echo " S_FUNC_MMMV_SHRED_T1_MODE=$S_FUNC_MMMV_SHRED_T1_MODE" 831 - echo "" 832 - echo " S_CMD=$S_CMD" 833 - echo "" 834 - echo "GUID==$S_GUID" 835 - echo "GUID=='73d84042-9e60-4316-b3db-f1e0305090e7'" 836 - echo "" 837 - #---- 838 - cd $S_FP_ORIG 839 - exit 1 # exit with error 840 - fi 841 - fi 842 - S_GUID="'693c9923-46d0-4603-92db-f1e0305090e7'" #counters S_GUID related flaws 843 - #-------------------- 844 - if [ -e $S_FP_IN ]; then 845 - echo "" 846 - echo "The deletion of the " 847 - echo " S_FP_IN=$S_FP_IN" 848 - echo "failed or the file or folder was re-created by " 849 - echo "some other process before this file existance check." 850 - echo "GUID=='4c690312-7d59-43db-95cb-f1e0305090e7'" 851 - echo "" 852 - #---- 853 - cd $S_FP_ORIG 854 - exit 1 # exit with error 855 - fi 856 - #-------------------- 857 - cd $S_FP_PWD_BEFORE_SHREDDING 858 -} # func_mmmv_shred_t1 859 - 860 - 861 -#-------------------------------------------------------------------------- 862 -S_TMP_0="" 863 -S_ACTIVITY_OF_THIS_SCRIPT=$1 864 -S_URL_REMOTE_REPOSITORY="" 865 -SB_EXIT_WITH_ERROR="f" 866 - 867 -# needed for scriptability 868 -S_ARGNAME_ACTIVITY_SHRED_ARG_2="do_not_prompt_for_confirmation" 869 - 870 -fun_print_msg_t1() { 871 - echo "" 872 - echo "The second console argument " 873 - echo "is expected to be the URL of the remote repository." 874 -} # fun_print_msg_t1 875 - 876 - 877 -fun_exit_without_any_errors_t1() { 878 - local X_SKIP_MESSAGE="$1" 879 - if [ "$X_SKIP_MESSAGE" == "" ]; then 880 - echo "" 881 - echo "Aborting script without doing anything." 882 - echo "" 883 - fi 884 - #---- 885 - cd $S_FP_ORIG 886 - exit 0 887 -} # fun_exit_without_any_errors_t1 888 - 889 -#-------------------------------------------------------------------------- 890 - 891 -SB_FUNC_MMMV_ASSERT_FILE_PATHS_DIFFER_T1_ASSERTION_FAILED="f" 892 -func_mmmv_assert_file_paths_differ_t1(){ 893 - local S_FP_0="$1" 894 - local S_FP_1="$2" 895 - local S_GUID="$3" 896 - local SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE="$4" # domain: {"","f","t"} 897 - #-------- 898 - if [ "$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE" != "" ] ; then 899 - if [ "$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE" != "t" ] ; then 900 - if [ "$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE" != "f" ] ; then 901 - echo "" 902 - echo "The fourth parameter of this function, the " 903 - echo "" 904 - echo " SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE(==$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE)" 905 - echo "" 906 - echo "is optional, but its range is {\"\",\"f\",\"t\"}," 907 - echo "without the quotation marks." 908 - echo "GUID=='55200d1b-73f9-46a3-82cb-f1e0305090e7'" 909 - echo "" 910 - #---- 911 - cd $S_FP_ORIG 912 - exit 1 # exit with error 913 - fi 914 - fi 915 - else # $SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE == "" 916 - SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE="f" 917 - fi 918 - SB_FUNC_MMMV_ASSERT_FILE_PATHS_DIFFER_T1_ASSERTION_FAILED="f" # global 919 - #-------- 920 - # The block of if-else statements for comparing the 2 paths 921 - # is so error prone to write that this function is written 922 - # according to a schematic that resides at: 923 - # http://longterm.softf1.com/documentation_fragments/2016_09_03_comparison_of_file_paths_t1/ 924 - # https://archive.is/R4yw9 925 - #-------- 926 - # Declarations: 927 - local S_GUID_CRAWL="S_GUID_CRAWL not set" # tree crawling at the schematic 928 - local S_GUID_CMP="S_GUID_CMP not set" # comparison at tree leaf 929 - # Some leaves are equivalent. 930 - local S_COMPARISON_MODE="" 931 - local SB_THROW="f" 932 - local SB_ASSERTION_FAILED="f" 933 - local SB_STR0="f" # whether S_FP_0 is compared purely as a string 934 - local SB_STR1="f" # whether S_FP_1 is compared purely as a string 935 - local S_FP_0_STR="$S_FP_0" 936 - local S_FP_1_STR="$S_FP_1" 937 - local S_FP_X="" # a temporary variable for holding path value 938 - local S_RUBY_SRC_0="" 939 - #-------- 940 - if [ "$S_FP_0" == "$S_FP_1" ]; then 941 - # Covers also the case, where both are existing 942 - # folders, but the paths to them contains "../". 943 - # By making the string comparison to be the first thing tried 944 - # a few file system accesses might be saved. 945 - SB_ASSERTION_FAILED="t" 946 - S_GUID_CRAWL="644d292d-c01e-47d0-855c-f1e0305090e7" 947 - S_GUID_CMP="57bc9b05-da56-4eff-954c-f1e0305090e7" 948 - else # the rest of the 3 comparison modes 949 - #-------- 950 - if [ -e $S_FP_0 ]; then 951 - if [ -d $S_FP_0 ]; then 952 - if [ -e $S_FP_1 ]; then 953 - if [ -d $S_FP_1 ]; then 954 - S_COMPARISON_MODE="cmode_cd0_cd1" 955 - else 956 - S_COMPARISON_MODE="cmode_cd0_str1" 957 - SB_STR1="t" 958 - fi 959 - else 960 - S_COMPARISON_MODE="cmode_cd0_str1" 961 - SB_STR1="t" 962 - fi 963 - else 964 - if [ -e $S_FP_1 ]; then 965 - if [ -d $S_FP_1 ]; then 966 - S_COMPARISON_MODE="cmode_str0_cd1" 967 - SB_STR0="t" 968 - else 969 - S_COMPARISON_MODE="cmode_str0_str1" 970 - SB_STR0="t" 971 - SB_STR1="t" 972 - fi 973 - else 974 - S_COMPARISON_MODE="cmode_str0_str1" 975 - SB_STR0="t" 976 - SB_STR1="t" 977 - fi 978 - fi 979 - else # $S_FP_0 is missing or it is a broken symbolic link 980 - if [ -e $S_FP_1 ]; then 981 - if [ -d $S_FP_1 ]; then 982 - S_COMPARISON_MODE="cmode_str0_cd1" 983 - SB_STR0="t" 984 - else 985 - S_COMPARISON_MODE="cmode_str0_str1" 986 - SB_STR0="t" 987 - SB_STR1="t" 988 - fi 989 - else 990 - S_COMPARISON_MODE="cmode_str0_str1" 991 - SB_STR0="t" 992 - SB_STR1="t" 993 - fi 994 - fi 995 - #---------------- 996 - # The "cmode_str0_str1" was tried 997 - # at the first if-clause of the block, but 998 - # that does not catch equivalent cases like 999 - # 1000 - # S_FP_0="`pwd`/././////a_nonexisting_file_or_folder" 1001 - # S_FP_1="`pwd`/a_nonexisting_file_or_folder" 1002 - # 1003 - # S_FP_0="./a_nonexisting_file_or_folder" 1004 - # S_FP_1="././././././a_nonexisting_file_or_folder" 1005 - # 1006 - # S_FP_0="/a_nonexisting_file_or_folder" 1007 - # S_FP_1="/////a_nonexisting_file_or_folder" 1008 - # 1009 - # S_FP_0="/a_nonexisting_file_or_folder" 1010 - # S_FP_1="/..///../a_nonexisting_file_or_folder" 1011 - # 1012 - # String normalization is required whenever at least 1013 - # one of the paths is used at comparison 1014 - # purely as a string. 1015 - # 1016 - #----start-of-Ruby-script-header--for-copy/pasting---- 1017 - # #!/usr/bin/env ruby 1018 - # 1019 - # s_fp_0="./a_nonexisting_file_or_folder" 1020 - # s_fp_1="././..//../.././a_nonexisting_file_or_folder" 1021 - # 1022 - # # The path "/../foo" is equivalent to "/foo". 1023 - # s_fp_2="/././..//../.././a_nonexisting_file_or_folder" 1024 - # 1025 - # # This script does not cover the case, 1026 - # # where "./aa/../bb" is equivalent to "./bb" 1027 - #----end---of-Ruby-script-header-for-copy/pasting---- 1028 - S_RUBY_SRC_0="\ 1029 - s_0='';\ 1030 - s_1=ARGV[0].to_s;\ 1031 - rgx_0=/[\\/][.][\\/]/;\ 1032 - rgx_1=/^[.][\\/]/;\ 1033 - rgx_2=/^[\\/][.][.][\\/]/;\ 1034 - i_4safety=0;\ 1035 - while s_0!=s_1 do ;\ 1036 - s_0=s_1;\ 1037 - s_1=s_0.gsub(rgx_0,'/');\ 1038 - i_4safety=i_4safety+1;\ 1039 - if 10000<i_4safety then ;\ 1040 - raise(Exception.new('boo'));\ 1041 - end;\ 1042 - end ;\ 1043 - s_0=s_1;\ 1044 - s_1=s_0.gsub(rgx_1,'');\ 1045 - s_0=s_1;\ 1046 - s_1=s_0.gsub(/[\\/]+/,'/');\ 1047 - ;\ 1048 - ;\ 1049 - i_4safety=0;\ 1050 - while s_0!=s_1 do ;\ 1051 - s_0=s_1;\ 1052 - s_1=s_0.gsub(rgx_2,'/');\ 1053 - i_4safety=i_4safety+1;\ 1054 - if 10000<i_4safety then ;\ 1055 - raise(Exception.new('10b7aae4-1940-4361-a4cb-f1e0305090e7'));\ 1056 - end;\ 1057 - end ;\ 1058 - s_0=s_1;\ 1059 - s_1=s_0.gsub(rgx_1,'');\ 1060 - s_0=s_1;\ 1061 - s_1=s_0.gsub(/[\\/]+/,'/');\ 1062 - ;\ 1063 - print s_1;\ 1064 - " 1065 - #---- 1066 - if [ "$SB_STR0" == "t" ]; then 1067 - S_FP_0_STR="`ruby -e \"$S_RUBY_SRC_0\" $S_FP_0`" 1068 - fi 1069 - if [ "$SB_STR1" == "t" ]; then 1070 - S_FP_1_STR="`ruby -e \"$S_RUBY_SRC_0\" $S_FP_1`" 1071 - fi 1072 - #---------------- 1073 - if [ "$S_COMPARISON_MODE" == "cmode_cd0_str1" ]; then 1074 - # 2 cases at the schematic 1075 - S_FP_X="`cd $S_FP_0;pwd`" 1076 - if [ "$S_FP_X" == "$S_FP_1_STR" ]; then 1077 - SB_ASSERTION_FAILED="t" 1078 - S_GUID_CMP="3a6056a5-c267-4111-b24c-f1e0305090e7" 1079 - fi 1080 - if [ "$SB_ASSERTION_FAILED" != "t" ]; then 1081 - if [ "$S_FP_X" == "$S_FP_1" ]; then # just in case 1082 - SB_ASSERTION_FAILED="t" 1083 - S_GUID_CMP="57a656e5-aa92-40a8-a53c-f1e0305090e7" 1084 - fi 1085 - fi 1086 - else 1087 - if [ "$S_COMPARISON_MODE" == "cmode_str0_cd1" ]; then 1088 - # 2 cases at the schematic 1089 - S_FP_X="`cd $S_FP_1;pwd`" 1090 - if [ "$S_FP_0_STR" == "$S_FP_X" ]; then 1091 - SB_ASSERTION_FAILED="t" 1092 - S_GUID_CMP="2bc33092-26d1-4787-953c-f1e0305090e7" 1093 - fi 1094 - if [ "$SB_ASSERTION_FAILED" != "t" ]; then 1095 - if [ "$S_FP_0" == "$S_FP_X" ]; then # just in case 1096 - SB_ASSERTION_FAILED="t" 1097 - S_GUID_CMP="05494129-51a8-4d7d-923c-f1e0305090e7" 1098 - fi 1099 - fi 1100 - else 1101 - if [ "$S_COMPARISON_MODE" == "cmode_cd0_cd1" ]; then 1102 - if [ "`cd $S_FP_0;pwd`" == "`cd $S_FP_1;pwd`" ]; then 1103 - SB_ASSERTION_FAILED="t" 1104 - S_GUID_CMP="37d42234-a57e-4d78-b52c-f1e0305090e7" 1105 - fi 1106 - else 1107 - if [ "$S_COMPARISON_MODE" == "cmode_str0_str1" ]; then 1108 - if [ "$S_FP_0_STR" == "$S_FP_1_STR" ]; then 1109 - SB_ASSERTION_FAILED="t" 1110 - S_GUID_CMP="b0eb5d1d-9b86-4d66-812c-f1e0305090e7" 1111 - fi 1112 - # The if [ "$S_FP_0" == "$S_FP_1" ] ... 1113 - # has already been tried at the very start 1114 - # of the huge if-block. 1115 - else 1116 - echo "" 1117 - echo "This script is flawed." 1118 - echo "" 1119 - echo " S_FP_0=$S_FP_0" 1120 - echo " S_FP_1=$S_FP_1" 1121 - echo " S_GUID_CRAWL=$S_GUID_CRAWL" 1122 - echo " S_GUID_CMP=$S_GUID_CMP" 1123 - echo " S_COMPARISON_MODE=$S_COMPARISON_MODE" 1124 - echo "" 1125 - echo "GUID=='14286012-4658-42f9-94cb-f1e0305090e7'" 1126 - echo "" 1127 - #---- 1128 - cd $S_FP_ORIG 1129 - exit 1 # exit with error 1130 - fi 1131 - fi 1132 - fi 1133 - fi 1134 - fi 1135 - #-------- 1136 - SB_FUNC_MMMV_ASSERT_FILE_PATHS_DIFFER_T1_ASSERTION_FAILED="$SB_ASSERTION_FAILED" # global 1137 - if [ "$SB_ASSERTION_FAILED" == "t" ]; then 1138 - if [ "$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE" != "t" ]; then 1139 - echo "" 1140 - echo "The file paths " 1141 - echo "" 1142 - echo " S_FP_0=$S_FP_0" 1143 - echo "" 1144 - echo " S_FP_1=$S_FP_1" 1145 - echo "" 1146 - echo "are required to differ and " 1147 - echo "they are required to differ also after normalization." 1148 - echo "" 1149 - echo "GUID=='3f8afd21-08d6-487f-b3cb-f1e0305090e7'" 1150 - echo "GUID=='$S_GUID_CMP'" # comparison 1151 - echo "GUID=='$S_GUID_CRAWL'" # tree crawling at the schematic 1152 - if [ "$S_GUID" != "" ]; then 1153 - echo "GUID=='$S_GUID'" # GUID as an input parameter 1154 - fi 1155 - echo "" 1156 - #---- 1157 - cd $S_FP_ORIG 1158 - exit 1 # exit with error 1159 - fi 1160 - fi 1161 -} # func_mmmv_assert_file_paths_differ_t1 1162 - 1163 - 1164 -#-------------------------------------------------------------------------- 1165 -# Activity aliases for comfort. 1166 - 1167 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "up" ]; then 1168 - S_ACTIVITY_OF_THIS_SCRIPT="overwrite_remote_with_local" 1169 -fi 1170 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "upload" ]; then 1171 - S_ACTIVITY_OF_THIS_SCRIPT="overwrite_remote_with_local" 1172 -fi 1173 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "ci" ]; then 1174 - S_ACTIVITY_OF_THIS_SCRIPT="overwrite_remote_with_local" 1175 -fi 1176 -#-------- 1177 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "down" ]; then 1178 - S_ACTIVITY_OF_THIS_SCRIPT="overwrite_local_with_remote" 1179 -fi 1180 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "download" ]; then 1181 - S_ACTIVITY_OF_THIS_SCRIPT="overwrite_local_with_remote" 1182 -fi 1183 -#-------- 1184 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "co" ]; then 1185 - S_ACTIVITY_OF_THIS_SCRIPT="clone_all" 1186 -fi 1187 -#-------- 1188 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "?" ]; then 1189 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1190 -fi 1191 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "-?" ]; then 1192 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1193 -fi 1194 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "--help" ]; then 1195 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1196 -fi 1197 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "-help" ]; then 1198 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1199 -fi 1200 -#-------- 1201 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "rm" ]; then 1202 - S_ACTIVITY_OF_THIS_SCRIPT="delete_local_copy" 1203 -fi 1204 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "del" ]; then 1205 - S_ACTIVITY_OF_THIS_SCRIPT="delete_local_copy" 1206 -fi 1207 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "delete" ]; then 1208 - S_ACTIVITY_OF_THIS_SCRIPT="delete_local_copy" 1209 -fi 1210 -#-------- 1211 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "info" ]; then 1212 - S_ACTIVITY_OF_THIS_SCRIPT="about" 1213 -fi 1214 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "--info" ]; then 1215 - S_ACTIVITY_OF_THIS_SCRIPT="about" 1216 -fi 1217 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "-info" ]; then 1218 - S_ACTIVITY_OF_THIS_SCRIPT="about" 1219 -fi 1220 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "--about" ]; then 1221 - S_ACTIVITY_OF_THIS_SCRIPT="about" 1222 -fi 1223 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "-about" ]; then 1224 - S_ACTIVITY_OF_THIS_SCRIPT="about" 1225 -fi 1226 -#-------- 1227 -#-------------------------------------------------------------------------- 1228 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "about" ]; then 1229 - echo "" 1230 - echo " The initial version of this script has been written by " 1231 - echo " Martin.Vahi@softf1.com " 1232 - echo " in 2016_02. The initial version is in public domain." 1233 - echo " The command \"help\" offers more information. " 1234 - echo "" 1235 - echo " Thank You for using this script :-)" 1236 - echo "" 1237 - echo "" 1238 - fun_exit_without_any_errors_t1 "t" 1239 -fi 1240 -#-------------------------------------------------------------------------- 1241 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "exit" ]; then 1242 - fun_exit_without_any_errors_t1 1243 -else 1244 - if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "clone_all" ]; then 1245 - if [ "$2" == "" ]; then 1246 - fun_print_msg_t1 1247 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1248 - SB_EXIT_WITH_ERROR="t" 1249 - else 1250 - S_URL_REMOTE_REPOSITORY="$2" 1251 - fi 1252 - else 1253 - if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "clone_public" ]; then 1254 - if [ "$2" == "" ]; then 1255 - fun_print_msg_t1 1256 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1257 - SB_EXIT_WITH_ERROR="t" 1258 - else 1259 - S_URL_REMOTE_REPOSITORY="$2" 1260 - fi 1261 - else 1262 - if [ "$S_ACTIVITY_OF_THIS_SCRIPT" != "overwrite_local_with_remote" ]; then 1263 - if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "overwrite_remote_with_local" ]; then 1264 - if [ "$2" != "" ]; then 1265 - if [ "$2" == "use_autogenerated_commit_message" ]; then 1266 - if [ "$3" != "" ]; then 1267 - echo "" 1268 - echo "If the first console argument is \"overwrite_local_with_remote\" and" 1269 - echo "the second console argument is \"use_autogenerated_commit_message\", " 1270 - echo "then there should not be a 3. console argument." 1271 - echo "GUID=='468fa904-55da-4388-81cb-f1e0305090e7'" 1272 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1273 - SB_EXIT_WITH_ERROR="t" 1274 - fi 1275 - else 1276 - if [ "$2" == "read_commit_message_from_file" ]; then 1277 - S_FP_MESSAGE_FILE_CANDIDATE="$3" # file path candidate 1278 - if [ "$S_FP_MESSAGE_FILE_CANDIDATE" == "" ]; then 1279 - echo "" 1280 - echo "If the first console argument is " 1281 - echo "\"overwrite_local_with_remote\" and" 1282 - echo "the second console argument is " 1283 - echo "\"read_commit_message_from_file\", " 1284 - echo "then there should be also a 3. console argument " 1285 - echo "that is expected to be a file path to a text file." 1286 - echo "GUID=='559c7db3-15af-4a7d-bdbb-f1e0305090e7'" 1287 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1288 - SB_EXIT_WITH_ERROR="t" 1289 - fi 1290 - if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then 1291 - if [ "$4" != "" ]; then 1292 - echo "" 1293 - echo "If the first console argument is " 1294 - echo "\"overwrite_local_with_remote\" and" 1295 - echo "the second console argument is " 1296 - echo "\"read_commit_message_from_file\", " 1297 - echo "then there should be exactly 3. console arguments, " 1298 - echo "not 4 or more. Unfortunately the 4. argument is currently " 1299 - echo "---citation--start---" 1300 - echo "$4" 1301 - echo "---citation--end-----" 1302 - echo "GUID=='5e662e45-13a1-499b-9dbb-f1e0305090e7'" 1303 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1304 - SB_EXIT_WITH_ERROR="t" 1305 - fi 1306 - fi 1307 - if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then 1308 - if [ ! -e "$S_FP_MESSAGE_FILE_CANDIDATE" ]; then 1309 - echo "" 1310 - echo "The commit message file path candidate " 1311 - echo "references either a missing file or " 1312 - echo "a broken symlink." 1313 - echo "GUID=='15f6e772-31ba-4f5e-97bb-f1e0305090e7'" 1314 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1315 - SB_EXIT_WITH_ERROR="t" 1316 - fi 1317 - fi 1318 - if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then 1319 - if [ -d "$S_FP_MESSAGE_FILE_CANDIDATE" ]; then 1320 - echo "" 1321 - echo "The commit message file path candidate " 1322 - echo "references a folder, but it should " 1323 - echo "reference a text file." 1324 - echo "GUID=='3225928c-0920-4018-95bb-f1e0305090e7'" 1325 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1326 - SB_EXIT_WITH_ERROR="t" 1327 - fi 1328 - fi 1329 - if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then 1330 - S_TMP_0="`filesize $S_FP_MESSAGE_FILE_CANDIDATE`" 1331 - S_TMP_1="`ruby -e \"s_out='OK'; if (2000<$S_TMP_0) then s_out='too_big' end; print(s_out);\"`" 1332 - if [ "$S_TMP_1" == "too_big" ]; then 1333 - echo "" 1334 - echo "The commit message file path " 1335 - echo "references a file that has a size of $S_TMP_0 bytes." 1336 - echo "The suspicion is that it is a wrong file. " 1337 - echo "because a commit message is usually not that lengthy." 1338 - echo "GUID=='21090045-08fe-4487-81bb-f1e0305090e7'" 1339 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1340 - SB_EXIT_WITH_ERROR="t" 1341 - else 1342 - if [ "$S_TMP_0" == "0" ]; then 1343 - echo "" 1344 - echo "The commit message file path " 1345 - echo "references a file that has a size of 0 (zero) bytes." 1346 - echo "" 1347 - echo "The generation of commit message files " 1348 - echo "can be avoided by using the option " 1349 - echo "" 1350 - echo " \"use_autogenerated_commit_message\"" 1351 - echo "" 1352 - echo "in stead of the option " 1353 - echo "" 1354 - echo " \"read_commit_message_from_file\" ." 1355 - echo "" 1356 - echo "GUID=='a539fb61-243d-4e0c-82bb-f1e0305090e7'" 1357 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1358 - SB_EXIT_WITH_ERROR="t" 1359 - fi 1360 - fi 1361 - fi 1362 - if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then 1363 - S_TMP_0="`file --mime-type $S_FP_MESSAGE_FILE_CANDIDATE | grep text `" 1364 - if [ "$S_TMP_0" == "" ]; then 1365 - echo "" 1366 - echo "The commit message file path " 1367 - echo "references a file that has a MIME type of " 1368 - echo "" 1369 - echo "`file --mime-type $S_FP_MESSAGE_FILE_CANDIDATE`" 1370 - echo "" 1371 - echo "The commit message file must be a text file and " 1372 - echo "text files have the string \"text\" in their MIME type name." 1373 - echo "GUID=='0e00aa42-a7dd-4e63-b2ab-f1e0305090e7'" 1374 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1375 - SB_EXIT_WITH_ERROR="t" 1376 - fi 1377 - fi 1378 - fi # read_commit_message_from_file 1379 - fi 1380 - fi 1381 - else 1382 - if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "delete_local_copy" ]; then 1383 - if [ "$2" != "" ]; then # the 2. arg is optional here 1384 - if [ "$2" != "$S_ARGNAME_ACTIVITY_SHRED_ARG_2" ]; then 1385 - echo "" 1386 - echo "If the first console argument is \"delete_local_copy\", then" 1387 - echo "the second console argument is allowed to be only " 1388 - echo "" 1389 - echo " \"$S_ARGNAME_ACTIVITY_SHRED_ARG_2\", without quotation marks." 1390 - echo "GUID=='53d97712-0caf-4847-b5ab-f1e0305090e7'" 1391 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1392 - SB_EXIT_WITH_ERROR="t" 1393 - fi 1394 - fi 1395 - else 1396 - if [ "$S_ACTIVITY_OF_THIS_SCRIPT" != "print_script_version" ]; then 1397 - if [ "$S_ACTIVITY_OF_THIS_SCRIPT" != "help" ]; then 1398 - echo "" 1399 - echo "The very first console argument " 1400 - echo "of this script is expected to be " 1401 - echo "a command that is specific to this script." 1402 - echo "GUID=='5d8d1e92-ac26-408a-81ab-f1e0305090e7'" 1403 - S_ACTIVITY_OF_THIS_SCRIPT="help" 1404 - SB_EXIT_WITH_ERROR="t" 1405 - fi 1406 - fi 1407 - fi 1408 - fi 1409 - fi 1410 - fi 1411 - fi 1412 -fi 1413 - 1414 -#-------------------------------------------------------------------------- 1415 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "help" ]; then 1416 - echo "" 1417 - echo "Possible console argument sets are:" 1418 - echo "" 1419 - echo " clone_all <remote repository url>" 1420 - echo " clone_public <remote repository url>" 1421 - echo " overwrite_local_with_remote" 1422 - echo "" 1423 - echo " overwrite_remote_with_local (use_autogenerated_commit_message)?" 1424 - echo " overwrite_remote_with_local read_commit_message_from_file <path to a text file>" 1425 - echo "" 1426 - echo " delete_local_copy ($S_ARGNAME_ACTIVITY_SHRED_ARG_2)?" 1427 - echo " help" 1428 - echo " print_script_version" 1429 - echo " exit # just for testing" 1430 - echo "" 1431 - #---- 1432 - cd $S_FP_ORIG 1433 - if [ "$SB_EXIT_WITH_ERROR" == "t" ]; then 1434 - exit 1 # To let the parent script know that 1435 - # the parent script calls this script with 1436 - # flawed console argument values. 1437 - else 1438 - exit 0 1439 - fi 1440 -fi 1441 - 1442 -#-------------------------------------------------------------------------- 1443 -# The script version is needed by other scripts that depend on this script. 1444 -# The script version GUID must not be surrounded by 1445 -# any quote signs (',"), because otherwise the 1446 -# version GUID will be overwritten by the UpGUID tool, 1447 -# but unlike error message GUID-s this GUID must stay constant. 1448 -# To allow the version to be used as sub-part of file names and 1449 -# folder names, the version must not contain any spaces, line breaks 1450 -# and other characters that have a special meaning in Bash. 1451 -# 1452 -# If the version ID did not match the GUID regex, then I would have to 1453 -# write a long comment about it not being allowed to match the 1454 -# GUID regex. :-D 1455 -S_VERSION_OF_THIS_SCRIPT="23dc37cc-4d31-4444-a52c-f1e0305090e7" 1456 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "print_script_version" ]; then 1457 - echo "The version of this script is: $S_VERSION_OF_THIS_SCRIPT" 1458 - #---- 1459 - cd $S_FP_ORIG 1460 - exit 0 1461 -fi 1462 - 1463 - 1464 -#-------------------------------------------------------------------------- 1465 -S_FP_SANDBOX_DIRECTORY_NAME="sandbox_of_the_Fossil_repository" 1466 -S_FP_SANDBOX="$S_FP_DIR/$S_FP_SANDBOX_DIRECTORY_NAME" 1467 -#---- 1468 -S_FP_ARCHIVES_DIRECTORY_NAME="archival_copies_of_the_Fossil_repository_sandbox" 1469 -S_FP_ARCHIVES="$S_FP_DIR/$S_FP_ARCHIVES_DIRECTORY_NAME" 1470 -S_FP_ARCHIVES_TS="$S_FP_ARCHIVES/v$S_TIMESTAMP" 1471 -#---- 1472 -S_FP_FOSSILFILE_NAME="repository_storage.fossil" 1473 -S_FP_FOSSILFILE="$S_FP_DIR/$S_FP_FOSSILFILE_NAME" 1474 - 1475 -#-------- 1476 -S_LC_NOT_DETERMINED="not determined" 1477 -SB_SANDBOX_DIR_EXISTS="$S_LC_NOT_DETERMINED" 1478 -fun_sandbox_folder_or_symlink_exists() { 1479 - SB_SANDBOX_DIR_EXISTS="f" 1480 - if [ ! -e $S_FP_SANDBOX ]; then 1481 - # Does not exist or it is a broken symbolic link. 1482 - SB_SANDBOX_DIR_EXISTS="f" 1483 - else 1484 - if [ -d $S_FP_SANDBOX ]; then 1485 - SB_SANDBOX_DIR_EXISTS="t" 1486 - fi 1487 - fi 1488 -} # fun_sandbox_folder_or_symlink_exists 1489 - 1490 -SB_FOSSILFILE_EXISTS="$S_LC_NOT_DETERMINED" 1491 -fun_fossil_repository_file_or_symlink_exists() { 1492 - SB_FOSSILFILE_EXISTS="t" 1493 - if [ ! -e $S_FP_FOSSILFILE ]; then 1494 - # Does not exist or it is a broken symbolic link. 1495 - SB_FOSSILFILE_EXISTS="f" 1496 - else 1497 - if [ -d $S_FP_FOSSILFILE ]; then 1498 - SB_FOSSILFILE_EXISTS="f" 1499 - fi 1500 - fi 1501 -} # fun_fossil_repository_file_or_symlink_exists 1502 - 1503 -S_LC_NOT_DETERMINED="not determined" 1504 -SB_ARCHIVE_DIR_EXISTS="$S_LC_NOT_DETERMINED" 1505 -fun_archives_folder_or_symlink_exists() { 1506 - SB_ARCHIVE_DIR_EXISTS="f" 1507 - if [ ! -e $S_FP_ARCHIVES ]; then 1508 - # Does not exist or it is a broken symbolic link. 1509 - SB_ARCHIVE_DIR_EXISTS="f" 1510 - else 1511 - if [ -d $S_FP_ARCHIVES ]; then 1512 - SB_ARCHIVE_DIR_EXISTS="t" 1513 - fi 1514 - fi 1515 -} # fun_archives_folder_or_symlink_exists 1516 - 1517 -#-------- 1518 -fun_fossil_repository_file_or_symlink_exists 1519 -fun_sandbox_folder_or_symlink_exists 1520 -fun_archives_folder_or_symlink_exists 1521 - 1522 -fun_assertion_t1() { 1523 - local SB_CANDIDATE=$1 1524 - local SB_THROW="t" 1525 - #---- 1526 - if [ "$SB_CANDIDATE" == "t" ]; then 1527 - SB_THROW="f" 1528 - else 1529 - if [ "$SB_CANDIDATE" == "f" ]; then 1530 - SB_THROW="f" 1531 - fi 1532 - fi 1533 - #---- 1534 - if [ "$SB_THROW" == "t" ]; then 1535 - echo "" 1536 - echo "This Bash script is flawed. " 1537 - echo "fun_assertion_t1() assertion failed." 1538 - echo "GUID=='c2afa84b-ad9b-41b4-a4ab-f1e0305090e7'" 1539 - echo "" 1540 - #---- 1541 - cd $S_FP_ORIG 1542 - exit 1 1543 - fi 1544 -} # fun_assertion_t1 1545 - 1546 -fun_assertion_t1 "$SB_FOSSILFILE_EXISTS" 1547 -fun_assertion_t1 "$SB_SANDBOX_DIR_EXISTS" 1548 -fun_assertion_t1 "$SB_ARCHIVE_DIR_EXISTS" 1549 - 1550 -#-------------------------------------------------------------------------- 1551 - 1552 -fun_assert_repository_local_copy_existence() { 1553 - fun_fossil_repository_file_or_symlink_exists 1554 - if [ "$SB_FOSSILFILE_EXISTS" == "f" ]; then 1555 - echo "" 1556 - echo "The directory " 1557 - echo "`pwd`" 1558 - echo "does not contain a Fossil repository file named " 1559 - echo "" 1560 - echo " $S_FP_FOSSILFILE_NAME" 1561 - echo "" 1562 - echo "Aborting script." 1563 - echo "GUID=='b6307f42-cfba-4f42-b4ab-f1e0305090e7'" 1564 - echo "" 1565 - #---- 1566 - cd $S_FP_ORIG 1567 - exit 1 1568 - fi 1569 - fun_sandbox_folder_or_symlink_exists 1570 - if [ "$SB_SANDBOX_DIR_EXISTS" == "f" ]; then 1571 - echo "" 1572 - echo "The directory " 1573 - echo "`pwd`" 1574 - echo "does not contain a directory named " 1575 - echo "" 1576 - echo " $S_FP_SANDBOX_DIRECTORY_NAME" 1577 - echo "" 1578 - echo "Aborting script." 1579 - echo "GUID=='2619a005-53ea-46b9-a79b-f1e0305090e7'" 1580 - echo "" 1581 - #---- 1582 - cd $S_FP_ORIG 1583 - exit 1 1584 - fi 1585 -} # fun_assert_repository_local_copy_existence 1586 - 1587 - 1588 -fun_assert_the_lack_of_repository_local_copy_t1() { 1589 - if [ "$SB_FOSSILFILE_EXISTS" == "t" ]; then 1590 - echo "" 1591 - echo "The directory " 1592 - echo "`pwd`" 1593 - echo "already contain a file named " 1594 - echo "" 1595 - echo " $S_FP_FOSSILFILE_NAME" 1596 - echo "" 1597 - echo "To avoid overwriting an existing local copy, this script is aborted" 1598 - echo "and nothing is downloaded/uploaded by this script." 1599 - echo "GUID=='3cdf8c33-e911-4ecf-819b-f1e0305090e7'" 1600 - echo "" 1601 - #---- 1602 - cd $S_FP_ORIG 1603 - exit 1 1604 - fi 1605 - if [ "$SB_SANDBOX_DIR_EXISTS" == "t" ]; then 1606 - echo "" 1607 - echo "The directory " 1608 - echo "`pwd`" 1609 - echo "already contains a directory named " 1610 - echo "" 1611 - echo " $S_FP_SANDBOX_DIRECTORY_NAME" 1612 - echo "" 1613 - echo "To avoid overwriting an existing local copy, this script is aborted" 1614 - echo "and nothing is downloaded/uploaded by this script." 1615 - echo "GUID=='e054e73b-52b7-4999-929b-f1e0305090e7'" 1616 - echo "" 1617 - #---- 1618 - cd $S_FP_ORIG 1619 - exit 1 1620 - fi 1621 -} # fun_assert_the_lack_of_repository_local_copy_t1 1622 - 1623 - 1624 - 1625 -fun_initialize_sandbox_t1() { 1626 - mkdir -p $S_FP_SANDBOX 1627 - sync; 1628 - cd $S_FP_SANDBOX 1629 - fossil open $S_FP_DIR/$S_FP_FOSSILFILE_NAME # full path for reliability 1630 - fossil settings autosync off ; 1631 - fossil settings case-sensitive TRUE ; 1632 - fossil checkout --force --latest 1633 - fossil pull 1634 - fossil close 1635 - sync; 1636 -} # fun_initialize_sandbox_t1 1637 - 1638 - 1639 -#-------------------------------------------------------------------------- 1640 -fun_last_minute_checks_t1() { 1641 - # Last minute checks, just to be sure. 1642 - local S_FP_FORBIDDEN_VALUE=$1 1643 - if [ "$S_FP_FORBIDDEN_VALUE" == "/" ]; then 1644 - echo "" 1645 - echo "This Bash script is flawed." 1646 - echo "GUID=='3c4e5af3-7901-474c-939b-f1e0305090e7'" 1647 - echo "" 1648 - #---- 1649 - cd $S_FP_ORIG 1650 - exit 1 1651 - fi 1652 - if [ "$S_FP_FORBIDDEN_VALUE" == "$HOME" ]; then 1653 - echo "" 1654 - echo "This Bash script is flawed." 1655 - echo "GUID=='c200ef46-b3f7-4204-919b-f1e0305090e7'" 1656 - echo "" 1657 - #---- 1658 - cd $S_FP_ORIG 1659 - exit 1 1660 - fi 1661 - if [ "$S_FP_FORBIDDEN_VALUE" == "/home" ]; then 1662 - echo "" 1663 - echo "This Bash script is flawed." 1664 - echo "GUID=='d2a65b5e-0591-4332-948b-f1e0305090e7'" 1665 - echo "" 1666 - #---- 1667 - cd $S_FP_ORIG 1668 - exit 1 1669 - fi 1670 - if [ "$S_FP_FORBIDDEN_VALUE" == "/root" ]; then 1671 - echo "" 1672 - echo "This Bash script is flawed." 1673 - echo "GUID=='03b089fe-baa7-4a68-b38b-f1e0305090e7'" 1674 - echo "" 1675 - #---- 1676 - cd $S_FP_ORIG 1677 - exit 1 1678 - fi 1679 - if [ "$S_FP_FORBIDDEN_VALUE" == "/etc" ]; then 1680 - echo "" 1681 - echo "This Bash script is flawed." 1682 - echo "GUID=='0062ae2c-e3a2-4764-b28b-f1e0305090e7'" 1683 - echo "" 1684 - #---- 1685 - cd $S_FP_ORIG 1686 - exit 1 1687 - fi 1688 - if [ "$S_FP_FORBIDDEN_VALUE" == "/usr" ]; then 1689 - echo "" 1690 - echo "This Bash script is flawed." 1691 - echo "GUID=='9de55d34-dbca-4803-918b-f1e0305090e7'" 1692 - echo "" 1693 - #---- 1694 - cd $S_FP_ORIG 1695 - exit 1 1696 - fi 1697 -} # fun_last_minute_checks_t1 1698 - 1699 - 1700 -#-------------------------------------------------------------------------- 1701 -SB_FOLDER_IS_EMPTY="$S_LC_NOT_DETERMINED" 1702 -fun_folder_is_empty_t1() { 1703 - local S_FP_FOLDER_TO_STUDY=$1 1704 - local S_FP_ORIG_LOCAL="`pwd`" 1705 - #-------- 1706 - SB_FOLDER_IS_EMPTY="t" 1707 - local S_TMP_0="`cd $S_FP_FOLDER_TO_STUDY; ls -l | grep \"total 0\"`" 1708 - if [ "$S_TMP_0" == "" ]; then 1709 - SB_FOLDER_IS_EMPTY="f" 1710 - fi 1711 - #-------- 1712 - cd $S_FP_ORIG_LOCAL # just in case 1713 -} # fun_folder_is_empty_t1 1714 - 1715 -fun_folder_is_empty_t1 "$S_FP_DIR" 1716 -fun_assertion_t1 "$SB_FOLDER_IS_EMPTY" 1717 -if [ "$SB_FOLDER_IS_EMPTY" == "t" ]; then 1718 - echo "" 1719 - echo "This Bash script is flawed. The " 1720 - echo "$S_FP_DIR" 1721 - echo "can not possibly be empty, because it contains " 1722 - echo "at least one file, which is " 1723 - echo "this very same Bash script that outputs the current error message." 1724 - echo "GUID=='fb573a47-7195-4c06-b18b-f1e0305090e7'" 1725 - echo "" 1726 - #---- 1727 - cd $S_FP_ORIG 1728 - exit 1 1729 -fi 1730 - 1731 -#-------------------------------------------------------------------------- 1732 - 1733 -fun_activity_core_overwrite_local_with_remote() { 1734 - fun_assert_repository_local_copy_existence 1735 - #-------- 1736 - # The checks are party to cope with the `whoami`=="root" case. 1737 - fun_last_minute_checks_t1 "$S_FP_SANDBOX" 1738 - fun_last_minute_checks_t1 "$S_FP_ARCHIVES" 1739 - fun_last_minute_checks_t1 "$S_FP_ARCHIVES_TS" 1740 - #-------- 1741 - chmod -f -R u+rx $S_FP_SANDBOX 1742 - fun_folder_is_empty_t1 "$S_FP_SANDBOX" 1743 - if [ "$SB_FOLDER_IS_EMPTY" == "f" ]; then 1744 - # This if-statement is needed because the 1745 - # cp -f -R AnEmptyDirectory/* ToSomewhere/ 1746 - # gives an error. 1747 - #---- 1748 - mkdir -p $S_FP_ARCHIVES_TS 1749 - #---- 1750 - # The "chmod -f -R " is not used because it would 1751 - # waste time on folders that are named by 1752 - # the older $S_FP_ARCHIVES_TS values. 1753 - chmod -f 0700 $S_FP_ARCHIVES 1754 - chmod -f 0700 $S_FP_ARCHIVES_TS 1755 - #---- 1756 - # The separate cp and rm of the sandbox 1757 - # contents is to somewhat retain the original 1758 - # file premissions of the sandbox contents. 1759 - cp -f -R $S_FP_SANDBOX/* $S_FP_ARCHIVES_TS/ 1760 - fun_last_minute_checks_t1 "$S_FP_SANDBOX" 1761 - chmod -f -R u+rwx $S_FP_SANDBOX 1762 - rm -fr $S_FP_SANDBOX/* 1763 - fi 1764 - #-------- 1765 - cd $S_FP_SANDBOX 1766 - fossil open $S_FP_DIR/$S_FP_FOSSILFILE_NAME # full path for reliability 1767 - fossil settings autosync off ; 1768 - fossil checkout --force --latest 1769 - fossil pull 1770 - fossil close 1771 -} # fun_activity_core_overwrite_local_with_remote 1772 - 1773 - 1774 - 1775 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "overwrite_local_with_remote" ]; then 1776 - fun_activity_core_overwrite_local_with_remote 1777 - #---- 1778 - cd $S_FP_ORIG 1779 - exit 0 1780 -fi # overwrite_local_with_remote 1781 - 1782 - 1783 - 1784 -#-------------------------------------------------------------------------- 1785 -fossil close 2>/dev/null 1786 - 1787 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "clone_public" ]; then 1788 - fun_assert_the_lack_of_repository_local_copy_t1 1789 - cd $S_FP_DIR 1790 - fossil clone $S_URL_REMOTE_REPOSITORY ./$S_FP_FOSSILFILE_NAME 1791 - fun_initialize_sandbox_t1 1792 - cd $S_FP_ORIG 1793 - #---- 1794 - sync 1795 - fun_activity_core_overwrite_local_with_remote 1796 - cd $S_FP_ORIG 1797 - sync 1798 - #---- 1799 - exit 0 1800 -fi # clone_public 1801 - 1802 - 1803 -#-------------------------------------------------------------------------- 1804 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "clone_all" ]; then 1805 - fun_assert_the_lack_of_repository_local_copy_t1 1806 - cd $S_FP_DIR 1807 - #-------- 1808 - S_USERNAME="" 1809 - while [ "$S_USERNAME" == "" ] 1810 - do 1811 - echo "" 1812 - echo "Please enter a username: " 1813 - S_USERNAME="`ruby -e \"s=gets.gsub(/[\n\r\s]/,'');print(s)\"`" 1814 - S_URL="`export S_USERNAME=\"$S_USERNAME\"; S_URL=\"$S_URL_REMOTE_REPOSITORY\" ruby -e 's_0=ENV[\"S_URL\"].sub(\"http://\",\"http:/\").sub(\"http:/\",\"http://\"+ENV[\"S_USERNAME\"].to_s+\":nonsensepassword@\");print(s_0)'`" 1815 - done 1816 - #-------- 1817 - fossil clone --private $S_URL ./$S_FP_FOSSILFILE_NAME 1818 - fun_initialize_sandbox_t1 1819 - cd $S_FP_ORIG 1820 - #---- 1821 - sync 1822 - fun_activity_core_overwrite_local_with_remote 1823 - cd $S_FP_ORIG 1824 - sync 1825 - #---- 1826 - exit 0 1827 -fi # clone_all 1828 - 1829 - 1830 -#-------------------------------------------------------------------------- 1831 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "overwrite_remote_with_local" ]; then 1832 - fun_assert_repository_local_copy_existence 1833 - #-------- 1834 - # It's important that this script will not try 1835 - # to recursively copy/move the content of the "/" to 1836 - # a subfolder of the "/", the "/tmp". 1837 - # The other folders that are covered by the 1838 - # test are a bit of an overkill here, may be even an 1839 - # annoying and unjustified restrictions, but 1840 - # in most cases those restrictions do not hurt either. 1841 - fun_last_minute_checks_t1 "$S_FP_SANDBOX" 1842 - #---- 1843 - S_TMP_0="/tmp/tmp_mmmv_$S_VERSION_OF_THIS_SCRIPT" 1844 - S_TMP_1="__" 1845 - #-- 1846 - func_mmmv_GUID_t1 1847 - S_TMP_FOR_LOCAL="$S_TMP_0$S_TMP_1$S_FUNC_MMMV_GUID_T1_RESULT" 1848 - #-- 1849 - func_mmmv_GUID_t1 1850 - S_TMP_FOR_COMMIT_MESSAGE="$S_TMP_0$S_TMP_1$S_FUNC_MMMV_GUID_T1_RESULT" 1851 - mkdir -p $S_TMP_FOR_LOCAL 1852 - chmod -f -R u+rwx $S_FP_SANDBOX 1853 - mv -f $S_FP_SANDBOX/* $S_TMP_FOR_LOCAL/ # the -f is for empty sandbox 1854 - #-------- 1855 - fun_activity_core_overwrite_local_with_remote 1856 - fun_last_minute_checks_t1 "$S_FP_SANDBOX" # should there be flaws elsewhere 1857 - chmod -f -R u+rwx $S_FP_SANDBOX # to be able to delete the old content 1858 - #-------- 1859 - cd $S_FP_SANDBOX 1860 - fossil open $S_FP_DIR/$S_FP_FOSSILFILE_NAME # full path for reliability 1861 - fossil settings autosync off ; 1862 - fun_folder_is_empty_t1 "$S_FP_SANDBOX" 1863 - SB_SANDBOX_CONTENT_MIGHT_HAVE_BEEN_CHANGED="f" 1864 - if [ "$SB_FOLDER_IS_EMPTY" == "f" ]; then 1865 - fossil rm --hard --case-sensitive TRUE ./* 1866 - SB_SANDBOX_CONTENT_MIGHT_HAVE_BEEN_CHANGED="t" 1867 - fun_last_minute_checks_t1 "`pwd`" 1868 - if [ "$S_FP_SANDBOX" == "`pwd`" ]; then 1869 - rm -fr ./* 1870 - else 1871 - echo "" 1872 - echo "This Bash script is flawed." 1873 - echo "GUID=='20848e2d-db76-40f0-b18b-f1e0305090e7'" 1874 - echo "" 1875 - #---- 1876 - cd $S_FP_ORIG 1877 - exit 1 1878 - fi 1879 - fi 1880 - mv -f $S_TMP_FOR_LOCAL/* $S_FP_SANDBOX/ # the -f is for empty source 1881 - #---- 1882 - fun_last_minute_checks_t1 "$S_TMP_FOR_LOCAL" 1883 - rm -fr $S_TMP_FOR_LOCAL 1884 - #---- 1885 - fun_folder_is_empty_t1 "$S_FP_SANDBOX" 1886 - if [ "$SB_FOLDER_IS_EMPTY" == "f" ]; then 1887 - if [ "$S_FP_SANDBOX" != "`pwd`" ]; then 1888 - echo "" 1889 - echo "This Bash script is flawed." 1890 - echo "GUID=='74c20b5b-81c4-4dea-a17b-f1e0305090e7'" 1891 - echo "" 1892 - #---- 1893 - cd $S_FP_ORIG 1894 - exit 1 1895 - fi 1896 - find . -name '*' | xargs fossil add --force --dotfiles --case-sensitive TRUE 1897 - SB_SANDBOX_CONTENT_MIGHT_HAVE_BEEN_CHANGED="t" 1898 - fi 1899 - if [ "$SB_SANDBOX_CONTENT_MIGHT_HAVE_BEEN_CHANGED" == "t" ]; then 1900 - if [ "$2" == "" ]; then 1901 - echo "" 1902 - #echo "Please enter a one-liner commit message: " 1903 - #S_TMP_0="`ruby -e \"s=gets.gsub(/[\n\r\s]/,'');print(s)\"`" 1904 - # TODO: improve this script so that it would not ask 1905 - # for a commit message, when nothing changed. It requires 1906 - # some recursive analysis of files, which might be slow. 1907 - # This script is not optimal for speed even now and that would 1908 - # make it even slower. On the other hand, usually when 1909 - # the upload operation is initiated, there are some changes, 1910 - # which means that the slow analysis would be useless in 1911 - # most frequent cases. So this thing needs to be figured out 1912 - # at some later time, when there is more experience with the 1913 - # use of this script. 1914 - read -p "Please enter a one-liner commit message: " S_TMP_0 1915 - echo $S_TMP_0 > $S_TMP_FOR_COMMIT_MESSAGE 1916 - else 1917 - if [ "$2" == "use_autogenerated_commit_message" ]; then 1918 - echo "Autogenerated commit message timestamp: $S_TIMESTAMP" > $S_TMP_FOR_COMMIT_MESSAGE 1919 - else 1920 - if [ "$2" == "read_commit_message_from_file" ]; then 1921 - S_FP_MESSAGE_FILE_CANDIDATE="$3" # file path candidate 1922 - # Initial file existence and type checks for the 1923 - # $S_FP_MESSAGE_FILE_CANDIDATE 1924 - # were conducted at the start of the script. 1925 - # but the $S_FP_MESSAGE_FILE_CANDIDATE might have 1926 - # referenced a file in the sandbox and 1927 - # that file might have been just removed/deleted. 1928 - # 1929 - # There is no threat that the file got changed to a folder 1930 - # or a symlink switched from a file to a folder, 1931 - # at least that's the case for the single threaded model. 1932 - if [ ! -e "$S_FP_MESSAGE_FILE_CANDIDATE" ]; then 1933 - # missing or a broken symlink 1934 - echo "" 1935 - echo "The commit message file is missing or " 1936 - echo "references a broken symlink." 1937 - echo "The file or symlink to it was fine at " 1938 - echo "the start of this script, it passed the various tests, " 1939 - echo "but for some reason it got deleted or its target . " 1940 - echo "got deleted. If the commit message file or" 1941 - echo "the symlink target resided within the sandbox, then " 1942 - echo "a recommendation is to use a file that resides " 1943 - echo "outside of the sandbox." 1944 - echo "GUID=='489d0043-ac2a-46ae-857b-f1e0305090e7'" 1945 - echo "" 1946 - #---- 1947 - cd $S_FP_ORIG 1948 - exit 1 1949 - fi 1950 - if [ -d "$S_FP_MESSAGE_FILE_CANDIDATE" ]; then 1951 - # folder or a symlink to a folder 1952 - echo "" 1953 - echo "The commit message file path does not reference " 1954 - echo "a file. It references a folder or a symlink to a folder." 1955 - echo "The file or symlink to it was fine at " 1956 - echo "the start of this script, it passed the various tests, " 1957 - echo "but for some reason there were changes. " 1958 - echo "GUID=='1c1054d1-d44f-4830-a47b-f1e0305090e7'" 1959 - echo "" 1960 - #---- 1961 - cd $S_FP_ORIG 1962 - exit 1 1963 - fi 1964 - cat $S_FP_MESSAGE_FILE_CANDIDATE > $S_TMP_FOR_COMMIT_MESSAGE 1965 - # else 1966 - # Due to the checks at the start of the script 1967 - # this else branch is useless. 1968 - fi 1969 - fi 1970 - fi 1971 - #-------- 1972 - fossil commit --message-file $S_TMP_FOR_COMMIT_MESSAGE 1973 - #---- 1974 - fun_last_minute_checks_t1 "$S_TMP_FOR_COMMIT_MESSAGE" 1975 - rm -f $S_TMP_FOR_COMMIT_MESSAGE 1976 - #---- 1977 - fi 1978 - #-------- 1979 - fossil push --private 1980 - fossil push 1981 - fossil pull --private 1982 - fossil close 1983 - #---- 1984 - cd $S_FP_ORIG 1985 - exit 0 1986 -fi # overwrite_remote_with_local 1987 - 1988 - 1989 -#-------------------------------------------------------------------------- 1990 -if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "delete_local_copy" ]; then 1991 - #-------- 1992 - SB_THERE_IS_SOMETHING_TO_DELETE="f" 1993 - if [ "$SB_FOSSILFILE_EXISTS" == "t" ]; then 1994 - SB_THERE_IS_SOMETHING_TO_DELETE="t" 1995 - fi 1996 - if [ "$SB_SANDBOX_DIR_EXISTS" == "t" ]; then 1997 - SB_THERE_IS_SOMETHING_TO_DELETE="t" 1998 - fi 1999 - if [ "$SB_ARCHIVE_DIR_EXISTS" == "t" ]; then 2000 - SB_THERE_IS_SOMETHING_TO_DELETE="t" 2001 - fi 2002 - #-------- 2003 - if [ "$SB_THERE_IS_SOMETHING_TO_DELETE" == "t" ]; then 2004 - if [ "$2" != "$S_ARGNAME_ACTIVITY_SHRED_ARG_2" ]; then 2005 - # Includes the $2=="" case 2006 - # id est if the control flow is in here, then there 2007 - # is a need to prompt for confirmation. 2008 - # The skipping of the prompt is necessary for 2009 - # software that use this script as its sub-component. 2010 - #-------- 2011 - echo "" 2012 - echo "The command \"delete_local_copy\" deletes " 2013 - echo "the repository file, the sandbox and " 2014 - echo "the associated automatically created archives." 2015 - echo "" 2016 - read -p "Proceed with deletion? (Yes/whatever_else) " S_TMP_0 2017 - S_TMP_1="`echo $S_TMP_0 | gawk '{print tolower($1)}'`" 2018 - if [ "$S_TMP_1" == "yes" ]; then 2019 - echo "" 2020 - printf "Deleting ... " 2021 - else 2022 - fun_exit_without_any_errors_t1 2023 - fi 2024 - fi 2025 - fi 2026 - #-------- 2027 - cd $S_FP_ORIG # to make sure that we're not in the sandbox directory and 2028 - # to make sure that we're not in the archive directory 2029 - #---- 2030 - # The next 3 checks can bee seen to form a complete graph, 2031 - # in this case a triangle, with corner points 2032 - # S_FP_SANDBOX, S_FP_ARCHIVES, S_FP_FOSSILFILE connected 2033 - # with lines of type "!=". 2034 - S_GUID="470c7051-b162-4cba-b51c-f1e0305090e7" 2035 - func_mmmv_assert_file_paths_differ_t1 "$S_FP_FOSSILFILE" "$S_FP_SANDBOX" "$S_GUID" 2036 - 2037 - S_GUID="45b8df6a-0c67-4d1e-a71c-f1e0305090e7" 2038 - func_mmmv_assert_file_paths_differ_t1 "$S_FP_SANDBOX" "$S_FP_ARCHIVES" "$S_GUID" 2039 - 2040 - S_GUID="42226761-7b9d-4cfb-bc1c-f1e0305090e7" 2041 - func_mmmv_assert_file_paths_differ_t1 "$S_FP_ARCHIVES" "$S_FP_FOSSILFILE" "$S_GUID" 2042 - #---- 2043 - # The next 3 checks turn the triangle to a tetrahedron, where 2044 - # the S_FP_ORIG is the "top of the pyramid". 2045 - S_GUID="a9379a5b-d3aa-419b-820c-f1e0305090e7" 2046 - func_mmmv_assert_file_paths_differ_t1 "$S_FP_ORIG" "$S_FP_FOSSILFILE" "$S_GUID" 2047 - 2048 - S_GUID="6d2d0251-9d35-4747-940c-f1e0305090e7" 2049 - func_mmmv_assert_file_paths_differ_t1 "$S_FP_ORIG" "$S_FP_ARCHIVES" "$S_GUID" 2050 - 2051 - S_GUID="3b972413-c33d-4867-910c-f1e0305090e7" 2052 - func_mmmv_assert_file_paths_differ_t1 "$S_FP_ORIG" "$S_FP_SANDBOX" "$S_GUID" 2053 - #-------- 2054 - cd $S_FP_ORIG # just in case 2055 - SB_OK_TO_USE_RM_IN_STEAD_OF_SHRED="t" # shred is still used, if available 2056 - if [ "$SB_FOSSILFILE_EXISTS" == "t" ]; then 2057 - fun_last_minute_checks_t1 "`pwd`" 2058 - func_mmmv_shred_t1 "$S_FP_FOSSILFILE" "$SB_OK_TO_USE_RM_IN_STEAD_OF_SHRED" 2059 - fi 2060 - if [ "$SB_SANDBOX_DIR_EXISTS" == "t" ]; then 2061 - fun_last_minute_checks_t1 "`pwd`" 2062 - func_mmmv_shred_t1 "$S_FP_SANDBOX" "$SB_OK_TO_USE_RM_IN_STEAD_OF_SHRED" 2063 - fi 2064 - if [ "$SB_ARCHIVE_DIR_EXISTS" == "t" ]; then 2065 - fun_last_minute_checks_t1 "`pwd`" 2066 - func_mmmv_shred_t1 "$S_FP_ARCHIVES" "$SB_OK_TO_USE_RM_IN_STEAD_OF_SHRED" 2067 - fi 2068 - #-------- 2069 - if [ "$SB_THERE_IS_SOMETHING_TO_DELETE" == "t" ]; then 2070 - if [ "$2" != "$S_ARGNAME_ACTIVITY_SHRED_ARG_2" ]; then 2071 - echo "✓" 2072 - echo "" 2073 - fi 2074 - fi 2075 - #-------- 2076 - cd $S_FP_ORIG 2077 - exit 0 2078 -fi # delete_local_copy 2079 - 2080 - 2081 -#-------------------------------------------------------------------------- 2082 -# All possible actions must have been described 2083 -# above this code block. 2084 -echo "" 2085 -echo "This Bash script is flawed." 2086 -echo "GUID=='1b3f0b52-848d-494a-a47b-f1e0305090e7'" 2087 -echo "" 2088 -#---- 2089 -cd $S_FP_ORIG 2090 -exit 1 2091 - 2092 -#========================================================================== 2093 -
Added work_in_progress/repository_maintenance/download_Silkotrrent_repository_and_run_local_web_server.bash version [0d05147f51].
1 +#!/usr/bin/env bash 2 +# Initial author: martin.vahi@softf1.com 3 +# This file is in public domain. 4 +# For further information please see 5 +# 6 +# http://www.silktorrent.ch 7 +# 8 +#========================================================================= 9 +S_FP_ORIG="`pwd`" 10 +#------------------------------------------------------------------------- 11 + 12 +func_mmmv_exit_if_not_on_path_t2() { # S_COMMAND_NAME 13 + local S_COMMAND_NAME=$1 14 + local S_LOCAL_VARIABLE="`which $S_COMMAND_NAME 2>/dev/null`" 15 + if [ "$S_LOCAL_VARIABLE" == "" ]; then 16 + echo "" 17 + echo "Command \"$S_COMMAND_NAME\" could not be found from the PATH. " 18 + echo "The Fossil source code might be available from a link at " 19 + echo "http://www.softf1.com/cgi-bin/tree1/technology/flaws/silktorrent.bash/wiki?name=Fossil+Repository+Related+Links+and+Comments" 20 + echo "" 21 + echo "The execution of the Bash script is aborted." 22 + echo "GUID=='3f7ad84e-e0f2-45c8-94e7-217051d1a0e7'" 23 + echo "" 24 + #-------- 25 + cd $S_FP_ORIG 26 + exit 1; # exit with an error 27 + fi 28 +} # func_mmmv_exit_if_not_on_path_t2 29 + 30 +func_mmmv_exit_if_not_on_path_t2 "fossil" 31 + 32 +#------------------------------------------------------------------------- 33 + 34 + mkdir ./stuff 35 + cd ./stuff 36 + wget http://www.softf1.com/cgi-bin/tree1/technology/flaws/silktorrent.bash/raw/work_in_progress/mmmv_Fossil_operator_t1.bash?name=ebb536fdad89b21bd6180652275b3571b3ab4cef --output-document=`pwd`/mmmv_Fossil_operator_t1.bash 37 + echo "" 38 + echo "Now it will probably take a while, because it needs to dowload ~500MiB of files." 39 + echo "" 40 + bash ./mmmv_Fossil_operator_t1.bash clone_public http://www.softf1.com/cgi-bin/tree1/technology/flaws/silktorrent.bash/ 41 + fossil ui `pwd`/repository_storage.fossil # Runs a Fossil web server at localhost 42 + # and opens the default web browser. 43 + 44 +#------------------------------------------------------------------------- 45 +cd $S_FP_ORIG 46 +#========================================================================= 47 +
Added work_in_progress/repository_maintenance/mmmv_Fossil_operator_t1.bash version [ebb536fdad].
1 +#!/usr/bin/env bash 2 +# Initial author: Martin.Vahi@softf1.com 3 +# This file is in the public domain. 4 +#========================================================================== 5 +S_FP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 6 +S_FP_ORIG="`pwd`" 7 +S_TIMESTAMP="`date +%Y`_`date +%m`_`date +%d`_T_`date +%H`h_`date +%M`min_`date +%S`s" 8 + 9 + 10 +func_assert_exists_on_path_t2 () { 11 + local S_NAME_OF_THE_EXECUTABLE_1="$1" # first function argument 12 + local S_NAME_OF_THE_EXECUTABLE_2="$2" # optional argument 13 + local S_NAME_OF_THE_EXECUTABLE_3="$3" # optional argument 14 + local S_NAME_OF_THE_EXECUTABLE_4="$4" # optional argument 15 + #-------- 16 + # Function calls like 17 + # 18 + # func_assert_exists_on_path_t2 "" "" "ls" 19 + # func_assert_exists_on_path_t2 "ls" "" "ps" 20 + # 21 + # are not allowed by the spec of this function, but it's OK to call 22 + # 23 + # func_assert_exists_on_path_t2 "ls" "" 24 + # func_assert_exists_on_path_t2 "ls" "ps" "" 25 + # func_assert_exists_on_path_t2 "ls" "" "" "" 26 + # 27 + # 28 + local SB_THROW="f" 29 + if [ "$S_NAME_OF_THE_EXECUTABLE_1" == "" ] ; then 30 + SB_THROW="t" 31 + else 32 + if [ "$S_NAME_OF_THE_EXECUTABLE_2" == "" ] ; then 33 + if [ "$S_NAME_OF_THE_EXECUTABLE_3" != "" ] ; then 34 + SB_THROW="t" 35 + fi 36 + if [ "$S_NAME_OF_THE_EXECUTABLE_4" != "" ] ; then 37 + SB_THROW="t" 38 + fi 39 + else 40 + if [ "$S_NAME_OF_THE_EXECUTABLE_3" == "" ] ; then 41 + if [ "$S_NAME_OF_THE_EXECUTABLE_4" != "" ] ; then 42 + SB_THROW="t" 43 + fi 44 + fi 45 + fi 46 + fi 47 + #---- 48 + if [ "$SB_THROW" == "t" ] ; then 49 + echo "" 50 + echo "The Bash function " 51 + echo "" 52 + echo " func_assert_exists_on_path_t2 " 53 + echo "" 54 + echo "is not designed to handle series of arguments, where " 55 + echo "empty strings preced non-empty strings." 56 + echo "GUID=='0541255e-4633-4cd9-b55c-f1e0305090e7'" 57 + echo "" 58 + #---- 59 + cd $S_FP_ORIG 60 + exit 1 # exit with error 61 + fi 62 + if [ "$5" != "" ] ; then 63 + echo "" 64 + echo "This Bash function is designed to work with at most 4 input arguments" 65 + echo "GUID=='41001a45-42a8-4dd3-824c-f1e0305090e7'" 66 + echo "" 67 + #---- 68 + cd $S_FP_ORIG 69 + exit 1 # exit with error 70 + fi 71 + #-------- 72 + # Function calls like 73 + # 74 + # func_assert_exists_on_path_t2 " " 75 + # func_assert_exists_on_path_t2 "ls ps" # contains a space 76 + # 77 + # are not allowed. 78 + SB_THROW="f" 79 + local S_TMP_0="" 80 + local S_TMP_1="" 81 + local S_TMP_2="" 82 + #---- 83 + if [ "$SB_THROW" == "f" ] ; then 84 + S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_1\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`" 85 + if [ "$S_NAME_OF_THE_EXECUTABLE_1" != "$S_TMP_0" ] ; then 86 + SB_THROW="t" 87 + S_TMP_1="$S_NAME_OF_THE_EXECUTABLE_1" 88 + S_TMP_2="GUID=='2a1fd3d0-3841-4e87-854c-f1e0305090e7'" 89 + fi 90 + fi 91 + #---- 92 + if [ "$SB_THROW" == "f" ] ; then 93 + S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_2\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`" 94 + if [ "$S_NAME_OF_THE_EXECUTABLE_2" != "$S_TMP_0" ] ; then 95 + SB_THROW="t" 96 + S_TMP_1="$S_NAME_OF_THE_EXECUTABLE_2" 97 + S_TMP_2="GUID=='d23cd2de-f38c-43f2-894c-f1e0305090e7'" 98 + fi 99 + fi 100 + #---- 101 + if [ "$SB_THROW" == "f" ] ; then 102 + S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_3\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`" 103 + if [ "$S_NAME_OF_THE_EXECUTABLE_3" != "$S_TMP_0" ] ; then 104 + SB_THROW="t" 105 + S_TMP_1="$S_NAME_OF_THE_EXECUTABLE_3" 106 + S_TMP_2="GUID=='7bf6f543-26c4-400e-a33c-f1e0305090e7'" 107 + fi 108 + fi 109 + #---- 110 + if [ "$SB_THROW" == "f" ] ; then 111 + S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_4\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`" 112 + if [ "$S_NAME_OF_THE_EXECUTABLE_4" != "$S_TMP_0" ] ; then 113 + SB_THROW="t" 114 + S_TMP_1="$S_NAME_OF_THE_EXECUTABLE_4" 115 + S_TMP_2="GUID=='a8746d54-43bc-4958-923c-f1e0305090e7'" 116 + fi 117 + fi 118 + #-------- 119 + if [ "$SB_THROW" == "t" ] ; then 120 + echo "" 121 + echo "The Bash function " 122 + echo "" 123 + echo " func_assert_exists_on_path_t2 " 124 + echo "" 125 + echo "is not designed to handle an argument value that contains " 126 + echo "spaces or tabulation characters." 127 + echo "The unaccepted value in parenthesis:($S_TMP_1)." 128 + echo "Branch $S_TMP_2." 129 + echo "GUID=='c3948131-401e-470a-a53c-f1e0305090e7'" 130 + echo "" 131 + #---- 132 + cd $S_FP_ORIG 133 + exit 1 # exit with error 134 + fi 135 + SB_THROW="f" # Just a reset, should I forget to reset it later. 136 + #--------------- 137 + S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_1 2>/dev/null\`" 138 + local S_TMP_1="" 139 + local S_TMP_2="S_TMP_1=$S_TMP_0" 140 + eval ${S_TMP_2} 141 + #---- 142 + if [ "$S_TMP_1" == "" ] ; then 143 + if [ "$S_NAME_OF_THE_EXECUTABLE_2" == "" ] ; then 144 + if [ "$S_NAME_OF_THE_EXECUTABLE_3" == "" ] ; then 145 + if [ "$S_NAME_OF_THE_EXECUTABLE_4" == "" ] ; then 146 + echo "" 147 + echo "This bash script requires the \"$S_NAME_OF_THE_EXECUTABLE_1\" to be on the PATH." 148 + echo "GUID=='f284925c-b40f-4549-b22c-f1e0305090e7'" 149 + echo "" 150 + #---- 151 + cd $S_FP_ORIG 152 + exit 1 # exit with error 153 + fi 154 + fi 155 + fi 156 + else 157 + return # at least one of the programs was available at the PATH 158 + fi 159 + #-------- 160 + S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_2 2>/dev/null\`" 161 + S_TMP_1="" 162 + S_TMP_2="S_TMP_1=$S_TMP_0" 163 + eval ${S_TMP_2} 164 + #---- 165 + if [ "$S_TMP_1" == "" ] ; then 166 + if [ "$S_NAME_OF_THE_EXECUTABLE_3" == "" ] ; then 167 + if [ "$S_NAME_OF_THE_EXECUTABLE_4" == "" ] ; then 168 + echo "" 169 + echo "This bash script requires that either \"$S_NAME_OF_THE_EXECUTABLE_1\" or " 170 + echo " \"$S_NAME_OF_THE_EXECUTABLE_2\" is available on the PATH." 171 + echo "GUID=='7f92b447-d805-460e-912c-f1e0305090e7'" 172 + echo "" 173 + #---- 174 + cd $S_FP_ORIG 175 + exit 1 # exit with error 176 + fi 177 + fi 178 + else 179 + return # at least one of the programs was available at the PATH 180 + fi 181 + #-------- 182 + S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_3 2>/dev/null\`" 183 + S_TMP_1="" 184 + S_TMP_2="S_TMP_1=$S_TMP_0" 185 + eval ${S_TMP_2} 186 + #---- 187 + if [ "$S_TMP_1" == "" ] ; then 188 + if [ "$S_NAME_OF_THE_EXECUTABLE_4" == "" ] ; then 189 + echo "" 190 + echo "This bash script requires that either \"$S_NAME_OF_THE_EXECUTABLE_1\" or " 191 + echo " \"$S_NAME_OF_THE_EXECUTABLE_2\" or \"$S_NAME_OF_THE_EXECUTABLE_3\" " 192 + echo "is available on the PATH." 193 + echo "GUID=='39c63c1f-eec1-450d-b12c-f1e0305090e7'" 194 + echo "" 195 + #---- 196 + cd $S_FP_ORIG 197 + exit 1 # exit with error 198 + fi 199 + else 200 + return # at least one of the programs was available at the PATH 201 + fi 202 + #-------- 203 + S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_4 2>/dev/null\`" 204 + S_TMP_1="" 205 + S_TMP_2="S_TMP_1=$S_TMP_0" 206 + eval ${S_TMP_2} 207 + #---- 208 + if [ "$S_TMP_1" == "" ] ; then 209 + echo "" 210 + echo "This bash script requires that either \"$S_NAME_OF_THE_EXECUTABLE_1\" or " 211 + echo " \"$S_NAME_OF_THE_EXECUTABLE_2\" or \"$S_NAME_OF_THE_EXECUTABLE_3\" or " 212 + echo " \"$S_NAME_OF_THE_EXECUTABLE_4\" is available on the PATH." 213 + echo "GUID=='71c5f5de-2801-47fc-841c-f1e0305090e7'" 214 + echo "" 215 + #---- 216 + cd $S_FP_ORIG 217 + exit 1 # exit with error 218 + else 219 + return # at least one of the programs was available at the PATH 220 + fi 221 + #-------- 222 +} # func_assert_exists_on_path_t2 223 + 224 + 225 +func_assert_exists_on_path_t2 "cat" 226 +func_assert_exists_on_path_t2 "file" # for checking MIME types 227 +func_assert_exists_on_path_t2 "find" # for recursing 228 +func_assert_exists_on_path_t2 "fossil" # tested with v1.34 229 +func_assert_exists_on_path_t2 "gawk" 230 +func_assert_exists_on_path_t2 "grep" 231 +func_assert_exists_on_path_t2 "nice" 232 +func_assert_exists_on_path_t2 "ruby" # anything over/equal v.2.1 will probably do 233 +func_assert_exists_on_path_t2 "shred" "gshred" "rm" # for shredding, if possible 234 +func_assert_exists_on_path_t2 "uname" # to check the OS type 235 +func_assert_exists_on_path_t2 "uuidgen" "uuid" # for generating tmp file names 236 +func_assert_exists_on_path_t2 "xargs" # find . -name '*' | xargs blabla 237 +func_assert_exists_on_path_t2 "wc" 238 + 239 + 240 +#-------------------------------------------------------------------------- 241 + 242 +S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT="" 243 +func_mmmv_operating_system_type_t1() { 244 + if [ "$S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT" == "" ]; then 245 + S_TMP_0="`uname -a | grep -E [Ll]inux`" 246 + if [ "$S_TMP_0" != "" ]; then 247 + S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT="Linux" 248 + else 249 + S_TMP_0="`uname -a | grep BSD `" 250 + if [ "$S_TMP_0" != "" ]; then 251 + S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT="BSD" 252 + else 253 + S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT="undetermined" 254 + fi 255 + fi 256 + fi 257 +} # func_mmmv_operating_system_type_t1 258 + 259 +func_mmmv_operating_system_type_t1 260 + 261 +if [ "$S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT" != "Linux" ]; then 262 + if [ "$S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT" != "BSD" ]; then 263 + echo "" 264 + echo " The classical command line utilities at " 265 + echo " different operating systems, for example, Linux and BSD," 266 + echo " differ. This script is designed to run only on " 267 + echo " Linux and some BSD variants." 268 + echo " If You are willing to risk that some of Your data " 269 + echo " is deleted and/or Your operating system instance" 270 + echo " becomes permanently flawed, to the point that " 271 + echo " it will not even boot, then You may edit the Bash script that " 272 + echo " displays this error message by modifying the test that " 273 + echo " checks for the operating system type." 274 + echo "" 275 + echo " If You do decide to edit this Bash script, then " 276 + echo " a recommendation is to test Your modifications " 277 + echo " within a virtual machine or, if virtual machines are not" 278 + echo " an option, as some new operating system user that does not have " 279 + echo " any access to the vital data/files." 280 + echo " GUID=='52460304-7c62-4f4e-b51c-f1e0305090e7'" 281 + echo "" 282 + echo " Aborting script without doing anything." 283 + echo "" 284 + exit 1 # exit with error 285 + fi 286 +fi 287 + 288 + 289 +#-------------------------------------------------------------------------- 290 + 291 +SB_EXISTS_ON_PATH_T1_RESULT="f" 292 +func_sb_exists_on_path_t1 () { 293 + local S_NAME_OF_THE_EXECUTABLE_1="$1" # first function argument 294 + #-------- 295 + # Function calls like 296 + # 297 + # func_sb_exists_on_path_t1 "" 298 + # func_sb_exists_on_path_t1 " " 299 + # func_sb_exists_on_path_t1 "ls ps" # contains a space 300 + # 301 + # are not allowed. 302 + if [ "$S_NAME_OF_THE_EXECUTABLE_1" == "" ] ; then 303 + echo "" 304 + echo "The Bash function " 305 + echo "" 306 + echo " func_sb_exists_on_path_t1 " 307 + echo "" 308 + echo "is not designed to handle an argument that " 309 + echo "equals with an empty string." 310 + echo "GUID=='31ed2a21-41ac-4368-831c-f1e0305090e7'" 311 + echo "" 312 + #---- 313 + cd $S_FP_ORIG 314 + exit 1 # exit with error 315 + fi 316 + local S_TMP_0="`printf \"$S_NAME_OF_THE_EXECUTABLE_1\" | gawk '{gsub(/\s/,"");printf "%s", $1 }'`" 317 + if [ "$S_NAME_OF_THE_EXECUTABLE_1" != "$S_TMP_0" ] ; then 318 + echo "" 319 + echo "The Bash function " 320 + echo "" 321 + echo " func_sb_exists_on_path_t1 " 322 + echo "" 323 + echo "is not designed to handle an argument value that contains " 324 + echo "spaces or tabulation characters." 325 + echo "The received value in parenthesis:($S_NAME_OF_THE_EXECUTABLE_1)." 326 + echo "GUID=='40cb1b02-90f3-404e-8a0c-f1e0305090e7'" 327 + echo "" 328 + #---- 329 + cd $S_FP_ORIG 330 + exit 1 # exit with error 331 + fi 332 + #-------- 333 + S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE_1 2>/dev/null\`" 334 + local S_TMP_1="" 335 + local S_TMP_2="S_TMP_1=$S_TMP_0" 336 + eval ${S_TMP_2} 337 + #---- 338 + if [ "$S_TMP_1" == "" ] ; then 339 + SB_EXISTS_ON_PATH_T1_RESULT="f" 340 + else 341 + SB_EXISTS_ON_PATH_T1_RESULT="t" 342 + fi 343 +} # func_sb_exists_on_path_t1 344 + 345 + 346 +#-------------------------------------------------------------------------- 347 + 348 +S_FUNC_MMMV_GUID_T1_RESULT="not_yet_set" 349 +S_FUNC_MMMV_GUID_T1_MODE="" # optim. to skip repeating console tool selection 350 +func_mmmv_GUID_t1() { 351 + # Does not take any arguments. 352 + #-------- 353 + #func_mmmv_exc_hash_function_input_verification_t1 "func_mmmv_GUID_t1" "$1" 354 + #-------------------- 355 + local S_TMP_0="" # declaration 356 + local S_TMP_1="" # declaration 357 + # Mode selection: 358 + if [ "$S_FUNC_MMMV_GUID_T1_MODE" == "" ] ; then 359 + SB_EXISTS_ON_PATH_T1_RESULT="f" # if-block init 360 + #---- 361 + if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then 362 + S_TMP_0="uuidgen" # Linux version 363 + func_sb_exists_on_path_t1 "$S_TMP_0" 364 + if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then 365 + S_FUNC_MMMV_GUID_T1_MODE="$S_TMP_0" 366 + fi 367 + fi 368 + #---- 369 + if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then 370 + S_TMP_0="uuid" # BSD version 371 + func_sb_exists_on_path_t1 "$S_TMP_0" 372 + if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then 373 + S_FUNC_MMMV_GUID_T1_MODE="$S_TMP_0" 374 + fi 375 + fi 376 + #-------- 377 + if [ "$S_FUNC_MMMV_GUID_T1_MODE" == "" ] ; then 378 + echo "" 379 + echo "All of the GUID generation implementations that this script " 380 + echo "is capable of using (uuidgen, uuid) " 381 + echo "are missing from the PATH." 382 + echo "GUID=='3094c835-5f40-4884-b40c-f1e0305090e7'" 383 + echo "" 384 + #---- 385 + cd $S_FP_ORIG 386 + exit 1 # exit with error 387 + fi 388 + #-------- 389 + if [ "$?" != "0" ]; then 390 + echo "" 391 + echo "This script is flawed." 392 + echo "GUID=='817cc031-3315-4771-a3fb-f1e0305090e7'" 393 + echo "" 394 + #---- 395 + cd $S_FP_ORIG 396 + exit 1 # exit with error 397 + fi 398 + #-------- 399 + fi 400 + #-------------------- 401 + S_FUNC_MMMV_GUID_T1_RESULT="" 402 + #-------------------- 403 + if [ "$S_FUNC_MMMV_GUID_T1_MODE" == "uuidgen" ]; then 404 + S_TMP_0="`uuidgen`" 405 + if [ "$?" != "0" ]; then 406 + echo "" 407 + echo "The console application \"uuidgen\" " 408 + echo "exited with an error." 409 + echo "" 410 + echo "----console--output--citation--start-----" 411 + echo "`uuidgen`" # stdout and stderr 412 + echo "----console--output--citation--end-------" 413 + echo "" 414 + echo "GUID=='46b00d44-8784-489e-a5fb-f1e0305090e7'" 415 + echo "" 416 + #---- 417 + cd $S_FP_ORIG 418 + exit 1 # exit with error 419 + fi 420 + #---- 421 + S_FUNC_MMMV_GUID_T1_RESULT="$S_TMP_0" 422 + fi 423 + #-------------------- 424 + if [ "$S_FUNC_MMMV_GUID_T1_MODE" == "uuid" ]; then 425 + S_TMP_0="`uuid`" 426 + if [ "$?" != "0" ]; then 427 + echo "" 428 + echo "The console application \"uuid\" " 429 + echo "exited with an error." 430 + echo "" 431 + echo "----console--output--citation--start-----" 432 + echo "`uuid`" # stdout and stderr 433 + echo "----console--output--citation--end-------" 434 + echo "" 435 + echo "GUID=='c3d42e43-1f05-4355-93fb-f1e0305090e7'" 436 + echo "" 437 + #---- 438 + cd $S_FP_ORIG 439 + exit 1 # exit with error 440 + fi 441 + #---- 442 + S_FUNC_MMMV_GUID_T1_RESULT="$S_TMP_0" 443 + fi 444 + #-------------------- 445 + S_TMP_0="`printf \"$S_FUNC_MMMV_GUID_T1_RESULT\" | wc -m | gawk '{gsub(/\s/,"");printf "%s", $1 }'`" 446 + S_TMP_1="36" 447 + if [ "$S_TMP_0" != "$S_TMP_1" ]; then 448 + echo "" 449 + echo "According to the GUID specification, IETF RFC 4122, " 450 + echo "the lenght of the GUID is " 451 + echo "$S_TMP_1 characters, but the result of the " 452 + echo "" 453 + echo " func_mmmv_GUID_t1" 454 + echo "" 455 + echo "is something else. The flawed GUID candidate in parenthesis:" 456 + echo "($S_FUNC_MMMV_GUID_T1_RESULT)" 457 + echo "" 458 + echo "The lenght candidate of the flawed GUID candidate in parenthesis:" 459 + echo "($S_TMP_0)." 460 + echo "" 461 + echo "GUID=='4bba14f5-f666-40a4-9efb-f1e0305090e7'" 462 + echo "" 463 + #---- 464 + cd $S_FP_ORIG 465 + exit 1 # exit with error 466 + fi 467 + #-------------------- 468 +} # func_mmmv_GUID_t1 469 + 470 + 471 +#-------------------------------------------------------------------------- 472 + 473 +S_FUNC_MMMV_SHRED_T1_MODE="" # optim. to skip repeating console tool selection 474 +func_mmmv_shred_t1() { 475 + local S_FP_IN="$1" # path to the file or folder to be shredded 476 + # The next input parameter is a shoddy compromise, 477 + # for the case, where shred/gshred is not installed: 478 + local SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE="$2" # domain: {"","f","t"} 479 + #-------------------- 480 + if [ "$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE" != "" ] ; then 481 + if [ "$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE" != "t" ] ; then 482 + if [ "$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE" != "f" ] ; then 483 + echo "" 484 + echo "The second parameter of this function, the " 485 + echo "" 486 + echo " SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE(==$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE)" 487 + echo "" 488 + echo "is optional, but its range is {\"\",\"f\",\"t\"}," 489 + echo "without the quotation marks." 490 + echo "GUID=='502df336-4c86-4286-83fb-f1e0305090e7'" 491 + echo "" 492 + #---- 493 + cd $S_FP_ORIG 494 + exit 1 # exit with error 495 + fi 496 + fi 497 + else # $SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE == "" 498 + SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE="f" 499 + fi 500 + #-------------------- 501 + # Declarations: 502 + local SB_THROW="" 503 + local SB_USE_RUBY="" 504 + local S_CMD="" 505 + local S_GUID="" 506 + local S_TMP_0="" 507 + local S_TMP_1="" 508 + local S_TMP_2="" 509 + local SI_0="-9999" 510 + local SI_1="-9999" 511 + local S_SHREDDER_APPLICATION_NAME="" 512 + local S_FP_PWD_BEFORE_SHREDDING="" 513 + #-------------------- 514 + # Mode selection: 515 + if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "" ] ; then 516 + SB_EXISTS_ON_PATH_T1_RESULT="f" # if-block init 517 + #---- 518 + if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then 519 + S_TMP_0="shred" # Linux version 520 + func_sb_exists_on_path_t1 "$S_TMP_0" 521 + if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then 522 + S_FUNC_MMMV_SHRED_T1_MODE="$S_TMP_0" 523 + fi 524 + fi 525 + #---- 526 + if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then 527 + S_TMP_0="gshred" # BSD version 528 + func_sb_exists_on_path_t1 "$S_TMP_0" 529 + if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then 530 + S_FUNC_MMMV_SHRED_T1_MODE="$S_TMP_0" 531 + fi 532 + fi 533 + #---- 534 + if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "f" ] ; then 535 + if [ "$SB_OK_TO_USE_RM_IF_SHREDDING_APPS_NOT_AVAILABLE" == "t" ] ; then 536 + S_TMP_0="rm" # a shoddy compromise version for exeptional cases 537 + func_sb_exists_on_path_t1 "$S_TMP_0" 538 + if [ "$SB_EXISTS_ON_PATH_T1_RESULT" == "t" ] ; then 539 + func_mmmv_operating_system_type_t1 540 + if [ "$S_FUNC_MMMV_OPERATING_SYSTEM_TYPE_T1_RESULT" != "BSD" ]; then 541 + S_FUNC_MMMV_SHRED_T1_MODE="rm_BSD" 542 + else # Linux and all the rest 543 + S_FUNC_MMMV_SHRED_T1_MODE="rm_plain" 544 + fi 545 + else 546 + echo "" 547 + echo "Something is wrong at the operating system " 548 + echo "environment setup. All UNIX-like operating systems " 549 + echo "and their emulators " 550 + echo "are expected to have the \"rm\" command." 551 + echo "" 552 + echo " \$(which rm)==\"`which rm`\"" 553 + echo "" 554 + echo " PATH=$PATH" # will be a huge string 555 + echo "" 556 + echo "GUID=='a6e67041-a70f-4e87-92fb-f1e0305090e7'" 557 + echo "" 558 + #---- 559 + cd $S_FP_ORIG 560 + exit 1 # exit with error 561 + fi 562 + fi 563 + fi 564 + #-------- 565 + if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "" ] ; then 566 + echo "" 567 + echo "All of the file shredding implementations that this script " 568 + echo "is capable of using (shred, gshred) " 569 + echo "are missing from the PATH." 570 + echo "GUID=='2db9ac59-a8f0-4852-a1eb-f1e0305090e7'" 571 + echo "" 572 + #---- 573 + cd $S_FP_ORIG 574 + exit 1 # exit with error 575 + fi 576 + #-------- 577 + if [ "$?" != "0" ]; then 578 + echo "" 579 + echo "This script is flawed." 580 + echo "GUID=='4a9e0e43-a179-434b-81eb-f1e0305090e7'" 581 + echo "" 582 + #---- 583 + cd $S_FP_ORIG 584 + exit 1 # exit with error 585 + fi 586 + #-------- 587 + fi 588 + #-------------------- 589 + S_TMP_0=$(echo $S_FP_IN | gawk '{gsub(/^[\/]/,""); printf "%s",$1 }') 590 + if [ "$S_TMP_0" == "$S_FP_IN" ]; then 591 + echo "" 592 + echo "The path is expected to be an absolute path, " 593 + echo "but currently it is not." 594 + echo " S_FP_IN==$S_FP_IN" 595 + echo "GUID=='b72d3528-b829-43dd-b4eb-f1e0305090e7'" 596 + echo "" 597 + #---- 598 + cd $S_FP_ORIG 599 + exit 1 # exit with an error 600 + fi 601 + #-------- 602 + if [ -h $S_FP_IN ]; then 603 + # The control flow is in here regardless of 604 + # whether the symbolic link is broken or not. 605 + # If the path is to a non-existing file/link/folder, 606 + # then the control flow will not enter this branch. 607 + echo "" 608 + echo "The " 609 + echo " S_FP_IN=$S_FP_IN" 610 + echo "is a symbolic link, but it is expected to " 611 + echo "be a file or a folder." 612 + echo "GUID=='2ff01c25-3734-48c8-a9eb-f1e0305090e7'" 613 + echo "" 614 + #---- 615 + cd $S_FP_ORIG 616 + exit 1 # exit with error 617 + fi 618 + if [ ! -e $S_FP_IN ]; then 619 + echo "" 620 + echo "The " 621 + echo " S_FP_IN=$S_FP_IN" 622 + echo "does not exist." 623 + echo "GUID=='2b88f713-2945-4752-a4eb-f1e0305090e7'" 624 + echo "" 625 + #---- 626 + cd $S_FP_ORIG 627 + exit 1 # exit with error 628 + fi 629 + #-------- 630 + if [ -d $S_FP_IN ]; then 631 + #--------start--of--sub-path--check---- 632 + # If the $S_FP_IN is a folder, then the `pwd` 633 + # should not be a sub-path or a path of the 634 + # folder that is being deleted. 635 + S_TMP_0="`cd $S_FP_IN;pwd`/" 636 + S_TMP_1="`pwd`/" 637 + #---- 638 + if [ "$S_TMP_0" == "$S_TMP_1" ]; then 639 + if [ ! -d $S_FP_IN ]; then 640 + echo "" 641 + echo "This Bash script is flawed. " 642 + echo " S_FP_IN=$S_FP_IN" 643 + echo "GUID=='5b46db54-09a9-41ab-b5eb-f1e0305090e7'" 644 + echo "" 645 + #---- 646 + cd $S_FP_ORIG 647 + exit 1 648 + fi 649 + #---- 650 + echo "" 651 + echo "The working directory, " 652 + echo "" 653 + echo " PWD=$PWD" 654 + echo "" 655 + echo "equals with the folder that is being deleted." 656 + echo "" 657 + echo " S_TMP_0=$S_TMP_0" 658 + echo "" 659 + echo " S_FP_IN=$S_FP_IN" 660 + echo "" 661 + echo "GUID=='167f9421-0412-433c-91db-f1e0305090e7'" 662 + echo "" 663 + #---- 664 + cd $S_FP_ORIG 665 + exit 1 # exit with error 666 + fi 667 + #---- 668 + # If the normalized $S_FP_IN is a folder and 669 + # the "`pwd`/" is shorter than the normalized $S_FP_IN, then, 670 + # with the exceptions of some symbolic links, 671 + # the "`pwd`/" can not be equal to the normalized $S_FP_IN, 672 + # nor can the "`pwd`/" be a folder that is a sub-folder 673 + # of the $S_FP_IN. 674 + # 675 + # The paht lenght code is: 676 + # 677 + # SI_0="` echo \"$S_TMP_0\" | gawk '{i=length;printf "%s", i }' `" # S_FP_IN 678 + # SI_1="` echo \"$S_TMP_1\" | gawk '{i=length;printf "%s", i }' `" # pwd 679 + # if [ "$SI_0" -lt "$SI_1" ]; then # $SI_0 < $SI_1 680 + # #echo "$SI_0 < $SI_1" 681 + # # 682 + # # In here the length of the normalized form of the $S_FP_IN 683 + # # is shorter than the "`pwd`/" and therefore the working directory 684 + # # has a greater probability to be at a sub-path of the $S_FP_IN. 685 + # 686 + # < 687 + # A lot of Ruby code, because 688 + # the gawk code will have trouble with folders that 689 + # contain spaces and other special characters 690 + # > 691 + # fi 692 + # 693 + # but unfortunately the Ruby code that uses 694 + # temporary files and the String.index would be 695 + # unstable due to the 696 + # 697 + # https://bugs.ruby-lang.org/issues/12710 698 + # https://archive.is/AJpgL 699 + # 700 + # Add to that the fact that this Bash function 701 + # would be much more appealing, if it did not launch 702 + # any 40BiB sized interpreters like the Ruby interpreter (in 2016) 703 + # and the temptation to just skip testing, whether the 704 + # working directory (`pwd`) resides at a directory that 705 + # is a sub-path of the $S_FP_IN, grows even higher. 706 + # So, for the time being that check is omitted from here. 707 + # 708 + # TODO: If the year is at least 2020, then try to find out, 709 + # whether there's some elegant way to implement that check. 710 + # 711 + # A code fragment for later consideration: 712 + # S_TMP_2="`echo \"$S_TMP_0\" | gawk '{gsub(/\s/,\"NotASpace\");printf \"%s\", \$1 }' `" 713 + # if [ "$S_TMP_2" != "$S_TMP_0" ]; then 714 + # # S_TMP_0 contains strings 715 + # SB_USE_RUBY="t" 716 + # fi 717 + #--------end--of--sub-path--check---- 718 + fi 719 + #-------------------- 720 + S_FP_PWD_BEFORE_SHREDDING="`pwd`" 721 + S_CMD="" # to be sure 722 + #-------------------- 723 + S_TMP_0="cd $S_FP_IN ; nice -n10 find . -name '*' | nice -n10 xargs " 724 + # The space after the "cd $S_FP_IN" and before the ";" is compulsory. 725 + #---- 726 + # The "2>/dev/null" after the shredding/deletion command 727 + # is to hide the file permissions related error messages. 728 + # The failure is detected by studying file existence. 729 + #-------------------- 730 + if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "shred" ]; then 731 + S_SHREDDER_APPLICATION_NAME="shred" 732 + if [ -d $S_FP_IN ]; then 733 + S_CMD="$S_TMP_0 \ 734 + $S_SHREDDER_APPLICATION_NAME -f --remove 2>/dev/null " 735 + else 736 + S_CMD="nice -n10 $S_SHREDDER_APPLICATION_NAME -f --remove $S_FP_IN 2>/dev/null " 737 + fi 738 + fi 739 + #---- 740 + if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "gshred" ]; then 741 + S_SHREDDER_APPLICATION_NAME="gshred" 742 + if [ -d $S_FP_IN ]; then 743 + S_CMD="$S_TMP_0 \ 744 + $S_SHREDDER_APPLICATION_NAME --force --iterations=2 --remove -z 2>/dev/null " 745 + else 746 + S_CMD="nice -n10 \ 747 + $S_SHREDDER_APPLICATION_NAME --force --iterations=2 --remove -z $S_FP_IN 2>/dev/null " 748 + fi 749 + fi 750 + #---- 751 + # The "rm" on Linux and BSD differ, 752 + # a bit like the "ps" # on Linux and BSD differ. 753 + # The "rm -f -P foo" overwrites the file with NON-random 754 + # values before deleting. 755 + # The "rm -f foo" works, whenever the "rm" is called by the file owner. 756 + # The "rm -f -P foo" requires write permissions even, 757 + # if the "rm" is called by the file owner. 758 + if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "rm_BSD" ]; then 759 + S_SHREDDER_APPLICATION_NAME="rm" 760 + if [ -d $S_FP_IN ]; then 761 + S_CMD="$S_TMP_0 \ 762 + $S_SHREDDER_APPLICATION_NAME -f -P $S_FP_IN 2>/dev/null " 763 + else 764 + S_CMD="nice -n10 $S_SHREDDER_APPLICATION_NAME -f -P $S_FP_IN 2>/dev/null " 765 + fi 766 + fi 767 + if [ "$S_FUNC_MMMV_SHRED_T1_MODE" == "rm_plain" ]; then 768 + # The "rm -f foo" seems to be universally available 769 + # at all UNIX-like environments. 770 + S_SHREDDER_APPLICATION_NAME="rm" 771 + if [ -d $S_FP_IN ]; then 772 + S_CMD="$S_TMP_0 \ 773 + $S_SHREDDER_APPLICATION_NAME -f $S_FP_IN 2>/dev/null " 774 + else 775 + S_CMD="nice -n10 $S_SHREDDER_APPLICATION_NAME -f $S_FP_IN 2>/dev/null " 776 + fi 777 + fi 778 + #-------------------- 779 + eval "$S_CMD" # the "eval" is required due to the command "find" 780 + cd $S_FP_PWD_BEFORE_SHREDDING # required if the $S_FP_IN was a folder 781 + if [ -e $S_FP_IN ]; then 782 + # If the control flow is here, then the $S_FP_IN was 783 + # a folder or the deletion failed or both. 784 + chmod -f -R 0700 $S_FP_IN # chmod 0777 would introduce s security flaw 785 + eval "$S_CMD" # the "eval" is required due to the command "find" 786 + cd $S_FP_PWD_BEFORE_SHREDDING 787 + #---- 788 + SB_THROW="f" 789 + if [ -d $S_FP_IN ]; then 790 + S_TMP_0="`cd $S_FP_IN; pwd`" # "./home///foo" -> "/home/foo" 791 + # Checks are intentionally missing to 792 + # allow this Bash function to be universal, without exceptions. 793 + #---- 794 + cd $S_TMP_0 795 + S_TMP_1="`find . -name '*' | \ 796 + xargs file --mime-type | \ 797 + grep -v directory | grep -v folder `" 798 + # The file --mime-type foo 799 + # works on both, Linux and BSD. 800 + cd $S_FP_PWD_BEFORE_SHREDDING 801 + #---- 802 + if [ "$S_TMP_1" == "" ]; then 803 + rm -fr $S_TMP_0 804 + else 805 + SB_THROW="t" 806 + S_GUID="'23c2b1e5-3972-4dc6-a2db-f1e0305090e7'" 807 + fi 808 + fi 809 + #---- 810 + if [ "$SB_THROW" == "f" ]; then # to avoid overwriting the S_GUID 811 + if [ -e $S_FP_IN ]; then 812 + SB_THROW="t" 813 + S_GUID="'ca0b9b36-4ea9-4be6-92db-f1e0305090e7'" 814 + fi 815 + fi 816 + if [ "$SB_THROW" == "t" ]; then 817 + echo "" 818 + echo "The deletion failed even after the " 819 + echo "" 820 + echo " chmod -f -R 0700 $S_FP_IN " 821 + echo "" 822 + echo "The " 823 + echo "" 824 + echo " chmod 0777 " 825 + echo "" 826 + echo "is not done automatically in this " 827 + echo "Bash function, because " 828 + echo "it might introduce a security flaw." 829 + echo "" 830 + echo " S_FUNC_MMMV_SHRED_T1_MODE=$S_FUNC_MMMV_SHRED_T1_MODE" 831 + echo "" 832 + echo " S_CMD=$S_CMD" 833 + echo "" 834 + echo "GUID==$S_GUID" 835 + echo "GUID=='73d84042-9e60-4316-b3db-f1e0305090e7'" 836 + echo "" 837 + #---- 838 + cd $S_FP_ORIG 839 + exit 1 # exit with error 840 + fi 841 + fi 842 + S_GUID="'693c9923-46d0-4603-92db-f1e0305090e7'" #counters S_GUID related flaws 843 + #-------------------- 844 + if [ -e $S_FP_IN ]; then 845 + echo "" 846 + echo "The deletion of the " 847 + echo " S_FP_IN=$S_FP_IN" 848 + echo "failed or the file or folder was re-created by " 849 + echo "some other process before this file existance check." 850 + echo "GUID=='4c690312-7d59-43db-95cb-f1e0305090e7'" 851 + echo "" 852 + #---- 853 + cd $S_FP_ORIG 854 + exit 1 # exit with error 855 + fi 856 + #-------------------- 857 + cd $S_FP_PWD_BEFORE_SHREDDING 858 +} # func_mmmv_shred_t1 859 + 860 + 861 +#-------------------------------------------------------------------------- 862 +S_TMP_0="" 863 +S_ACTIVITY_OF_THIS_SCRIPT=$1 864 +S_URL_REMOTE_REPOSITORY="" 865 +SB_EXIT_WITH_ERROR="f" 866 + 867 +# needed for scriptability 868 +S_ARGNAME_ACTIVITY_SHRED_ARG_2="do_not_prompt_for_confirmation" 869 + 870 +fun_print_msg_t1() { 871 + echo "" 872 + echo "The second console argument " 873 + echo "is expected to be the URL of the remote repository." 874 +} # fun_print_msg_t1 875 + 876 + 877 +fun_exit_without_any_errors_t1() { 878 + local X_SKIP_MESSAGE="$1" 879 + if [ "$X_SKIP_MESSAGE" == "" ]; then 880 + echo "" 881 + echo "Aborting script without doing anything." 882 + echo "" 883 + fi 884 + #---- 885 + cd $S_FP_ORIG 886 + exit 0 887 +} # fun_exit_without_any_errors_t1 888 + 889 +#-------------------------------------------------------------------------- 890 + 891 +SB_FUNC_MMMV_ASSERT_FILE_PATHS_DIFFER_T1_ASSERTION_FAILED="f" 892 +func_mmmv_assert_file_paths_differ_t1(){ 893 + local S_FP_0="$1" 894 + local S_FP_1="$2" 895 + local S_GUID="$3" 896 + local SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE="$4" # domain: {"","f","t"} 897 + #-------- 898 + if [ "$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE" != "" ] ; then 899 + if [ "$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE" != "t" ] ; then 900 + if [ "$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE" != "f" ] ; then 901 + echo "" 902 + echo "The fourth parameter of this function, the " 903 + echo "" 904 + echo " SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE(==$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE)" 905 + echo "" 906 + echo "is optional, but its range is {\"\",\"f\",\"t\"}," 907 + echo "without the quotation marks." 908 + echo "GUID=='55200d1b-73f9-46a3-82cb-f1e0305090e7'" 909 + echo "" 910 + #---- 911 + cd $S_FP_ORIG 912 + exit 1 # exit with error 913 + fi 914 + fi 915 + else # $SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE == "" 916 + SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE="f" 917 + fi 918 + SB_FUNC_MMMV_ASSERT_FILE_PATHS_DIFFER_T1_ASSERTION_FAILED="f" # global 919 + #-------- 920 + # The block of if-else statements for comparing the 2 paths 921 + # is so error prone to write that this function is written 922 + # according to a schematic that resides at: 923 + # http://longterm.softf1.com/documentation_fragments/2016_09_03_comparison_of_file_paths_t1/ 924 + # https://archive.is/R4yw9 925 + #-------- 926 + # Declarations: 927 + local S_GUID_CRAWL="S_GUID_CRAWL not set" # tree crawling at the schematic 928 + local S_GUID_CMP="S_GUID_CMP not set" # comparison at tree leaf 929 + # Some leaves are equivalent. 930 + local S_COMPARISON_MODE="" 931 + local SB_THROW="f" 932 + local SB_ASSERTION_FAILED="f" 933 + local SB_STR0="f" # whether S_FP_0 is compared purely as a string 934 + local SB_STR1="f" # whether S_FP_1 is compared purely as a string 935 + local S_FP_0_STR="$S_FP_0" 936 + local S_FP_1_STR="$S_FP_1" 937 + local S_FP_X="" # a temporary variable for holding path value 938 + local S_RUBY_SRC_0="" 939 + #-------- 940 + if [ "$S_FP_0" == "$S_FP_1" ]; then 941 + # Covers also the case, where both are existing 942 + # folders, but the paths to them contains "../". 943 + # By making the string comparison to be the first thing tried 944 + # a few file system accesses might be saved. 945 + SB_ASSERTION_FAILED="t" 946 + S_GUID_CRAWL="644d292d-c01e-47d0-855c-f1e0305090e7" 947 + S_GUID_CMP="57bc9b05-da56-4eff-954c-f1e0305090e7" 948 + else # the rest of the 3 comparison modes 949 + #-------- 950 + if [ -e $S_FP_0 ]; then 951 + if [ -d $S_FP_0 ]; then 952 + if [ -e $S_FP_1 ]; then 953 + if [ -d $S_FP_1 ]; then 954 + S_COMPARISON_MODE="cmode_cd0_cd1" 955 + else 956 + S_COMPARISON_MODE="cmode_cd0_str1" 957 + SB_STR1="t" 958 + fi 959 + else 960 + S_COMPARISON_MODE="cmode_cd0_str1" 961 + SB_STR1="t" 962 + fi 963 + else 964 + if [ -e $S_FP_1 ]; then 965 + if [ -d $S_FP_1 ]; then 966 + S_COMPARISON_MODE="cmode_str0_cd1" 967 + SB_STR0="t" 968 + else 969 + S_COMPARISON_MODE="cmode_str0_str1" 970 + SB_STR0="t" 971 + SB_STR1="t" 972 + fi 973 + else 974 + S_COMPARISON_MODE="cmode_str0_str1" 975 + SB_STR0="t" 976 + SB_STR1="t" 977 + fi 978 + fi 979 + else # $S_FP_0 is missing or it is a broken symbolic link 980 + if [ -e $S_FP_1 ]; then 981 + if [ -d $S_FP_1 ]; then 982 + S_COMPARISON_MODE="cmode_str0_cd1" 983 + SB_STR0="t" 984 + else 985 + S_COMPARISON_MODE="cmode_str0_str1" 986 + SB_STR0="t" 987 + SB_STR1="t" 988 + fi 989 + else 990 + S_COMPARISON_MODE="cmode_str0_str1" 991 + SB_STR0="t" 992 + SB_STR1="t" 993 + fi 994 + fi 995 + #---------------- 996 + # The "cmode_str0_str1" was tried 997 + # at the first if-clause of the block, but 998 + # that does not catch equivalent cases like 999 + # 1000 + # S_FP_0="`pwd`/././////a_nonexisting_file_or_folder" 1001 + # S_FP_1="`pwd`/a_nonexisting_file_or_folder" 1002 + # 1003 + # S_FP_0="./a_nonexisting_file_or_folder" 1004 + # S_FP_1="././././././a_nonexisting_file_or_folder" 1005 + # 1006 + # S_FP_0="/a_nonexisting_file_or_folder" 1007 + # S_FP_1="/////a_nonexisting_file_or_folder" 1008 + # 1009 + # S_FP_0="/a_nonexisting_file_or_folder" 1010 + # S_FP_1="/..///../a_nonexisting_file_or_folder" 1011 + # 1012 + # String normalization is required whenever at least 1013 + # one of the paths is used at comparison 1014 + # purely as a string. 1015 + # 1016 + #----start-of-Ruby-script-header--for-copy/pasting---- 1017 + # #!/usr/bin/env ruby 1018 + # 1019 + # s_fp_0="./a_nonexisting_file_or_folder" 1020 + # s_fp_1="././..//../.././a_nonexisting_file_or_folder" 1021 + # 1022 + # # The path "/../foo" is equivalent to "/foo". 1023 + # s_fp_2="/././..//../.././a_nonexisting_file_or_folder" 1024 + # 1025 + # # This script does not cover the case, 1026 + # # where "./aa/../bb" is equivalent to "./bb" 1027 + #----end---of-Ruby-script-header-for-copy/pasting---- 1028 + S_RUBY_SRC_0="\ 1029 + s_0='';\ 1030 + s_1=ARGV[0].to_s;\ 1031 + rgx_0=/[\\/][.][\\/]/;\ 1032 + rgx_1=/^[.][\\/]/;\ 1033 + rgx_2=/^[\\/][.][.][\\/]/;\ 1034 + i_4safety=0;\ 1035 + while s_0!=s_1 do ;\ 1036 + s_0=s_1;\ 1037 + s_1=s_0.gsub(rgx_0,'/');\ 1038 + i_4safety=i_4safety+1;\ 1039 + if 10000<i_4safety then ;\ 1040 + raise(Exception.new('boo'));\ 1041 + end;\ 1042 + end ;\ 1043 + s_0=s_1;\ 1044 + s_1=s_0.gsub(rgx_1,'');\ 1045 + s_0=s_1;\ 1046 + s_1=s_0.gsub(/[\\/]+/,'/');\ 1047 + ;\ 1048 + ;\ 1049 + i_4safety=0;\ 1050 + while s_0!=s_1 do ;\ 1051 + s_0=s_1;\ 1052 + s_1=s_0.gsub(rgx_2,'/');\ 1053 + i_4safety=i_4safety+1;\ 1054 + if 10000<i_4safety then ;\ 1055 + raise(Exception.new('10b7aae4-1940-4361-a4cb-f1e0305090e7'));\ 1056 + end;\ 1057 + end ;\ 1058 + s_0=s_1;\ 1059 + s_1=s_0.gsub(rgx_1,'');\ 1060 + s_0=s_1;\ 1061 + s_1=s_0.gsub(/[\\/]+/,'/');\ 1062 + ;\ 1063 + print s_1;\ 1064 + " 1065 + #---- 1066 + if [ "$SB_STR0" == "t" ]; then 1067 + S_FP_0_STR="`ruby -e \"$S_RUBY_SRC_0\" $S_FP_0`" 1068 + fi 1069 + if [ "$SB_STR1" == "t" ]; then 1070 + S_FP_1_STR="`ruby -e \"$S_RUBY_SRC_0\" $S_FP_1`" 1071 + fi 1072 + #---------------- 1073 + if [ "$S_COMPARISON_MODE" == "cmode_cd0_str1" ]; then 1074 + # 2 cases at the schematic 1075 + S_FP_X="`cd $S_FP_0;pwd`" 1076 + if [ "$S_FP_X" == "$S_FP_1_STR" ]; then 1077 + SB_ASSERTION_FAILED="t" 1078 + S_GUID_CMP="3a6056a5-c267-4111-b24c-f1e0305090e7" 1079 + fi 1080 + if [ "$SB_ASSERTION_FAILED" != "t" ]; then 1081 + if [ "$S_FP_X" == "$S_FP_1" ]; then # just in case 1082 + SB_ASSERTION_FAILED="t" 1083 + S_GUID_CMP="57a656e5-aa92-40a8-a53c-f1e0305090e7" 1084 + fi 1085 + fi 1086 + else 1087 + if [ "$S_COMPARISON_MODE" == "cmode_str0_cd1" ]; then 1088 + # 2 cases at the schematic 1089 + S_FP_X="`cd $S_FP_1;pwd`" 1090 + if [ "$S_FP_0_STR" == "$S_FP_X" ]; then 1091 + SB_ASSERTION_FAILED="t" 1092 + S_GUID_CMP="2bc33092-26d1-4787-953c-f1e0305090e7" 1093 + fi 1094 + if [ "$SB_ASSERTION_FAILED" != "t" ]; then 1095 + if [ "$S_FP_0" == "$S_FP_X" ]; then # just in case 1096 + SB_ASSERTION_FAILED="t" 1097 + S_GUID_CMP="05494129-51a8-4d7d-923c-f1e0305090e7" 1098 + fi 1099 + fi 1100 + else 1101 + if [ "$S_COMPARISON_MODE" == "cmode_cd0_cd1" ]; then 1102 + if [ "`cd $S_FP_0;pwd`" == "`cd $S_FP_1;pwd`" ]; then 1103 + SB_ASSERTION_FAILED="t" 1104 + S_GUID_CMP="37d42234-a57e-4d78-b52c-f1e0305090e7" 1105 + fi 1106 + else 1107 + if [ "$S_COMPARISON_MODE" == "cmode_str0_str1" ]; then 1108 + if [ "$S_FP_0_STR" == "$S_FP_1_STR" ]; then 1109 + SB_ASSERTION_FAILED="t" 1110 + S_GUID_CMP="b0eb5d1d-9b86-4d66-812c-f1e0305090e7" 1111 + fi 1112 + # The if [ "$S_FP_0" == "$S_FP_1" ] ... 1113 + # has already been tried at the very start 1114 + # of the huge if-block. 1115 + else 1116 + echo "" 1117 + echo "This script is flawed." 1118 + echo "" 1119 + echo " S_FP_0=$S_FP_0" 1120 + echo " S_FP_1=$S_FP_1" 1121 + echo " S_GUID_CRAWL=$S_GUID_CRAWL" 1122 + echo " S_GUID_CMP=$S_GUID_CMP" 1123 + echo " S_COMPARISON_MODE=$S_COMPARISON_MODE" 1124 + echo "" 1125 + echo "GUID=='14286012-4658-42f9-94cb-f1e0305090e7'" 1126 + echo "" 1127 + #---- 1128 + cd $S_FP_ORIG 1129 + exit 1 # exit with error 1130 + fi 1131 + fi 1132 + fi 1133 + fi 1134 + fi 1135 + #-------- 1136 + SB_FUNC_MMMV_ASSERT_FILE_PATHS_DIFFER_T1_ASSERTION_FAILED="$SB_ASSERTION_FAILED" # global 1137 + if [ "$SB_ASSERTION_FAILED" == "t" ]; then 1138 + if [ "$SB_DO_NOT_TRHOW_ON_ASSERTION_FAILURE" != "t" ]; then 1139 + echo "" 1140 + echo "The file paths " 1141 + echo "" 1142 + echo " S_FP_0=$S_FP_0" 1143 + echo "" 1144 + echo " S_FP_1=$S_FP_1" 1145 + echo "" 1146 + echo "are required to differ and " 1147 + echo "they are required to differ also after normalization." 1148 + echo "" 1149 + echo "GUID=='3f8afd21-08d6-487f-b3cb-f1e0305090e7'" 1150 + echo "GUID=='$S_GUID_CMP'" # comparison 1151 + echo "GUID=='$S_GUID_CRAWL'" # tree crawling at the schematic 1152 + if [ "$S_GUID" != "" ]; then 1153 + echo "GUID=='$S_GUID'" # GUID as an input parameter 1154 + fi 1155 + echo "" 1156 + #---- 1157 + cd $S_FP_ORIG 1158 + exit 1 # exit with error 1159 + fi 1160 + fi 1161 +} # func_mmmv_assert_file_paths_differ_t1 1162 + 1163 + 1164 +#-------------------------------------------------------------------------- 1165 +# Activity aliases for comfort. 1166 + 1167 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "up" ]; then 1168 + S_ACTIVITY_OF_THIS_SCRIPT="overwrite_remote_with_local" 1169 +fi 1170 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "upload" ]; then 1171 + S_ACTIVITY_OF_THIS_SCRIPT="overwrite_remote_with_local" 1172 +fi 1173 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "ci" ]; then 1174 + S_ACTIVITY_OF_THIS_SCRIPT="overwrite_remote_with_local" 1175 +fi 1176 +#-------- 1177 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "down" ]; then 1178 + S_ACTIVITY_OF_THIS_SCRIPT="overwrite_local_with_remote" 1179 +fi 1180 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "download" ]; then 1181 + S_ACTIVITY_OF_THIS_SCRIPT="overwrite_local_with_remote" 1182 +fi 1183 +#-------- 1184 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "co" ]; then 1185 + S_ACTIVITY_OF_THIS_SCRIPT="clone_all" 1186 +fi 1187 +#-------- 1188 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "?" ]; then 1189 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1190 +fi 1191 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "-?" ]; then 1192 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1193 +fi 1194 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "--help" ]; then 1195 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1196 +fi 1197 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "-help" ]; then 1198 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1199 +fi 1200 +#-------- 1201 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "rm" ]; then 1202 + S_ACTIVITY_OF_THIS_SCRIPT="delete_local_copy" 1203 +fi 1204 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "del" ]; then 1205 + S_ACTIVITY_OF_THIS_SCRIPT="delete_local_copy" 1206 +fi 1207 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "delete" ]; then 1208 + S_ACTIVITY_OF_THIS_SCRIPT="delete_local_copy" 1209 +fi 1210 +#-------- 1211 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "info" ]; then 1212 + S_ACTIVITY_OF_THIS_SCRIPT="about" 1213 +fi 1214 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "--info" ]; then 1215 + S_ACTIVITY_OF_THIS_SCRIPT="about" 1216 +fi 1217 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "-info" ]; then 1218 + S_ACTIVITY_OF_THIS_SCRIPT="about" 1219 +fi 1220 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "--about" ]; then 1221 + S_ACTIVITY_OF_THIS_SCRIPT="about" 1222 +fi 1223 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "-about" ]; then 1224 + S_ACTIVITY_OF_THIS_SCRIPT="about" 1225 +fi 1226 +#-------- 1227 +#-------------------------------------------------------------------------- 1228 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "about" ]; then 1229 + echo "" 1230 + echo " The initial version of this script has been written by " 1231 + echo " Martin.Vahi@softf1.com " 1232 + echo " in 2016_02. The initial version is in public domain." 1233 + echo " The command \"help\" offers more information. " 1234 + echo "" 1235 + echo " Thank You for using this script :-)" 1236 + echo "" 1237 + echo "" 1238 + fun_exit_without_any_errors_t1 "t" 1239 +fi 1240 +#-------------------------------------------------------------------------- 1241 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "exit" ]; then 1242 + fun_exit_without_any_errors_t1 1243 +else 1244 + if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "clone_all" ]; then 1245 + if [ "$2" == "" ]; then 1246 + fun_print_msg_t1 1247 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1248 + SB_EXIT_WITH_ERROR="t" 1249 + else 1250 + S_URL_REMOTE_REPOSITORY="$2" 1251 + fi 1252 + else 1253 + if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "clone_public" ]; then 1254 + if [ "$2" == "" ]; then 1255 + fun_print_msg_t1 1256 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1257 + SB_EXIT_WITH_ERROR="t" 1258 + else 1259 + S_URL_REMOTE_REPOSITORY="$2" 1260 + fi 1261 + else 1262 + if [ "$S_ACTIVITY_OF_THIS_SCRIPT" != "overwrite_local_with_remote" ]; then 1263 + if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "overwrite_remote_with_local" ]; then 1264 + if [ "$2" != "" ]; then 1265 + if [ "$2" == "use_autogenerated_commit_message" ]; then 1266 + if [ "$3" != "" ]; then 1267 + echo "" 1268 + echo "If the first console argument is \"overwrite_local_with_remote\" and" 1269 + echo "the second console argument is \"use_autogenerated_commit_message\", " 1270 + echo "then there should not be a 3. console argument." 1271 + echo "GUID=='468fa904-55da-4388-81cb-f1e0305090e7'" 1272 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1273 + SB_EXIT_WITH_ERROR="t" 1274 + fi 1275 + else 1276 + if [ "$2" == "read_commit_message_from_file" ]; then 1277 + S_FP_MESSAGE_FILE_CANDIDATE="$3" # file path candidate 1278 + if [ "$S_FP_MESSAGE_FILE_CANDIDATE" == "" ]; then 1279 + echo "" 1280 + echo "If the first console argument is " 1281 + echo "\"overwrite_local_with_remote\" and" 1282 + echo "the second console argument is " 1283 + echo "\"read_commit_message_from_file\", " 1284 + echo "then there should be also a 3. console argument " 1285 + echo "that is expected to be a file path to a text file." 1286 + echo "GUID=='559c7db3-15af-4a7d-bdbb-f1e0305090e7'" 1287 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1288 + SB_EXIT_WITH_ERROR="t" 1289 + fi 1290 + if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then 1291 + if [ "$4" != "" ]; then 1292 + echo "" 1293 + echo "If the first console argument is " 1294 + echo "\"overwrite_local_with_remote\" and" 1295 + echo "the second console argument is " 1296 + echo "\"read_commit_message_from_file\", " 1297 + echo "then there should be exactly 3. console arguments, " 1298 + echo "not 4 or more. Unfortunately the 4. argument is currently " 1299 + echo "---citation--start---" 1300 + echo "$4" 1301 + echo "---citation--end-----" 1302 + echo "GUID=='5e662e45-13a1-499b-9dbb-f1e0305090e7'" 1303 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1304 + SB_EXIT_WITH_ERROR="t" 1305 + fi 1306 + fi 1307 + if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then 1308 + if [ ! -e "$S_FP_MESSAGE_FILE_CANDIDATE" ]; then 1309 + echo "" 1310 + echo "The commit message file path candidate " 1311 + echo "references either a missing file or " 1312 + echo "a broken symlink." 1313 + echo "GUID=='15f6e772-31ba-4f5e-97bb-f1e0305090e7'" 1314 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1315 + SB_EXIT_WITH_ERROR="t" 1316 + fi 1317 + fi 1318 + if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then 1319 + if [ -d "$S_FP_MESSAGE_FILE_CANDIDATE" ]; then 1320 + echo "" 1321 + echo "The commit message file path candidate " 1322 + echo "references a folder, but it should " 1323 + echo "reference a text file." 1324 + echo "GUID=='3225928c-0920-4018-95bb-f1e0305090e7'" 1325 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1326 + SB_EXIT_WITH_ERROR="t" 1327 + fi 1328 + fi 1329 + if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then 1330 + S_TMP_0="`filesize $S_FP_MESSAGE_FILE_CANDIDATE`" 1331 + S_TMP_1="`ruby -e \"s_out='OK'; if (2000<$S_TMP_0) then s_out='too_big' end; print(s_out);\"`" 1332 + if [ "$S_TMP_1" == "too_big" ]; then 1333 + echo "" 1334 + echo "The commit message file path " 1335 + echo "references a file that has a size of $S_TMP_0 bytes." 1336 + echo "The suspicion is that it is a wrong file. " 1337 + echo "because a commit message is usually not that lengthy." 1338 + echo "GUID=='21090045-08fe-4487-81bb-f1e0305090e7'" 1339 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1340 + SB_EXIT_WITH_ERROR="t" 1341 + else 1342 + if [ "$S_TMP_0" == "0" ]; then 1343 + echo "" 1344 + echo "The commit message file path " 1345 + echo "references a file that has a size of 0 (zero) bytes." 1346 + echo "" 1347 + echo "The generation of commit message files " 1348 + echo "can be avoided by using the option " 1349 + echo "" 1350 + echo " \"use_autogenerated_commit_message\"" 1351 + echo "" 1352 + echo "in stead of the option " 1353 + echo "" 1354 + echo " \"read_commit_message_from_file\" ." 1355 + echo "" 1356 + echo "GUID=='a539fb61-243d-4e0c-82bb-f1e0305090e7'" 1357 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1358 + SB_EXIT_WITH_ERROR="t" 1359 + fi 1360 + fi 1361 + fi 1362 + if [ "$SB_EXIT_WITH_ERROR" == "f" ]; then 1363 + S_TMP_0="`file --mime-type $S_FP_MESSAGE_FILE_CANDIDATE | grep text `" 1364 + if [ "$S_TMP_0" == "" ]; then 1365 + echo "" 1366 + echo "The commit message file path " 1367 + echo "references a file that has a MIME type of " 1368 + echo "" 1369 + echo "`file --mime-type $S_FP_MESSAGE_FILE_CANDIDATE`" 1370 + echo "" 1371 + echo "The commit message file must be a text file and " 1372 + echo "text files have the string \"text\" in their MIME type name." 1373 + echo "GUID=='0e00aa42-a7dd-4e63-b2ab-f1e0305090e7'" 1374 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1375 + SB_EXIT_WITH_ERROR="t" 1376 + fi 1377 + fi 1378 + fi # read_commit_message_from_file 1379 + fi 1380 + fi 1381 + else 1382 + if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "delete_local_copy" ]; then 1383 + if [ "$2" != "" ]; then # the 2. arg is optional here 1384 + if [ "$2" != "$S_ARGNAME_ACTIVITY_SHRED_ARG_2" ]; then 1385 + echo "" 1386 + echo "If the first console argument is \"delete_local_copy\", then" 1387 + echo "the second console argument is allowed to be only " 1388 + echo "" 1389 + echo " \"$S_ARGNAME_ACTIVITY_SHRED_ARG_2\", without quotation marks." 1390 + echo "GUID=='53d97712-0caf-4847-b5ab-f1e0305090e7'" 1391 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1392 + SB_EXIT_WITH_ERROR="t" 1393 + fi 1394 + fi 1395 + else 1396 + if [ "$S_ACTIVITY_OF_THIS_SCRIPT" != "print_script_version" ]; then 1397 + if [ "$S_ACTIVITY_OF_THIS_SCRIPT" != "help" ]; then 1398 + echo "" 1399 + echo "The very first console argument " 1400 + echo "of this script is expected to be " 1401 + echo "a command that is specific to this script." 1402 + echo "GUID=='5d8d1e92-ac26-408a-81ab-f1e0305090e7'" 1403 + S_ACTIVITY_OF_THIS_SCRIPT="help" 1404 + SB_EXIT_WITH_ERROR="t" 1405 + fi 1406 + fi 1407 + fi 1408 + fi 1409 + fi 1410 + fi 1411 + fi 1412 +fi 1413 + 1414 +#-------------------------------------------------------------------------- 1415 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "help" ]; then 1416 + echo "" 1417 + echo "Possible console argument sets are:" 1418 + echo "" 1419 + echo " clone_all <remote repository url>" 1420 + echo " clone_public <remote repository url>" 1421 + echo " overwrite_local_with_remote" 1422 + echo "" 1423 + echo " overwrite_remote_with_local (use_autogenerated_commit_message)?" 1424 + echo " overwrite_remote_with_local read_commit_message_from_file <path to a text file>" 1425 + echo "" 1426 + echo " delete_local_copy ($S_ARGNAME_ACTIVITY_SHRED_ARG_2)?" 1427 + echo " help" 1428 + echo " print_script_version" 1429 + echo " exit # just for testing" 1430 + echo "" 1431 + #---- 1432 + cd $S_FP_ORIG 1433 + if [ "$SB_EXIT_WITH_ERROR" == "t" ]; then 1434 + exit 1 # To let the parent script know that 1435 + # the parent script calls this script with 1436 + # flawed console argument values. 1437 + else 1438 + exit 0 1439 + fi 1440 +fi 1441 + 1442 +#-------------------------------------------------------------------------- 1443 +# The script version is needed by other scripts that depend on this script. 1444 +# The script version GUID must not be surrounded by 1445 +# any quote signs (',"), because otherwise the 1446 +# version GUID will be overwritten by the UpGUID tool, 1447 +# but unlike error message GUID-s this GUID must stay constant. 1448 +# To allow the version to be used as sub-part of file names and 1449 +# folder names, the version must not contain any spaces, line breaks 1450 +# and other characters that have a special meaning in Bash. 1451 +# 1452 +# If the version ID did not match the GUID regex, then I would have to 1453 +# write a long comment about it not being allowed to match the 1454 +# GUID regex. :-D 1455 +S_VERSION_OF_THIS_SCRIPT="23dc37cc-4d31-4444-a52c-f1e0305090e7" 1456 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "print_script_version" ]; then 1457 + echo "The version of this script is: $S_VERSION_OF_THIS_SCRIPT" 1458 + #---- 1459 + cd $S_FP_ORIG 1460 + exit 0 1461 +fi 1462 + 1463 + 1464 +#-------------------------------------------------------------------------- 1465 +S_FP_SANDBOX_DIRECTORY_NAME="sandbox_of_the_Fossil_repository" 1466 +S_FP_SANDBOX="$S_FP_DIR/$S_FP_SANDBOX_DIRECTORY_NAME" 1467 +#---- 1468 +S_FP_ARCHIVES_DIRECTORY_NAME="archival_copies_of_the_Fossil_repository_sandbox" 1469 +S_FP_ARCHIVES="$S_FP_DIR/$S_FP_ARCHIVES_DIRECTORY_NAME" 1470 +S_FP_ARCHIVES_TS="$S_FP_ARCHIVES/v$S_TIMESTAMP" 1471 +#---- 1472 +S_FP_FOSSILFILE_NAME="repository_storage.fossil" 1473 +S_FP_FOSSILFILE="$S_FP_DIR/$S_FP_FOSSILFILE_NAME" 1474 + 1475 +#-------- 1476 +S_LC_NOT_DETERMINED="not determined" 1477 +SB_SANDBOX_DIR_EXISTS="$S_LC_NOT_DETERMINED" 1478 +fun_sandbox_folder_or_symlink_exists() { 1479 + SB_SANDBOX_DIR_EXISTS="f" 1480 + if [ ! -e $S_FP_SANDBOX ]; then 1481 + # Does not exist or it is a broken symbolic link. 1482 + SB_SANDBOX_DIR_EXISTS="f" 1483 + else 1484 + if [ -d $S_FP_SANDBOX ]; then 1485 + SB_SANDBOX_DIR_EXISTS="t" 1486 + fi 1487 + fi 1488 +} # fun_sandbox_folder_or_symlink_exists 1489 + 1490 +SB_FOSSILFILE_EXISTS="$S_LC_NOT_DETERMINED" 1491 +fun_fossil_repository_file_or_symlink_exists() { 1492 + SB_FOSSILFILE_EXISTS="t" 1493 + if [ ! -e $S_FP_FOSSILFILE ]; then 1494 + # Does not exist or it is a broken symbolic link. 1495 + SB_FOSSILFILE_EXISTS="f" 1496 + else 1497 + if [ -d $S_FP_FOSSILFILE ]; then 1498 + SB_FOSSILFILE_EXISTS="f" 1499 + fi 1500 + fi 1501 +} # fun_fossil_repository_file_or_symlink_exists 1502 + 1503 +S_LC_NOT_DETERMINED="not determined" 1504 +SB_ARCHIVE_DIR_EXISTS="$S_LC_NOT_DETERMINED" 1505 +fun_archives_folder_or_symlink_exists() { 1506 + SB_ARCHIVE_DIR_EXISTS="f" 1507 + if [ ! -e $S_FP_ARCHIVES ]; then 1508 + # Does not exist or it is a broken symbolic link. 1509 + SB_ARCHIVE_DIR_EXISTS="f" 1510 + else 1511 + if [ -d $S_FP_ARCHIVES ]; then 1512 + SB_ARCHIVE_DIR_EXISTS="t" 1513 + fi 1514 + fi 1515 +} # fun_archives_folder_or_symlink_exists 1516 + 1517 +#-------- 1518 +fun_fossil_repository_file_or_symlink_exists 1519 +fun_sandbox_folder_or_symlink_exists 1520 +fun_archives_folder_or_symlink_exists 1521 + 1522 +fun_assertion_t1() { 1523 + local SB_CANDIDATE=$1 1524 + local SB_THROW="t" 1525 + #---- 1526 + if [ "$SB_CANDIDATE" == "t" ]; then 1527 + SB_THROW="f" 1528 + else 1529 + if [ "$SB_CANDIDATE" == "f" ]; then 1530 + SB_THROW="f" 1531 + fi 1532 + fi 1533 + #---- 1534 + if [ "$SB_THROW" == "t" ]; then 1535 + echo "" 1536 + echo "This Bash script is flawed. " 1537 + echo "fun_assertion_t1() assertion failed." 1538 + echo "GUID=='c2afa84b-ad9b-41b4-a4ab-f1e0305090e7'" 1539 + echo "" 1540 + #---- 1541 + cd $S_FP_ORIG 1542 + exit 1 1543 + fi 1544 +} # fun_assertion_t1 1545 + 1546 +fun_assertion_t1 "$SB_FOSSILFILE_EXISTS" 1547 +fun_assertion_t1 "$SB_SANDBOX_DIR_EXISTS" 1548 +fun_assertion_t1 "$SB_ARCHIVE_DIR_EXISTS" 1549 + 1550 +#-------------------------------------------------------------------------- 1551 + 1552 +fun_assert_repository_local_copy_existence() { 1553 + fun_fossil_repository_file_or_symlink_exists 1554 + if [ "$SB_FOSSILFILE_EXISTS" == "f" ]; then 1555 + echo "" 1556 + echo "The directory " 1557 + echo "`pwd`" 1558 + echo "does not contain a Fossil repository file named " 1559 + echo "" 1560 + echo " $S_FP_FOSSILFILE_NAME" 1561 + echo "" 1562 + echo "Aborting script." 1563 + echo "GUID=='b6307f42-cfba-4f42-b4ab-f1e0305090e7'" 1564 + echo "" 1565 + #---- 1566 + cd $S_FP_ORIG 1567 + exit 1 1568 + fi 1569 + fun_sandbox_folder_or_symlink_exists 1570 + if [ "$SB_SANDBOX_DIR_EXISTS" == "f" ]; then 1571 + echo "" 1572 + echo "The directory " 1573 + echo "`pwd`" 1574 + echo "does not contain a directory named " 1575 + echo "" 1576 + echo " $S_FP_SANDBOX_DIRECTORY_NAME" 1577 + echo "" 1578 + echo "Aborting script." 1579 + echo "GUID=='2619a005-53ea-46b9-a79b-f1e0305090e7'" 1580 + echo "" 1581 + #---- 1582 + cd $S_FP_ORIG 1583 + exit 1 1584 + fi 1585 +} # fun_assert_repository_local_copy_existence 1586 + 1587 + 1588 +fun_assert_the_lack_of_repository_local_copy_t1() { 1589 + if [ "$SB_FOSSILFILE_EXISTS" == "t" ]; then 1590 + echo "" 1591 + echo "The directory " 1592 + echo "`pwd`" 1593 + echo "already contain a file named " 1594 + echo "" 1595 + echo " $S_FP_FOSSILFILE_NAME" 1596 + echo "" 1597 + echo "To avoid overwriting an existing local copy, this script is aborted" 1598 + echo "and nothing is downloaded/uploaded by this script." 1599 + echo "GUID=='3cdf8c33-e911-4ecf-819b-f1e0305090e7'" 1600 + echo "" 1601 + #---- 1602 + cd $S_FP_ORIG 1603 + exit 1 1604 + fi 1605 + if [ "$SB_SANDBOX_DIR_EXISTS" == "t" ]; then 1606 + echo "" 1607 + echo "The directory " 1608 + echo "`pwd`" 1609 + echo "already contains a directory named " 1610 + echo "" 1611 + echo " $S_FP_SANDBOX_DIRECTORY_NAME" 1612 + echo "" 1613 + echo "To avoid overwriting an existing local copy, this script is aborted" 1614 + echo "and nothing is downloaded/uploaded by this script." 1615 + echo "GUID=='e054e73b-52b7-4999-929b-f1e0305090e7'" 1616 + echo "" 1617 + #---- 1618 + cd $S_FP_ORIG 1619 + exit 1 1620 + fi 1621 +} # fun_assert_the_lack_of_repository_local_copy_t1 1622 + 1623 + 1624 + 1625 +fun_initialize_sandbox_t1() { 1626 + mkdir -p $S_FP_SANDBOX 1627 + sync; 1628 + cd $S_FP_SANDBOX 1629 + fossil open $S_FP_DIR/$S_FP_FOSSILFILE_NAME # full path for reliability 1630 + fossil settings autosync off ; 1631 + fossil settings case-sensitive TRUE ; 1632 + fossil checkout --force --latest 1633 + fossil pull 1634 + fossil close 1635 + sync; 1636 +} # fun_initialize_sandbox_t1 1637 + 1638 + 1639 +#-------------------------------------------------------------------------- 1640 +fun_last_minute_checks_t1() { 1641 + # Last minute checks, just to be sure. 1642 + local S_FP_FORBIDDEN_VALUE=$1 1643 + if [ "$S_FP_FORBIDDEN_VALUE" == "/" ]; then 1644 + echo "" 1645 + echo "This Bash script is flawed." 1646 + echo "GUID=='3c4e5af3-7901-474c-939b-f1e0305090e7'" 1647 + echo "" 1648 + #---- 1649 + cd $S_FP_ORIG 1650 + exit 1 1651 + fi 1652 + if [ "$S_FP_FORBIDDEN_VALUE" == "$HOME" ]; then 1653 + echo "" 1654 + echo "This Bash script is flawed." 1655 + echo "GUID=='c200ef46-b3f7-4204-919b-f1e0305090e7'" 1656 + echo "" 1657 + #---- 1658 + cd $S_FP_ORIG 1659 + exit 1 1660 + fi 1661 + if [ "$S_FP_FORBIDDEN_VALUE" == "/home" ]; then 1662 + echo "" 1663 + echo "This Bash script is flawed." 1664 + echo "GUID=='d2a65b5e-0591-4332-948b-f1e0305090e7'" 1665 + echo "" 1666 + #---- 1667 + cd $S_FP_ORIG 1668 + exit 1 1669 + fi 1670 + if [ "$S_FP_FORBIDDEN_VALUE" == "/root" ]; then 1671 + echo "" 1672 + echo "This Bash script is flawed." 1673 + echo "GUID=='03b089fe-baa7-4a68-b38b-f1e0305090e7'" 1674 + echo "" 1675 + #---- 1676 + cd $S_FP_ORIG 1677 + exit 1 1678 + fi 1679 + if [ "$S_FP_FORBIDDEN_VALUE" == "/etc" ]; then 1680 + echo "" 1681 + echo "This Bash script is flawed." 1682 + echo "GUID=='0062ae2c-e3a2-4764-b28b-f1e0305090e7'" 1683 + echo "" 1684 + #---- 1685 + cd $S_FP_ORIG 1686 + exit 1 1687 + fi 1688 + if [ "$S_FP_FORBIDDEN_VALUE" == "/usr" ]; then 1689 + echo "" 1690 + echo "This Bash script is flawed." 1691 + echo "GUID=='9de55d34-dbca-4803-918b-f1e0305090e7'" 1692 + echo "" 1693 + #---- 1694 + cd $S_FP_ORIG 1695 + exit 1 1696 + fi 1697 +} # fun_last_minute_checks_t1 1698 + 1699 + 1700 +#-------------------------------------------------------------------------- 1701 +SB_FOLDER_IS_EMPTY="$S_LC_NOT_DETERMINED" 1702 +fun_folder_is_empty_t1() { 1703 + local S_FP_FOLDER_TO_STUDY=$1 1704 + local S_FP_ORIG_LOCAL="`pwd`" 1705 + #-------- 1706 + SB_FOLDER_IS_EMPTY="t" 1707 + local S_TMP_0="`cd $S_FP_FOLDER_TO_STUDY; ls -l | grep \"total 0\"`" 1708 + if [ "$S_TMP_0" == "" ]; then 1709 + SB_FOLDER_IS_EMPTY="f" 1710 + fi 1711 + #-------- 1712 + cd $S_FP_ORIG_LOCAL # just in case 1713 +} # fun_folder_is_empty_t1 1714 + 1715 +fun_folder_is_empty_t1 "$S_FP_DIR" 1716 +fun_assertion_t1 "$SB_FOLDER_IS_EMPTY" 1717 +if [ "$SB_FOLDER_IS_EMPTY" == "t" ]; then 1718 + echo "" 1719 + echo "This Bash script is flawed. The " 1720 + echo "$S_FP_DIR" 1721 + echo "can not possibly be empty, because it contains " 1722 + echo "at least one file, which is " 1723 + echo "this very same Bash script that outputs the current error message." 1724 + echo "GUID=='fb573a47-7195-4c06-b18b-f1e0305090e7'" 1725 + echo "" 1726 + #---- 1727 + cd $S_FP_ORIG 1728 + exit 1 1729 +fi 1730 + 1731 +#-------------------------------------------------------------------------- 1732 + 1733 +fun_activity_core_overwrite_local_with_remote() { 1734 + fun_assert_repository_local_copy_existence 1735 + #-------- 1736 + # The checks are party to cope with the `whoami`=="root" case. 1737 + fun_last_minute_checks_t1 "$S_FP_SANDBOX" 1738 + fun_last_minute_checks_t1 "$S_FP_ARCHIVES" 1739 + fun_last_minute_checks_t1 "$S_FP_ARCHIVES_TS" 1740 + #-------- 1741 + chmod -f -R u+rx $S_FP_SANDBOX 1742 + fun_folder_is_empty_t1 "$S_FP_SANDBOX" 1743 + if [ "$SB_FOLDER_IS_EMPTY" == "f" ]; then 1744 + # This if-statement is needed because the 1745 + # cp -f -R AnEmptyDirectory/* ToSomewhere/ 1746 + # gives an error. 1747 + #---- 1748 + mkdir -p $S_FP_ARCHIVES_TS 1749 + #---- 1750 + # The "chmod -f -R " is not used because it would 1751 + # waste time on folders that are named by 1752 + # the older $S_FP_ARCHIVES_TS values. 1753 + chmod -f 0700 $S_FP_ARCHIVES 1754 + chmod -f 0700 $S_FP_ARCHIVES_TS 1755 + #---- 1756 + # The separate cp and rm of the sandbox 1757 + # contents is to somewhat retain the original 1758 + # file premissions of the sandbox contents. 1759 + cp -f -R $S_FP_SANDBOX/* $S_FP_ARCHIVES_TS/ 1760 + fun_last_minute_checks_t1 "$S_FP_SANDBOX" 1761 + chmod -f -R u+rwx $S_FP_SANDBOX 1762 + rm -fr $S_FP_SANDBOX/* 1763 + fi 1764 + #-------- 1765 + cd $S_FP_SANDBOX 1766 + fossil open $S_FP_DIR/$S_FP_FOSSILFILE_NAME # full path for reliability 1767 + fossil settings autosync off ; 1768 + fossil checkout --force --latest 1769 + fossil pull 1770 + fossil close 1771 +} # fun_activity_core_overwrite_local_with_remote 1772 + 1773 + 1774 + 1775 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "overwrite_local_with_remote" ]; then 1776 + fun_activity_core_overwrite_local_with_remote 1777 + #---- 1778 + cd $S_FP_ORIG 1779 + exit 0 1780 +fi # overwrite_local_with_remote 1781 + 1782 + 1783 + 1784 +#-------------------------------------------------------------------------- 1785 +fossil close 2>/dev/null 1786 + 1787 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "clone_public" ]; then 1788 + fun_assert_the_lack_of_repository_local_copy_t1 1789 + cd $S_FP_DIR 1790 + fossil clone $S_URL_REMOTE_REPOSITORY ./$S_FP_FOSSILFILE_NAME 1791 + fun_initialize_sandbox_t1 1792 + cd $S_FP_ORIG 1793 + #---- 1794 + sync 1795 + fun_activity_core_overwrite_local_with_remote 1796 + cd $S_FP_ORIG 1797 + sync 1798 + #---- 1799 + exit 0 1800 +fi # clone_public 1801 + 1802 + 1803 +#-------------------------------------------------------------------------- 1804 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "clone_all" ]; then 1805 + fun_assert_the_lack_of_repository_local_copy_t1 1806 + cd $S_FP_DIR 1807 + #-------- 1808 + S_USERNAME="" 1809 + while [ "$S_USERNAME" == "" ] 1810 + do 1811 + echo "" 1812 + echo "Please enter a username: " 1813 + S_USERNAME="`ruby -e \"s=gets.gsub(/[\n\r\s]/,'');print(s)\"`" 1814 + S_URL="`export S_USERNAME=\"$S_USERNAME\"; S_URL=\"$S_URL_REMOTE_REPOSITORY\" ruby -e 's_0=ENV[\"S_URL\"].sub(\"http://\",\"http:/\").sub(\"http:/\",\"http://\"+ENV[\"S_USERNAME\"].to_s+\":nonsensepassword@\");print(s_0)'`" 1815 + done 1816 + #-------- 1817 + fossil clone --private $S_URL ./$S_FP_FOSSILFILE_NAME 1818 + fun_initialize_sandbox_t1 1819 + cd $S_FP_ORIG 1820 + #---- 1821 + sync 1822 + fun_activity_core_overwrite_local_with_remote 1823 + cd $S_FP_ORIG 1824 + sync 1825 + #---- 1826 + exit 0 1827 +fi # clone_all 1828 + 1829 + 1830 +#-------------------------------------------------------------------------- 1831 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "overwrite_remote_with_local" ]; then 1832 + fun_assert_repository_local_copy_existence 1833 + #-------- 1834 + # It's important that this script will not try 1835 + # to recursively copy/move the content of the "/" to 1836 + # a subfolder of the "/", the "/tmp". 1837 + # The other folders that are covered by the 1838 + # test are a bit of an overkill here, may be even an 1839 + # annoying and unjustified restrictions, but 1840 + # in most cases those restrictions do not hurt either. 1841 + fun_last_minute_checks_t1 "$S_FP_SANDBOX" 1842 + #---- 1843 + S_TMP_0="/tmp/tmp_mmmv_$S_VERSION_OF_THIS_SCRIPT" 1844 + S_TMP_1="__" 1845 + #-- 1846 + func_mmmv_GUID_t1 1847 + S_TMP_FOR_LOCAL="$S_TMP_0$S_TMP_1$S_FUNC_MMMV_GUID_T1_RESULT" 1848 + #-- 1849 + func_mmmv_GUID_t1 1850 + S_TMP_FOR_COMMIT_MESSAGE="$S_TMP_0$S_TMP_1$S_FUNC_MMMV_GUID_T1_RESULT" 1851 + mkdir -p $S_TMP_FOR_LOCAL 1852 + chmod -f -R u+rwx $S_FP_SANDBOX 1853 + mv -f $S_FP_SANDBOX/* $S_TMP_FOR_LOCAL/ # the -f is for empty sandbox 1854 + #-------- 1855 + fun_activity_core_overwrite_local_with_remote 1856 + fun_last_minute_checks_t1 "$S_FP_SANDBOX" # should there be flaws elsewhere 1857 + chmod -f -R u+rwx $S_FP_SANDBOX # to be able to delete the old content 1858 + #-------- 1859 + cd $S_FP_SANDBOX 1860 + fossil open $S_FP_DIR/$S_FP_FOSSILFILE_NAME # full path for reliability 1861 + fossil settings autosync off ; 1862 + fun_folder_is_empty_t1 "$S_FP_SANDBOX" 1863 + SB_SANDBOX_CONTENT_MIGHT_HAVE_BEEN_CHANGED="f" 1864 + if [ "$SB_FOLDER_IS_EMPTY" == "f" ]; then 1865 + fossil rm --hard --case-sensitive TRUE ./* 1866 + SB_SANDBOX_CONTENT_MIGHT_HAVE_BEEN_CHANGED="t" 1867 + fun_last_minute_checks_t1 "`pwd`" 1868 + if [ "$S_FP_SANDBOX" == "`pwd`" ]; then 1869 + rm -fr ./* 1870 + else 1871 + echo "" 1872 + echo "This Bash script is flawed." 1873 + echo "GUID=='20848e2d-db76-40f0-b18b-f1e0305090e7'" 1874 + echo "" 1875 + #---- 1876 + cd $S_FP_ORIG 1877 + exit 1 1878 + fi 1879 + fi 1880 + mv -f $S_TMP_FOR_LOCAL/* $S_FP_SANDBOX/ # the -f is for empty source 1881 + #---- 1882 + fun_last_minute_checks_t1 "$S_TMP_FOR_LOCAL" 1883 + rm -fr $S_TMP_FOR_LOCAL 1884 + #---- 1885 + fun_folder_is_empty_t1 "$S_FP_SANDBOX" 1886 + if [ "$SB_FOLDER_IS_EMPTY" == "f" ]; then 1887 + if [ "$S_FP_SANDBOX" != "`pwd`" ]; then 1888 + echo "" 1889 + echo "This Bash script is flawed." 1890 + echo "GUID=='74c20b5b-81c4-4dea-a17b-f1e0305090e7'" 1891 + echo "" 1892 + #---- 1893 + cd $S_FP_ORIG 1894 + exit 1 1895 + fi 1896 + find . -name '*' | xargs fossil add --force --dotfiles --case-sensitive TRUE 1897 + SB_SANDBOX_CONTENT_MIGHT_HAVE_BEEN_CHANGED="t" 1898 + fi 1899 + if [ "$SB_SANDBOX_CONTENT_MIGHT_HAVE_BEEN_CHANGED" == "t" ]; then 1900 + if [ "$2" == "" ]; then 1901 + echo "" 1902 + #echo "Please enter a one-liner commit message: " 1903 + #S_TMP_0="`ruby -e \"s=gets.gsub(/[\n\r\s]/,'');print(s)\"`" 1904 + # TODO: improve this script so that it would not ask 1905 + # for a commit message, when nothing changed. It requires 1906 + # some recursive analysis of files, which might be slow. 1907 + # This script is not optimal for speed even now and that would 1908 + # make it even slower. On the other hand, usually when 1909 + # the upload operation is initiated, there are some changes, 1910 + # which means that the slow analysis would be useless in 1911 + # most frequent cases. So this thing needs to be figured out 1912 + # at some later time, when there is more experience with the 1913 + # use of this script. 1914 + read -p "Please enter a one-liner commit message: " S_TMP_0 1915 + echo $S_TMP_0 > $S_TMP_FOR_COMMIT_MESSAGE 1916 + else 1917 + if [ "$2" == "use_autogenerated_commit_message" ]; then 1918 + echo "Autogenerated commit message timestamp: $S_TIMESTAMP" > $S_TMP_FOR_COMMIT_MESSAGE 1919 + else 1920 + if [ "$2" == "read_commit_message_from_file" ]; then 1921 + S_FP_MESSAGE_FILE_CANDIDATE="$3" # file path candidate 1922 + # Initial file existence and type checks for the 1923 + # $S_FP_MESSAGE_FILE_CANDIDATE 1924 + # were conducted at the start of the script. 1925 + # but the $S_FP_MESSAGE_FILE_CANDIDATE might have 1926 + # referenced a file in the sandbox and 1927 + # that file might have been just removed/deleted. 1928 + # 1929 + # There is no threat that the file got changed to a folder 1930 + # or a symlink switched from a file to a folder, 1931 + # at least that's the case for the single threaded model. 1932 + if [ ! -e "$S_FP_MESSAGE_FILE_CANDIDATE" ]; then 1933 + # missing or a broken symlink 1934 + echo "" 1935 + echo "The commit message file is missing or " 1936 + echo "references a broken symlink." 1937 + echo "The file or symlink to it was fine at " 1938 + echo "the start of this script, it passed the various tests, " 1939 + echo "but for some reason it got deleted or its target . " 1940 + echo "got deleted. If the commit message file or" 1941 + echo "the symlink target resided within the sandbox, then " 1942 + echo "a recommendation is to use a file that resides " 1943 + echo "outside of the sandbox." 1944 + echo "GUID=='489d0043-ac2a-46ae-857b-f1e0305090e7'" 1945 + echo "" 1946 + #---- 1947 + cd $S_FP_ORIG 1948 + exit 1 1949 + fi 1950 + if [ -d "$S_FP_MESSAGE_FILE_CANDIDATE" ]; then 1951 + # folder or a symlink to a folder 1952 + echo "" 1953 + echo "The commit message file path does not reference " 1954 + echo "a file. It references a folder or a symlink to a folder." 1955 + echo "The file or symlink to it was fine at " 1956 + echo "the start of this script, it passed the various tests, " 1957 + echo "but for some reason there were changes. " 1958 + echo "GUID=='1c1054d1-d44f-4830-a47b-f1e0305090e7'" 1959 + echo "" 1960 + #---- 1961 + cd $S_FP_ORIG 1962 + exit 1 1963 + fi 1964 + cat $S_FP_MESSAGE_FILE_CANDIDATE > $S_TMP_FOR_COMMIT_MESSAGE 1965 + # else 1966 + # Due to the checks at the start of the script 1967 + # this else branch is useless. 1968 + fi 1969 + fi 1970 + fi 1971 + #-------- 1972 + fossil commit --message-file $S_TMP_FOR_COMMIT_MESSAGE 1973 + #---- 1974 + fun_last_minute_checks_t1 "$S_TMP_FOR_COMMIT_MESSAGE" 1975 + rm -f $S_TMP_FOR_COMMIT_MESSAGE 1976 + #---- 1977 + fi 1978 + #-------- 1979 + fossil push --private 1980 + fossil push 1981 + fossil pull --private 1982 + fossil close 1983 + #---- 1984 + cd $S_FP_ORIG 1985 + exit 0 1986 +fi # overwrite_remote_with_local 1987 + 1988 + 1989 +#-------------------------------------------------------------------------- 1990 +if [ "$S_ACTIVITY_OF_THIS_SCRIPT" == "delete_local_copy" ]; then 1991 + #-------- 1992 + SB_THERE_IS_SOMETHING_TO_DELETE="f" 1993 + if [ "$SB_FOSSILFILE_EXISTS" == "t" ]; then 1994 + SB_THERE_IS_SOMETHING_TO_DELETE="t" 1995 + fi 1996 + if [ "$SB_SANDBOX_DIR_EXISTS" == "t" ]; then 1997 + SB_THERE_IS_SOMETHING_TO_DELETE="t" 1998 + fi 1999 + if [ "$SB_ARCHIVE_DIR_EXISTS" == "t" ]; then 2000 + SB_THERE_IS_SOMETHING_TO_DELETE="t" 2001 + fi 2002 + #-------- 2003 + if [ "$SB_THERE_IS_SOMETHING_TO_DELETE" == "t" ]; then 2004 + if [ "$2" != "$S_ARGNAME_ACTIVITY_SHRED_ARG_2" ]; then 2005 + # Includes the $2=="" case 2006 + # id est if the control flow is in here, then there 2007 + # is a need to prompt for confirmation. 2008 + # The skipping of the prompt is necessary for 2009 + # software that use this script as its sub-component. 2010 + #-------- 2011 + echo "" 2012 + echo "The command \"delete_local_copy\" deletes " 2013 + echo "the repository file, the sandbox and " 2014 + echo "the associated automatically created archives." 2015 + echo "" 2016 + read -p "Proceed with deletion? (Yes/whatever_else) " S_TMP_0 2017 + S_TMP_1="`echo $S_TMP_0 | gawk '{print tolower($1)}'`" 2018 + if [ "$S_TMP_1" == "yes" ]; then 2019 + echo "" 2020 + printf "Deleting ... " 2021 + else 2022 + fun_exit_without_any_errors_t1 2023 + fi 2024 + fi 2025 + fi 2026 + #-------- 2027 + cd $S_FP_ORIG # to make sure that we're not in the sandbox directory and 2028 + # to make sure that we're not in the archive directory 2029 + #---- 2030 + # The next 3 checks can bee seen to form a complete graph, 2031 + # in this case a triangle, with corner points 2032 + # S_FP_SANDBOX, S_FP_ARCHIVES, S_FP_FOSSILFILE connected 2033 + # with lines of type "!=". 2034 + S_GUID="470c7051-b162-4cba-b51c-f1e0305090e7" 2035 + func_mmmv_assert_file_paths_differ_t1 "$S_FP_FOSSILFILE" "$S_FP_SANDBOX" "$S_GUID" 2036 + 2037 + S_GUID="45b8df6a-0c67-4d1e-a71c-f1e0305090e7" 2038 + func_mmmv_assert_file_paths_differ_t1 "$S_FP_SANDBOX" "$S_FP_ARCHIVES" "$S_GUID" 2039 + 2040 + S_GUID="42226761-7b9d-4cfb-bc1c-f1e0305090e7" 2041 + func_mmmv_assert_file_paths_differ_t1 "$S_FP_ARCHIVES" "$S_FP_FOSSILFILE" "$S_GUID" 2042 + #---- 2043 + # The next 3 checks turn the triangle to a tetrahedron, where 2044 + # the S_FP_ORIG is the "top of the pyramid". 2045 + S_GUID="a9379a5b-d3aa-419b-820c-f1e0305090e7" 2046 + func_mmmv_assert_file_paths_differ_t1 "$S_FP_ORIG" "$S_FP_FOSSILFILE" "$S_GUID" 2047 + 2048 + S_GUID="6d2d0251-9d35-4747-940c-f1e0305090e7" 2049 + func_mmmv_assert_file_paths_differ_t1 "$S_FP_ORIG" "$S_FP_ARCHIVES" "$S_GUID" 2050 + 2051 + S_GUID="3b972413-c33d-4867-910c-f1e0305090e7" 2052 + func_mmmv_assert_file_paths_differ_t1 "$S_FP_ORIG" "$S_FP_SANDBOX" "$S_GUID" 2053 + #-------- 2054 + cd $S_FP_ORIG # just in case 2055 + SB_OK_TO_USE_RM_IN_STEAD_OF_SHRED="t" # shred is still used, if available 2056 + if [ "$SB_FOSSILFILE_EXISTS" == "t" ]; then 2057 + fun_last_minute_checks_t1 "`pwd`" 2058 + func_mmmv_shred_t1 "$S_FP_FOSSILFILE" "$SB_OK_TO_USE_RM_IN_STEAD_OF_SHRED" 2059 + fi 2060 + if [ "$SB_SANDBOX_DIR_EXISTS" == "t" ]; then 2061 + fun_last_minute_checks_t1 "`pwd`" 2062 + func_mmmv_shred_t1 "$S_FP_SANDBOX" "$SB_OK_TO_USE_RM_IN_STEAD_OF_SHRED" 2063 + fi 2064 + if [ "$SB_ARCHIVE_DIR_EXISTS" == "t" ]; then 2065 + fun_last_minute_checks_t1 "`pwd`" 2066 + func_mmmv_shred_t1 "$S_FP_ARCHIVES" "$SB_OK_TO_USE_RM_IN_STEAD_OF_SHRED" 2067 + fi 2068 + #-------- 2069 + if [ "$SB_THERE_IS_SOMETHING_TO_DELETE" == "t" ]; then 2070 + if [ "$2" != "$S_ARGNAME_ACTIVITY_SHRED_ARG_2" ]; then 2071 + echo "✓" 2072 + echo "" 2073 + fi 2074 + fi 2075 + #-------- 2076 + cd $S_FP_ORIG 2077 + exit 0 2078 +fi # delete_local_copy 2079 + 2080 + 2081 +#-------------------------------------------------------------------------- 2082 +# All possible actions must have been described 2083 +# above this code block. 2084 +echo "" 2085 +echo "This Bash script is flawed." 2086 +echo "GUID=='1b3f0b52-848d-494a-a47b-f1e0305090e7'" 2087 +echo "" 2088 +#---- 2089 +cd $S_FP_ORIG 2090 +exit 1 2091 + 2092 +#========================================================================== 2093 +