v2.1.0
This commit is contained in:
85
bootstrap.sh
Normal file
85
bootstrap.sh
Normal file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env bash
|
||||
CBUILD_BOOTSTRAP_VERSION=1.0.0
|
||||
set -eo pipefail
|
||||
|
||||
function version_parse {
|
||||
local value="$1"
|
||||
var_name="$2"
|
||||
IFS_backup="$IFS"
|
||||
IFS='.'
|
||||
local v_array=($value)
|
||||
IFS="$IFS_backup"
|
||||
eval ${var_name}_version_major=${v_array[0]}
|
||||
eval ${var_name}_version_minor=${v_array[1]}
|
||||
eval ${var_name}_version_patch=${v_array[2]}
|
||||
}
|
||||
|
||||
function safeprint {
|
||||
printf "%s" "$@"
|
||||
}
|
||||
|
||||
function exec_script_line {
|
||||
local script="$1"
|
||||
local line_num="$2"
|
||||
local line_str="$(sed $line_num'!d' $script)"
|
||||
if [ -z "$line_str" ]; then
|
||||
echo "script line is empty"
|
||||
exit 1
|
||||
fi
|
||||
eval "$line_str"
|
||||
}
|
||||
|
||||
# parse command line arguments
|
||||
project_config_path="./project.config"
|
||||
args=($@)
|
||||
args_count=${#args[@]}
|
||||
i=0
|
||||
|
||||
function get_next_arg {
|
||||
i=$((i+1))
|
||||
safeprint "${args[i]}"
|
||||
}
|
||||
|
||||
while [ $i -lt $args_count ]
|
||||
do
|
||||
case "${args[i]}" in
|
||||
'-v' | '--version')
|
||||
echo "cbuild-bootstrap v$CBUILD_BOOTSTRAP_VERSION"
|
||||
;;
|
||||
'-c' | '--config')
|
||||
project_config_path="$(get_next_arg)"
|
||||
;;
|
||||
'-n' | '--new-project')
|
||||
echo "enter project cbuild version (example: 2.1.0)"
|
||||
read -r CBUILD_VERSION
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
i=$((i+1))
|
||||
done
|
||||
|
||||
# read version from project config if not specified
|
||||
if [ -z "$CBUILD_VERSION" ]; then
|
||||
exec_script_line "$project_config_path" 2
|
||||
fi
|
||||
|
||||
version_parse "$CBUILD_VERSION"
|
||||
cbuild_ommand="cbuild${_version_major}.${_version_minor} $@"
|
||||
|
||||
LOG_FILE="$(realpath cbuild.log)"
|
||||
set +eo pipefail
|
||||
# enable logging stdout and stderr to file
|
||||
$cbuild_ommand 2>&1 | tee "$LOG_FILE"
|
||||
# log file can be deleted by clean task
|
||||
if [ -f "$LOG_FILE" ]; then
|
||||
# remove terminal escape codes
|
||||
sed -e 's/[^[:blank:][:print:]]//g' \
|
||||
-e 's/\[0;[0-9][0-9]m//g' \
|
||||
-e 's/\[0;[0-9]m//g' \
|
||||
-e 's/\[[0-9][0-9]m//g' \
|
||||
-e 's/\[[0-9]m//g' \
|
||||
-e 's/ H //g' \
|
||||
-e 's/\[3gH //g' \
|
||||
-i "$LOG_FILE"
|
||||
fi
|
||||
Reference in New Issue
Block a user