]> Frank Brehm's Git Trees - my-stuff/tools.git/commitdiff
Creating main loop
authorFrank Brehm <frank@brehm-online.com>
Sat, 18 Nov 2017 15:34:29 +0000 (16:34 +0100)
committerFrank Brehm <frank@brehm-online.com>
Sat, 18 Nov 2017 15:34:29 +0000 (16:34 +0100)
bin/convert-stack.sh

index bae2a1213475b0a299638ef94afc4377c285d5c4..53597ee490e274af6d975434643efdf1c3074c61 100755 (executable)
@@ -11,7 +11,7 @@ DEBUG="n"
 QUIET='n'
 SIMULATE="n"
 
-VERSION="0.2"
+VERSION="0.3"
 
 # console colors:
 RED=""
@@ -247,9 +247,13 @@ get_options() {
         exit 5
     fi
 
-    if [[ -n "${LINK_DIR}" && ! -d "${LINK_DIR}" ]] ; then
-        error "Given link directory '${RED}${LINK_DIR}${NORMAL}' does not exists."
-        exit 1
+    if [[ -n "${LINK_DIR}" ]] ; then
+        if [[ ! -d "${LINK_DIR}" ]] ; then
+            error "Given link directory '${RED}${LINK_DIR}${NORMAL}' does not exists."
+            exit 1
+        fi
+        LINK_DIR=$( readlink --canonicalize "${LINK_DIR}" )
+        debug "Directory for hard links is: '${LINK_DIR}'."
     fi
 
 }
@@ -312,18 +316,52 @@ LN() {
 ##
 ################################################################################
 
+#------------------------------------------------------------------------------
+perform_csv() {
+
+    local lnr=0
+    local oifs="${IFS}"
+    IFS="
+"
+
+    local -a lines=()
+    local line=
+
+    for line in $( cat "${CSV_FILE}" ); do
+        lines+=( $line )
+    done
+    IFS="$oifs"
+
+    for line in "${lines[@]}" ; do
+
+        lnr=$(( $lnr + 1 ))
+
+        if echo "${line}" | egrep -q '^[       ]*(#.*)?$' ; then
+            debug "Don't evaluate line ${lnr}: ${line}"
+            continue
+        fi
+        debug "Evaluating line ${lnr}: ${line}"
+
+    done
+
+}
+
 #------------------------------------------------------------------------------
 main() {
 
     get_options "$@"
+    if [[ "${SIMULATE}" == "y" ]] ; then
+        info "Simulation mode, nothing will be really done."
+        echo
+    fi
+
+    cd $( dirname "${CSV_FILE}" )
+    debug "Current directory is now: '$( pwd )'."
 
-#    prepare_dirs
-#    info "Starting backup ..."
-#    cleanup_old_backups
-#    get_zones
-#    backup_zones
+    info "Starting stack converting ..."
+    perform_csv
 
-#    empty_line
+    echo
     info "Finished."
 
 }