From 2188cab275f4a361f57a3fdd6912ca7b35386cd5 Mon Sep 17 00:00:00 2001 From: Peter Forret Date: Sun, 19 May 2024 13:50:06 +0200 Subject: [PATCH] MOD: script.sh --- template/script.sh | 316 +++++++++++++++++++++++---------------------- 1 file changed, 162 insertions(+), 154 deletions(-) diff --git a/template/script.sh b/template/script.sh index 5db1b05..38681f7 100755 --- a/template/script.sh +++ b/template/script.sh @@ -13,19 +13,13 @@ readonly script_author="author@email.com" readonly script_created="meta_today" readonly run_as_root=-1 # run_as_root: 0 = don't check anything / 1 = script MUST run as root / -1 = script MAY NOT run as root readonly script_description="package_description" -## some initialisation -action="" -script_prefix="" -script_basename="" -install_package="" -temp_files=() function Option:config() { ### Change the next lines to reflect which flags/options/parameters you need ### flag: switch a flag 'on' / no value specified ### flag||| - ### e.g. "-v" or "--verbose" for verbose output / default is always 'off' - ### will be available as $ in the script e.g. $verbose + ### e.g. "-v" or "--VERBOSE" for VERBOSE output / default is always 'off' + ### will be available as $ in the script e.g. $VERBOSE ### option: set an option / 1 value specified ### option|||| ### e.g. "-e " or "--extension " for a file extension @@ -43,14 +37,15 @@ function Option:config() { ### choice: is like a param, but when there are limited options ### choice||||choice1,choice2,... ### = 1 for single parameters - e.g. param|1|output expects 1 parameter - grep <<< " + grep <<<" #commented lines will be filtered flag|h|help|show usage -flag|q|quiet|no output -flag|v|verbose|also show debug messages -flag|f|force|do not ask for confirmation (always yes) -option|l|log_dir|folder for log files |$HOME/log/$script_prefix -option|t|tmp_dir|folder for temp files|/tmp/$script_prefix +flag|Q|QUIET|no output +flag|V|VERBOSE|also show debug messages +flag|f|FORCE|do not ask for confirmation (always yes) +option|L|LOG_DIR|folder for log files |$HOME/log/$script_prefix +option|T|TMP_DIR|folder for temp files|/tmp/$script_prefix +#option|W|WIDTH|width of the picture|800 choice|1|action|action to perform|action1,action2,check,env,update param|?|input|input file/text " -v -e '^#' -e '^\s*$' @@ -66,37 +61,44 @@ function Script:main() { Os:require "awk" case "${action,,}" in - action1) - #TIP: use «$script_prefix action1» to ... - #TIP:> $script_prefix action1 - do_action1 - ;; - - action2) - #TIP: use «$script_prefix action2» to ... - #TIP:> $script_prefix action2 - do_action2 - ;; - - check | env) - ## leave this default action, it will make it easier to test your script - #TIP: use «$script_prefix check» to check if this script is ready to execute and what values the options/flags are - #TIP:> $script_prefix check - #TIP: use «$script_prefix env» to generate an example .env file - #TIP:> $script_prefix env > .env - Script:check - ;; - - update) - ## leave this default action, it will make it easier to test your script - #TIP: use «$script_prefix update» to update to the latest version - #TIP:> $script_prefix update - Script:git_pull - ;; - - *) - IO:die "action [$action] not recognized" - ;; + action1) + #TIP: use «$script_prefix action1» to ... + #TIP:> $script_prefix action1 + do_action1 + ;; + + action2) + #TIP: use «$script_prefix action2» to ... + #TIP:> $script_prefix action2 + do_action2 + ;; + + action3) + #TIP: use «$script_prefix action3» to ... + #TIP:> $script_prefix action3 + # Os:require "convert" "imagemagick" + # CONVERT $input $output + ;; + + check | env) + ## leave this default action, it will make it easier to test your script + #TIP: use «$script_prefix check» to check if this script is ready to execute and what values the options/flags are + #TIP:> $script_prefix check + #TIP: use «$script_prefix env» to generate an example .env file + #TIP:> $script_prefix env > .env + Script:check + ;; + + update) + ## leave this default action, it will make it easier to test your script + #TIP: use «$script_prefix update» to update to the latest version + #TIP:> $script_prefix update + Script:git_pull + ;; + + *) + IO:die "action [$action] not recognized" + ;; esac IO:log "[$script_basename] ended after $SECONDS secs" #TIP: >>> bash script created with «pforret/bashew» @@ -126,21 +128,37 @@ function do_action2() { ################### DO NOT MODIFY BELOW THIS LINE ################### ##################################################################### +action="" +git_repo_remote="" +git_repo_root="" +install_package="" +os_kernel="" +os_machine="" +os_name="" +os_version="" +script_basename="" +script_hash="?" +script_lines="?" +script_prefix="" +shell_brand="" +shell_version="" +temp_files=() + # set strict mode - via http://redsymbol.net/articles/unofficial-bash-strict-mode/ # removed -e because it made basic [[ testing ]] difficult set -uo pipefail IFS=$'\n\t' -force=0 +FORCE=0 help=0 error_prefix="" -#to enable verbose even before option parsing -verbose=0 -[[ $# -gt 0 ]] && [[ $1 == "-v" ]] && verbose=1 +#to enable VERBOSE even before option parsing +VERBOSE=0 +[[ $# -gt 0 ]] && [[ $1 == "-v" ]] && VERBOSE=1 -#to enable quiet even before option parsing -quiet=0 -[[ $# -gt 0 ]] && [[ $1 == "-q" ]] && quiet=1 +#to enable QUIET even before option parsing +QUIET=0 +[[ $# -gt 0 ]] && [[ $1 == "-q" ]] && QUIET=1 txtReset="" txtError="" @@ -167,7 +185,7 @@ function IO:initialize() { [[ "${BASH_SOURCE[0]:-}" != "${0}" ]] && sourced=1 || sourced=0 [[ -t 1 ]] && piped=0 || piped=1 # detect if output is piped - if [[ $piped -eq 0 ]]; then + if [[ $piped -eq 0 && -n "$TERM" ]]; then txtReset=$(tput sgr0) txtError=$(tput setaf 160) txtInfo=$(tput setaf 2) @@ -192,17 +210,17 @@ function IO:initialize() { } function IO:print() { - ((quiet)) && true || printf '%b\n' "$*" + ((QUIET)) && true || printf '%b\n' "$*" } function IO:debug() { - ((verbose)) && IO:print "${txtInfo}# $* ${txtReset}" >&2 + ((VERBOSE)) && IO:print "${txtInfo}# $* ${txtReset}" >&2 true } function IO:die() { IO:print "${txtError}${char_fail} $script_basename${txtReset}: $*" >&2 - tput bel + Os:beep Script:exit } @@ -220,9 +238,9 @@ function IO:announce() { } function IO:progress() { - ((quiet)) || ( + ((QUIET)) || ( local screen_width - screen_width=$(tput cols 2> /dev/null || echo 80) + screen_width=$(tput cols 2>/dev/null || echo 80) local rest_of_line rest_of_line=$((screen_width - 5)) @@ -251,7 +269,7 @@ function IO:countdown() { ### interactive function IO:confirm() { - ((force)) && return 0 + ((FORCE)) && return 0 read -r -p "$1 [y/N] " -n 1 echo " " [[ $REPLY =~ ^[Yy]$ ]] @@ -265,7 +283,7 @@ function IO:question() { } function IO:log() { - [[ -n "${log_file:-}" ]] && echo "$(date '+%H:%M:%S') | $*" >> "$log_file" + [[ -n "${log_file:-}" ]] && echo "$(date '+%H:%M:%S') | $*" >>"$log_file" } function Tool:calc() { @@ -290,7 +308,7 @@ function Tool:time() { python3 -c 'import time; print(time.time()) ' elif [[ $(command -v node) ]]; then node -e 'console.log(+new Date() / 1000)' - elif [[ $(command -v ruby) ]] ; then + elif [[ $(command -v ruby) ]]; then ruby -e 'STDOUT.puts(Time.now.to_f)' else date '+%s.000' @@ -309,14 +327,14 @@ function Tool:throughput() { time_finished="$(Tool:time)" duration="$(Tool:calc "$time_finished - $time_started")" seconds="$(Tool:round "$duration")" - if [[ "$operations" -gt 1 ]] ; then - if [[ $operations -gt $seconds ]] ; then - ops=$(Tool:calc "$operations / $duration" ) + if [[ "$operations" -gt 1 ]]; then + if [[ $operations -gt $seconds ]]; then + ops=$(Tool:calc "$operations / $duration") ops=$(Tool:round "$ops" 3) duration=$(Tool:round "$duration" 2) IO:print "$operations $name finished in $duration secs: $ops $name/sec" else - ops=$(Tool:calc "$duration / $operations" ) + ops=$(Tool:calc "$duration / $operations") ops=$(Tool:round "$ops" 3) duration=$(Tool:round "$duration" 2) IO:print "$operations $name finished in $duration secs: $ops sec/$name" @@ -415,15 +433,17 @@ function Str:digest() { function Gha:finish() { [[ -z "${RUNNER_OS:-}" ]] && IO:die "This should only run inside a Github Action, don't run it on your machine" + local timestamp message git config user.name "Bashew Runner" git config user.email "actions@users.noreply.github.com" - timestamp=$(date -u) - message="$timestamp < $script_basename $script_version" git add -A + timestamp="$(date -u)" + message="$timestamp < $script_basename $script_version" + IO:print "Commit Message: $message" git commit -m "${message}" || exit 0 git pull --rebase git push - exit 0 + IO:success "Commit OK!" } trap "IO:die \"ERROR \$? after \$SECONDS seconds \n\ @@ -447,18 +467,18 @@ Script:exit() { Script:check_version() { ( # shellcheck disable=SC2164 - pushd "$script_install_folder" &> /dev/null + pushd "$script_install_folder" &>/dev/null if [[ -d .git ]]; then local remote remote="$(git remote -v | grep fetch | awk 'NR == 1 {print $2}')" IO:progress "Check for latest version - $remote" - git remote update &> /dev/null - if [[ $(git rev-list --count "HEAD...HEAD@{upstream}" 2> /dev/null) -gt 0 ]]; then + git remote update &>/dev/null + if [[ $(git rev-list --count "HEAD...HEAD@{upstream}" 2>/dev/null) -gt 0 ]]; then IO:print "There is a more recent update of this script - run <<$script_prefix update>> to update" fi fi # shellcheck disable=SC2164 - popd &> /dev/null + popd &>/dev/null ) } @@ -473,7 +493,7 @@ Script:git_pull() { Script:show_tips() { ((sourced)) && return 0 # shellcheck disable=SC2016 - grep < "${BASH_SOURCE[0]}" -v '$0' | + grep <"${BASH_SOURCE[0]}" -v '$0' | awk \ -v green="$txtInfo" \ -v yellow="$txtWarn" \ @@ -497,6 +517,7 @@ Script:check() { if [[ -n $(Option:filter flag) ]]; then IO:print "## ${txtInfo}boolean flags${txtReset}:" Option:filter flag | + grep -v help | while read -r name; do declare -p "$name" | cut -d' ' -f3- done @@ -550,7 +571,7 @@ Option:usage() { IO:print "Program : ${txtInfo}$script_basename${txtReset} by ${txtWarn}$script_author${txtReset}" IO:print "Version : ${txtInfo}v$script_version${txtReset} (${txtWarn}$script_modified${txtReset})" IO:print "Purpose : ${txtInfo}$script_description${txtReset}" - echo -n "Usage : $script_basename" + echo -n "Usage : $script_basename" Option:config | awk ' BEGIN { FS="|"; OFS=" "; oneline="" ; fulltext="Flags, options and parameters:"} @@ -616,7 +637,7 @@ function Script:show_required() { function Option:initialize() { local init_command init_command=$(Option:config | - grep -v "verbose|" | + grep -v "VERBOSE|" | awk ' BEGIN { FS="|"; OFS=" ";} $1 ~ /flag/ && $5 == "" {print $3 "=0; "} @@ -632,10 +653,10 @@ function Option:initialize() { fi } -function Option:has_single() { Option:config | grep 'param|1|' > /dev/null; } -function Option:has_choice() { Option:config | grep 'choice|1' > /dev/null; } -function Option:has_optional() { Option:config | grep 'param|?|' > /dev/null; } -function Option:has_multi() { Option:config | grep 'param|n|' > /dev/null; } +function Option:has_single() { Option:config | grep 'param|1|' >/dev/null; } +function Option:has_choice() { Option:config | grep 'choice|1' >/dev/null; } +function Option:has_optional() { Option:config | grep 'param|?|' >/dev/null; } +function Option:has_multi() { Option:config | grep 'param|n|' >/dev/null; } function Option:parse() { if [[ $# -eq 0 ]]; then @@ -669,7 +690,7 @@ function Option:parse() { $1 ~ /secret/ && "--"$3 == opt {print $3"=${2:-}; shift #noshow"} ') if [[ -n "$save_option" ]]; then - if echo "$save_option" | grep shift >> /dev/null; then + if echo "$save_option" | grep shift >>/dev/null; then local save_var save_var=$(echo "$save_option" | cut -d= -f1) IO:debug "$config_icon parameter: ${save_var}=$2" @@ -701,8 +722,8 @@ function Option:parse() { choices=$(Option:config | awk -F"|" ' $1 == "choice" && $2 == 1 {print $3} ') - option_list=$(xargs <<< "$choices") - option_count=$(wc <<< "$choices" -w | xargs) + option_list=$(xargs <<<"$choices") + option_count=$(wc <<<"$choices" -w | xargs) IO:debug "$config_icon Expect : $option_count choice(s): $option_list" [[ $# -eq 0 ]] && IO:die "need the choice(s) [$option_list]" @@ -714,7 +735,7 @@ function Option:parse() { IO:debug "$config_icon Assign : $param=$1" # check if choice is in list choices_list=$(Option:config | awk -F"|" -v choice="$param" '$1 == "choice" && $3 = choice {print $5}') - valid_choice=$(tr <<< "$choices_list" "," "\n" | grep "$1") + valid_choice=$(tr <<<"$choices_list" "," "\n" | grep "$1") [[ -z "$valid_choice" ]] && IO:die "choice [$1] is not valid, should be in list [$choices_list]" eval "$param=\"$1\"" @@ -730,8 +751,8 @@ function Option:parse() { single_params=$(Option:config | awk -F"|" ' $1 == "param" && $2 == 1 {print $3} ') - option_list=$(xargs <<< "$single_params") - option_count=$(wc <<< "$single_params" -w | xargs) + option_list=$(xargs <<<"$single_params") + option_count=$(wc <<<"$single_params" -w | xargs) IO:debug "$config_icon Expect : $option_count single parameter(s): $option_list" [[ $# -eq 0 ]] && IO:die "need the parameter(s) [$option_list]" @@ -752,7 +773,7 @@ function Option:parse() { local optional_params local optional_count optional_params=$(Option:config | grep 'param|?|' | cut -d'|' -f3) - optional_count=$(wc <<< "$optional_params" -w | xargs) + optional_count=$(wc <<<"$optional_params" -w | xargs) IO:debug "$config_icon Expect : $optional_count optional parameter(s): $(echo "$optional_params" | xargs)" for param in $optional_params; do @@ -794,7 +815,7 @@ function Os:require() { local path_binary # $1 = binary that is required binary="$1" - path_binary=$(command -v "$binary" 2> /dev/null) + path_binary=$(command -v "$binary" 2>/dev/null) [[ -n "$path_binary" ]] && IO:debug "️$require_icon required [$binary] -> $path_binary" && return 0 # $2 = how to install it IO:alert "$script_basename needs [$binary] but it cannot be found" @@ -802,7 +823,7 @@ function Os:require() { install_instructions="$install_package $1" [[ $words -eq 1 ]] && install_instructions="$install_package $2" [[ $words -gt 1 ]] && install_instructions="${2:-}" - if ((force)); then + if ((FORCE)); then IO:announce "Installing [$1] ..." eval "$install_instructions" else @@ -829,12 +850,12 @@ function Os:folder() { function Os:follow_link() { [[ ! -L "$1" ]] && echo "$1" && return 0 ## if it's not a symbolic link, return immediately local file_folder link_folder link_name symlink - file_folder="$(dirname "$1")" ## check if file has absolute/relative/no path - [[ "$file_folder" != /* ]] && file_folder="$(cd -P "$file_folder" &> /dev/null && pwd)" ## a relative path was given, resolve it - symlink=$(readlink "$1") ## follow the link - link_folder=$(dirname "$symlink") ## check if link has absolute/relative/no path - [[ -z "$link_folder" ]] && link_folder="$file_folder" ## if no link path, stay in same folder - [[ "$link_folder" == \.* ]] && link_folder="$(cd -P "$file_folder" && cd -P "$link_folder" &> /dev/null && pwd)" ## a relative link path was given, resolve it + file_folder="$(dirname "$1")" ## check if file has absolute/relative/no path + [[ "$file_folder" != /* ]] && file_folder="$(cd -P "$file_folder" &>/dev/null && pwd)" ## a relative path was given, resolve it + symlink=$(readlink "$1") ## follow the link + link_folder=$(dirname "$symlink") ## check if link has absolute/relative/no path + [[ -z "$link_folder" ]] && link_folder="$file_folder" ## if no link path, stay in same folder + [[ "$link_folder" == \.* ]] && link_folder="$(cd -P "$file_folder" && cd -P "$link_folder" &>/dev/null && pwd)" ## a relative link path was given, resolve it link_name=$(basename "$symlink") IO:debug "$info_icon Symbolic ln: $1 -> [$link_folder/$link_name]" Os:follow_link "$link_folder/$link_name" ## recurse @@ -855,7 +876,7 @@ function Os:busy() { local message="${2:-}" local frames=("|" "/" "-" "\\") ( - while kill -0 "$pid" &> /dev/null; do + while kill -0 "$pid" &>/dev/null; do for frame in "${frames[@]}"; do printf "\r[ $frame ] %s..." "$message" sleep 0.5 @@ -866,25 +887,12 @@ function Os:busy() { } function Os:beep() { - local type="${1=-info}" - case $type in - *) - tput bel - ;; - esac + if [[ -n "$TERM" ]]; then + tput bel + fi } function Script:meta() { - git_repo_remote="" - git_repo_root="" - os_kernel="" - os_machine="" - os_name="" - os_version="" - script_hash="?" - script_lines="?" - shell_brand="" - shell_version="" script_prefix=$(basename "${BASH_SOURCE[0]}" .sh) script_basename=$(basename "${BASH_SOURCE[0]}") @@ -897,8 +905,8 @@ function Script:meta() { script_install_folder="$(cd -P "$(dirname "$script_install_path")" && pwd)" IO:debug "$info_icon In folder : $script_install_folder" if [[ -f "$script_install_path" ]]; then - script_hash=$(Str:digest < "$script_install_path" 8) - script_lines=$(awk < "$script_install_path" 'END {print NR}') + script_hash=$(Str:digest <"$script_install_path" 8) + script_lines=$(awk <"$script_install_path" 'END {print NR}') fi # get shell/operating system/versions @@ -918,35 +926,35 @@ function Script:meta() { os_machine=$(uname -m) install_package="" case "$os_kernel" in - CYGWIN* | MSYS* | MINGW*) - os_name="Windows" - ;; - Darwin) - os_name=$(sw_vers -productName) # macOS - os_version=$(sw_vers -productVersion) # 11.1 - install_package="brew install" - ;; - Linux | GNU*) - if [[ $(command -v lsb_release) ]]; then - # 'normal' Linux distributions - os_name=$(lsb_release -i | awk -F: '{$1=""; gsub(/^[\s\t]+/,"",$2); gsub(/[\s\t]+$/,"",$2); print $2}') # Ubuntu/Raspbian - os_version=$(lsb_release -r | awk -F: '{$1=""; gsub(/^[\s\t]+/,"",$2); gsub(/[\s\t]+$/,"",$2); print $2}') # 20.04 - else - # Synology, QNAP, - os_name="Linux" - fi - [[ -x /bin/apt-cyg ]] && install_package="apt-cyg install" # Cygwin - [[ -x /bin/dpkg ]] && install_package="dpkg -i" # Synology - [[ -x /opt/bin/ipkg ]] && install_package="ipkg install" # Synology - [[ -x /usr/sbin/pkg ]] && install_package="pkg install" # BSD - [[ -x /usr/bin/pacman ]] && install_package="pacman -S" # Arch Linux - [[ -x /usr/bin/zypper ]] && install_package="zypper install" # Suse Linux - [[ -x /usr/bin/emerge ]] && install_package="emerge" # Gentoo - [[ -x /usr/bin/yum ]] && install_package="yum install" # RedHat RHEL/CentOS/Fedora - [[ -x /usr/bin/apk ]] && install_package="apk add" # Alpine - [[ -x /usr/bin/apt-get ]] && install_package="apt-get install" # Debian - [[ -x /usr/bin/apt ]] && install_package="apt install" # Ubuntu - ;; + CYGWIN* | MSYS* | MINGW*) + os_name="Windows" + ;; + Darwin) + os_name=$(sw_vers -productName) # macOS + os_version=$(sw_vers -productVersion) # 11.1 + install_package="brew install" + ;; + Linux | GNU*) + if [[ $(command -v lsb_release) ]]; then + # 'normal' Linux distributions + os_name=$(lsb_release -i | awk -F: '{$1=""; gsub(/^[\s\t]+/,"",$2); gsub(/[\s\t]+$/,"",$2); print $2}') # Ubuntu/Raspbian + os_version=$(lsb_release -r | awk -F: '{$1=""; gsub(/^[\s\t]+/,"",$2); gsub(/[\s\t]+$/,"",$2); print $2}') # 20.04 + else + # Synology, QNAP, + os_name="Linux" + fi + [[ -x /bin/apt-cyg ]] && install_package="apt-cyg install" # Cygwin + [[ -x /bin/dpkg ]] && install_package="dpkg -i" # Synology + [[ -x /opt/bin/ipkg ]] && install_package="ipkg install" # Synology + [[ -x /usr/sbin/pkg ]] && install_package="pkg install" # BSD + [[ -x /usr/bin/pacman ]] && install_package="pacman -S" # Arch Linux + [[ -x /usr/bin/zypper ]] && install_package="zypper install" # Suse Linux + [[ -x /usr/bin/emerge ]] && install_package="emerge" # Gentoo + [[ -x /usr/bin/yum ]] && install_package="yum install" # RedHat RHEL/CentOS/Fedora + [[ -x /usr/bin/apk ]] && install_package="apk add" # Alpine + [[ -x /usr/bin/apt-get ]] && install_package="apt-get install" # Debian + [[ -x /usr/bin/apt ]] && install_package="apt install" # Ubuntu + ;; esac IO:debug "$info_icon System OS : $os_name ($os_kernel) $os_version on $os_machine" @@ -954,8 +962,8 @@ function Script:meta() { # get last modified date of this script script_modified="??" - [[ "$os_kernel" == "Linux" ]] && script_modified=$(stat -c %y "$script_install_path" 2> /dev/null | cut -c1-16) # generic linux - [[ "$os_kernel" == "Darwin" ]] && script_modified=$(stat -f "%Sm" "$script_install_path" 2> /dev/null) # for MacOS + [[ "$os_kernel" == "Linux" ]] && script_modified=$(stat -c %y "$script_install_path" 2>/dev/null | cut -c1-16) # generic linux + [[ "$os_kernel" == "Darwin" ]] && script_modified=$(stat -f "%Sm" "$script_install_path" 2>/dev/null) # for MacOS IO:debug "$info_icon Version : $script_version" IO:debug "$info_icon Created : $script_created" @@ -965,7 +973,7 @@ function Script:meta() { IO:debug "$info_icon User : $USER@$HOSTNAME" # if run inside a git repo, detect for which remote repo it is - if git status &> /dev/null; then + if git status &>/dev/null; then git_repo_remote=$(git remote -v | awk '/(fetch)/ {print $2}') IO:debug "$info_icon git remote : $git_repo_remote" git_repo_root=$(git rev-parse --show-toplevel) @@ -975,26 +983,26 @@ function Script:meta() { # get script version from VERSION.md file - which is automatically updated by pforret/setver [[ -f "$script_install_folder/VERSION.md" ]] && script_version=$(cat "$script_install_folder/VERSION.md") # get script version from git tag file - which is automatically updated by pforret/setver - [[ -n "$git_repo_root" ]] && [[ -n "$(git tag &> /dev/null)" ]] && script_version=$(git tag --sort=version:refname | tail -1) + [[ -n "$git_repo_root" ]] && [[ -n "$(git tag &>/dev/null)" ]] && script_version=$(git tag --sort=version:refname | tail -1) } function Script:initialize() { log_file="" - if [[ -n "${tmp_dir:-}" ]]; then + if [[ -n "${TMP_DIR:-}" ]]; then # clean up TMP folder after 1 day - Os:folder "$tmp_dir" 1 + Os:folder "$TMP_DIR" 1 fi - if [[ -n "${log_dir:-}" ]]; then + if [[ -n "${LOG_DIR:-}" ]]; then # clean up LOG folder after 1 month - Os:folder "$log_dir" 30 - log_file="$log_dir/$script_prefix.$execution_day.log" + Os:folder "$LOG_DIR" 30 + log_file="$LOG_DIR/$script_prefix.$execution_day.log" IO:debug "$config_icon log_file: $log_file" fi } function Os:tempfile() { local extension=${1:-txt} - local file="${tmp_dir:-/tmp}/$execution_day.$RANDOM.$extension" + local file="${TMP_DIR:-/tmp}/$execution_day.$RANDOM.$extension" IO:debug "$config_icon tmp_file: $file" temp_files+=("$file") echo "$file" @@ -1035,7 +1043,7 @@ function Os:clean_env() { local output="$1.__.sh" [[ ! -f "$input" ]] && IO:die "Input file [$input] does not exist" IO:debug "$clean_icon Clean dotenv: [$output]" - awk < "$input" ' + awk <"$input" ' function ltrim(s) { sub(/^[ \t\r\n]+/, "", s); return s } function rtrim(s) { sub(/[ \t\r\n]+$/, "", s); return s } function trim(s) { return rtrim(ltrim(s)); } @@ -1052,7 +1060,7 @@ function Os:clean_env() { } } } - ' > "$output" + ' >"$output" echo "$output" }