Built and tested basic structure of the source of debmirrorman, added build.sh for building the source into a single executable file from the individual .sh and .lib.sh files.
This commit is contained in:
99
source/build.sh
Executable file
99
source/build.sh
Executable file
@@ -0,0 +1,99 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ -z "${1}" ]]; then
|
||||
echo "Must give Bash filename..." >&2
|
||||
echo "Example:" >&2
|
||||
echo " $0 bashscript.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ${1: -3} != ".sh" ]]; then
|
||||
echo "Bash file ${1} does not have a .sh extension..." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ -f "${1}" ]]; then
|
||||
bashscript="${1}"
|
||||
else
|
||||
echo "Bash file ${1} does not exist..." >&2
|
||||
exit 3
|
||||
fi
|
||||
|
||||
declaration="$(head -1 "${bashscript}")"
|
||||
|
||||
if [[ ${declaration: -5} != '/bash' ]]; then
|
||||
echo "Bash file ${bashscript} does not invoke Bash binary..." >&2
|
||||
exit 4
|
||||
fi
|
||||
|
||||
pathtobash="${declaration:2}"
|
||||
|
||||
if [[ ! -f "${pathtobash}" ]]; then
|
||||
echo "Bash file ${bashscript} invokes Bash binary at invalid location ${pathtobash}..." >&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
builddatetime="$(date "+%y%m%d%H%M")"
|
||||
builddatestring="$(date)"
|
||||
|
||||
bashscriptfile="${bashscript##*/}"
|
||||
bashscriptpath="${bashscript%/*}"
|
||||
if [[ -z "${bashscriptpath}" || "${bashscriptpath}" == "${bashscriptfile}" ]]; then
|
||||
bashscriptpath="."
|
||||
fi
|
||||
|
||||
if [[ ! -f "${bashscriptpath}/build.count" ]]; then
|
||||
buildcount=1
|
||||
else
|
||||
buildcount=$(head -1 "${bashscriptpath}/build.count")
|
||||
#######################################################
|
||||
# Add Regex to check buildcount is an integer about 0 #
|
||||
#######################################################
|
||||
((buildcount++))
|
||||
fi
|
||||
echo ${buildcount} > "${bashscriptpath}/build.count"
|
||||
buildfile="${bashscriptfile%.*}"
|
||||
buildpath="./build-${builddatetime}-${buildcount}"
|
||||
|
||||
echo "Reading ${bashscriptfile}"
|
||||
echo "Project path ${bashscriptpath}"
|
||||
echo "Build number ${buildcount}"
|
||||
echo "Build date and time ${builddatetime}"
|
||||
echo "Build path ${buildpath}"
|
||||
echo "Writing to ${buildfile}"
|
||||
|
||||
isstart=true
|
||||
|
||||
mkdir -p "${buildpath}"
|
||||
while IFS= read -r line; do
|
||||
if [[ ${isstart} == true ]]; then
|
||||
echo "${line}" > "${buildpath}/${buildfile}"
|
||||
echo "## Built on ${builddatestring}" >> "${buildpath}/${buildfile}"
|
||||
echo "## Source script ${bashscriptfile}" >> "${buildpath}/${buildfile}"
|
||||
echo "## Project path ${bashscriptpath}" >> "${buildpath}/${buildfile}"
|
||||
echo "## Build number ${buildcount}" >> "${buildpath}/${buildfile}"
|
||||
echo "## Build path ${buildpath}" >> "${buildpath}/${buildfile}"
|
||||
echo "## Build file ${buildfile}" >> "${buildpath}/${buildfile}"
|
||||
echo >> "${buildpath}/${buildfile}"
|
||||
isstart=false
|
||||
else
|
||||
if [[ "$line" =~ ^[[:space:]]*source[[:space:]]+([^[:space:]]+\.lib\.sh)[[:space:]]*$ ]]; then
|
||||
library="${BASH_REMATCH[1]}"
|
||||
#if [[ ${line} =~ ^source && ${line} =~ \.lib\.sh$ ]]; then
|
||||
# library="${line:7}"
|
||||
if [[ -f "${bashscriptpath}/${library}" ]]; then
|
||||
echo "Importing library ${library} from path ${bashscriptpath}"
|
||||
cat "${bashscriptpath}/${library}" >> "${buildpath}/${buildfile}"
|
||||
echo >> "${buildpath}/${buildfile}"
|
||||
else
|
||||
echo "Library ${library} not found at ${bashscriptpath}"
|
||||
echo "Build failed!"
|
||||
exit 6
|
||||
fi
|
||||
else
|
||||
echo "${line}" >> "${buildpath}/${buildfile}"
|
||||
fi
|
||||
fi
|
||||
done < "${bashscript}"
|
||||
chmod +x "${buildpath}/${buildfile}"
|
||||
echo "Build complete!"
|
||||
Reference in New Issue
Block a user