-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enter-tdd-jenkins-service.sh: Cleanups
Signed-off-by: Geoff Levand <[email protected]>
- Loading branch information
Showing
1 changed file
with
111 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,134 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
script_name="${0##*/}" | ||
|
||
usage () { | ||
usage() { | ||
local old_xtrace | ||
old_xtrace="$(shopt -po xtrace || :)" | ||
set +o xtrace | ||
echo "${script_name} - Enter tdd-jenkins.server container." >&2 | ||
echo "Usage: ${script_name} [flags]" >&2 | ||
echo "Option flags:" >&2 | ||
echo " -c --clean - Clean kernel rootfs files." >&2 | ||
echo " -h --help - Show this help and exit." >&2 | ||
echo " -v --verbose - Verbose execution." >&2 | ||
|
||
{ | ||
echo "${script_name} - Enter tdd-jenkins.service container." | ||
echo "Usage: ${script_name} [flags]" | ||
echo "Option flags:" | ||
echo " -c --clean - Clean kernel rootfs files. Default: '${clean}'." | ||
echo " -h --help - Show this help and exit." | ||
echo " -g --debug - Extra verbose execution. Default: '${debug}'." | ||
echo "Info:" | ||
print_project_info | ||
} >&2 | ||
eval "${old_xtrace}" | ||
} | ||
|
||
short_opts="chv" | ||
long_opts="clean,help,verbose" | ||
process_opts() { | ||
local short_opts='chg' | ||
local long_opts='clean,help,debug' | ||
|
||
opts=$(getopt --options ${short_opts} --long ${long_opts} -n "${script_name}" -- "$@") | ||
local opts | ||
opts=$(getopt --options ${short_opts} --long ${long_opts} -n "${script_name}" -- "$@") | ||
|
||
if [ $? != 0 ]; then | ||
echo "${script_name}: ERROR: Internal getopt" >&2 | ||
exit 1 | ||
fi | ||
eval set -- "${opts}" | ||
|
||
while true ; do | ||
# echo "${FUNCNAME[0]}: (${#}) '${*}'" | ||
case "${1}" in | ||
-c | --clean) | ||
clean=1 | ||
shift | ||
;; | ||
-h | --help) | ||
usage=1 | ||
shift | ||
;; | ||
-g | --debug) | ||
verbose=1 | ||
debug=1 | ||
set -x | ||
shift | ||
;; | ||
--) | ||
shift | ||
extra_args="${*}" | ||
break | ||
;; | ||
*) | ||
echo "${script_name}: ERROR: Internal opts: '${*}'" >&2 | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
} | ||
|
||
eval set -- "${opts}" | ||
|
||
while true ; do | ||
case "${1}" in | ||
-c | --clean) | ||
clean=1 | ||
shift | ||
;; | ||
-h | --help) | ||
usage=1 | ||
shift | ||
;; | ||
-v | --verbose) | ||
set -x | ||
verbose=1 | ||
export PS4='\[\e[0;33m\]+ ${BASH_SOURCE##*/}:${LINENO}:(${FUNCNAME[0]:-main}):\[\e[0m\] ' | ||
shift | ||
;; | ||
--) | ||
shift | ||
break | ||
;; | ||
*) | ||
echo "${script_name}: ERROR: Internal opts: '${@}'" >&2 | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
print_project_banner() { | ||
echo "${script_name} (@PACKAGE_NAME@) - ${start_time}" | ||
} | ||
|
||
print_project_info() { | ||
echo " @PACKAGE_NAME@ ${script_name}" | ||
echo " Version: @PACKAGE_VERSION@" | ||
echo " Project Home: @PACKAGE_URL@" | ||
} | ||
|
||
on_exit() { | ||
local result=${1} | ||
|
||
local sec="${SECONDS}" | ||
|
||
set +x | ||
echo "${script_name}: Done: ${result}, ${sec} sec." >&2 | ||
} | ||
|
||
on_err() { | ||
local f_name=${1} | ||
local line_no=${2} | ||
local err_no=${3} | ||
|
||
echo "${script_name}: ERROR: function=${f_name}, line=${line_no}, result=${err_no}" | ||
exit "${err_no}" | ||
} | ||
|
||
#=============================================================================== | ||
export PS4='\[\e[0;33m\]+ ${BASH_SOURCE##*/}:${LINENO}:(${FUNCNAME[0]:-main}):\[\e[0m\] ' | ||
|
||
script_name="${0##*/}" | ||
|
||
SECONDS=0 | ||
start_time="$(date +%Y.%m.%d-%H.%M.%S)" | ||
|
||
real_source="$(realpath "${BASH_SOURCE[0]}")" | ||
SCRIPT_TOP="$(realpath "${SCRIPT_TOP:-${real_source%/*}}")" | ||
|
||
trap "on_exit 'Failed'" EXIT | ||
trap 'on_err ${FUNCNAME[0]:-main} ${LINENO} ${?}' ERR | ||
trap 'on_err SIGUSR1 ? 3' SIGUSR1 | ||
|
||
set -eE | ||
set -o pipefail | ||
set -o nounset | ||
|
||
clean='' | ||
usage='' | ||
debug='' | ||
|
||
process_opts "${@}" | ||
|
||
if [[ ${usage} ]]; then | ||
usage | ||
trap - EXIT | ||
exit 0 | ||
fi | ||
|
||
print_project_banner >&2 | ||
|
||
if [[ ${extra_args} ]]; then | ||
set +o xtrace | ||
echo "${script_name}: ERROR: Got extra args: '${extra_args}'" >&2 | ||
usage | ||
exit 1 | ||
fi | ||
|
||
kernel_rootfs=/var/jenkins_home/workspace/tdd/kernel/kernel-test/arm64-debian-buster.rootfs | ||
|
||
if [[ ${clean} ]]; then | ||
exec docker exec --privileged tdd-jenkins.service sudo rm -rf ${kernel_rootfs} | ||
else | ||
exec docker exec -it --privileged tdd-jenkins.service /bin/bash | ||
fi | ||
|
||
exec docker exec -it --privileged tdd-jenkins.service /bin/bash |