Skip to content

Commit 446d28e

Browse files
committed
[Tools] Add tool to update third party cookbooks.
Signed-off-by: Giacomo Marciani <[email protected]>
1 parent 1e787cf commit 446d28e

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

util/update-cookbook-dependency.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env sh
2+
set -e
3+
4+
# This script updates Cookbook dependencies.
5+
# Usage: update-cookbook-dependencies.sh [PACKAGE] [VERSION]
6+
# Example: update-cookbook-dependencies.sh apt 7.4.0
7+
8+
PACKAGE=$1
9+
VERSION=$2
10+
11+
[[ -z ${PACKAGE} ]] && echo "[ERROR] Missing required argument PACKAGE. Usage: update-cookbook-dependencies.sh [PACKAGE] [VERSION]" && exit 1
12+
[[ -z ${VERSION} ]] && echo "[ERROR] Missing required argument VERSION. Usage: update-cookbook-dependencies.sh [PACKAGE] [VERSION]" && exit 1
13+
14+
# On Mac OS, the default implementation of sed is BSD sed, but this script requires GNU sed.
15+
if [ "$(uname)" == "Darwin" ]; then
16+
command -v gsed >/dev/null 2>&1 || { echo >&2 "[ERROR] Mac OS detected: please install GNU sed with 'brew install gnu-sed'"; exit 1; }
17+
PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
18+
fi
19+
20+
echo "[INFO] Updating dependency: ${PACKAGE} ${VERSION}..."
21+
22+
PARALLEL_CLUSTER_COOKBOOK_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
23+
BERKS_FILE="${PARALLEL_CLUSTER_COOKBOOK_DIR}/Berksfile"
24+
METADATA_FILE="${PARALLEL_CLUSTER_COOKBOOK_DIR}/metadata.rb"
25+
THIRD_PARTY_DIR="${PARALLEL_CLUSTER_COOKBOOK_DIR}/third-party"
26+
DEPENDENCY_DIR="${THIRD_PARTY_DIR}/${PACKAGE}-${VERSION}"
27+
DEPENDENCY_ZIP="${DEPENDENCY_DIR}.tar.gz"
28+
CHEF_REPO_URL="https://github.com/sous-chefs/${PACKAGE}/archive/refs/tags/${VERSION}.tar.gz"
29+
30+
echo "[INFO] Detecting current version of ${PACKAGE}"
31+
CURRENT_VERSION=$(ls ${THIRD_PARTY_DIR} | grep ${PACKAGE} | cut -d '-' -f 2)
32+
if [[ -z ${CURRENT_VERSION} ]]; then
33+
echo "[ERROR] Cannot find current version of ${PACKAGE}"
34+
exit 1
35+
else
36+
echo "[INFO] Current version of ${PACKAGE} is: ${CURRENT_VERSION}"
37+
if [[ ${VERSION} == ${CURRENT_VERSION} ]]; then
38+
echo "[WARN] Current version of ${PACKAGE} ${VERSION} already installed. No update required."
39+
exit 0
40+
fi
41+
fi
42+
43+
echo "[INFO] Downloading ${PACKAGE} ${VERSION} from Chef Marketplace"
44+
wget -O ${DEPENDENCY_ZIP} ${CHEF_REPO_URL}
45+
mkdir -p ${DEPENDENCY_DIR}
46+
tar xzf ${DEPENDENCY_ZIP} -C ${DEPENDENCY_DIR} --strip-components 1
47+
rm ${DEPENDENCY_ZIP}
48+
49+
METADATA_FILES=(
50+
"${PARALLEL_CLUSTER_COOKBOOK_DIR}/metadata.rb"
51+
"${PARALLEL_CLUSTER_COOKBOOK_DIR}/cookbooks/aws-parallelcluster-awsbatch/metadata.rb"
52+
"${PARALLEL_CLUSTER_COOKBOOK_DIR}/cookbooks/aws-parallelcluster-config/metadata.rb"
53+
"${PARALLEL_CLUSTER_COOKBOOK_DIR}/cookbooks/aws-parallelcluster-install/metadata.rb"
54+
"${PARALLEL_CLUSTER_COOKBOOK_DIR}/cookbooks/aws-parallelcluster-scheduler-plugin/metadata.rb"
55+
"${PARALLEL_CLUSTER_COOKBOOK_DIR}/cookbooks/aws-parallelcluster-slurm/metadata.rb"
56+
"${PARALLEL_CLUSTER_COOKBOOK_DIR}/cookbooks/aws-parallelcluster-scheduler-plugin/metadata.rb"
57+
"${PARALLEL_CLUSTER_COOKBOOK_DIR}/cookbooks/aws-parallelcluster-test/metadata.rb"
58+
)
59+
60+
for metadata_file in ${METADATA_FILES[@]}; do
61+
echo "[INFO] Updating metadata: ${metadata_file}"
62+
sed -i "s/depends '${PACKAGE}', '~> ${CURRENT_VERSION}'/depends '${PACKAGE}', '~> ${VERSION}'/" ${metadata_file}
63+
done
64+
65+
echo "[INFO] Updating Berksfile: ${BERKS_FILE}"
66+
sed -i "s/${PACKAGE}-${CURRENT_VERSION}/${PACKAGE}-${VERSION}/" ${BERKS_FILE}
67+
68+
echo "[INFO] Removing previous version of ${PACKAGE} ${CURRENT_VERSION}"
69+
rm -rf "${THIRD_PARTY_DIR}/${PACKAGE}-${CURRENT_VERSION}"
70+
71+
echo "[INFO] Dependency updated: ${PACKAGE} ${VERSION}"

0 commit comments

Comments
 (0)