Files
rdlink/build.sh

85 lines
2.7 KiB
Bash
Executable File

#!/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