Introduce build script which extracts script logic and removes debug output
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
**/release
|
84
build.sh
Executable file
84
build.sh
Executable file
@@ -0,0 +1,84 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
build::rdlink() {
|
||||||
|
readonly build_dir="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
|
||||||
|
readonly rdlinkRelease="${build_dir}/release/rdlink.sh"
|
||||||
|
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
|
||||||
|
#
|
||||||
|
# License: GNU GPL V3 or later
|
||||||
|
# Author: Martin Winkler
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"
|
||||||
|
local testresult_graphic=
|
||||||
|
testresult_graphic="${color_green}✔${color_less}" # alt. symbol ✓
|
||||||
|
testresult_graphic_fail="${color_red}✗${color_less}" # alt. symbol ≠
|
||||||
|
|
||||||
|
if ! mkdir -p "$(dirname -- "${rdlinkRelease}")" ; then
|
||||||
|
printf " [ERROR] Cannot create release directory\n"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "# Building rdlink release\n"
|
||||||
|
|
||||||
|
# Write header
|
||||||
|
printf "%s" "${fileHeader}" > "${rdlinkRelease}"
|
||||||
|
|
||||||
|
printf " Extracting script part and removing debug information..."
|
||||||
|
# Get essential script content
|
||||||
|
# * extract script part
|
||||||
|
# * remove script marker
|
||||||
|
# * remove debug function calls
|
||||||
|
# * remove debug options from rdlink
|
||||||
|
# * 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" \
|
||||||
|
| sed '/### Script.*/d; /^[[:blank:]]*info/d; /-d\{1,2\}/,/;;/d' \
|
||||||
|
| sed '/^$/N; /^\n$/D' \
|
||||||
|
>> "${rdlinkRelease}" 2>/dev/null ; then
|
||||||
|
printf "%b" "${testresult_graphic}\n"
|
||||||
|
else
|
||||||
|
printf "%b" "${testresult_graphic_fail}\n"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${shellcheck_cmd}" ]] ; then
|
||||||
|
printf "%b\n" " Running shellcheck...\033[1A\033[s\n"
|
||||||
|
if "${shellcheck_cmd}" "${rdlinkRelease}" ; then
|
||||||
|
printf "%b" "\033[u${testresult_graphic}\n"
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
chmod +x "${rdlinkRelease}"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
build::rdlink
|
||||||
|
|
@@ -49,8 +49,7 @@ rl::rdlink() {
|
|||||||
|
|
||||||
# Follow multiple symlinks
|
# Follow multiple symlinks
|
||||||
while subject="$(rl::quicklink "${subject}")" ; do
|
while subject="$(rl::quicklink "${subject}")" ; do
|
||||||
# A link was resolved at least once
|
: # A link was resolved at least once
|
||||||
:
|
|
||||||
info " rl::rdlink - Link found: $subject"
|
info " rl::rdlink - Link found: $subject"
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -129,6 +128,7 @@ rl::canon() {
|
|||||||
|
|
||||||
subject="${work}${bname:+"/${bname}"}"
|
subject="${work}${bname:+"/${bname}"}"
|
||||||
info " rl::canon valid parent: ${subject}"
|
info " rl::canon valid parent: ${subject}"
|
||||||
|
|
||||||
# Special: Succeed with valid element after second run; see special below
|
# Special: Succeed with valid element after second run; see special below
|
||||||
# e.g. /root/.
|
# e.g. /root/.
|
||||||
# * /root is valid but not accessible
|
# * /root is valid but not accessible
|
||||||
@@ -165,8 +165,8 @@ rl::cleanpath() {
|
|||||||
local rex_tmp=
|
local rex_tmp=
|
||||||
|
|
||||||
info "Cleaning path... ${1:-}"
|
info "Cleaning path... ${1:-}"
|
||||||
|
|
||||||
work="${1:-}"
|
work="${1:-}"
|
||||||
|
|
||||||
# Remove multiple /
|
# Remove multiple /
|
||||||
while [[ "${work:-}" = *"//"* ]]; do
|
while [[ "${work:-}" = *"//"* ]]; do
|
||||||
work="${work//'//'/'/'}"
|
work="${work//'//'/'/'}"
|
||||||
@@ -180,8 +180,8 @@ rl::normalize() {
|
|||||||
local work=
|
local work=
|
||||||
|
|
||||||
info "Normalizing path... ${1:-}"
|
info "Normalizing path... ${1:-}"
|
||||||
|
|
||||||
work="${1:-}"
|
work="${1:-}"
|
||||||
|
|
||||||
# Remove dir/.. sequences.
|
# Remove dir/.. sequences.
|
||||||
local rex_tmp='[^/][^/]*/\.\./*'
|
local rex_tmp='[^/][^/]*/\.\./*'
|
||||||
while [[ "${work}" =~ $rex_tmp ]] ; do
|
while [[ "${work}" =~ $rex_tmp ]] ; do
|
||||||
|
Reference in New Issue
Block a user