From 393cbe2a12c8d429e4205e280b0fdf35b5a437b8 Mon Sep 17 00:00:00 2001 From: meo <83820503+meo-pill@users.noreply.github.com> Date: Mon, 6 Jan 2025 00:43:43 +0100 Subject: [PATCH] FreeBSD fix and test (#55) * add: test on freebsd * test fix vm * fix: transform to lowercase transform the `OSTYPE` to a lowercase and store it inside `OSName` * add: caching of the vm --- .github/workflows/test.yml | 27 ++++++++++++++++++++++++++- zfs-inplace-rebalancing.sh | 14 ++++++++------ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8bc609f..02e3b01 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,4 +25,29 @@ jobs: - uses: actions/checkout@v4 - name: Run testing script on macOS - run: ./testing.sh \ No newline at end of file + run: ./testing.sh + + FreeBSDTest: + name: Test on FreeBSD + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ~/.cache + key: ${{ runner.os }}-cache-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-cache- + + - name: Test in FreeBSD + id: test + uses: vmactions/freebsd-vm@v1 + with: + usesh: true + prepare: | + pkg install -y bash + run: | + ./testing.sh \ No newline at end of file diff --git a/zfs-inplace-rebalancing.sh b/zfs-inplace-rebalancing.sh index 262d0f6..9497103 100755 --- a/zfs-inplace-rebalancing.sh +++ b/zfs-inplace-rebalancing.sh @@ -59,7 +59,7 @@ function rebalance() { # this shouldn't be needed in the typical case of `find` only finding files with links == 1 # but this can run for a long time, so it's good to double check if something changed if [[ "${skip_hardlinks_flag}" == "true"* ]]; then - if [[ "${OSTYPE}" == "linux-gnu"* ]]; then + if [[ "${OSName}" == "linux-gnu"* ]]; then # Linux # # -c --format=FORMAT @@ -68,7 +68,7 @@ function rebalance() { # %h number of hard links hardlink_count=$(stat -c "%h" "${file_path}") - elif [[ "${OSTYPE}" == "darwin"* ]] || [[ "${OSTYPE}" == "freebsd"* ]]; then + elif [[ "${OSName}" == "darwin"* ]] || [[ "${OSName}" == "freebsd"* ]]; then # Mac OS # FreeBSD # -f format @@ -108,7 +108,7 @@ function rebalance() { tmp_file_path="${file_path}${tmp_extension}" echo "Copying '${file_path}' to '${tmp_file_path}'..." - if [[ "${OSTYPE}" == "linux-gnu"* ]]; then + if [[ "${OSName}" == "linux-gnu"* ]]; then # Linux # --reflink=never -- force standard copy (see ZFS Block Cloning) @@ -116,7 +116,7 @@ function rebalance() { # -p -- preserve ACLs to # -x -- stay on one system cp --reflink=never -ax "${file_path}" "${tmp_file_path}" - elif [[ "${OSTYPE}" == "darwin"* ]] || [[ "${OSTYPE}" == "freebsd"* ]]; then + elif [[ "${OSName}" == "darwin"* ]] || [[ "${OSName}" == "freebsd"* ]]; then # Mac OS # FreeBSD @@ -133,7 +133,7 @@ function rebalance() { # compare copy against original to make sure nothing went wrong if [[ "${checksum_flag}" == "true"* ]]; then echo "Comparing copy against original..." - if [[ "${OSTYPE}" == "linux-gnu"* ]]; then + if [[ "${OSName}" == "linux-gnu"* ]]; then # Linux # file attributes @@ -156,7 +156,7 @@ function rebalance() { copy_md5="${copy_md5} $(md5sum -b "${tmp_file_path}")" # remove the temporary extension copy_md5=${copy_md5%"${tmp_extension}"} - elif [[ "${OSTYPE}" == "darwin"* ]] || [[ "${OSTYPE}" == "freebsd"* ]]; then + elif [[ "${OSName}" == "darwin"* ]] || [[ "${OSName}" == "freebsd"* ]]; then # Mac OS # FreeBSD @@ -250,6 +250,8 @@ done root_path=$1 +OSName=$(echo "$OSTYPE" | tr '[:upper:]' '[:lower:]') + color_echo "$Cyan" "Start rebalancing $(date):" color_echo "$Cyan" " Path: ${root_path}" color_echo "$Cyan" " Rebalancing Passes: ${passes_flag}"