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