Skip to content

Commit

Permalink
Shellcheck warning fixes for util files
Browse files Browse the repository at this point in the history
Signed-off-by: Judy Ng <[email protected]>
  • Loading branch information
judysng committed Jan 17, 2024
1 parent 717373a commit b78b8b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
8 changes: 4 additions & 4 deletions util/bump-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if [ "$(uname)" == "Darwin" ]; then
PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
fi

if [ -z "$1" -o -z "$2" ]; then
if [ -z "$1" ] || [ -z "$2" ]; then
echo "New version not specified. Usage: bump-version.sh NEW_PCLUSTER_VERSION NEW_AWSBATCH_CLI_VERSION"
exit 1
fi
Expand All @@ -35,13 +35,13 @@ for cookbook in "${COOKBOOKS[@]}"; do
done

# Update version in specific cookbook metadata
sed -i "s/version '${CURRENT_PCLUSTER_VERSION_SHORT}'/version '${NEW_PCLUSTER_VERSION_SHORT}'/g" ${METADATA_FILES[*]}
sed -i "s/version '${CURRENT_PCLUSTER_VERSION_SHORT}'/version '${NEW_PCLUSTER_VERSION_SHORT}'/g" "${METADATA_FILES[@]}"

for COOKBOOK in ${COOKBOOKS[*]}; do
for COOKBOOK in "${COOKBOOKS[@]}"; do
# Update dependencies version in main cookbook metadata
sed -i "s/depends '${COOKBOOK}', '~> ${CURRENT_PCLUSTER_VERSION_SHORT}'/depends '${COOKBOOK}', '~> ${NEW_PCLUSTER_VERSION_SHORT}'/g" metadata.rb
# Update dependencies version in specific cookbook metadata
sed -i "s/depends '${COOKBOOK}', '~> ${CURRENT_PCLUSTER_VERSION_SHORT}'/depends '${COOKBOOK}', '~> ${NEW_PCLUSTER_VERSION_SHORT}'/g" ${METADATA_FILES[*]}
sed -i "s/depends '${COOKBOOK}', '~> ${CURRENT_PCLUSTER_VERSION_SHORT}'/depends '${COOKBOOK}', '~> ${NEW_PCLUSTER_VERSION_SHORT}'/g" "${METADATA_FILES[@]}"
done

# Update AWS Batch CLI version
Expand Down
25 changes: 14 additions & 11 deletions util/cinc-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ checksum_mismatch() {
unable_to_retrieve_package() {
echo "Unable to retrieve a valid package!"
report_bug
# shellcheck disable=SC2154
echo "Metadata URL: $metadata_url"
if test "x$download_url" != "x"; then
echo "Download URL: $download_url"
Expand Down Expand Up @@ -132,7 +133,7 @@ do_wget() {
wget --user-agent="User-Agent: mixlib-install/3.12.27" -O "$2" "$1" 2>$tmp_dir/stderr
rc=$?
# check for 404
grep "ERROR 404" $tmp_dir/stderr 2>&1 >/dev/null
grep "ERROR 404" $tmp_dir/stderr >/dev/null 2>&1
if test $? -eq 0; then
echo "ERROR 404"
http_404_error
Expand All @@ -153,7 +154,7 @@ do_curl() {
curl -A "User-Agent: mixlib-install/3.12.27" --retry 5 -sL -D $tmp_dir/stderr "$1" > "$2"
rc=$?
# check for 404
grep "404 Not Found" $tmp_dir/stderr 2>&1 >/dev/null
grep "404 Not Found" $tmp_dir/stderr >/dev/null 2>&1
if test $? -eq 0; then
echo "ERROR 404"
http_404_error
Expand Down Expand Up @@ -183,7 +184,7 @@ do_perl() {
perl -e 'use LWP::Simple; getprint($ARGV[0]);' "$1" > "$2" 2>$tmp_dir/stderr
rc=$?
# check for 404
grep "404 Not Found" $tmp_dir/stderr 2>&1 >/dev/null
grep "404 Not Found" $tmp_dir/stderr >/dev/null 2>&1
if test $? -eq 0; then
echo "ERROR 404"
http_404_error
Expand All @@ -204,7 +205,7 @@ do_python() {
python -c "import sys,urllib2; sys.stdout.write(urllib2.urlopen(urllib2.Request(sys.argv[1], headers={ 'User-Agent': 'mixlib-install/3.12.27' })).read())" "$1" > "$2" 2>$tmp_dir/stderr
rc=$?
# check for 404
grep "HTTP Error 404" $tmp_dir/stderr 2>&1 >/dev/null
grep "HTTP Error 404" $tmp_dir/stderr >/dev/null 2>&1
if test $? -eq 0; then
echo "ERROR 404"
http_404_error
Expand All @@ -222,12 +223,12 @@ do_python() {
do_checksum() {
if exists sha256sum; then
echo "Comparing checksum with sha256sum..."
checksum=`sha256sum $1 | awk '{ print $1 }'`
return `test "x$checksum" = "x$2"`
checksum=$(sha256sum $1 | awk '{ print $1 }')
return "$(test "x$checksum" = "x$2")"
elif exists shasum; then
echo "Comparing checksum with shasum..."
checksum=`shasum -a 256 $1 | awk '{ print $1 }'`
return `test "x$checksum" = "x$2"`
checksum=$(shasum -a 256 $1 | awk '{ print $1 }')
return "$(test "x$checksum" = "x$2")"
else
echo "WARNING: could not find a valid checksum program, pre-install shasum or sha256sum in your O/S image to get validation..."
return 0
Expand Down Expand Up @@ -311,7 +312,7 @@ install_file() {
"deb")
echo "installing with dpkg..."
# WARNING: Custom fix to avoid hangs when another installation is running
flock $(apt-config shell StateDir Dir::State/d | sed -r "s/.*'(.*)'$/\1/")daily_lock dpkg -i "$2"
flock "$(apt-config shell StateDir Dir::State/d | sed -r "s/.*'(.*)'$/\1/")daily_lock" dpkg -i "$2"
;;
"bff")
echo "installing with installp..."
Expand All @@ -333,7 +334,7 @@ install_file() {
echo "installing dmg file..."
hdiutil detach "/Volumes/cinc_project" >/dev/null 2>&1 || true
hdiutil attach "$2" -mountpoint "/Volumes/cinc_project"
cd / && /usr/sbin/installer -pkg `find "/Volumes/cinc_project" -name \*.pkg` -target /
cd / && /usr/sbin/installer -pkg "$(find "/Volumes/cinc_project" -name \*.pkg)" -target /
hdiutil detach "/Volumes/cinc_project"
;;
"sh" )
Expand Down Expand Up @@ -408,7 +409,7 @@ do
esac
done

shift `expr $OPTIND - 1`
shift "$(expr $OPTIND - 1)"


if test -d "/opt/$project" && test "x$install_strategy" = "xonce"; then
Expand Down Expand Up @@ -530,6 +531,7 @@ elif test "x$os" = "xAIX"; then
elif test -f "/etc/os-release"; then
. /etc/os-release
if test "x$CISCO_RELEASE_INFO" != "x"; then
# shellcheck source=/dev/null
. $CISCO_RELEASE_INFO
fi

Expand Down Expand Up @@ -633,6 +635,7 @@ if test "x$platform" = "xsolaris2"; then
fi

# WARNING: Custom code to detect AWS Region
# shellcheck disable=SC2034 # instance_metadata_file is used below
instance_metadata_file=$tmp_dir/instance_metadata
get_region instance_metadata_file

Expand Down
7 changes: 4 additions & 3 deletions util/upload-cookbook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ _info() {
}

_help() {
local -- _cmd=$(basename "$0")
local -- _cmd
_cmd=$(basename "$0")

cat <<EOF
Expand Down Expand Up @@ -84,11 +85,11 @@ main() {

# Create archive and md5
_cwd=$(pwd)
pushd "${_srcdir}" > /dev/null
pushd "${_srcdir}" > /dev/null || exit
_stashName=$(git stash create)
git archive --format tar --prefix="aws-parallelcluster-cookbook-${_version}/" "${_stashName:-HEAD}" | gzip > "${_cwd}/aws-parallelcluster-cookbook-${_version}.tgz"
#tar zcvf "${_cwd}/aws-parallelcluster-cookbook-${_version}.tgz" --transform "s,^aws-parallelcluster-cookbook/,aws-parallelcluster-cookbook-${_version}/," ../aws-parallelcluster-cookbook
popd > /dev/null
popd > /dev/null || exit
md5sum aws-parallelcluster-cookbook-${_version}.tgz > aws-parallelcluster-cookbook-${_version}.md5

# upload packages
Expand Down

0 comments on commit b78b8b9

Please sign in to comment.