Generating also starter.sh from rdlink.sh to serve as "origin finder"
This commit is contained in:
113
build.sh
113
build.sh
@@ -1,23 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
build::rdlink() {
|
build::addLicense() {
|
||||||
readonly build_dir="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
|
local target="${1:?}"
|
||||||
readonly rdlinkRelease="${build_dir}/release/rdlink.sh"
|
local licenseText="#
|
||||||
readonly color_green='\033[1;32m'
|
|
||||||
readonly color_red='\033[1;31m'
|
|
||||||
readonly color_less='\033[0m'
|
|
||||||
readonly shellcheck_cmd="$(command -v shellcheck)"
|
|
||||||
readonly fileHeader="#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# rdlink [OPTIONS] <PATH>
|
|
||||||
# [OPTION]
|
|
||||||
# -- : End of options marker
|
|
||||||
# -* : Other options are ignored
|
|
||||||
#
|
|
||||||
# Version: $(git describe --long --tags --always --dirty)
|
|
||||||
# Author: Martin Winkler
|
|
||||||
# Origin: https://winklerfamilie.eu/git/efelon/rdlink.git
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
@@ -32,51 +17,111 @@ build::rdlink() {
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
"
|
"
|
||||||
|
printf '%s' "${licenseText}" >> "${target}"
|
||||||
|
}
|
||||||
|
|
||||||
|
build::headerRdlink() {
|
||||||
|
local target="${1:?}"
|
||||||
|
local fileHeader="#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# rdlink.sh [OPTIONS] <PATH>
|
||||||
|
# [OPTION]
|
||||||
|
# -- : End of options marker
|
||||||
|
# -* : Other options are ignored
|
||||||
|
#
|
||||||
|
# Version: $(git describe --long --tags --always --dirty)
|
||||||
|
# Author: Martin Winkler
|
||||||
|
# Origin: https://winklerfamilie.eu/git/efelon/rdlink.git
|
||||||
|
"
|
||||||
|
printf '%s' "${fileHeader}" > "${target}"
|
||||||
|
build::addLicense "${target}"
|
||||||
|
}
|
||||||
|
|
||||||
|
build::headerStarter() {
|
||||||
|
local target="${1:?}"
|
||||||
|
local fileHeader="#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# starter.sh
|
||||||
|
#
|
||||||
|
# Start or source your application at the end to have the
|
||||||
|
# environment variable \$_origin available.
|
||||||
|
#
|
||||||
|
# Version: $(git describe --long --tags --always --dirty)
|
||||||
|
# Author: Martin Winkler
|
||||||
|
# Origin: https://winklerfamilie.eu/git/efelon/rdlink.git
|
||||||
|
"
|
||||||
|
printf '%s' "${fileHeader}" > "${target}"
|
||||||
|
build::addLicense "${target}"
|
||||||
|
}
|
||||||
|
|
||||||
|
build::rdlink() {
|
||||||
|
readonly build_dir="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
|
||||||
|
readonly rdlinkRelease="${build_dir}/release/rdlink.sh"
|
||||||
|
readonly starterRelease="${build_dir}/release/starter.sh"
|
||||||
|
readonly color_green='\033[1;32m'
|
||||||
|
readonly color_red='\033[1;31m'
|
||||||
|
readonly color_less='\033[0m'
|
||||||
|
readonly shellcheck_cmd="$(command -v shellcheck)"
|
||||||
local testresult_graphic=
|
local testresult_graphic=
|
||||||
testresult_graphic="${color_green}✔${color_less}" # alt. symbol ✓
|
testresult_graphic="${color_green}✔${color_less}" # alt. symbol ✓
|
||||||
testresult_graphic_fail="${color_red}✗${color_less}" # alt. symbol ≠
|
testresult_graphic_fail="${color_red}✗${color_less}" # alt. symbol ≠
|
||||||
|
|
||||||
if ! mkdir -p "$(dirname -- "${rdlinkRelease}")" ; then
|
if ! mkdir -p "$(dirname -- "${rdlinkRelease}")" ; then
|
||||||
printf " [ERROR] Cannot create release directory\n"
|
printf ' [ERROR] Cannot create release directory\n'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "# Building rdlink release\n"
|
printf '# Building rdlink release\n'
|
||||||
|
|
||||||
# Write header
|
build::headerRdlink "${rdlinkRelease}"
|
||||||
printf "%s" "${fileHeader}" > "${rdlinkRelease}"
|
printf ' Extracting script part and removing debug information...'
|
||||||
|
|
||||||
printf " Extracting script part and removing debug information..."
|
|
||||||
# Get essential script content
|
# Get essential script content
|
||||||
# * extract script part
|
# * extract script part
|
||||||
# * remove script marker
|
# * remove script marker
|
||||||
# * remove debug function calls
|
# * remove debug function calls
|
||||||
# * remove debug options from rdlink
|
# * remove debug options from rdlink
|
||||||
# * replace multiple empty lines with one
|
# * replace multiple empty lines with one
|
||||||
#if cat "${build_dir}/rdlink.sh" \
|
|
||||||
# | sed -n '/### Script.*/,/### Script EOF/ p' \
|
|
||||||
# | sed '/### Script.*/d; /^[[:blank:]]*info/d; /-d\{1,2\}/,/;;/d' \
|
|
||||||
# | sed '/^$/N; /^\n$/D' \
|
|
||||||
# >> "${rdlinkRelease}" 2>/dev/null ; then
|
|
||||||
if sed -n '/### Script.*/,/### Script EOF/ p' < "${build_dir}/rdlink.sh" \
|
if sed -n '/### Script.*/,/### Script EOF/ p' < "${build_dir}/rdlink.sh" \
|
||||||
| sed '/### Script.*/d; /^[[:blank:]]*info/d; /-d\{1,2\}/,/;;/d' \
|
| sed '/### Script.*/d; /^[[:blank:]]*info/d; /-d\{1,2\}/,/;;/d' \
|
||||||
| sed '/^$/N; /^\n$/D' \
|
| sed '/^$/N; /^\n$/D' \
|
||||||
>> "${rdlinkRelease}" 2>/dev/null ; then
|
>> "${rdlinkRelease}" 2>/dev/null ; then
|
||||||
printf "%b" "${testresult_graphic}\n"
|
printf '%b' "${testresult_graphic}\n"
|
||||||
else
|
else
|
||||||
printf "%b" "${testresult_graphic_fail}\n"
|
printf '%b' "${testresult_graphic_fail}\n"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
{
|
||||||
|
build::headerStarter "${starterRelease}"
|
||||||
|
printf ' Building starter...'
|
||||||
|
if sed -n '/### Script.*/,/### Script Starter EOF/ p' < "${build_dir}/rdlink.sh" \
|
||||||
|
| sed '/### Script.*/d; /^[[:blank:]]*info/d; /-d\{1,2\}/,/;;/d' \
|
||||||
|
| sed '/^$/N; /^\n$/D' \
|
||||||
|
>> "${starterRelease}" 2>/dev/null ; then
|
||||||
|
printf '%b' "${testresult_graphic}\n"
|
||||||
|
else
|
||||||
|
printf '%b' "${testresult_graphic_fail}\n"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf '_origin="$(cd "$(dirname -- "$(rl::rdlink "${BASH_SOURCE[0]}")")" >/dev/null 2>&1 && pwd)"\n' >> "${starterRelease}"
|
||||||
|
printf 'export _origin\n\n' >> "${starterRelease}"
|
||||||
|
|
||||||
|
printf '# Uncomment one of the next lines and replace "tostart.sh" with your script\n' >> "${starterRelease}"
|
||||||
|
printf '# to have _origin available even on platform not supporting readlink -f.\n\n' >> "${starterRelease}"
|
||||||
|
printf '#bash "${_origin}/tostart.sh"\n' >> "${starterRelease}"
|
||||||
|
printf '#. "${_origin}/tostart.sh"\n' >> "${starterRelease}"
|
||||||
|
printf '#"${_origin}/tostart.sh"\n' >> "${starterRelease}"
|
||||||
|
}
|
||||||
|
|
||||||
if [[ "${shellcheck_cmd}" ]] ; then
|
if [[ "${shellcheck_cmd}" ]] ; then
|
||||||
printf "%b\n" " Running shellcheck...\033[1A\033[s\n"
|
printf '%b\n' " Running shellcheck...\033[1A\033[s\n"
|
||||||
if "${shellcheck_cmd}" "${rdlinkRelease}" ; then
|
if "${shellcheck_cmd}" "${rdlinkRelease}" ; then
|
||||||
printf "%b" "\033[u${testresult_graphic}\n"
|
printf '%b' "\033[u${testresult_graphic}\n"
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chmod +x "${rdlinkRelease}"
|
chmod +x "${rdlinkRelease}"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user