diff --git a/generate_package.sh b/generate_package.sh index 07c0d87..a6f328e 100755 --- a/generate_package.sh +++ b/generate_package.sh @@ -1,25 +1,31 @@ #!/bin/bash -e -readonly REPO_NAME="syscare" -readonly REPO_PROVIDER="openeuler" -readonly REPO_URL="https://gitee.com/$REPO_PROVIDER/$REPO_NAME" -readonly REPO_BRANCH="openEuler-22.03" +readonly SPEC_FILE="$(find . -name '*.spec' | head -n 1)" + +readonly REPO_NAME="$(basename ${SPEC_FILE} | sed 's/.spec//')" +readonly REPO_URL="https://gitee.com/openeuler/${REPO_NAME}" +readonly REPO_BRANCH="$(git branch --show-current | sed 's/-LTS.*//')" +readonly REPO_VERSION="$(grep Version ${SPEC_FILE} | head -n 1 | awk -F ' ' '{print $NF}')" + +readonly PKG_NAME="${REPO_NAME}-${REPO_VERSION}" +readonly PKG_DIR="$(realpath ./${PKG_NAME})" + +echo "Preparing..." +rm -rf ./${REPO_NAME} ./${PKG_NAME} +rm -f ./*.tar.gz + +echo "--------------------------" +echo "Name: ${REPO_NAME}" +echo "Branch: ${REPO_BRANCH}" +echo "--------------------------" echo "Cloning source code..." -repo_version=$(grep "Version" "$REPO_NAME.spec" | head -n 1 | awk -F ' ' '{print $NF}') -repo_dir="$REPO_NAME-$repo_version" - -rm -rf "$REPO_NAME" "$repo_dir" -git clone "$REPO_URL" - -echo "Prepare build requirements..." -pushd "$REPO_NAME" - -echo "Checking out dest branch..." -git checkout "$REPO_BRANCH" +git clone ${REPO_URL} -b ${REPO_BRANCH} ${PKG_NAME} echo "Vendoring dependencies..." -cargo vendor --respect-source-config --sync Cargo.toml +pushd ${PKG_DIR} > /dev/null + +cargo vendor --quiet --respect-source-config --sync Cargo.toml mkdir -p .cargo cat << EOF > .cargo/config.toml @@ -30,14 +36,12 @@ replace-with = "vendored-sources" directory = "vendor" EOF -popd +popd > /dev/null echo "Compressing package..." -mv "$REPO_NAME" "$repo_dir" -tar -czf "$repo_dir.tar.gz" "$repo_dir" +tar -czf ./${PKG_NAME}.tar.gz ${PKG_NAME} echo "Cleaning up..." -rm -rf "$repo_dir" +rm -rf ${PKG_DIR} echo "Done" - diff --git a/generate_patches.sh b/generate_patches.sh index b0f1ee9..69e31b4 100755 --- a/generate_patches.sh +++ b/generate_patches.sh @@ -1,48 +1,47 @@ #!/bin/bash -e -readonly ROOT_DIR="$(dirname $(readlink -f ${BASH_SOURCE[0]}))" readonly SPEC_FILE="$(find . -name '*.spec' | head -n 1)" + readonly REPO_NAME="$(basename ${SPEC_FILE} | sed 's/.spec//')" +readonly REPO_URL="https://gitee.com/openeuler/${REPO_NAME}" +readonly REPO_BRANCH="$(git branch --show-current | sed 's/-LTS.*//')" readonly REPO_VERSION="$(grep Version ${SPEC_FILE} | head -n 1 | awk -F ' ' '{print $NF}')" -readonly REPO_REMOTE="origin" readonly PKG_NAME="${REPO_NAME}-${REPO_VERSION}" -readonly PKG_DIR="${ROOT_DIR}/${PKG_NAME}" -readonly PKG_BRANCH="$(git branch --show-current | sed 's/-LTS.*//')" +readonly PKG_DIR="$(realpath ./${PKG_NAME})" + +readonly PATCH_DIR="$(pwd)" echo "Preparing..." -# clean old files -rm -f ${ROOT_DIR}/*.patch rm -rf ${PKG_DIR} +rm -f ./*.patch -# extract package -tar -xf ${PKG_NAME}.tar.gz +tar -xf ./${PKG_NAME}.tar.gz -# fetch baseline pushd ${PKG_DIR} > /dev/null -readonly PKG_BASELINE=$(git rev-parse --short HEAD) +readonly REPO_BASELINE="$(git rev-parse --short HEAD)" popd > /dev/null echo "------------------------------" -echo "Name: ${PKG_NAME}" -echo "Branch: ${PKG_BRANCH}" -echo "Baseline: ${PKG_BASELINE}" +echo "Name: ${REPO_NAME}" +echo "Branch: ${REPO_BRANCH}" +echo "Baseline: ${REPO_BASELINE}" echo "------------------------------" echo "Syncing with remote..." pushd ${PKG_DIR} > /dev/null -git fetch ${REPO_REMOTE} +git fetch origin popd > /dev/null echo "Generating patches..." # format patches pushd ${PKG_DIR} > /dev/null -git checkout -q ${REPO_REMOTE}/${PKG_BRANCH} -git format-patch -qN -o ${ROOT_DIR} ${PKG_BASELINE} +git checkout -q origin/${REPO_BRANCH} +git format-patch -qN -o ${PATCH_DIR} ${REPO_BASELINE} popd > /dev/null # print patch list -patch_list="$(find ${ROOT_DIR} -maxdepth 1 -name "*.patch" | sort)" +patch_list="$(find . -maxdepth 1 -name "*.patch" | sort)" for patch_file in ${patch_list}; do patch_name="$(basename ${patch_file})" patch_id="$(echo ${patch_name} | awk -F '-' '{print $1}')"