Skip to content

Commit

Permalink
updated the script and cleaned it up
Browse files Browse the repository at this point in the history
  • Loading branch information
osamaesmailmsft committed Feb 12, 2025
1 parent 2aa7c02 commit 2d1e25f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 65 deletions.
42 changes: 21 additions & 21 deletions SPECS/flux/generate_source_tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,31 @@ if [ -z "$VENDOR_VERSION" ]; then
fi

echo "-- create temp folder"
tmpdir=$(mktemp -d)
TEMP_DIR=$(mktemp -d)
function cleanup {
echo "+++ cleanup -> remove $tmpdir"
rm -rf $tmpdir
echo "+++ cleanup -> remove $TEMP_DIR"
rm -rf $TEMP_DIR
}
trap cleanup EXIT

pushd $tmpdir > /dev/null
pushd $TEMP_DIR > /dev/null

tarball_name=$(basename "$SRC_TARBALL")
TARBALL_NAME=$(basename "$SRC_TARBALL")

cache_name=${tarball_name%.*}
if [[ "$cache_name" =~ \.tar$ ]]
PKG_NAME=${TARBALL_NAME%.*}
if [[ "$PKG_NAME" =~ \.tar$ ]]
then
cache_name=${cache_name%.*}
PKG_NAME=${PKG_NAME%.*}
fi

cache_tarball_name="$cache_name-$PKG_VERSION-cargovendor-v$VENDOR_VERSION.tar.gz"
VENDOR_TARBALL="$PKG_NAME-$PKG_VERSION-cargovendor-v$VENDOR_VERSION.tar.gz"

if [[ -f "$tarball_name" ]]
if [[ -f "$TARBALL_NAME" ]]
then
cp "$SRC_TARBALL" "$tmpdir"
cp "$SRC_TARBALL" "$TEMP_DIR"
else
echo "Tarball '$tarball_name' doesn't exist. Will attempt to download from blobstorage."
if ! wget -q "https://azurelinuxsrcstorage.blob.core.windows.net/sources/core/$tarball_name" -O "$tmpdir/$tarball_name"
echo "Tarball '$TARBALL_NAME' doesn't exist. Will attempt to download from blobstorage."
if ! wget -q "https://azurelinuxsrcstorage.blob.core.windows.net/sources/core/$TARBALL_NAME" -O "$TEMP_DIR/$TARBALL_NAME"
then
echo "ERROR: failed to download the source tarball."
exit 1
Expand All @@ -123,20 +123,20 @@ echo "Unpacking source tarball..."
tar -xf $SRC_TARBALL

echo "Vendor cargo ..."
directory_name=($(ls -d */))
DIRECTORY_NAME=($(ls -d */))

# assume there is only one directory in the tarball
directory_name=${directory_name[0]%//}
DIRECTORY_NAME=${DIRECTORY_NAME[0]%//}

pushd "$directory_name" &> /dev/null
echo "Fetching dependencies to a temporary cache in $directory_name."
pushd "$DIRECTORY_NAME" &> /dev/null
echo "Fetching dependencies to a temporary cache in $DIRECTORY_NAME."

#TODO: installing rust as auto-patcher does not have it installed by default. Possibly remove if auto-patcher will be changed to have rust included.
sudo apt install -y rustc

# assume there is only one Cargo.toml
toml_location="libflux"
cd $toml_location
TOML_LOCATION=$(find . -maxdepth 2 -name "Cargo.toml" -exec dirname {} \;)
pushd $TOML_LOCATION &> /dev/null
cargo vendor > config.toml

echo ""
Expand All @@ -146,7 +146,7 @@ tar --sort=name \
--mtime="2021-04-26 00:00Z" \
--owner=0 --group=0 --numeric-owner \
--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \
-czf "$cache_tarball_name" vendor
-I pigz -cf "$VENDOR_TARBALL" vendor

popd > /dev/null
echo "$PKG_NAME vendored modules are available at $cache_tarball_name and static assets in $STATIC_ASSETS_TARBALL"
echo "$PKG_NAME vendored modules are available at $VENDOR_TARBALL"
43 changes: 21 additions & 22 deletions SPECS/virtiofsd/generate_source_tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,31 @@ if [ -z "$VENDOR_VERSION" ]; then
fi

echo "-- create temp folder"
tmpdir=$(mktemp -d)
TEMP_DIR=$(mktemp -d)
function cleanup {
echo "+++ cleanup -> remove $tmpdir"
rm -rf $tmpdir
echo "+++ cleanup -> remove $TEMP_DIR"
rm -rf $TEMP_DIR
}
trap cleanup EXIT

pushd $tmpdir > /dev/null
pushd $TEMP_DIR > /dev/null

tarball_name=$(basename "$SRC_TARBALL")
TARBALL_NAME=$(basename "$SRC_TARBALL")

cache_name=${tarball_name%.*}
if [[ "$cache_name" =~ \.tar$ ]]
PKG_NAME=${TARBALL_NAME%.*}
if [[ "$PKG_NAME" =~ \.tar$ ]]
then
cache_name=${cache_name%.*}
PKG_NAME=${PKG_NAME%.*}
fi

cache_tarball_name="$cache_name-$PKG_VERSION-cargovendor-v$VENDOR_VERSION.tar.gz"
VENDOR_TARBALL="$PKG_NAME-$PKG_VERSION-cargovendor-v$VENDOR_VERSION.tar.gz"

if [[ -f "$tarball_name" ]]
if [[ -f "$TARBALL_NAME" ]]
then
cp "$SRC_TARBALL" "$tmpdir"
cp "$SRC_TARBALL" "$TEMP_DIR"
else
echo "Tarball '$tarball_name' doesn't exist. Will attempt to download from blobstorage."
if ! wget -q "https://azurelinuxsrcstorage.blob.core.windows.net/sources/core/$tarball_name" -O "$tmpdir/$tarball_name"
echo "Tarball '$TARBALL_NAME' doesn't exist. Will attempt to download from blobstorage."
if ! wget -q "https://azurelinuxsrcstorage.blob.core.windows.net/sources/core/$TARBALL_NAME" -O "$TEMP_DIR/$TARBALL_NAME"
then
echo "ERROR: failed to download the source tarball."
exit 1
Expand All @@ -123,21 +123,20 @@ echo "Unpacking source tarball..."
tar -xf $SRC_TARBALL

echo "Vendor cargo ..."
directory_name=($(ls -d */))
DIRECTORY_NAME=($(ls -d */))

# assume there is only one directory in the tarball
directory_name=${directory_name[0]%//}
DIRECTORY_NAME=${DIRECTORY_NAME[0]%//}

pushd "$directory_name" &> /dev/null
echo "Fetching dependencies to a temporary cache in $directory_name."
pushd "$DIRECTORY_NAME" &> /dev/null
echo "Fetching dependencies to a temporary cache in $DIRECTORY_NAME."

#TODO: installing rust as auto-patcher does not have it installed by default. Possibly remove if auto-patcher will be changed to have rust included.
sudo apt install -y rustc

# assume there is only one Cargo.toml
toml_location=$(dirname $(find . -name "Cargo.toml"))
echo $toml_location
cd $toml_location
TOML_LOCATION=$(find . -maxdepth 2 -name "Cargo.toml" -exec dirname {} \;)
pushd $TOML_LOCATION &> /dev/null
cargo vendor > config.toml

echo ""
Expand All @@ -147,7 +146,7 @@ tar --sort=name \
--mtime="2021-04-26 00:00Z" \
--owner=0 --group=0 --numeric-owner \
--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \
-czf "$cache_tarball_name" vendor
-I pigz -cf "$VENDOR_TARBALL" vendor

popd > /dev/null
echo "$PKG_NAME vendored modules are available at $cache_tarball_name and static assets in $STATIC_ASSETS_TARBALL"
echo "$PKG_NAME vendored modules are available at $VENDOR_TARBALL"
43 changes: 21 additions & 22 deletions toolkit/scripts/build_cargo_cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,31 @@ if [ -z "$VENDOR_VERSION" ]; then
fi

echo "-- create temp folder"
tmpdir=$(mktemp -d)
TEMP_DIR=$(mktemp -d)
function cleanup {
echo "+++ cleanup -> remove $tmpdir"
rm -rf $tmpdir
echo "+++ cleanup -> remove $TEMP_DIR"
rm -rf $TEMP_DIR
}
trap cleanup EXIT

pushd $tmpdir > /dev/null
pushd $TEMP_DIR > /dev/null

tarball_name=$(basename "$SRC_TARBALL")
TARBALL_NAME=$(basename "$SRC_TARBALL")

cache_name=${tarball_name%.*}
if [[ "$cache_name" =~ \.tar$ ]]
PKG_NAME=${TARBALL_NAME%.*}
if [[ "$PKG_NAME" =~ \.tar$ ]]
then
cache_name=${cache_name%.*}
PKG_NAME=${PKG_NAME%.*}
fi

cache_tarball_name="$cache_name-$PKG_VERSION-cargovendor-v$VENDOR_VERSION.tar.gz"
VENDOR_TARBALL="$PKG_NAME-$PKG_VERSION-cargovendor-v$VENDOR_VERSION.tar.gz"

if [[ -f "$tarball_name" ]]
if [[ -f "$TARBALL_NAME" ]]
then
cp "$SRC_TARBALL" "$tmpdir"
cp "$SRC_TARBALL" "$TEMP_DIR"
else
echo "Tarball '$tarball_name' doesn't exist. Will attempt to download from blobstorage."
if ! wget -q "https://azurelinuxsrcstorage.blob.core.windows.net/sources/core/$tarball_name" -O "$tmpdir/$tarball_name"
echo "Tarball '$TARBALL_NAME' doesn't exist. Will attempt to download from blobstorage."
if ! wget -q "https://azurelinuxsrcstorage.blob.core.windows.net/sources/core/$TARBALL_NAME" -O "$TEMP_DIR/$TARBALL_NAME"
then
echo "ERROR: failed to download the source tarball."
exit 1
Expand All @@ -123,21 +123,20 @@ echo "Unpacking source tarball..."
tar -xf $SRC_TARBALL

echo "Vendor cargo ..."
directory_name=($(ls -d */))
DIRECTORY_NAME=($(ls -d */))

# assume there is only one directory in the tarball
directory_name=${directory_name[0]%//}
DIRECTORY_NAME=${DIRECTORY_NAME[0]%//}

pushd "$directory_name" &> /dev/null
echo "Fetching dependencies to a temporary cache in $directory_name."
pushd "$DIRECTORY_NAME" &> /dev/null
echo "Fetching dependencies to a temporary cache in $DIRECTORY_NAME."

#TODO: installing rust as auto-patcher does not have it installed by default. Possibly remove if auto-patcher will be changed to have rust included.
sudo apt install -y rustc

# assume there is only one Cargo.toml
toml_location=$(dirname $(find . -name "Cargo.toml"))
echo $toml_location
cd $toml_location
TOML_LOCATION=$(find . -maxdepth 2 -name "Cargo.toml" -exec dirname {} \;)
pushd $TOML_LOCATION &> /dev/null
cargo vendor > config.toml

echo ""
Expand All @@ -147,7 +146,7 @@ tar --sort=name \
--mtime="2021-04-26 00:00Z" \
--owner=0 --group=0 --numeric-owner \
--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \
-czf "$VENDOR_TARBALL" vendor
-I pigz -cf "$VENDOR_TARBALL" vendor

popd > /dev/null
echo "$PKG_NAME vendored modules are available at $VENDOR_TARBALL and static assets in $STATIC_ASSETS_TARBALL"
echo "$PKG_NAME vendored modules are available at $VENDOR_TARBALL"

0 comments on commit 2d1e25f

Please sign in to comment.