diff --git a/.ci/lib.sh b/.ci/lib.sh index 8ca7d5f186..200fd71957 100644 --- a/.ci/lib.sh +++ b/.ci/lib.sh @@ -5,7 +5,7 @@ # SPDX-License-Identifier: Apache-2.0 # If we fail for any reason a message will be displayed -die(){ +die() { msg="$*" echo "ERROR: $msg" >&2 exit 1 @@ -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 @@ -30,7 +28,7 @@ install_yq() { path=$1 local yq_path=${path}/yq local yq_pkg="github.com/mikefarah/yq" - [ -x "${yq_path}" ] && return + [ -x "${yq_path}" ] && return case "$(arch)" in "aarch64") @@ -60,7 +58,6 @@ install_yq() { # https://github.com/mikefarah/yq/releases/tag/ 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} diff --git a/.ci/run.sh b/.ci/run.sh index 2e1aba2c7c..226c92411e 100755 --- a/.ci/run.sh +++ b/.ci/run.sh @@ -15,7 +15,7 @@ source /etc/os-release # This script will execute packaging tests suite -if [ "$ID" == ubuntu ];then - echo "Building snap image" +if [ "$ID" == ubuntu ]; then + echo "Building snap image" make snap fi diff --git a/.ci/setup.sh b/.ci/setup.sh index e27ca768fb..35e6729b79 100755 --- a/.ci/setup.sh +++ b/.ci/setup.sh @@ -11,9 +11,9 @@ set -o pipefail source /etc/os-release -echo "Setup script for packaging" +echo "Setup script for packaging" -if [ "$ID" == ubuntu ];then +if [ "$ID" == ubuntu ]; then echo "Install snap dependencies" sudo apt-get install -y snapd snapcraft diff --git a/kata-deploy/scripts/install-kata-containerd.sh b/kata-deploy/scripts/install-kata-containerd.sh index cd2ed9d1f3..a61f7b47b6 100755 --- a/kata-deploy/scripts/install-kata-containerd.sh +++ b/kata-deploy/scripts/install-kata-containerd.sh @@ -17,10 +17,10 @@ echo "create containerd configuration for Kata" mkdir -p /etc/containerd/ if [ -f /etc/containerd/config.toml ]; then - cp /etc/containerd/config.toml /etc/containerd/config.toml.bak + cp /etc/containerd/config.toml /etc/containerd/config.toml.bak fi -cat << EOT | tee /etc/containerd/config.toml +cat < @@ -58,16 +58,16 @@ EOT exit "${exit_code}" } -main(){ +main() { local branch="${1:-}" [ -n "${branch}" ] || usage "missing branch" "1" - pushd "${script_dir}/kata-containers-image/" >> /dev/null + pushd "${script_dir}/kata-containers-image/" >>/dev/null echo "Building image" image_tarball=$(find . -name 'kata-containers-'"${branch}"'-*.tar.gz') [ -f "${image_tarball}" ] || "${script_dir}/../obs-packaging/kata-containers-image/build_image.sh" -v "${branch}" image_tarball=$(find . -name 'kata-containers-'"${branch}"'-*.tar.gz') [ -f "${image_tarball}" ] || die "image not found" - popd >> /dev/null + popd >>/dev/null sudo docker build \ --build-arg http_proxy="${http_proxy}" \ --build-arg https_proxy="${https_proxy}" \ diff --git a/obs-packaging/gen_versions_txt.sh b/obs-packaging/gen_versions_txt.sh index 22692ec851..27aee7ee41 100755 --- a/obs-packaging/gen_versions_txt.sh +++ b/obs-packaging/gen_versions_txt.sh @@ -15,23 +15,22 @@ project="kata-containers" source "${script_dir}/../scripts/lib.sh" -get_kata_hash_from_tag(){ +get_kata_hash_from_tag() { repo=$1 git ls-remote --tags "https://github.com/${project}/${repo}.git" | grep "refs/tags/${kata_version}^{}" | awk '{print $1}' } -gen_version_file(){ +gen_version_file() { local branch="$1" [ -n "${branch}" ] || exit 1 - local kata_version=$(curl --silent -L "https://raw.githubusercontent.com/${project}/runtime/${branch}/VERSION") + local kata_version=$(curl --silent -L "https://raw.githubusercontent.com/${project}/runtime/${branch}/VERSION") kata_runtime_hash=$(get_kata_hash_from_tag "runtime" "${kata_version}") kata_proxy_hash=$(get_kata_hash_from_tag "proxy" "${kata_version}") kata_shim_hash=$(get_kata_hash_from_tag "shim" "${kata_version}") 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}') @@ -48,7 +47,7 @@ gen_version_file(){ golang_version="1.10.2" golang_x84_64_sha256=$(curl -s -L "https://storage.googleapis.com/golang/go${golang_version}.linux-amd64.tar.gz.sha256") -cat > versions.txt << EOT + cat >versions.txt < @@ -95,7 +94,7 @@ EOT exit "${exit_code}" } -main(){ +main() { local branch="${1:-}" [ -n "${branch}" ] || usage "missing branch" "1" gen_version_file "${branch}" diff --git a/obs-packaging/kata-containers-image/build_image.sh b/obs-packaging/kata-containers-image/build_image.sh index fc9a7750ab..746c94a3da 100755 --- a/obs-packaging/kata-containers-image/build_image.sh +++ b/obs-packaging/kata-containers-image/build_image.sh @@ -5,7 +5,7 @@ # SPDX-License-Identifier: Apache-2.0 # -[ -z "${DEBUG}" ] || set -x +[ -z "${DEBUG}" ] || set -x set -o errexit set -o nounset @@ -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,31 +29,30 @@ kata_osbuilder_version="${KATA_OSBUILDER_VERSION:-}" # Agent version agent_version="${AGENT_VERSION:-}" - readonly destdir="${PWD}" -build_initrd(){ - sudo -E PATH="$PATH" make initrd\ - DISTRO="$initrd_distro" \ - DEBUG="${DEBUG:-}" \ - AGENT_VERSION="${agent_version}" \ - OS_VERSION="${initrd_os_version}" \ - DISTRO_ROOTFS="${tmp_dir}/initrd-image" \ - USE_DOCKER=1 \ - AGENT_INIT="yes" +build_initrd() { + sudo -E PATH="$PATH" make initrd \ + DISTRO="$initrd_distro" \ + DEBUG="${DEBUG:-}" \ + AGENT_VERSION="${agent_version}" \ + OS_VERSION="${initrd_os_version}" \ + DISTRO_ROOTFS="${tmp_dir}/initrd-image" \ + USE_DOCKER=1 \ + AGENT_INIT="yes" } -build_image(){ +build_image() { sudo -E PATH="${PATH}" make image \ - DISTRO="${img_distro}" \ - DEBUG="${DEBUG:-}" \ - AGENT_VERSION="${agent_version}" \ - IMG_OS_VERSION="${img_os_version}" \ - DISTRO_ROOTFS="${tmp_dir}/rootfs-image" + DISTRO="${img_distro}" \ + DEBUG="${DEBUG:-}" \ + AGENT_VERSION="${agent_version}" \ + IMG_OS_VERSION="${img_os_version}" \ + DISTRO_ROOTFS="${tmp_dir}/rootfs-image" } -create_tarball(){ +create_tarball() { agent_sha=$(get_repo_hash "${GOPATH}/src/github.com/kata-containers/agent") #reduce sha size for short names agent_sha=${agent_sha:0:11} @@ -68,9 +65,9 @@ create_tarball(){ sudo tar cfzv "${tarball_name}" "${initrd_name}" "${image_name}" } -usage(){ +usage() { return_code=${1:-0} -cat << EOT + cat <&2 "ERROR: $msg" exit 1 } -info() -{ +info() { msg="$*" echo "INFO: $msg" } -function verify() -{ - # This function perform some checks in order to make sure - # the script will run flawlessly. +function verify() { + # This function perform some checks in order to make sure + # the script will run flawlessly. - # Make sure this script is called from ./ - [ "$SCRIPT_DIR" != "." ] && die "The script must be called from its base dir." + # Make sure this script is called from ./ + [ "$SCRIPT_DIR" != "." ] && die "The script must be called from its base dir." - # Verify if osc is installed, exit otherwise. - [ ! -x "$(command -v osc)" ] && die "osc is not installed." + # Verify if osc is installed, exit otherwise. + [ ! -x "$(command -v osc)" ] && die "osc is not installed." - info "OK" + info "OK" } -function clean() -{ - # This function clean generated files - for file in "$@" - do - [ -e $file ] && rm -v $file - done - [ -e ./debian.changelog ] && git checkout ./debian.changelog - [ -e ./release ] && git checkout ./release - echo "Clean done." +function clean() { + # This function clean generated files + for file in "$@"; do + [ -e $file ] && rm -v $file + done + [ -e ./debian.changelog ] && git checkout ./debian.changelog + [ -e ./release ] && git checkout ./release + echo "Clean done." } -function get_git_info() -{ - AUTHOR=${AUTHOR:-$(git config user.name)} - AUTHOR_EMAIL=${AUTHOR_EMAIL:-$(git config user.email)} +function get_git_info() { + AUTHOR=${AUTHOR:-$(git config user.name)} + AUTHOR_EMAIL=${AUTHOR_EMAIL:-$(git config user.email)} } -function set_versions() -{ - local commit_hash="$1" - hash_tag="$commit_hash" - short_hashtag="${hash_tag:0:7}" +function set_versions() { + local commit_hash="$1" + hash_tag="$commit_hash" + short_hashtag="${hash_tag:0:7}" } -function changelog_update { - d=$(date -R) - cat <<< "$PKG_NAME ($VERSION) stable; urgency=medium +function changelog_update() { + d=$(date -R) + cat <<<"$PKG_NAME ($VERSION) stable; urgency=medium * Update $PKG_NAME $VERSION ${hash_tag:0:7} -- $AUTHOR <$AUTHOR_EMAIL> $d -" > debian.changelog +" >debian.changelog # Append, so it can be copied to the OBS repository GENERATED_FILES+=('debian.changelog') } -function local_build() -{ - [ ! -e $PACKAGING_DIR ] && mkdir $PACKAGING_DIR - [ ! -e $LOG_DIR ] && mkdir $LOG_DIR +function local_build() { + [ ! -e $PACKAGING_DIR ] && mkdir $PACKAGING_DIR + [ ! -e $LOG_DIR ] && mkdir $LOG_DIR - pushd $OBS_WORKDIR + pushd $OBS_WORKDIR - BUILD_ARGS=('--local-package' '--no-verify' '--noservice' '--trust-all-projects' '--keep-pkgs=/var/packaging/results') - [ "$OFFLINE" == "true" ] && BUILD_ARGS+=('--offline') + BUILD_ARGS=('--local-package' '--no-verify' '--noservice' '--trust-all-projects' '--keep-pkgs=/var/packaging/results') + [ "$OFFLINE" == "true" ] && BUILD_ARGS+=('--offline') - osc service run - for distro in ${BUILD_DISTROS[@]} - do - # If more distros are supported, add here the relevant validations. - 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 + osc service run + for distro in ${BUILD_DISTROS[@]}; do + # If more distros are supported, add here the relevant validations. + 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 - echo "Perform a local build for ${distro}" - osc build ${BUILD_ARGS[@]} \ - ${distro} $BUILD_ARCH *.dsc | tee ${LOG_DIR}/${distro}_${PKG_NAME}_build.log - fi - done + 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 + fi + done } -function checkout_repo() -{ - local REPO="${1}" - if [ -z "${OBS_WORKDIR:-}" ] - then - OBS_WORKDIR=$(mktemp -d -u -t obs-repo.XXXXXXXXXXX) || exit 1 - osc co "${REPO}" -o "${OBS_WORKDIR}" - fi - find "${OBS_WORKDIR}" -maxdepth 1 -mindepth 1 ! -name '.osc' -prune -exec echo remove {} \; -exec rm -rf {} \; +function checkout_repo() { + local REPO="${1}" + if [ -z "${OBS_WORKDIR:-}" ]; then + OBS_WORKDIR=$(mktemp -d -u -t obs-repo.XXXXXXXXXXX) || exit 1 + osc co "${REPO}" -o "${OBS_WORKDIR}" + fi + find "${OBS_WORKDIR}" -maxdepth 1 -mindepth 1 ! -name '.osc' -prune -exec echo remove {} \; -exec rm -rf {} \; - mv "${GENERATED_FILES[@]}" "${OBS_WORKDIR}" - cp "${STATIC_FILES[@]}" "$OBS_WORKDIR" + mv "${GENERATED_FILES[@]}" "${OBS_WORKDIR}" + cp "${STATIC_FILES[@]}" "$OBS_WORKDIR" } -function obs_push() -{ - pushd $OBS_WORKDIR - osc addremove - osc commit -m "Update ${PKG_NAME} $VERSION: ${hash_tag:0:7}" - popd +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 ;; - * ) 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}" @@ -226,7 +243,7 @@ function build_pkg() } -function generate_files () { +function generate_files() { directory=$1 replace_list=$2 @@ -242,8 +259,8 @@ function generate_files () { # check replace list # key=val - for replace in "${replace_list[@]}" ; do - [[ "$replace" = *"="* ]] || die "invalid replace $replace" + for replace in "${replace_list[@]}"; do + [[ $replace == *"="* ]] || die "invalid replace $replace" local key="${replace%%=*}" local value="${replace##*=}" [ -n "$key" ] || die "${replace} key is empty" @@ -255,13 +272,13 @@ function generate_files () { genfile="${f%-template}" cp "$f" "${genfile}" info "Generate file ${genfile}" - for replace in "${replace_list[@]}" ; do - [[ "$replace" = *"="* ]] || die "invalid replace $replace" + for replace in "${replace_list[@]}"; do + [[ $replace == *"="* ]] || die "invalid replace $replace" local key="${replace%%=*}" local value="${replace##*=}" export k="@${key}@" export v="$value" - perl -p -e 's/$ENV{k}/$ENV{v}/g' "${genfile}" > "${genfile}.out" + perl -p -e 's/$ENV{k}/$ENV{v}/g' "${genfile}" >"${genfile}.out" mv "${genfile}.out" ${genfile} done done @@ -299,11 +316,11 @@ function get_obs_pkg_release() { spec_file=$(find "${repo_dir}" -maxdepth 1 -type f -name '*.spec' | head -1) # Find in specfile in Release: XX field. - release=$(grep -oP 'Release:\s+[0-9]+' "${spec_file}" | grep -oP '[0-9]+') + release=$(grep -oP 'Release:\s+[0-9]+' "${spec_file}" | grep -oP '[0-9]+') if [ -z "${release}" ]; then # Not release number found find in "%define release XX" - release=$(grep -oP '%define\s+release\s+[0-9]+' "${spec_file}" | grep -oP '[0-9]+') + release=$(grep -oP '%define\s+release\s+[0-9]+' "${spec_file}" | grep -oP '[0-9]+') fi release_file=$(find "${repo_dir}" -maxdepth 1 -type f -name 'pkg-release') @@ -335,11 +352,11 @@ function find_patches() { patches=$(find patches/ -type f -name '*.patch' -exec basename {} \;) n="1" rm -f debian.series - for p in ${patches} ; do + for p in ${patches}; do STATIC_FILES+=("patches/$p") RPM_PATCH_LIST+="Patch00${n}: $p"$'\n' RPM_APPLY_PATCHES+="%patch00${n} -p1"$'\n' - echo "$p" >> debian.series + echo "$p" >>debian.series ((n++)) done GENERATED_FILES+=(debian.series) diff --git a/obs-packaging/shim/update.sh b/obs-packaging/shim/update.sh index d950d88f0d..cc5aa081c3 100755 --- a/obs-packaging/shim/update.sh +++ b/obs-packaging/shim/update.sh @@ -36,12 +36,12 @@ RELEASE=$(get_obs_pkg_release "${PROJECT_REPO}") set_versions $kata_shim_hash replace_list=( -"GO_CHECKSUM=$go_checksum" -"GO_VERSION=$go_version" -"GO_ARCH=$GO_ARCH" -"HASH=$short_hashtag" -"RELEASE=$RELEASE" -"VERSION=$VERSION" + "GO_CHECKSUM=$go_checksum" + "GO_VERSION=$go_version" + "GO_ARCH=$GO_ARCH" + "HASH=$short_hashtag" + "RELEASE=$RELEASE" + "VERSION=$VERSION" ) verify diff --git a/release/kata-deploy-binaries.sh b/release/kata-deploy-binaries.sh index a40959f75e..b090afdef1 100755 --- a/release/kata-deploy-binaries.sh +++ b/release/kata-deploy-binaries.sh @@ -91,7 +91,7 @@ install_image() { install_kernel() { go get "github.com/${project}/packaging" || true pushd ${GOPATH}/src/github.com/${project}/packaging >>/dev/null - git checkout "${kata_version}-kernel-config" + git checkout "${kata_version}-kernel-config" popd >>/dev/null pushd "${script_dir}/../kernel" >>/dev/null diff --git a/release/tag_repos.sh b/release/tag_repos.sh index 944c27110d..1bd7114f60 100755 --- a/release/tag_repos.sh +++ b/release/tag_repos.sh @@ -88,7 +88,7 @@ tag_repos() { info "Creating tag ${kata_version} in all repos" for repo in "${repos[@]}"; do git clone --quiet "https://github.com/${OWNER}/${repo}.git" - pushd "${repo}" >> /dev/null + pushd "${repo}" >>/dev/null git remote set-url --push origin "git@github.com:${OWNER}/${repo}.git" git fetch origin --tags tag="$kata_version" @@ -99,7 +99,7 @@ tag_repos() { info "Creating tag ${tag} for ${repo}" git tag -a "${tag}" -s -m "${PROJECT} release ${tag}" fi - popd >> /dev/null + popd >>/dev/null done } @@ -107,21 +107,21 @@ push_tags() { info "Pushing tags to repos" build_hub for repo in "${repos[@]}"; do - pushd "${repo}" >> /dev/null + pushd "${repo}" >>/dev/null tag="$kata_version" [[ "packaging" == "${repo}" ]] && tag="${tag}-kernel-config" info "Push tag ${tag} for ${repo}" git push origin "${tag}" create_github_release "${PWD}" "${tag}" - popd >> /dev/null + popd >>/dev/null done } -create_github_release(){ +create_github_release() { repo_dir=${1:-} tag=${2:-} - [ -d "${repo_dir}" ] || die "No repository directory" - [ -n "${tag}" ] || die "No repository directory" + [ -d "${repo_dir}" ] || die "No repository directory" + [ -n "${tag}" ] || die "No repository directory" if ! "${hub_bin}" release | grep "${tag}"; then info "Creating Github release" "${hub_bin}" -C "${repo_dir}" release create -m "${PROJECT} ${tag}" "${tag}" @@ -136,13 +136,13 @@ while getopts "hp" opt; do p) PUSH="true" ;; esac done -shift $(($OPTIND - 1)) +shift $((OPTIND - 1)) subcmd=${1:-""} [ -z "${subcmd}" ] && usage && exit 0 -pushd "${tmp_dir}" >> /dev/null +pushd "${tmp_dir}" >>/dev/null case "${subcmd}" in status) @@ -167,4 +167,4 @@ tag) esac -popd >> /dev/null +popd >>/dev/null diff --git a/release/tag_repos_test.sh b/release/tag_repos_test.sh index 21afb21300..50b2fb5cc8 100755 --- a/release/tag_repos_test.sh +++ b/release/tag_repos_test.sh @@ -10,10 +10,10 @@ set -o nounset set -o pipefail echo "Check tag_repos.sh show help" -./release/tag_repos.sh | grep Usage +./release/tag_repos.sh | grep Usage echo "Check tag_repos.sh -h option" -./release/tag_repos.sh -h | grep Usage +./release/tag_repos.sh -h | grep Usage echo "Check tag_repos.sh status" ./release/tag_repos.sh status | grep runtime diff --git a/release/update-repository-version.sh b/release/update-repository-version.sh index 6506529b4f..056a0be2f6 100755 --- a/release/update-repository-version.sh +++ b/release/update-repository-version.sh @@ -9,7 +9,7 @@ set -o errexit set -o nounset set -o pipefail -readonly script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +readonly script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly script_name="$(basename "${BASH_SOURCE[0]}")" readonly tmp_dir=$(mktemp -t -d pr-bump.XXXX) @@ -19,7 +19,7 @@ GOPATH=${GOPATH:-${HOME}/go} source "${script_dir}/../scripts/lib.sh" -cleanup (){ +cleanup() { [ -d "${tmp_dir}" ] && rm -rf "${tmp_dir}" } @@ -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 @@ -71,7 +70,7 @@ bump_repo() { git clone --quiet "${remote_github}" - pushd "${repo}" >> /dev/null + pushd "${repo}" >>/dev/null # All repos we build should have a VERSION file [ -f "VERSION" ] || die "VERSION file not found " @@ -79,7 +78,7 @@ bump_repo() { info "Creating PR message" notes_file=notes.md - cat << EOT > "${notes_file}" + cat <"${notes_file}" # Kata Containers ${new_version} $(get_changes "$current_version") @@ -87,15 +86,15 @@ $(get_changes "$current_version") EOT info "Updating VERSION file" - echo "${new_version}" > VERSION + echo "${new_version}" >VERSION branch="${new_version}-branch-bump" git checkout -b "${branch}" master git add -u info "Creating commit with new changes" commit_msg="$(generate_commit $new_version $current_version)" - git commit -s -m "${commit_msg}" + 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 @@ -103,12 +102,12 @@ EOT ${hub_bin} push fork -f "${branch}" info "Create PR" out="" - out=$("${hub_bin}" pull-request -F "${notes_file}" 2>&1) || echo "$out" | grep "A pull request already exists" + out=$("${hub_bin}" pull-request -F "${notes_file}" 2>&1) || echo "$out" | grep "A pull request already exists" fi - popd >> /dev/null + popd >>/dev/null } -usage(){ +usage() { exit_code="$1" cat <> /dev/null +pushd "$tmp_dir" >>/dev/null bump_repo "${repo}" "${new_version}" -popd >> /dev/null +popd >>/dev/null diff --git a/release/update-repository-version_test.sh b/release/update-repository-version_test.sh index 590a5d0e57..594916dc47 100755 --- a/release/update-repository-version_test.sh +++ b/release/update-repository-version_test.sh @@ -9,37 +9,37 @@ set -o errexit set -o nounset set -o pipefail -readonly script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +readonly script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" out="" -handle_error(){ +handle_error() { echo "not ok" echo "output: ${out}" } -OK(){ +OK() { echo "ok" } -output_should_contain(){ +output_should_contain() { local output="$1" local text_to_find="$2" - [ -n "$output" ] - [ -n "$text_to_find" ] + [ -n "$output" ] + [ -n "$text_to_find" ] echo "${output}" | grep "${text_to_find}" } trap handle_error ERR echo "Missing args show help" -out=$("${script_dir}/update-repository-version.sh" 2>&1) || (($?!=0)) -echo "${out}" | grep Usage >> /dev/null +out=$("${script_dir}/update-repository-version.sh" 2>&1) || (($? != 0)) +echo "${out}" | grep Usage >>/dev/null output_should_contain "${out}" "Usage" OK echo "Missing version show help" -out=$("${script_dir}/update-repository-version.sh" runtime 2>&1) || (($?!=0)) -echo "${out}" | grep Usage >> /dev/null -echo "${out}" | grep "no new version">> /dev/null +out=$("${script_dir}/update-repository-version.sh" runtime 2>&1) || (($? != 0)) +echo "${out}" | grep Usage >>/dev/null +echo "${out}" | grep "no new version" >>/dev/null OK echo "help option" diff --git a/scripts/configure-hypervisor.sh b/scripts/configure-hypervisor.sh index e78abcf711..d0ab966adb 100755 --- a/scripts/configure-hypervisor.sh +++ b/scripts/configure-hypervisor.sh @@ -48,17 +48,15 @@ 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() -{ -cat <&2 "ERROR: $*" - exit 1 + echo >&2 "ERROR: $*" + exit 1 } info() { - echo >&2 "INFO: $*" + echo >&2 "INFO: $*" } -get_repo_hash(){ +get_repo_hash() { local repo_dir=${1:-} [ -d "${repo_dir}" ] || die "${repo_dir} is not a directory" - pushd "${repo_dir}" >> /dev/null + pushd "${repo_dir}" >>/dev/null git rev-parse --verify HEAD - popd >> /dev/null + popd >>/dev/null } build_hub() { @@ -68,18 +68,17 @@ build_hub() { if cmd=$(command -v hub); then hub_bin="${cmd}" - return + return else hub_bin="${tmp_dir:-/tmp}/hub-bin" fi local hub_repo="github.com/github/hub" local hub_repo_dir="${GOPATH}/src/${hub_repo}" - [ -d "${hub_repo_dir}" ]|| git clone --quiet --depth 1 "https://${hub_repo}.git" "${hub_repo_dir}" - pushd "${hub_repo_dir}" >> /dev/null + [ -d "${hub_repo_dir}" ] || git clone --quiet --depth 1 "https://${hub_repo}.git" "${hub_repo_dir}" + pushd "${hub_repo_dir}" >>/dev/null git checkout master git pull ./script/build -o "${hub_bin}" - popd >> /dev/null + popd >>/dev/null } - diff --git a/snap-build/config_amd64.sh b/snap-build/config_amd64.sh index 8bdad3f3d9..d8652d031f 100755 --- a/snap-build/config_amd64.sh +++ b/snap-build/config_amd64.sh @@ -13,7 +13,7 @@ local arch_bios_url="" local arch_qemu_cpu="qemu64" local arch_qemu_machine="pc" local arch_qemu_extra_opts="" -if [ "$(arch)" == "x86_64" ];then +if [ "$(arch)" == "x86_64" ]; then arch_qemu_cpu="host" arch_qemu_machine="pc,accel=kvm" arch_qemu_extra_opts="-enable-kvm" diff --git a/snap-build/lib.sh b/snap-build/lib.sh index f7df207d8a..385f4895ff 100644 --- a/snap-build/lib.sh +++ b/snap-build/lib.sh @@ -5,12 +5,12 @@ # SPDX-License-Identifier: Apache-2.0 # -error(){ +error() { msg="$*" echo "ERROR: $msg" >&2 } -die(){ +die() { error "$*" exit 1 } @@ -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 } @@ -63,7 +66,7 @@ ping_vm() { timeout=$4 minute=60 sleeptime=10 - timeoutsec=$((timeout*minute)) + timeoutsec=$((timeout * minute)) tries=$((timeoutsec/sleeptime)) for i in $(seq 1 ${tries}); do @@ -102,9 +105,9 @@ run_qemu() { fi qemu-system-${arch} -cpu "${cpu}" -machine "${machine}" -smp cpus=4 -m 2048M \ - -net nic,model=virtio -device virtio-rng-pci -net user,hostfwd=tcp:${ip}:${port}-:22,dnssearch="$(get_dnssearch)" \ - ${img_opts} ${seed_opts} \ - -display none -vga none -daemonize ${extra_opts} + -net nic,model=virtio -device virtio-rng-pci -net user,hostfwd=tcp:${ip}:${port}-:22,dnssearch="$(get_dnssearch)" \ + ${img_opts} ${seed_opts} \ + -display none -vga none -daemonize ${extra_opts} [ $? != 0 ] && return 1 # depending of the host's hw, it takes for around ~15 minutes diff --git a/snap-build/snap.sh b/snap-build/snap.sh index 48d7e39934..886cb86746 100755 --- a/snap-build/snap.sh +++ b/snap-build/snap.sh @@ -12,28 +12,28 @@ set -x -e sudo apt-get update -y sudo apt-get install -y \ - build-essential \ - cpio \ - docker.io \ - golang-go \ - libattr1-dev \ - libcap-dev \ - libcap-ng-dev \ - libdw-dev \ - libelf-dev \ - libfdt-dev \ - libglib2.0-dev \ - libiberty-dev \ - libnewt-dev \ - libpci-dev \ - libpixman-1-dev \ - librbd-dev \ - libssl-dev \ - libz-dev \ - openssl \ - python \ - snapcraft \ - snapd + build-essential \ + cpio \ + docker.io \ + golang-go \ + libattr1-dev \ + libcap-dev \ + libcap-ng-dev \ + libdw-dev \ + libelf-dev \ + libfdt-dev \ + libglib2.0-dev \ + libiberty-dev \ + libnewt-dev \ + libpci-dev \ + libpixman-1-dev \ + librbd-dev \ + libssl-dev \ + libz-dev \ + openssl \ + python \ + snapcraft \ + snapd # start docker sudo systemctl start docker diff --git a/snap-build/xbuild.sh b/snap-build/xbuild.sh index 8c338a2e52..51a3375ab4 100755 --- a/snap-build/xbuild.sh +++ b/snap-build/xbuild.sh @@ -23,7 +23,7 @@ scp="scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o Identiti gen_seed() { rm -f "${seed_img}" truncate --size 2M "${seed_img}" - mkfs.vfat -n cidata "${seed_img}" &> /dev/null + mkfs.vfat -n cidata "${seed_img}" &>/dev/null if [ -n "${http_proxy}" ]; then apt_proxy="apt:\n https_proxy: ${https_proxy}\n proxy: ${http_proxy}" @@ -38,7 +38,7 @@ gen_seed() { docker_dns="$(get_dns)" - [ ! -f "${id_rsa_file}" ] && ssh-keygen -t rsa -f ${id_rsa_file} -P '' &> /dev/null + [ ! -f "${id_rsa_file}" ] && ssh-keygen -t rsa -f ${id_rsa_file} -P '' &>/dev/null ssh_key="$(cat ${id_rsa_pub_file})" sed \ @@ -48,9 +48,9 @@ gen_seed() { -e "s|@DOCKER_ENV@|""${docker_env}""|g" \ -e "s|@DOCKER_DNS@|""${docker_dns}""|g" \ -e "s|@ENV@|""${env}""|g" \ - ${seed_dir}/user-data.in > ${seed_dir}/user-data + ${seed_dir}/user-data.in >${seed_dir}/user-data - mcopy -oi "${seed_img}" ${seed_dir}/user-data ${seed_dir}/meta-data :: + mcopy -oi "${seed_img}" ${seed_dir}/user-data ${seed_dir}/meta-data :: } poweroff_and_die() { @@ -77,13 +77,13 @@ build_arch() { # run QEMU run_qemu "${arch_qemu}" \ - "${arch_qemu_cpu}" \ - "${arch_qemu_machine}" \ - "${ip}" \ - "${port}" \ - "${arch_image}" \ - "${seed_img}" \ - "${arch_qemu_extra_opts}" + "${arch_qemu_cpu}" \ + "${arch_qemu_machine}" \ + "${ip}" \ + "${port}" \ + "${arch_image}" \ + "${seed_img}" \ + "${arch_qemu_extra_opts}" # copy snap script to VM ${scp} -P "${port}" "${snap_sh}" "${ip}:~/" || poweroff_and_die "${ip}" "${port}" "Could not copy snap script" @@ -92,15 +92,15 @@ build_arch() { ${ssh} "${ip}" -p "${port}" "~/snap.sh" || poweroff_and_die "${ip}" "${port}" "Failed to run build script" # copy snap image from VM - ${scp} -P "${port}" "${ip}:~/packaging/*.snap" . || poweroff_and_die "${ip}" "${port}" "Failed to get snap image" + ${scp} -P "${port}" "${ip}:~/packaging/*.snap" . || poweroff_and_die "${ip}" "${port}" "Failed to get snap image" # poweroff VM ${ssh} "${ip}" -p "${port}" sudo poweroff } -help() -{ - usage=$(cat << EOF +help() { + usage=$( + cat < "${arch}.log" + build_arch "${arch}" &>"${arch}.log" else for a in ${supported_archs[@]}; do - (build_arch "${a}" &> "${a}.log") & + (build_arch "${a}" &>"${a}.log") & done wait fi diff --git a/static-build/qemu/build-static-qemu.sh b/static-build/qemu/build-static-qemu.sh index e5bb08fb05..eae0d41633 100755 --- a/static-build/qemu/build-static-qemu.sh +++ b/static-build/qemu/build-static-qemu.sh @@ -8,7 +8,7 @@ set -o errexit set -o nounset set -o pipefail -script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${script_dir}/../../scripts/lib.sh" @@ -23,11 +23,10 @@ if [ -z "$qemu_repo" ]; then [ -n "$qemu_url" ] || die "failed to get qemu url" qemu_repo="${qemu_url}.git" fi -[ -n "$qemu_repo" ] || die "failed to get qemu repo" - +[ -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" +[ -n "$qemu_version" ] || die "failed to get qemu version" info "Build ${qemu_repo} version: ${qemu_version}"