Validate version string and clean up of subshell cmd sequences

This commit is contained in:
Xavier Moffett 2024-10-31 16:12:47 -04:00
parent e7fb0e3ca6
commit ed2a8ac1ca
Signed by: Sapphirus
GPG key ID: A6C061B2CEA1A7AC

18
dist/tools/common.sh vendored
View file

@ -81,18 +81,22 @@ layout_dir() {
#
package() {
[[ ! -f "$1" ]] && error_fatal "'$1': file not found"
([[ -z $1 ]] || [[ -z $2 ]] || [[ -z $3 ]]) && error_fatal "Invalid arguments."
[[ -z $1 ]] || [[ -z $2 ]] || [[ -z $3 ]] && error_fatal "Invalid arguments."
local version=$(version $3 $4)
local version_string=$(echo $version | head -n1 | sed -e 's/[]\/$*.^[]/\\&/g')
local version=$(version $3 $4)
local version_string=$(echo $version | sed -e 's/[]\/$*.^[]/\\&/g')
local placeholder="version_string_placeholder"
[[ -z "$version" ]] || [[ -z "$version_string" ]] && error_fatal "Version string undeclared"
sed -e "s/$placeholder/$version_string/g" < $1 > $2
packaged "${2##*/} v${version% (*}"
}
version() {
eval $(cat Cargo.toml | grep version | head -n1 | sed -e "s/version = /local version=/g")
eval $(grep -m 1 version Cargo.toml | sed -e "s/version = /local version=/g")
[[ -z "$version" ]] && return
if [[ ! -z "$(type -P git)" ]] && [[ -d ".git" ]]; then
local git=$(git rev-parse --short HEAD)
@ -101,9 +105,11 @@ version() {
local date=
case $1 in
release) release="RELEASE"
release)
release="RELEASE"
date=$(git log -1 --date=format:%d/%m/%Y --format=%cd);;
debug) release="DEV"
debug)
release="DEV"
date=$(date +'%d/%m/%Y %T%:z');;
esac