Bash : Kopeerimiseks-asetamiseks mõeldud kood

From mmmv_kos
Jump to: navigation, search

Bash


mmmv_notes koodinäited


Skriptilõigud

S_TIMESTAMP

S_TIMESTAMP="`date +%Y`_`date +%m`_`date +%d`_`date +%H`_`date +%M`_`date +%S`"
S_FP_prefix="`echo $S_TIMESTAMP`_"


Failirajast failinime leidmine

    #---------------
    export func_mmmv_angervaks_generate_single_torrent_file_S_FP_SEED="$S_FP_SEED"
    local S_FP_FILENAME=`ruby -e "s=ENV[\"func_mmmv_angervaks_generate_single_torrent_file_S_FP_SEED\"];print (s.reverse)[0..(s.reverse.index(\"/\")-1)].reverse"`
    #---------------


Linuxi ja BSD olemasolu kontroll

#--------------------------------------------------------------------------
S_TMP_0="`uname -a | grep -E [Ll]inux`"
if [ "$S_TMP_0" == "" ]; then
    S_TMP_0="`uname -a | grep -E [Bb][Ss][Dd]`"
    if [ "$S_TMP_0" == "" ]; 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 Linux and BSD."
        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 ""
        echo "  Aborting script without doing anything."
        echo ""
        echo "GUID=='33598139-07dd-484e-a5ec-91c29061b2e7'"
        echo ""
        cd $S_FP_ORIG
        exit 1 # exit with an error
    fi
fi

Funktsioonid

func_assert_error_code_zero_t1

func_assert_error_code_zero_t1(){
    local S_ERR_CODE=$1 # the "$?"
    local S_GUID_CANDIDATE=$2
    #--------
    # If the "$?" were evaluated in this function, 
    # then it would be "0" even, if it is
    # something else at the calling code.
    if [ "$S_ERR_CODE" != "0" ];then
        echo ""
        echo "Something went wrong. Error code: $S_ERR_CODE"
        echo "Aborting script."
        echo "GUID=='bc7f9059-249c-4f1e-a47c-8011d08112e7'"
        echo "S_GUID_CANDIDATE=='$S_GUID_CANDIDATE'"
        echo ""
        cd $S_FP_ORIG
        exit 1
    fi
} # func_assert_error_code_zero_t1

func_mmmv_exit_if_not_on_path_t2

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 execution of this Bash script is aborted."
        echo "GUID=='455b5615-c335-4ee1-9e03-e1d141816ed7'"
        echo ""
        cd $S_FP_ORIG
        exit 1;
    fi
} # func_mmmv_exit_if_not_on_path_t2


func_mmmv_exit_t1

Bash colors and formatting (archieval copy at softf1.com archive)

func_mmmv_exit_t1(){
    local S_GUID_CANDIDATE=$1 # first function argument
    echo ""
    echo -e "\e[32m\e[7m#======================================================="
    echo -e "\e[0m\e[32mIf You want to run this Bash script, the "
    echo "#--------------"
    echo "$S_FP_DIR/$S_FN_SCRIPTFILE_NAME"
    echo "#--------------"
    echo "then please edit it by outcommenting the line with the "
    echo "\"$S_GUID_CANDIDATE\"."
    echo "Thank You."
    echo -e "\e[32m\e[7m#======================================================="
    echo -e "\e[0m" # resets the text terminal style
    cd $S_FP_ORIG
    exit 1
} # func_mmmv_exit_t1


func_mmmv_exc_exit_with_an_error_t1

func_mmmv_exc_exit_with_an_error_t1(){
    local S_GUID_CANDIDATE=$1 # first function argument
    func_mmmv_exc_verify_S_FP_ORIG_t1
    #--------
    echo ""
    echo "The code of this script is flawed."
    echo "Aborting script."
    if [ "$S_GUID_CANDIDATE" != "" ]; then 
        echo "GUID_CANDIDATE=='$S_GUID_CANDIDATE'"
    fi
    echo "GUID=='314ae934-412a-4bb0-8490-f2426121b2e7'"
    echo ""
    cd $S_FP_ORIG
    exit 1 # exit with an error
} # func_mmmv_exc_exit_with_an_error_t1


func_mmmv_exc_exit_with_an_error_t2

func_mmmv_exc_exit_with_an_error_t2(){
    local S_GUID_CANDIDATE=$1   # first function argument
    local S_OPTIONAL_ERR_MSG=$2 # second function argument
    func_mmmv_exc_verify_S_FP_ORIG_t1
    #--------
    if [ "$S_GUID_CANDIDATE" == "" ]; then 
        echo ""
        echo "The code of this script is flawed. "
        if [ "$S_OPTIONAL_ERR_MSG" != "" ]; then 
            echo "$S_OPTIONAL_ERR_MSG"
        fi
        echo "Aborting script."
        echo "GUID=='1434d331-400d-4bb9-af90-f2426121b2e7'"
        echo ""
        cd $S_FP_ORIG
        exit 1 # exit with an error
    else
        echo ""
        echo "Something went wrong."
        if [ "$S_OPTIONAL_ERR_MSG" != "" ]; then 
            echo "$S_OPTIONAL_ERR_MSG"
        fi
        echo "Aborting script."
        echo "GUID_CANDIDATE=='$S_GUID_CANDIDATE'"
        echo "GUID=='d3d0ed48-d79b-4dda-9590-f2426121b2e7'"
        echo ""
        cd $S_FP_ORIG
        exit 1 # exit with an error
    fi
} # func_mmmv_exc_exit_with_an_error_t2


func_mmmv_exc_determine_Awk_command_t1

S_AWK_CMD="exit 1;"
  func_mmmv_exc_determine_Awk_command_t1() {
      S_AWK_CMD="exit 1;" # for reliability
      local SB_THROW="f"
      if [ "`which gawk`" != "" ]; then
          S_AWK_CMD="gawk"
      else
          if [ "`which awk`" != "" ]; then
              S_AWK_CMD="awk"
          else
              SB_THROW="t"
          fi
      fi
      if [ "$SB_THROW" != "f" ]; then
          echo ""
          echo "Neither 'gawk', nor 'awk' was available on PATH."
          echo "The execution of this Bash script is aborted."
          echo "GUID=='49713cc2-e38c-4505-b422-2223218152e7'"
          echo ""
          cd $S_FP_ORIG
          exit 1;
      fi
  } # func_mmmv_exc_determine_Awk_command_t1

func_mmmv_exc_is_folder_t1 func_mmmv_exc_is_file_t1

func_mmmv_exc_is_folder_t1() {
    local S_FP_CANDIDATE="$1" # folder path
    if [ ! -e "$S_FP_CANDIDATE" ]; then 
        echo ""
        echo "The folder"
        echo ""
        echo "    $S_FP_CANDIDATE "
        echo ""
        echo "does not exist."
        echo "GUID=='485ae338-4f2a-461f-a227-410090c1c0e7'"
        echo "Aborting without doing anything."
        echo ""
        exit 1 # exit with an error
    fi
    if [ ! -d "$S_FP_CANDIDATE" ]; then 
        echo ""
        echo "The path"
        echo ""
        echo "    $S_FP_CANDIDATE "
        echo ""
        if [ -h "$S_FP_CANDIDATE" ]; then 
            echo "references a symbolic link to a file, "
        else
            echo "references a file, "
        fi
        echo "but it is required to reference a folder."
        echo "GUID=='f6931e13-e668-43b0-b327-410090c1c0e7'"
        echo "Aborting without doing anything."
        echo ""
        exit 1 # exit with an error
    fi
} # func_mmmv_exc_is_folder_t1


func_mmmv_exc_is_file_t1() {
    local S_FP_CANDIDATE="$1" # folder path
    if [ ! -e "$S_FP_CANDIDATE" ]; then 
        echo ""
        echo "The file"
        echo ""
        echo "    $S_FP_CANDIDATE "
        echo ""
        echo "does not exist."
        echo "GUID=='515a1738-4f2a-461f-a227-410090c1c0e7'"
        echo "Aborting without doing anything."
        echo ""
        exit 1 # exit with an error
    fi
    if [ -d "$S_FP_CANDIDATE" ]; then 
        echo ""
        echo "The path"
        echo ""
        echo "    $S_FP_CANDIDATE "
        echo ""
        if [ -h "$S_FP_CANDIDATE" ]; then 
            echo "references a symbolic link to a folder, "
        else
            echo "references a folder, "
        fi
        echo "but it is required to reference a file."
        echo "GUID=='6d136b13-e668-43b0-b327-410090c1c0e7'"
        echo "Aborting without doing anything."
        echo ""
        exit 1 # exit with an error
    fi
} # func_mmmv_exc_is_file_t1


# # Test code:
# S_FP_TMP_0="/tmp/fff_testimine"
# S_FP_TMP_FF1="$S_FP_TMP_0/ff1"
# S_FP_TMP_FILE_1="$S_FP_TMP_0/file1.txt"
# S_FP_TMP_0_SYM_FLDR_OK="$S_FP_TMP_0/sym_folder_exists"
# S_FP_TMP_0_SYM_X_MISSING="$S_FP_TMP_0/sym_x_missing"
# S_FP_TMP_0_SYM_FILE_OK="$S_FP_TMP_0/sym_file_exists"
# rm -fr $S_FP_TMP_0
# mkdir -p $S_FP_TMP_FF1
# echo "Hello World :-)" > $S_FP_TMP_FILE_1
# ln -s $S_FP_TMP_FILE_1  $S_FP_TMP_0_SYM_FILE_OK
# ln -s $S_FP_TMP_FF1  $S_FP_TMP_0_SYM_FLDR_OK
# ln -s $S_FP_TMP_FF1/this_does_not_exist $S_FP_TMP_0_SYM_X_MISSING
# 
# # The following assertions must pass:
#     func_mmmv_exc_is_folder_t1 "$S_FP_TMP_FF1"
#     func_mmmv_exc_is_folder_t1 "$S_FP_TMP_0_SYM_FLDR_OK"
#     func_mmmv_exc_is_file_t1 "$S_FP_TMP_FILE_1"
#     func_mmmv_exc_is_file_t1 "$S_FP_TMP_0_SYM_FILE_OK"
# 
# # The following assertions must fail:
#     #func_mmmv_exc_is_folder_t1 "$S_FP_TMP_0_SYM_X_MISSING"
#     #func_mmmv_exc_is_file_t1 "$S_FP_TMP_0_SYM_X_MISSING"
# 
# rm -fr $S_FP_TMP_0
# exit 0

func_mmmv_create_folder_t1

func_mmmv_create_folder_t1(){
    local S_FP_FOLDER=$1 # first function argument
    #--------
    # The reason, why this function is used instead of the 
    #     mkdir -p $S_FP_FOLDER
    # is that there is no guarantee that the 
    #     mkdir -p $S_FP_FOLDER
    # succeeds and it would be a waste of
    # development time to write the file system related
    # tests from scatch every time a folder 
    # needs to be created.
    #--------
    func_mmmv_exc_verify_S_FP_ORIG_t1
    if [ "$S_FP_FOLDER" == "" ]; then
        echo ""
        echo "The function formal parameter S_FP_FOLDER "
        echo "is expected to be a full path to a folder that "
        echo "either already exists or that has to be created."
        echo "Aborting script."
        echo "GUID=='775d9a5a-cfda-40a9-81dc-91c29061b2e7'"
        echo ""
        cd $S_FP_ORIG
        exit 1 # exit with an error
    fi
    #--------
    if [ -e "$S_FP_FOLDER" ]; then 
        if [ ! -d "$S_FP_FOLDER" ]; then 
            echo ""
            echo "The "
            echo ""
            echo "    $S_FP_FOLDER"
            echo ""
            echo "is a file or a symlink to a file, but it "
            echo "is expected to be a full path to a folder, "
            echo "a symlink to a folder or it should not "
            echo "reference anything that already exists."
            echo "Aborting script."
            echo "GUID=='ab795230-f76c-4cc4-a4dc-91c29061b2e7'"
            echo ""
            cd $S_FP_ORIG
            exit 1 # exit with an error
        fi
    else
        mkdir -p $S_FP_FOLDER
        local S_TMP_0="$?"
        sync # for network drives and USB-sticks
        if [ "$S_TMP_0" != "0" ]; then 
            func_mmmv_exc_exit_with_an_error_t2 "ea9bfc35-69f6-4dfb-b1ec-91c29061b2e7" \
                "S_FP_FOLDER==$S_FP_FOLDER"
        fi
        if [ ! -e "$S_FP_FOLDER" ]; then 
            func_mmmv_exc_exit_with_an_error_t2 "57ae6455-51eb-4d99-a1ec-91c29061b2e7" \
                "Folder creation failed. S_FP_FOLDER==$S_FP_FOLDER"
        fi
    fi
    #--------
} # func_mmmv_create_folder_t1

func_assert_folder_exists_t1

func_assert_folder_exists_t1() {  # S_FP, S_GUID
    local S_FP="$1"
    local S_GUID="$2"
    #------------------------------
    if [ "$S_GUID" == "" ]; then
        echo ""
        echo "The code that calls this function is flawed."
        echo "This function requires 2 parameters: S_FP, S_GUID"
        echo "GUID=='6f5f4f52-25bf-4559-bc6e-13231130c0e7'"
        echo ""
        #--------
        cd $S_FP_ORIG
        exit 1 # exiting with an error
    fi
    #------------------------------
    if [ ! -e "$S_FP" ]; then
        if [ -h "$S_FP" ]; then
            echo ""
            echo "The path "
            echo ""
            echo "    $S_FP "
            echo ""
            echo "points to a broken symbolic link."
            echo "GUID==\"$S_GUID\""
            echo "GUID=='06c6fb2b-687e-4a06-b16e-13231130c0e7'"
            echo ""
            #--------
            cd $S_FP_ORIG
            exit 1 # exiting with an error
        else
            echo ""
            echo "The folder "
            echo ""
            echo "    $S_FP "
            echo ""
            echo "does not exist."
            echo "GUID==\"$S_GUID\""
            echo "GUID=='83ef2440-6f34-40a2-846e-13231130c0e7'"
            echo ""
            #--------
            cd $S_FP_ORIG
            exit 1 # exiting with an error
        fi
    fi
} # func_assert_folder_exists_t1


func_mmmv_exit_if_environment_variable_not_set_t1

func_mmmv_exit_if_environment_variable_not_set_t1() { # S_ENVIRONMENT_VARIABLE_NAME S_ENVIRONMENT_VARIABLE_DOCSTRING
    local S_ENVIRONMENT_VARIABLE_NAME="$1"
    local S_ENVIRONMENT_VARIABLE_DOCSTRING="$2" # will be appended to failure-message
    #---------------
    local S_ENVIR_VALUE=""
    local S_SCRIPT_0="S_ENVIR_VALUE=\"\`echo \$$S_ENVIRONMENT_VARIABLE_NAME\`\""
    eval "$S_SCRIPT_0"
    if [ "$S_ENVIR_VALUE" == "" ]; then
        echo ""
        echo "The environment variable $S_ENVIRONMENT_VARIABLE_NAME is not set, but "
        echo "it must be set or this script will not run (properly)."
        if [ "$S_ENVIRONMENT_VARIABLE_DOCSTRING" != "" ]; then
            echo ""
            echo "$S_ENVIRONMENT_VARIABLE_DOCSTRING"
        fi
        echo ""
        exit;
    #else 
         # echo "S_ENVIR_VALUE==\"$S_ENVIR_VALUE\""
    fi
} # func_mmmv_exit_if_environment_variable_not_set_t1

# func_mmmv_exit_if_environment_variable_not_set_t1 "CFLAGS"


func_mmmv_ar_ls_t1

func_mmmv_ar_ls_t1() { # S_ARRAY_VARIABLE_NAME S_FP_LS
    local S_ARRAY_VARIABLE_NAME=$1
    local S_FP_LS=$2
    #--------
    # The "ls -m " works on both, BSD and Linux.
    local AR_0=$( ls -m $S_FP_LS )
    #--------
    local S_SCRIPT_0="$S_ARRAY_VARIABLE_NAME=()"
    eval "$S_SCRIPT_0"
    local s_iter=""
    S_SCRIPT_0="$S_ARRAY_VARIABLE_NAME+=(\$s_iter)"
    local S_TMP_IFS="$IFS"
    # The IFS is an internal Bash variable, "Internal Field Separator".
    IFS="," # That should handle file names that contain spaces.
    for s_iter in ${AR_0[@]}; do
        eval "$S_SCRIPT_0"
    done
    IFS="$S_TMP_IFS"
    if [ -z "$IFS" ]; then  # The "-z" returns true, if the string length is zero.
        unset IFS
    fi
} # func_mmmv_ar_ls_t1

func_mmmv_ar_ls_t1 "AR_X" "$HOME"

AR_2=${AR_X[@]}  # flawed array assignment that tokenizes by space
S_TMP=${#AR_X[@]}
echo "AR_X length: $S_TMP"
echo ""
for s_iter in ${AR_X[@]}; do
     echo "AR_X element:[$s_iter]" 
done



func_mmmv_exec_with_every_ar_element_t1

func_mmmv_exec_with_every_ar_element_t1() { # S_CMD_PART_0  S_ARRAY_VARIABLE_NAME_OF_AR_S_CMD_PART_1 S_CMD_PART_2
    local S_CMD_PART_0=$1
    local S_ARRAY_VARIABLE_NAME_OF_AR_S_CMD_PART_1=$2
    local S_CMD_PART_2=$3
    #----------------
    local S_SCRIPT_0=""
    local S_SCRIPT_1=""
    local S_SCRIPT_2=""
    local S_SCRIPT_x0=""
    local S_SCRIPT_x1=""
    local S_SCRIPT_x2=""
    #----------------
    # Wastefully left uncommented to detect flaws and to make life more comfortable :-)
    local S_TMP=""
    S_SCRIPT_0="S_TMP=\${#"
    S_SCRIPT_1="$S_ARRAY_VARIABLE_NAME_OF_AR_S_CMD_PART_1"
    S_SCRIPT_2="[@]}"
    eval "$S_SCRIPT_0$S_SCRIPT_1$S_SCRIPT_2" 
    #echo "The length of the $S_ARRAY_VARIABLE_NAME_OF_AR_S_CMD_PART_1 is: $S_TMP"
    #----------------
    # The newline trick 
    local S_NEWLINE=$'\n'
    # originates from the answer of Gordon Davisson:
    # https://stackoverflow.com/questions/17821277/how-to-separate-multiple-commands-passed-to-eval-in-bash
    # archival copy: https://archive.fo/7XI3a 
    #--------
    local S_ITER=""
    S_SCRIPT_0="for S_ITER in \${$S_ARRAY_VARIABLE_NAME_OF_AR_S_CMD_PART_1[@]}; do " 
    S_SCRIPT_x0="echo \"\"; echo \"\$S_ITER\""
    #S_SCRIPT_1="echo \"\$S_ITER\" " 
    S_SCRIPT_1="$S_CMD_PART_0 \$S_ITER  $S_CMD_PART_2 ;" 
    S_SCRIPT_x1="echo \"\""
    S_SCRIPT_2="done"
    S_SCRIPT_x2=""
    #----
    local S_TMP_0="$S_SCRIPT_0$S_NEWLINE$S_SCRIPT_x0$S_NEWLINE"
    local S_TMP_1="$S_SCRIPT_1$S_NEWLINE$S_SCRIPT_x1$S_NEWLINE"
    local S_TMP_2="$S_SCRIPT_2$S_NEWLINE$S_SCRIPT_x2$S_NEWLINE"
    eval "$S_TMP_0$S_TMP_1$S_TMP_2"
} # func_mmmv_exec_with_every_ar_element_t1

func_mmmv_ar_range_t1

func_mmmv_ar_range_t1() { #S_ARRAY_VARIABLE_NAME I_MINIMUM_INDEX I_MAXIMUM_INDEX
    local S_ARRAY_VARIABLE_NAME=$1
    local I_MIN=$2
    local I_MAX_PLUS_ONE=`expr $3 + 1`
    local S_SCRIPT_0="$S_ARRAY_VARIABLE_NAME=()"
    eval "$S_SCRIPT_0"
    local i_n=""
    S_SCRIPT_0="$S_ARRAY_VARIABLE_NAME+=(\$i_n)"
    for ((i_n=$I_MIN;i_n<$I_MAX_PLUS_ONE;i_n++))
    do
        eval "$S_SCRIPT_0"
    done
} # func_mmmv_ar_range_t1

S_TMP="9"
func_mmmv_ar_range_t1 "AR_A_GLOBAL_VARIABLE" 4 $S_TMP
for s_iter in ${AR_A_GLOBAL_VARIABLE[@]}; do
        echo "s_iter==[$s_iter]"
done


func_mmmv_create_array_t1

func_mmmv_create_array_t1() {
    local ARRR=()
    #------- 
    ARRR+=("first value as string")
    ARRR+=("second value as string") 
    ARRR+=("third value as string")
    ARRR+=("fourth value as string")
    #------- 
    export ARRR_sz=`declare -p ARRR`
} # func_mmmv_create_array_t1



== func_mmmv_iterate_over_array_02n_t1 ==

func_mmmv_iterate_over_array_02n_t1() {
    local S_ARRAY_VARIABLE_NAME=$1 
    local S_ARRAY_SERIALIZED=$2 # `declare -p VARIABLENAME` or an empty string
    local S_ITERATION_FUNCTION_NAME=$3 # that accepts "$s_iter" as a parameter
    eval ${S_ARRAY_SERIALIZED}
    #-------
    local S_SCRIPT_0="local S_LEN=\${#$S_ARRAY_VARIABLE_NAME[@]}"
    eval ${S_SCRIPT_0}
    #echo "ARRR length: $S_LEN"
    local I_MAX=`expr $S_LEN + 0`
    #-------
    local i_n=42
    local s_iter=""
    local S_SCRIPT_LINE_1="for ((i_n=0;i_n<\$I_MAX;i_n++))"
    local S_SCRIPT_LINE_2="s_iter=\${$S_ARRAY_VARIABLE_NAME[\$i_n]}"
    local S_SCRIPT_LINE_3="$S_ITERATION_FUNCTION_NAME \"\$s_iter\""
    S_SCRIPT_0="$S_SCRIPT_LINE_1 "$'\n'"do"$'\n'"$S_SCRIPT_LINE_2 "$'\n'"$S_SCRIPT_LINE_3 "$'\n'"done"
    #echo "$S_SCRIPT_0"
    eval "$S_SCRIPT_0"
} # func_mmmv_iterate_over_array_02n_t1


func_iter() {
    local S_ITER=$1
    echo "Greetings from func_iter: $S_ITER"
} # func_iter

func_mmmv_create_array_t1
func_mmmv_iterate_over_array_02n_t1 "ARRR" "$ARRR_sz" "func_iter"


func_mmmv_sb_head_exists_t1

func_mmmv_sb_head_exists_t1() { # S_OUTPUT_VARIABLE_NAME, S_HEAD_REGEX , S_HAYSTACK
    local S_OUTPUT_VARIABLE_NAME=$1
    local S_HEAD_REGEX=$2
    local S_HAYSTACK=$3
    local S_SCRIPT_0="$S_OUTPUT_VARIABLE_NAME=\"f\""
    eval "$S_SCRIPT_0"
    local S_NUMBER_OF_MATCHING_CHARACTERS=`expr match "$S_HAYSTACK" "$S_HEAD_REGEX"`
    if [ "$S_NUMBER_OF_MATCHING_CHARACTERS" != "0" ]; then
        S_SCRIPT_0="$S_OUTPUT_VARIABLE_NAME=\"t\""
        eval "$S_SCRIPT_0"
    fi
} # func_mmmv_sb_head_exists_t1 

S_RGX="/home/ts2/tmp"
S_FP="/home/ts2/tmp/uuuuu/eee"

func_mmmv_sb_head_exists_t1 "S_CC" $S_RGX $S_FP
echo "S_CC: $S_CC"


func_mmmv_exc_verify_S_FP_ORIG_t1

func_mmmv_exc_verify_S_FP_ORIG_t1() {
    if [ "$S_FP_ORIG" == "" ]; then
        echo ""
        echo "The code of this script is flawed."
        echo "The environment variable S_FP_ORIG is expected "
        echo "to be initialized at the start of the script by "
        echo ""
        echo "    S_FP_ORIG=\"\`pwd\`\""
        echo ""
        echo "Aborting script."
        echo "GUID=='e9f85d51-2bd5-452e-b364-60516121b2e7'"
        echo ""
        exit 1 # exit with an error
    fi
    #------------------------
    local SB_IS_SYMLINK="f"     # possible values: "t", "f"
    if [ -h "$S_FP_ORIG" ]; then # Returns "false" for paths that 
                                # do not refer to anything.
        SB_IS_SYMLINK="t"
    fi
    #--------
    if [ ! -e "$S_FP_ORIG" ]; then
        if [ "$SB_IS_SYMLINK" == "t" ]; then
            echo "The "
        else
            echo "The file or folder "
        fi
        echo ""
        echo "    S_FP_ORIG==$S_FP_ORIG "
        echo ""
        if [ "$SB_IS_SYMLINK" == "t" ]; then
            echo "is a broken symlink. It is expected to be a folder that "
        else
            echo "does not exist. It is expected to be a folder that "
        fi
        echo "contains the script that prints this error message."
        echo "Aborting script."
        echo "GUID=='02a08c66-03d2-4ea1-a564-60516121b2e7'"
        echo ""
        exit 1 # exit with an error
    fi
    #------------------------
    if [ ! -d "$S_FP_ORIG" ]; then
        echo "The "
        echo ""
        echo "    S_FP_ORIG==$S_FP_ORIG "
        echo ""
        echo "is not a folder. It is expected to be a folder that "
        echo "contains the script that prints this error message."
        echo "Aborting script."
        echo "GUID=='2fea89b6-1a02-4092-b464-60516121b2e7'"
        echo ""
        exit 1 # exit with an error
    fi
} # func_mmmv_exc_verify_S_FP_ORIG_t1

func_mmmv_assert_exists_on_path_t1

func_mmmv_assert_exists_on_path_t1() {
    local S_NAME_OF_THE_EXECUTABLE=$1 # first function argument
    func_mmmv_exc_verify_S_FP_ORIG_t1
    #------------------------
    local S_TMP_0="\`which $S_NAME_OF_THE_EXECUTABLE 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
        S_TMP_0="This bash script requires the \""
        S_TMP_1="\" to be on the PATH."
        S_TMP_2="$S_TMP_0$S_NAME_OF_THE_EXECUTABLE$S_TMP_1"
        #--------
        echo ""
        echo "$S_TMP_2"
        echo "GUID=='e32ee53e-f7c4-4542-9354-60516121b2e7'"
        echo ""
        cd $S_FP_ORIG
        exit 1 # exit with an error
    fi
} # func_mmmv_assert_exists_on_path_t1

func_mmmv_assert_exists_on_path_t1 "ruby"
func_mmmv_assert_exists_on_path_t1 "rubyy"

func_mmmv_ln_create_or_overwrite_t1

func_mmmv_ln_create_or_overwrite_t1() { # S_FP_TARGET  S_FP_LINK
    local S_FP_TARGET=$1
    local S_FP_LINK=$2
    #--------------
    local S_CMD_LN="ln -s $S_FP_TARGET $S_FP_LINK"
    if [ -e "$S_FP_LINK" ]; then
        local S_FP_OLDTARGET="`readlink $S_FP_LINK`"
        if [ "$S_FP_OLDTARGET" != "$S_FP_TARGET" ]; then
            rm -f $S_FP_LINK
            $S_CMD_LN
        fi
    else
        $S_CMD_LN
    fi
    if [ ! -e "$S_FP_LINK" ]; then
        echo ""
        echo ""
        echo "Bash function execution failed. Could not execute the command:"
        echo "$S_CMD_LN"
        echo ""
        echo "PWD==`pwd`"
        echo "GUID=='45fb5615-cd35-4ee1-9e03-e1d141816ed7'"
        echo ""
        echo ""
        exit # to halt client code
    fi
} # func_mmmv_ln_create_or_overwrite_t1


uname -a .... Linux versus FreeBSD

func_mmmv_operatingsystem_is_Linux() { # S_SB_ANSWER
    local S_OUTPUT_VARIABLE_NAME=$1
    #-------
    local S_OUT="f"
    local S_X="`uname -a | grep -l Linux `"
    if [ "$S_X" == "(standard input)" ]; then
        S_OUT="t"
    fi
    local S_SCRIPT_0="$S_OUTPUT_VARIABLE_NAME=\"$S_OUT\""
    eval ${S_SCRIPT_0}
    # echo "ANSWER: $S_OUT"
} # func_mmmv_operatingsystem_is_Linux
#func_mmmv_operatingsystem_is_Linux "S_SB_ANSWER"

func_mmmv_operatingsystem_is_FreeBSD() { # S_SB_ANSWER
    local S_OUTPUT_VARIABLE_NAME=$1
    #-------
    local S_OUT="f"
    local S_X="`uname -a | grep -l FreeBSD`"
    if [ "$S_X" == "(standard input)" ]; then
        S_OUT="t"
    fi
    local S_SCRIPT_0="$S_OUTPUT_VARIABLE_NAME=\"$S_OUT\""
    eval ${S_SCRIPT_0}
    # echo "ANSWER: $S_OUT"
} # func_mmmv_operatingsystem_is_FreeBSD
#func_mmmv_operatingsystem_is_FreeBSD "S_SB_ANSWER"

func_mmmv_determine_operatingsystem_t1() {
    local SB_TMP_0_orig="$SB_TMP_0"
        func_mmmv_operatingsystem_is_Linux "SB_TMP_0"
        if [ "$SB_TMP_0" == "t" ]; then
            export S_MMMV_OPERATING_SYSTEM="linux"
        fi
        func_mmmv_operatingsystem_is_FreeBSD "SB_TMP_0"
        if [ "$SB_TMP_0" == "t" ]; then
            export S_MMMV_OPERATING_SYSTEM="freebsd"
        fi
    export SB_TMP_0="$SB_TMP_0_orig"
} # func_mmmv_determine_operatingsystem_t1
#func_mmmv_determine_operatingsystem_t1


func_mmmv_echo_t1

func_mmmv_echo_t1() {  # <text>, <optional log file path, has side effects>
    local S_FUNC_MMMV_ECHO_T1_MSG="$1" # the text
    local S_FUNC_MMMV_ECHO_T1_FP_LOGFILE="$2" # optional log file path
    #--------
    # The long weird names are a probabilistic workaround to 
    # an easily created flaw/bug, where somewhere outside of this Bash script, 
    # the short names like "S_TMP", "S_0", are used without the "local" keyword.
    local S_FUNC_MMMV_ECHO_T1_TMP_0=""     # declaration
    local S_FUNC_MMMV_ECHO_T1_TMP_1=""     # declaration
    local S_FUNC_MMMV_ECHO_T1_FP_LOG=""    # declaration
    local SB_FUNC_MMMV_ECHO_T1_FIRST_CALL="f" # {t,f}
    #----
    if [ "$S_FUNC_MMMV_ECHO_T1_FP_LOGFILE" != "" ]; then  # first call to this function
        SB_FUNC_MMMV_ECHO_T1_FIRST_CALL="t" # {t,f}
        if    [ "$S_FUNC_MMMV_ECHO_T1_FP_LOGFILE_CURRENT" != "" ]; then 
            # The S_FUNC_MMMV_ECHO_T1_FP_LOGFILE_CURRENT is a global variable.
            echo ""
            echo "Wrong use of the function func_mmmv_echo_t1(...). "
            echo "This function has an intentional side effect that it accepts "
            echo "the logfile path parameter only once per Bash proccess."
            echo ""
            echo "    S_FUNC_MMMV_ECHO_T1_FP_LOGFILE=$S_FUNC_MMMV_ECHO_T1_FP_LOGFILE"
            echo ""
            echo "GUID=='64cfa6b2-9d7a-47c3-bb2d-73f21101c0e7'"
            echo ""
            #----
            cd $S_FP_ORIG
            exit 1;
        fi
        S_FUNC_MMMV_ECHO_T1_TMP_0="`dirname $S_FUNC_MMMV_ECHO_T1_FP_LOGFILE`"
        mkdir -p $S_FUNC_MMMV_ECHO_T1_TMP_0 # might create a mess with relative path
        if [ "$?" != "0" ]; then 
            echo ""
            echo "The mkdir exited with error code: $? "
            echo ""
            echo "    S_FUNC_MMMV_ECHO_T1_TMP_0==$S_FUNC_MMMV_ECHO_T1_TMP_0"
            echo "    S_FUNC_MMMV_ECHO_T1_FP_LOGFILE=$S_FUNC_MMMV_ECHO_T1_FP_LOGFILE"
            echo ""
            echo "GUID=='cd3f52a4-2f49-4371-8b5c-73f21101c0e7'"
            echo ""
            #----
            cd $S_FP_ORIG
            exit 1;
        fi
        if [ ! -e "$S_FUNC_MMMV_ECHO_T1_TMP_0" ]; then 
            echo ""
            echo "The mkdir exited with error code $? , but the folder "
            echo ""
            echo "    $S_FUNC_MMMV_ECHO_T1_TMP_0"
            echo ""
            echo "is still missing."
            echo "GUID=='52aa56e4-ff1c-4579-a13c-73f21101c0e7'"
            echo ""
            #----
            cd $S_FP_ORIG
            exit 1;
        fi 
        #--------
        S_FUNC_MMMV_ECHO_T1_TMP_1="`cd $S_FUNC_MMMV_ECHO_T1_TMP_0 ; pwd`"
        S_FUNC_MMMV_ECHO_T1_TMP_0="`basename $S_FUNC_MMMV_ECHO_T1_FP_LOGFILE`"
        if [ "$S_FUNC_MMMV_ECHO_T1_TMP_0" == "" ]; then 
            echo ""
            echo "The basename of the logfile path must not be an empty string."
            echo ""
            echo "    S_FUNC_MMMV_ECHO_T1_FP_LOGFILE=$S_FUNC_MMMV_ECHO_T1_FP_LOGFILE"
            echo "    S_FUNC_MMMV_ECHO_T1_TMP_1==$S_FUNC_MMMV_ECHO_T1_TMP_1"
            echo ""
            echo "GUID=='95b37772-6281-4b16-bb5c-73f21101c0e7'"
            echo ""
            #----
            cd $S_FP_ORIG
            exit 1;
        fi
        S_FUNC_MMMV_ECHO_T1_FP_LOG="$S_FUNC_MMMV_ECHO_T1_TMP_1/$S_FUNC_MMMV_ECHO_T1_TMP_0"
        S_FUNC_MMMV_ECHO_T1_FP_LOGFILE_CURRENT="$S_FUNC_MMMV_ECHO_T1_FP_LOG"
    else # non-first call to this function
        if    [ "$S_FUNC_MMMV_ECHO_T1_FP_LOGFILE_CURRENT" == "" ]; then 
            # The S_FUNC_MMMV_ECHO_T1_FP_LOGFILE_CURRENT is a global variable.
            echo ""
            echo "Wrong use of the function func_mmmv_echo_t1(...). "
            echo "This function has an intentional side effect that its "
            echo "first call during a Bash process is required to include "
            echo "a full path to a logfile."
            echo ""
            echo "GUID=='f4e5eb73-7748-4493-8f3c-73f21101c0e7'"
            echo ""
            #----
            cd $S_FP_ORIG
            exit 1;
        fi
        S_FUNC_MMMV_ECHO_T1_FP_LOG="$S_FUNC_MMMV_ECHO_T1_FP_LOGFILE_CURRENT"
    fi
    #--------
    S_FUNC_MMMV_ECHO_T1_TMP_0="`dirname $S_FUNC_MMMV_ECHO_T1_FP_LOG`"
    # The file system accesses of the following few if-clauses 
    # are not as bad as they might look at first glance, because this function 
    # needs to access the file system anyway to write to the log file.
    if [ ! -e "$S_FUNC_MMMV_ECHO_T1_TMP_0" ]; then 
        echo ""
        echo "The folder, where the logfile is expected to be created, the"
        echo ""
        echo "    $S_FUNC_MMMV_ECHO_T1_TMP_0"
        echo ""
        echo "does not exist. "
        echo "If the code in this function, the func_mmmv_echo_t1(...), "
        echo "works as expected, then that folder did exist at some point "
        echo "before the control flow reached this error message."
        echo "GUID=='4c1ac273-c14e-4357-ba4c-73f21101c0e7'"
        echo ""
        #----
        cd $S_FP_ORIG
        exit 1;
    fi
    if [ -d "$S_FUNC_MMMV_ECHO_T1_FP_LOG" ]; then 
        echo ""
        echo "Something is wrong."
        echo "The path that is expected to reference a log file, "
        echo ""
        echo "    $S_FUNC_MMMV_ECHO_T1_FP_LOG"
        echo ""
        echo "references "
        if [ -h "$S_FUNC_MMMV_ECHO_T1_FP_LOG" ]; then 
            echo "a link to a folder. "
        else
            echo "a folder."
        fi
        if [ "$SB_FUNC_MMMV_ECHO_T1_FIRST_CALL" == "t" ]; then 
            echo ""
            echo "    S_FUNC_MMMV_ECHO_T1_FP_LOGFILE=$S_FUNC_MMMV_ECHO_T1_FP_LOGFILE"
            echo ""
        else
            if [ "$S_FUNC_MMMV_ECHO_T1_FP_LOGFILE" != "" ]; then 
                echo ""
                echo "The implementation of the function "
                echo "func_mmmv_echo_t1(...) is flawed."
                echo "GUID=='31e2b654-ffdb-44aa-a76c-73f21101c0e7'"
                echo ""
            fi
        fi
        echo "GUID=='16214e82-8096-40e4-b41c-73f21101c0e7'"
        echo ""
        #----
        cd $S_FP_ORIG
        exit 1;
    fi
    #--------
    echo "$S_FUNC_MMMV_ECHO_T1_MSG" | tee -a $S_FUNC_MMMV_ECHO_T1_FP_LOG
} # func_mmmv_echo_t1


Bash failide mallid

Mall 1

link wget'i jaoks.

#!/usr/bin/env bash 
#==========================================================================
S_FP_DIR_ORIG="$S_FP_DIR"
S_FP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
S_TIMESTAMP_PREFIX="`date +%Y`_`date +%m`_`date +%d`_`date +%H`_`date +%M`_`date +%S`_"
#==========================================================================

func_mmmv_exit_if_not_on_path_t2() { # S_COMMAND_NAME
    local S_COMMAND_NAME=$1
    local S_LOCAL_VARIABLE="`which $S_COMMAND_NAME`"
    if [ "$S_LOCAL_VARIABLE" == "" ]; then
        echo ""
        echo "Command \"$S_COMMAND_NAME\" could not be found from the PATH. "
        echo "The execution of this Bash script is aborted."
        echo ""
        exit;
    fi
} # func_mmmv_exit_if_not_on_path_t2

#func_mmmv_exit_if_not_on_path_t2  "ls"

#--------------------------------------------------------------------------

func_mmmv_exit_if_environment_variable_not_set_t1() { # S_ENVIRONMENT_VARIABLE_NAME
    local S_ENVIRONMENT_VARIABLE_NAME="$1"
    local S_ENVIRONMENT_VARIABLE_DOCSTRING="$2" # will be appended to failure-message
    #---------------
    local S_ENVIR_VALUE=""
    local S_SCRIPT_0="S_ENVIR_VALUE=\"\`echo \$$S_ENVIRONMENT_VARIABLE_NAME\`\""
    eval "$S_SCRIPT_0"
    if [ "$S_ENVIR_VALUE" == "" ]; then
        echo ""
        echo "The environment variable $S_ENVIRONMENT_VARIABLE_NAME is not set, but "
        echo "it must be set or this script will not run (properly)."
        if [ "$S_ENVIRONMENT_VARIABLE_DOCSTRING" != "" ]; then
            echo ""
            echo "$S_ENVIRONMENT_VARIABLE_DOCSTRING"
        fi
        echo ""
        exit;
    #else 
         # echo "S_ENVIR_VALUE==\"$S_ENVIR_VALUE\""
    fi
} # func_mmmv_exit_if_environment_variable_not_set_t1

# func_mmmv_exit_if_environment_variable_not_set_t1 "CFLAGS" 

#--------------------------------------------------------------------------


S_FP="/home/ts2/tmp/olematu_fail"
 
if [ -h "$S_FP" ]; then
    echo "symbolic link, regardless of whether it is broken or not"
    if [ ! -e "$S_FP" ]; then
        echo "the symbolic link is broken"
    else
        echo "the symbolic link is NOT broken"
    fi
else
    if [ -d "$S_FP" ]; then
        echo "folder"
    else
        if [ ! -d "$S_FP" ]; then
            echo "file, regardless of whether it exists of not"
        else
            echo "If this text is displayed,"
            echo "then this bash script has a flaw."
        fi
    fi
fi


#==========================================================================
S_FP_DIR="$S_FP_DIR_ORIG"


Mall 2: BitTorrent'i failide loomine, t1

#!/usr/bin/env bash 
#==========================================================================
# This file is in public domain.
#==========================================================================
S_FP_DIR_ORIG="$S_FP_DIR"
S_FP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#S_TIMESTAMP_PREFIX="`date +%Y`_`date +%m`_`date +%d`_`date +%H`_`date +%M`_`date +%S`_"
#==========================================================================

func_mmmv_exit_if_not_on_path_t2() { # S_COMMAND_NAME
    local S_COMMAND_NAME=$1
    local S_LOCAL_VARIABLE="`which $S_COMMAND_NAME`"
    if [ "$S_LOCAL_VARIABLE" == "" ]; then
        echo ""
        echo "Command \"$S_COMMAND_NAME\" could not be found from the PATH. "
        echo "The execution of this Bash script is aborted."
        echo ""
        exit;
    fi
} # func_mmmv_exit_if_not_on_path_t2

func_mmmv_exit_if_not_on_path_t2  "mktorrent"
func_mmmv_exit_if_not_on_path_t2  "ruby"

#--------------------------------------------------------------------------

func_mmmv_exit_if_environment_variable_not_set_t1() { # S_ENVIRONMENT_VARIABLE_NAME
    local S_ENVIRONMENT_VARIABLE_NAME="$1"
    local S_ENVIRONMENT_VARIABLE_DOCSTRING="$2" # will be appended to failure-message
    #---------------
    local S_ENVIR_VALUE=""
    local S_SCRIPT_0="S_ENVIR_VALUE=\"\`echo \$$S_ENVIRONMENT_VARIABLE_NAME\`\""
    eval "$S_SCRIPT_0"
    if [ "$S_ENVIR_VALUE" == "" ]; then
        echo ""
        echo "The environment variable $S_ENVIRONMENT_VARIABLE_NAME is not set, but "
        echo "it must be set or this script will not run (properly)."
        if [ "$S_ENVIRONMENT_VARIABLE_DOCSTRING" != "" ]; then
            echo ""
            echo "$S_ENVIRONMENT_VARIABLE_DOCSTRING"
        fi
        echo ""
        exit;
    #else 
         # echo "S_ENVIR_VALUE==\"$S_ENVIR_VALUE\""
    fi
} # func_mmmv_exit_if_environment_variable_not_set_t1

# func_mmmv_exit_if_environment_variable_not_set_t1 "CFLAGS"

#--------------------------------------------------------------------------

func_mmmv_angervaks_generate_single_torrent_file() { # S_FP_SEED
    local S_FP_SEED="$1"
    #---------------
    if [ "$S_SEED_MACHINE_URL" == "" ]; then
        echo ""
        echo "This bash script is flawed."
        echo "GUID='b4d9f4b9-fc93-437a-8e25-62f240711fd7'"
        echo ""
        exit;
    fi
    #---------------
    if [ -h "$S_FP_SEED" ]; then
        #echo "symbolic link, regardless of whether it is broken or not"
        if [ ! -e "$S_FP_SEED" ]; then
            echo ""
            echo "The symbolic link "
            echo "$S_FP_SEED"
            echo "is broken"
            echo ""
            exit
        else
            if [ -d "$S_FP_SEED" ]; then
                echo ""
                echo "The symbolic link "
                echo "$S_FP_SEED"
                echo "points to a folder, but it is expected to point to a file."
                echo ""
                exit
            fi
        fi
    else # not a symbolic link
        if [ ! -e "$S_FP_SEED" ]; then
            echo ""
            echo "The "
            echo "$S_FP_SEED"
            echo "is missing."
            echo ""
            exit
        fi
        if [ -d "$S_FP_SEED" ]; then
            echo ""
            echo "The "
            echo "$S_FP_SEED"
            echo "is a folder, but it is expected to be a file."
            echo ""
            exit
        fi
    fi # else
    #---------------
    local S_FP_DEST="$S_FP_SEED.torrent"
    if [ -h "$S_FP_DEST" ]; then
                echo ""
                echo "The "
                echo "$S_FP_DEST"
                echo "is a symbolic link, but it should be "
                echo "either missing or be a file. "
                echo "Something is wrong. Aborting script."
                exit
    else # not a symbolic link
        if [ -e "$S_FP_DEST" ]; then
            if [ -d "$S_FP_DEST" ]; then
                echo ""
                echo "The "
                echo "$S_FP_DEST"
                echo "is a folder, but it is expected to be either missing or to be a file."
                echo "Something is wrong. Aborting script."
                echo ""
                exit
            fi
        fi
    fi # else
    #---------------
    export func_mmmv_angervaks_generate_single_torrent_file_S_FP_SEED="$S_FP_SEED"
    local S_FP_FILENAME=`ruby -e "s=ENV[\"func_mmmv_angervaks_generate_single_torrent_file_S_FP_SEED\"];print (s.reverse)[0..(s.reverse.index(\"/\")-1)].reverse"`
    #---------------
    rm -f $S_FP_DEST
    local S_CMD_MKTORRENT_PART_1="mktorrent -a udp://tracker.publicbt.com:80/announce,udp://tracker.openbittorrent.com:80/announce,udp://tracker.istole.it:80,udp://tracker.ccc.de:80 -w "

    local S_SCRIPT_0="$S_CMD_MKTORRENT_PART_1 $S_SEED_MACHINE_URL/bittorrent_seeds/$S_FP_FILENAME $S_FP_SEED"
    $S_SCRIPT_0
} # func_mmmv_angervaks_generate_single_torrent_file

#--------------------------------------------------------------------------


func_mmmv_ar_ls_bz2_t1() { # S_ARRAY_VARIABLE_NAME S_FP_LS
    local S_ARRAY_VARIABLE_NAME=$1
    local S_FP_LS=$2
    #--------
    # The "ls -m " works on both, BSD and Linux.
    local AR_0=$( ls -m $S_FP_DIR/*.bz2 )
    #--------
    local S_SCRIPT_0="$S_ARRAY_VARIABLE_NAME=()"
    eval "$S_SCRIPT_0"
    local s_iter=""
    S_SCRIPT_0="$S_ARRAY_VARIABLE_NAME+=(\$s_iter)"
    local S_TMP_IFS="$IFS"
    # The IFS is an internal Bash variable, "Internal Field Separator".
    IFS="," # That should handle file names that contain spaces.
    for s_iter in ${AR_0[@]}; do
        eval "$S_SCRIPT_0"
    done
    IFS="$S_TMP_IFS"
    if [ -z "$IFS" ]; then  # The "-z" returns true, if the string length is zero.
        unset IFS
    fi
} # func_mmmv_ar_ls_bz2_t1


func_mmmv_angervaks_generate_torrent_files() { 
    local S_FP_PWD_ORIG="`pwd`"
    cd $S_FP_DIR
    #------------
    rm -f $S_FP_DIR/*.torrent
    func_mmmv_ar_ls_bz2_t1 "AR_FP_SEEDS" "$S_FP_DIR" 
    
    for s_iter in ${AR_FP_SEEDS[@]}; do
         # echo "AR_FP_SEEDS element:[$s_iter]" 
         func_mmmv_angervaks_generate_single_torrent_file "$s_iter"
    done
    #------------
    cd $S_FP_PWD_ORIG
} # func_mmmv_angervaks_generate_torrent_files
    
#--------------------------------------------------------------------------

S_SEED_MACHINE_URL="http://archivestoragenode1.softf1.com:1984/"

func_mmmv_angervaks_generate_torrent_files


#==========================================================================
S_FP_DIR="$S_FP_DIR_ORIG"

Git hoidla koopia uuendamis-skript

#!/usr/bin/env bash
#==========================================================================
S_FP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
S_TIMESTAMP="`date +%Y`_`date +%m`_`date +%d`_T_`date +%H`h_`date +%M`min_`date +%S`s"
S_FP_ARCHIVE="$S_FP_DIR/archives/$S_TIMESTAMP"
mkdir -p $S_FP_ARCHIVE

fun_update () {
    local AR_0=("mongo" "mongo-c-driver" "mongo-ruby-driver" "mongo-tools")
    local S_FP_FUNC_UPDATE_ORIG="`pwd`"
    for s_iter in ${AR_0[@]}; do
         S_FOLDER_NAME_OF_THE_LOCAL_COPY="$s_iter"
         echo ""
         echo "            Archiving a copy of $S_FOLDER_NAME_OF_THE_LOCAL_COPY"
         cp -f -R $S_FP_DIR/$S_FOLDER_NAME_OF_THE_LOCAL_COPY $S_FP_ARCHIVE/
         cd $S_FP_DIR/$S_FOLDER_NAME_OF_THE_LOCAL_COPY
         echo "Checking out a newer version of $S_FOLDER_NAME_OF_THE_LOCAL_COPY"
         #--------
         # downloads the newest version of the software to that folder.
         git pull --recurse-submodules
         #----
         # http://stackoverflow.com/questions/1030169/easy-way-pull-latest-of-all-submodules
         git submodule update --init --recursive
         #--------
         cd $S_FP_DIR
    done
    cd $S_FP_FUNC_UPDATE_ORIG
} # fun_update 


fun_update # is a call to the function
echo ""


Konsooli GUI

Dialoog 1

Allikas

#!/usr/bin/env bash
#=========================================================================
# Copy-pasted from 
# http://linuxgazette.net/101/sunil.html
DIALOG=${DIALOG=dialog}

$DIALOG --title " My first dialog" --clear \
        --yesno "Hello , this is my first dialog program" 10 30

case $? in
  0)
    echo "Yes chosen.";;
  1)
    echo "No chosen.";;
  255)
    echo "ESC pressed.";;
esac


xdialog/kdialog 1

Allikas

#!/usr/bin/env bash
#=========================================================================
# Copy-pasted from 
# http://xdialog.free.fr/doc/box.html

#xdialog --title "MESSAGE BOX" \
kdialog --title "MESSAGE BOX" \
        --yesno "Hi, this is a simple message box. You can use this to \
display any message you like. The box will remain until \
you press the ENTER key." 10 41

case $? in
  0)
    echo "OK";;
  1)
    echo "Uuu";;
#  255)
#    echo "Box closed.";
esac


Template Scripts