代码拉取完成,页面将自动刷新
#!/bin/bash
#########################################################
# Function :Generate tarball for upgrade #
# Platform :Linux Platform #
# Version :1.0 #
# Date :2024-08-21 #
# Author :gordonwwang #
#########################################################
# Function to handle errors
handle_error() {
echo "$1"
exit "$2"
}
# Function to check and install tools
check_tools() {
if ! command -v rpmspec &> /dev/null; then
dnf install /usr/bin/rpmspec -yq || handle_error 'Failed to install rpmspec' 1
fi
# cargo only for rust
if ! command -v cargo &> /dev/null; then
dnf install cargo -yq || handle_error 'Failed to install cargo' 1
fi
}
# Function tears down
tear_down() {
cd "$cur_dir"
rm -rf "$dir_name"
rm -f ./tmp_spec
echo "tears down before script exit."
}
# Function to generate the tarball
generate_tarball() {
# Get name, version, and source from spec
specname=$(basename "$PWD")
rpmspec -P "${specname}.spec" > ./tmp_spec
[ $? -eq 0 ] || handle_error "spec parse failed" 2
name=$(grep '^Name:' ./tmp_spec | awk '{print $2}')
version=$(grep '^Version:' ./tmp_spec | awk '{print $2}')
source0=$(grep '^Source0:' ./tmp_spec | awk '{print $2}')
source1=$(grep '^Source1:' ./tmp_spec | awk '{print $2}')
cur_dir=$(pwd)
# Download and unzip tarball
tarball_name=$(basename "${source0}")
wget "${source0}" -q --show-progress -O "${tarball_name}"
[ $? -eq 0 ] || handle_error "Failed to download source" 3
tar -xzf "${tarball_name}"
dir_name="cryptography-${version}"
cd "$dir_name"/src/rust
# Run cargo vendor
cargo vendor
[ $? -eq 0 ] || handle_error "cargo vendor failed" 4
# Tar and compress
echo "Generate vendor ..."
vendor_file=$(basename "${source1}") # e.g., "${name}-${version}-vendor.tar.bz2"
tar -cjf "${vendor_file}" vendor
mv "${vendor_file}" "$cur_dir"
}
# Ensure tear_down is called on script exit
trap tear_down EXIT
check_tools
generate_tarball
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。