Merge pull request #138 from jcvenegas/shfmt

format: use shfmt to format sh files.
This commit is contained in:
Julio Montes
2018-08-17 10:53:18 -05:00
committed by GitHub
31 changed files with 447 additions and 449 deletions

View File

@@ -14,12 +14,10 @@ die(){
export tests_repo="${tests_repo:-github.com/kata-containers/tests}"
export tests_repo_dir="$GOPATH/src/$tests_repo"
clone_tests_repo()
{
clone_tests_repo() {
# KATA_CI_NO_NETWORK is (has to be) ignored if there is
# no existing clone.
if [ -d "${tests_repo_dir}" ] && [ -n "${KATA_CI_NO_NETWORK:-}" ]
then
if [ -d "${tests_repo_dir}" ] && [ -n "${KATA_CI_NO_NETWORK:-}" ]; then
return
fi
@@ -60,7 +58,6 @@ install_yq() {
# https://github.com/mikefarah/yq/releases/tag/<VERSION-HERE>
yq_version=$(basename "${yq_latest_url}")
local yq_url="https://${yq_pkg}/releases/download/${yq_version}/yq_linux_${goarch}"
curl -o "${yq_path}" -L ${yq_url}
chmod +x ${yq_path}

View File

@@ -7,4 +7,3 @@ rm -f /etc/containerd/config.toml
if [ -f /etc/containerd/config.toml.bak ]; then
mv /etc/containerd/config.toml.bak /etc/containerd/config.toml
fi

View File

@@ -165,7 +165,7 @@ setup_kernel() {
download_kernel="true"
[ -n "$kernel_version" ] || die "failed to get kernel version: Kernel version is emtpy"
if [[ "${download_kernel}" == "true" ]]; then
if [[ ${download_kernel} == "true" ]]; then
get_kernel "${kernel_version}" "${kernel_path}"
fi
@@ -273,7 +273,7 @@ main() {
esac
done
shift $(($OPTIND - 1))
shift $((OPTIND - 1))
subcmd="${1:-}"

View File

@@ -1 +1 @@
8
9

View File

@@ -31,7 +31,6 @@ gen_version_file(){
kata_agent_hash=$(get_kata_hash_from_tag "agent" "${kata_version}")
kata_ksm_throttler_hash=$(get_kata_hash_from_tag "ksm-throttler" "${kata_version}")
qemu_lite_branch=$(get_from_kata_deps "assets.hypervisor.qemu-lite.branch" "${kata_version}")
qemu_lite_version=$(curl -s -L "https://raw.githubusercontent.com/${project}/qemu/${qemu_lite_branch}/VERSION")
qemu_lite_hash=$(git ls-remote https://github.com/${project}/qemu.git | grep "refs/heads/${qemu_lite_branch}" | awk '{print $1}')

View File

@@ -17,11 +17,9 @@ readonly project="kata-containers"
readonly tmp_dir=$(mktemp -d -t build-image-tmp.XXXXXXXXXX)
readonly osbuilder_url=https://github.com/${project}/osbuilder.git
export GOPATH=${GOPATH:-${HOME}/go}
source "${script_dir}/../../scripts/lib.sh"
arch_target="$(uname -m)"
kata_version="master"
@@ -31,7 +29,6 @@ kata_osbuilder_version="${KATA_OSBUILDER_VERSION:-}"
# Agent version
agent_version="${AGENT_VERSION:-}"
readonly destdir="${PWD}"
build_initrd() {
@@ -87,12 +84,14 @@ exit "${return_code}"
}
main() {
while getopts "v:h" opt
do
while getopts "v:h" opt; do
case "$opt" in
h) usage 0 ;;
v) kata_version="${OPTARG}" ;;
*) echo "Invalid option $opt"; usage 1;;
*)
echo "Invalid option $opt"
usage 1
;;
esac
done
# osbuilder info
@@ -108,7 +107,7 @@ main(){
initrd_distro=$(get_from_kata_deps "assets.image.architecture.${arch_target}.name" "${kata_version}")
initrd_os_version=$(get_from_kata_deps "assets.image.architecture.${arch_target}.version" "${kata_version}")
shift "$(( $OPTIND - 1 ))"
shift "$((OPTIND - 1))"
git clone "$osbuilder_url" "${tmp_dir}/osbuilder"
pushd "${tmp_dir}/osbuilder"
git checkout "${kata_osbuilder_version}"

View File

@@ -102,4 +102,3 @@ get_git_info
changelog_update $VERSION
generate_files "$SCRIPT_DIR" "${replace_list[@]}"
build_pkg "${PROJECT_REPO}"

View File

@@ -33,8 +33,7 @@ else
echo "Go not installed using $GO_ARCH to install go in dockerfile"
fi
function display_help()
{
function display_help() {
cat <<-EOL
$SCRIPT_NAME
@@ -68,21 +67,18 @@ function display_help()
exit 1
}
die()
{
die() {
msg="$*"
echo >&2 "ERROR: $msg"
exit 1
}
info()
{
info() {
msg="$*"
echo "INFO: $msg"
}
function verify()
{
function verify() {
# This function perform some checks in order to make sure
# the script will run flawlessly.
@@ -95,11 +91,9 @@ function verify()
info "OK"
}
function clean()
{
function clean() {
# This function clean generated files
for file in "$@"
do
for file in "$@"; do
[ -e $file ] && rm -v $file
done
[ -e ./debian.changelog ] && git checkout ./debian.changelog
@@ -107,20 +101,18 @@ function clean()
echo "Clean done."
}
function get_git_info()
{
function get_git_info() {
AUTHOR=${AUTHOR:-$(git config user.name)}
AUTHOR_EMAIL=${AUTHOR_EMAIL:-$(git config user.email)}
}
function set_versions()
{
function set_versions() {
local commit_hash="$1"
hash_tag="$commit_hash"
short_hashtag="${hash_tag:0:7}"
}
function changelog_update {
function changelog_update() {
d=$(date -R)
cat <<<"$PKG_NAME ($VERSION) stable; urgency=medium
@@ -132,8 +124,7 @@ function changelog_update {
GENERATED_FILES+=('debian.changelog')
}
function local_build()
{
function local_build() {
[ ! -e $PACKAGING_DIR ] && mkdir $PACKAGING_DIR
[ ! -e $LOG_DIR ] && mkdir $LOG_DIR
@@ -143,17 +134,14 @@ function local_build()
[ "$OFFLINE" == "true" ] && BUILD_ARGS+=('--offline')
osc service run
for distro in ${BUILD_DISTROS[@]}
do
for distro in ${BUILD_DISTROS[@]}; do
# If more distros are supported, add here the relevant validations.
if [[ "$distro" =~ ^Fedora.* ]] || [[ "$distro" =~ ^CentOS.* ]]
then
if [[ $distro =~ ^Fedora.* ]] || [[ $distro =~ ^CentOS.* ]]; then
echo "Perform a local build for ${distro}"
osc build ${BUILD_ARGS[@]} \
${distro} $BUILD_ARCH *.spec | tee ${LOG_DIR}/${distro}_${PKG_NAME}_build.log
elif [[ "$distro" =~ ^xUbuntu.* ]]
then
elif [[ $distro =~ ^xUbuntu.* ]]; then
echo "Perform a local build for ${distro}"
osc build ${BUILD_ARGS[@]} \
${distro} $BUILD_ARCH *.dsc | tee ${LOG_DIR}/${distro}_${PKG_NAME}_build.log
@@ -161,11 +149,9 @@ function local_build()
done
}
function checkout_repo()
{
function checkout_repo() {
local REPO="${1}"
if [ -z "${OBS_WORKDIR:-}" ]
then
if [ -z "${OBS_WORKDIR:-}" ]; then
OBS_WORKDIR=$(mktemp -d -u -t obs-repo.XXXXXXXXXXX) || exit 1
osc co "${REPO}" -o "${OBS_WORKDIR}"
fi
@@ -175,38 +161,69 @@ function checkout_repo()
cp "${STATIC_FILES[@]}" "$OBS_WORKDIR"
}
function obs_push()
{
function obs_push() {
pushd $OBS_WORKDIR
osc addremove
osc commit -m "Update ${PKG_NAME} $VERSION: ${hash_tag:0:7}"
popd
}
function cli()
{
function cli() {
OPTS=$(getopt -o abclprwvCVh: --long api-url,branch,commit-id,local-build,push,obs-repository,workdir,verbose,clean,verify,help -- "$@")
while true; do
case "${1}" in
-b | --branch ) BRANCH="true"; OBS_REVISION="$2"; shift 2;;
-l | --local-build ) LOCAL_BUILD="true"; shift;;
-p | --push ) OBS_PUSH="true"; shift;;
-r | --obs-repository ) PROJECT_REPO="$2"; shift 2;;
-w | --workdir ) OBS_WORKDIR="$2"; shift 2;;
-v | --verbose ) VERBOSE="true"; shift;;
-o | --offline ) OFFLINE="true"; shift;;
-C | --clean ) clean ${GENERATED_FILES[@]}; exit $?;;
-V | --verify ) verify; exit $?;;
-h | --help ) display_help; exit $?;;
-- ) shift; break ;;
-b | --branch)
BRANCH="true"
OBS_REVISION="$2"
shift 2
;;
-l | --local-build)
LOCAL_BUILD="true"
shift
;;
-p | --push)
OBS_PUSH="true"
shift
;;
-r | --obs-repository)
PROJECT_REPO="$2"
shift 2
;;
-w | --workdir)
OBS_WORKDIR="$2"
shift 2
;;
-v | --verbose)
VERBOSE="true"
shift
;;
-o | --offline)
OFFLINE="true"
shift
;;
-C | --clean)
clean ${GENERATED_FILES[@]}
exit $?
;;
-V | --verify)
verify
exit $?
;;
-h | --help)
display_help
exit $?
;;
--)
shift
break
;;
*) break ;;
esac
done
}
function build_pkg()
{
function build_pkg() {
obs_repository="${1}"
@@ -243,7 +260,7 @@ function generate_files () {
# check replace list
# key=val
for replace in "${replace_list[@]}"; do
[[ "$replace" = *"="* ]] || die "invalid replace $replace"
[[ $replace == *"="* ]] || die "invalid replace $replace"
local key="${replace%%=*}"
local value="${replace##*=}"
[ -n "$key" ] || die "${replace} key is empty"
@@ -256,7 +273,7 @@ function generate_files () {
cp "$f" "${genfile}"
info "Generate file ${genfile}"
for replace in "${replace_list[@]}"; do
[[ "$replace" = *"="* ]] || die "invalid replace $replace"
[[ $replace == *"="* ]] || die "invalid replace $replace"
local key="${replace%%=*}"
local value="${replace##*=}"
export k="@${key}@"

View File

@@ -136,7 +136,7 @@ while getopts "hp" opt; do
p) PUSH="true" ;;
esac
done
shift $(($OPTIND - 1))
shift $((OPTIND - 1))
subcmd=${1:-""}

View File

@@ -36,8 +36,7 @@ get_changes() {
fi
# list all PRs merged from $current_version to HEAD
git log --merges "${current_version}..HEAD" | awk '/Merge pull/{getline; getline;print }' | while read pr
do
git log --merges "${current_version}..HEAD" | awk '/Merge pull/{getline; getline;print }' | while read pr; do
echo "- ${pr}"
done
@@ -95,7 +94,7 @@ EOT
commit_msg="$(generate_commit $new_version $current_version)"
git commit -s -m "${commit_msg}"
if [[ "${PUSH}" == "true" ]]; then
if [[ ${PUSH} == "true" ]]; then
build_hub
info "Forking remote"
${hub_bin} fork --remote-name=fork
@@ -125,15 +124,14 @@ EOT
exit "$exit_code"
}
while getopts "hp" opt
do
while getopts "hp" opt; do
case $opt in
h) usage 0 ;;
p) PUSH="true" ;;
esac
done
shift $(( $OPTIND - 1 ))
shift $((OPTIND - 1))
repo=${1:-}
new_version=${2:-}

View File

@@ -48,16 +48,14 @@ recognised_tags=(
)
# Display message to stderr and exit indicating script failed.
die()
{
die() {
local msg="$*"
echo >&2 "$script_name: ERROR: $msg"
exit 1
}
# Display usage to stdout.
usage()
{
usage() {
cat <<EOT
Overview:
@@ -83,8 +81,7 @@ Example:
EOT
}
show_tags_header()
{
show_tags_header() {
local keys
local key
local value
@@ -98,8 +95,7 @@ EOT
keys=${!recognised_tags[@]}
keys=$(echo "$keys" | tr ' ' '\n' | sort -u)
for key in $keys
do
for key in $keys; do
value="${recognised_tags[$key]}"
printf "# %s\t%s.\n" "$key" "$value"
done
@@ -107,8 +103,7 @@ EOT
printf "#\n\n"
}
check_tag()
{
check_tag() {
local tag="$1"
local entry="$2"
@@ -123,8 +118,7 @@ check_tag()
die "invalid tag '$tag' found for entry '$entry'"
}
check_tags()
{
check_tags() {
local tags="$1"
local entry="$2"
@@ -133,8 +127,7 @@ check_tags()
tags=$(echo "$tags" | tr ',' '\n')
for tag in $tags
do
for tag in $tags; do
check_tag "$tag" "$entry"
done
}
@@ -151,8 +144,7 @@ check_tags()
# $2: (optional) "multi" - show values across multiple lines,
# "dump" - show full hash values. Any other value results in the
# options being displayed on a single line.
show_array()
{
show_array() {
local action="$1"
local _array=("$@")
_array=("${_array[@]:1}")
@@ -167,8 +159,7 @@ show_array()
[ "$action" = "dump" ] && show_tags_header
for entry in "${_array[@]}"
do
for entry in "${_array[@]}"; do
[ -z "$entry" ] && die "found empty entry"
tags=$(echo "$entry" | cut -s -d: -f1)
@@ -178,16 +169,13 @@ show_array()
check_tags "$tags" "$entry"
if [ "$action" = "dump" ]
then
if [ "$action" = "dump" ]; then
printf "%s\t\t%s\n" "$tags" "$elem"
elif [ "$action" = "multi" ]
then
if [ $i -eq $size ]
then
elif [ "$action" = "multi" ]; then
if [ $i -eq $size ]; then
suffix=""
else
suffix=" \\"
suffix=' \'
fi
printf '%s%s\n' "$elem" "$suffix"
@@ -202,8 +190,7 @@ show_array()
[ "$one_line" = yes ] && echo
}
generate_qemu_options()
{
generate_qemu_options() {
#---------------------------------------------------------------------
# Disabled options
@@ -272,7 +259,8 @@ generate_qemu_options()
# Disable debug and "-uuid ..." is always passed to the qemu binary so not required.
case "$arch" in
aarch64) qemu_options+=(size:--disable-uuid)
aarch64)
qemu_options+=(size:--disable-uuid)
;;
x86_64)
qemu_options+=(size:--disable-uuid)
@@ -420,12 +408,10 @@ generate_qemu_options()
}
# Entry point
main()
{
main() {
action=""
while getopts "dhms" opt
do
while getopts "dhms" opt; do
case "$opt" in
d)
action="dump"
@@ -445,7 +431,7 @@ main()
esac
done
shift $[$OPTIND-1]
shift $((OPTIND - 1))
[ -z "$1" ] && die "need hypervisor name"
hypervisor="$1"
@@ -456,18 +442,18 @@ main()
local qemu_version_major=$(cut -d. -f1 "${qemu_version_file}")
local qemu_version_minor=$(cut -d. -f2 "${qemu_version_file}")
[ -n "${qemu_version_major}" ] \
|| die "cannot determine qemu major version from file $qemu_version_file"
[ -n "${qemu_version_minor}" ] \
|| die "cannot determine qemu minor version from file $qemu_version_file"
[ -n "${qemu_version_major}" ] ||
die "cannot determine qemu major version from file $qemu_version_file"
[ -n "${qemu_version_minor}" ] ||
die "cannot determine qemu minor version from file $qemu_version_file"
local gcc_version_major=$(gcc -dumpversion | cut -f1 -d.)
local gcc_version_minor=$(gcc -dumpversion | cut -f2 -d.)
[ -n "${gcc_version_major}" ] \
|| die "cannot determine gcc major version, please ensure it is installed"
[ -n "${gcc_version_minor}" ] \
|| die "cannot determine gcc minor version, please ensure it is installed"
[ -n "${gcc_version_major}" ] ||
die "cannot determine gcc major version, please ensure it is installed"
[ -n "${gcc_version_minor}" ] ||
die "cannot determine gcc minor version, please ensure it is installed"
# Generate qemu options
generate_qemu_options

View File

@@ -82,4 +82,3 @@ build_hub() {
./script/build -o "${hub_bin}"
popd >>/dev/null
}

View File

@@ -46,7 +46,10 @@ setup_image() {
img_url=$1
img=$2
[ -f "${img}" ] && return
{ download "${img_url}" "$(dirname ${img})"; ret=$?; } || true
{
download "${img_url}" "$(dirname ${img})"
ret=$?
} || true
[ ${ret} != 0 ] && rm -f "${img}" && return
qemu-img resize "${img}" +5G
}

View File

@@ -98,9 +98,9 @@ build_arch() {
${ssh} "${ip}" -p "${port}" sudo poweroff
}
help()
{
usage=$(cat << EOF
help() {
usage=$(
cat <<EOF
Usage: $0 [-h] [options]
Description:
Build snap images.
@@ -109,7 +109,10 @@ Usage: $0 [-h] [options]
-h, Show this help text and exit.
Supported architectures:
$(IFS=$'\t'; echo -e "${supported_archs[*]}")
$(
IFS=$'\t'
echo -e "${supported_archs[*]}"
)
EOF
)
echo "$usage"
@@ -125,7 +128,7 @@ main() {
;;
h)
help
exit 0;
exit 0
;;
?)
# parse failure

View File

@@ -25,7 +25,6 @@ if [ -z "$qemu_repo" ]; then
fi
[ -n "$qemu_repo" ] || die "failed to get qemu repo"
[ -n "$qemu_version" ] || qemu_version=$(get_from_kata_deps "assets.hypervisor.qemu.version")
[ -n "$qemu_version" ] || die "failed to get qemu version"