CyberShadow / btdu

sampling disk usage profiler for btrfs
GNU General Public License v2.0
422 stars 6 forks source link

Packaging for OpenSUSE distros #29

Closed pallaswept closed 7 months ago

pallaswept commented 8 months ago

Opening a new issue so as not to hijack #25

Thank you for the kind words!

I agree that a package file provided by us wouldn't be too helpful in practice. What would be helpful though is to get btdu packaged in your distro. If that's something you'd be interested in doing, it will make the tool more accessible to that distro's users. I'm also happy to help with packaging issues.

You are most welcome. I'm certainly interested in helping to get this into OpenSUSE's distros. The first step in getting it into OpenSUSE will be that I will package it in my personal public repository on their build server, and then from there I submit it to the main repo and make any required adjustments until they are satisfied with the package, and then upon acceptance it will be available in the distros' package managers

The one thing I know will be the 'trick' is that this distro builds packages in RPM format, and adheres to redhat's practice of building from source on an 'island' which means no binaries in sources and notably no internet access during the build, so I'm sure that dub won't work in the usual way. For node and rust (npm/cargo) the way this is dealt with, is to 'vendor' the packages fetched by the build tool, into an additional source archive, and during the build, run those tools in a manner that prevents them from attempting to go online.

I did have a quick look at this and found that dub had a similar option to npm's --offline argument, but I'm not 100% across it yet - specifically I'm not sure how to get it to download the remote sources to form the 'vendored source' archive, and then where to put them so it will access them. I'm confident it's documented, but if you know the way to do this off the top of your head, I'd be very grateful for any tips - but if you're unsure, don't worry, leave it with me and I'll figure it out and ask here if I get stuck.

I do have some health issues so I am a little unreliable with times, so I may not be the fastest, but the way I see it, I owe you several hours of fixing my PC that would have happened without btdu to save me, so this is a high priority to me.

CyberShadow commented 8 months ago

Hi, thanks for working on this! I suggest to have a look at the Arch Linux and Nix packages, these both separate downloading and building so that building happens without Internet access.

pallaswept commented 8 months ago

Hi, thanks for working on this!

It's the least I could do!

I suggest to have a look at the Arch Linux and Nix packages

Ahh perfect, I can do it that way, thank you! I'll get on this shortly and reply here when the package is ready.

pallaswept commented 7 months ago

I have this tab open at the front of my to-do list of open issues I need to deal with (44 tabs in this window!), and noticed that it says it's been 3 weeks since I last commented. I thought I should drop by and take a moment to explain that I've had some medical issues, combined with some other PC issues (those other 43 tabs), keeping me very busy and my availability very limited, so I've been delayed in getting this done. I apologise for the delay. I will take care of this as soon as possible, though. I just felt an explanation was in order. Again, my apologies for the delay.

CyberShadow commented 7 months ago

Hi, there is nothing at all to apologize for. Please forget about this issue and concentrate on your well being. I am going to close this issue, but let me know if or when you would like to continue this. Best wishes!

pallaswept commented 7 months ago

Thanks mate, you're very kind. Let's leave this issue closed so that it's not making a mess on your github and I'll keep the tab open and let you know when the package is ready, if you don't mind staying subscribed to the issue. I definitely will be packaging this for opensuse, and soon - even if only for my own use.

Slightly off-topic:

I made this little bash script that maybe you or others might find useful, too. Not part of the opensuse packaging, just something I made for myself, but I've used it across a few systems now, and I thought maybe you or other users might find it handy? Basically it's so that I don't have to remember the proper steps in readme.md and can 'no-brainer' my way to using the tool, even on systems where I don't know what partition is what. :)

It just takes care of mounting the appropriate volume and then launching your tool. I put it in the directory with btdu, named it runbtdu and made it executable, then I just run it with runbtdu /dev/nvme0n1p2, or on systems where I don't know the partition layout at all, or if I am just feeling lazy (or in pain) and want to type less, I can just run runbtdu and it gives me a list of partitions to attempt to mount - it will fail if you try to mount an invalid partition, and generally errs toward safety by exiting (after 'cleaning up after itself') whenever there is a problem detected, and offering the user plenty of visibility of what commands it is running, and giving opportunity to cancel if things don't look right.... It's made for transparency by showing it's actions, rather than being 'pretty' by hiding them.

I was considering an option to mount read-only for a "look but don't touch" option, but it's commented out as I found your tool to be sufficiently safe that I never bothered to finish that part (if I try to delete, btdu prompts for confirmation anyway)

You can just ignore this, or if you want to use it in your repo, feel free to modify it in any way you see fit, or whatever... I just have found it useful for myself, and I thought, hey, might as well put it somewhere aside from my own disks :) No licensing or anything, so you are free to do whatever you like with it, including taking it and putting your name on it, or laughing at it and forgetting about it :laughing:

I'll look forward to speaking to you again very soon.

#! /bin/bash

echo '
        ----= Automatic mount script for CyberShadows BTDU =----
'

rootpart=$1
scriptdir=`dirname "$0"`

if [[ -z $rootpart ]] ; then
# No partition provided.
echo 'Usage: runbtdu [path to partition holding BTRFS root]
eg: runbtdu /dev/nvme0n1p2
eg: runbtdu /dev/sda4

Alternatively, select from the following options:'
# List all possible partitions
# sudo fdisk -l | grep '^/dev/' | sed -E 's:(/dev/[0-z]*).*:\1:'

options=(`sudo fdisk -l | grep '^/dev/' | sed -E 's:(/dev/[0-z]*).*:"\1":'` "Quit")
Errors_Detected=$(($Errors_Detected + $?))

select opt in "${options[@]}"
do
    case $opt in
        "Quit") echo '        You have selected to quit. Have a nice day!'
                exit ;;
        *) echo '        You have selected partition' $opt
                if [[ -z $opt ]] ;
                then
                echo '        You have selected an invalid path, please re-run the script to try again.'
                exit
                else
                rootpart=`echo $opt | sed -E 's/"(.*)"/\1/'`
                Errors_Detected=$(($Errors_Detected + $?))
                fi
                break ;;
    esac
done
fi

# Function to offer a chance to bail if something goes wrong mounting the drive
function confirm() {
    if [[ $Errors_Detected -gt 0 ]]; then
        echo '
        ERRORS HAVE BEEN DETECTED IN THE SETUP OF THIS SCRIPT.
        ABORTING btdu LAUNCH FOR SAFETY.

        Please review the above output for errors before retrying.'

        return 1;
    fi
    while true; do
        read -p "        Do you want to proceed? (Yes or No) " yn
        case $yn in
            [Yy]* ) return 0;;
            [Nn]* ) return 1;;
            * ) echo '        Please answer YES or NO (y or n). Defaulting to not continue, for safety.'
                return 1;;
        esac
    done
}

echo '        Changing directory from ' $(pwd) ' ...'
echo '        ... to the location of this script',$scriptdir
echo "        btdu binary should be in the same directory as this script!
"

set -x
pushd "$scriptdir"
Errors_Detected=$(($Errors_Detected + $?))
{ set +x; } 2>/dev/null

if [[ ! -f ./btdu-static-x86_64 ]] ;
then echo '
        btdu binary not found, aborting!'
set -x
popd
exit
{ set +x; } 2>/dev/null
fi

# Make a temp dir to mount the BTRFS root
echo '
        Making working directory to mount BTRFS root volume...'

set -x
mkdir /tmp/btdu
Errors_Detected=$(($Errors_Detected + $?))
{ set +x; } 2>/dev/null

# Mount BTRFS root read-only to be safe
# A safe option, mounted read-only: sudo mount -o ro,subvol=/,subvolid=5 $rootpart /tmp/btdu

# Real deal mount which will allow deletion
echo '
        Mounting BTRFS root volune...'

set -x
sudo mount -t btrfs -o subvol=/,subvolid=5 $rootpart /tmp/btdu
Errors_Detected=$(($Errors_Detected + $?))
{ set +x; } 2>/dev/null

# Confirm all is well before continuing
if [[ $Errors_Detected -gt 0 ]]; then
echo '

        WARNING!
        ERRORS HAVE BEEN DETECTED IN THE EXECUTION OF THIS SCRIPT. EXECUTION OF btdu WILL NOT CONTINUE.

        You should check the output above to confirm this.'
else
echo '
        No errors have been detected in the execution of this script. You should check the output above to confirm this.
        If you see no errors it should be safe to proceed.'
fi

if confirm; then 

# Run the tool, using 8 threads, eXpert mode, stop scanning when resolution is accurate to 1MB, and dump du-style output to file
echo "
        Launching BTDU... output will be available in /tmp/btdu.txt upon completion."

set -x
sudo ./btdu-static-x86_64 -j8 -x --min-resolution=1MB --du /tmp/btdu > /tmp/btdu.txt
Errors_Detected=$(($Errors_Detected + $?))
{ set +x; } 2>/dev/null

else
echo "
        Aborted btdu launch!"
fi

# Cleanup on Aisle 42
echo '
        Cleaning up...'

# Unmount BTRFS root and remove the mount point
echo '
        Unmounting BTRFS root volume...'

set -x
sudo umount /tmp/btdu
Errors_Detected=$(($Errors_Detected + $?))
{ set +x; } 2>/dev/null

echo '
        Removing working directory...'

set -x
rmdir /tmp/btdu/
Errors_Detected=$(($Errors_Detected + $?))
{ set +x; } 2>/dev/null

echo '
        Returning to previous working directory'

set -x
popd
Errors_Detected=$(($Errors_Detected + $?))
{ set +x; } 2>/dev/null

unset scriptdir
Errors_Detected=$(($Errors_Detected + $?))

echo '
        Done! Thanks CyberShadow, for sharing a great tool!'
if [[ $Errors_Detected -gt 0 ]]; then

# Final check for errors
echo '

        WARNING!
        ERRORS HAVE BEEN DETECTED IN THE EXECUTION OF THIS SCRIPT.

        You should check the output above to see if further action is needed.'
else
echo '
        No errors have been detected in the execution of this script. You should check the output above to confirm this, but all should be well. Have a nice day!'
fi