Project #1: PackagerBuddy

  • Respository: link
  • I wrote a software package manager because the world didn't have enough of them.

    In all seriousness, PackagerBuddy is JSON configured command line software package manager fully written in Python.

    Demo

    Why?

    Around 2015 I was distro-hopping a lot and I found myself setting up virtual machines and installing the same software over and over again. I realized that most, if not all, software I was installing had a dedicated version number and download link. This means that by knowing the software name and version, you can determine the download link and have a quick and easy way to download the desired software.

    That's all fine and dandy, but once downloaded, sometimes you end up with a compressed file, directory or straight up executable. What then? Some need unpacking, compiling, moving to a specific location or all of the above. But all of these scenarios seemed quite easy to cover, so I got to it.

    First iteration was a bash script per software handling all sections in one file. It would take two arguments, software and version, to create the download link. Then it would download, extract and run custom actions if necessary, ranging from compiling to creating executable symbolic links.

    Only problem was, the more software I supported, the more bash scripts I ended up with all sharing a ton of similar code. I quickly decided to refactor it into a command line tool that would replace all my bash scripts, and potentially help others as well.

    What can it do?

    What does it look like?

    # configure software
    packagerbuddy add --software {NAME} --url {URL}
    packagerbuddy remove --software {NAME}
    
    # list available software to download
    packagerbuddy avail
    
    # download software (can be skipped, covered by install)
    packagerbuddy download --software {NAME} --version {VERSION}
    
    # install software
    packagerbuddy install --software {NAME} --version {VERSION}
    
    # list installed software
    packagerbuddy list
    
    # uninstall software
    packagerbuddy uninstall --software {NAME}
    packagerbuddy uninstall --software {NAME} --version {VERSION}
    

    How does it work?

    We previously established that software to install needs to be downloaded, then followed by a set of actions to finally be able to use the software. We can define the workflow in three major components.

    1. Dowload
    2. Unpack
    3. Install

    Download

    The first step is most likely the simplest one. Once a URL can be determined, a couple of lines of Python are enough to create a request, read the contents and write it all out. If the request cannot be read out, an error will be shown stating the problem. Typically an invalid or dead URL. If all goes accordingly, we can move to step two.

    Unpack

    The second step is a little trickier. Whether unpacking is even necessary or supported, is based on the extension of the downloaded content. Knowing the extension, we can determine the read mode required to unpack accordingly. With the read mode known, we can extract the contents. Currently following extensions are supported:

    A common problem with extracting is that if the compressed content was not a directory, you'll end up loosely extracting files into a target directory creating a mess. To avoid that mess, PackagerBuddy will detect the compressed content, neatly and consistently extract into a directory.

    Install

    The third step can be as simple or difficult as you like.

    Installing in itself is simply copying downloaded contents of the desired software version to an install directory. However, PackagerBuddy allows you to configure bash scripts which will be executed on install. From there it's open field.

    These scripts can be version specific or agnostic. This allows for multiple post install workflows to be run. Scripts will be called after having moved the downloaded contents over, with the install directory as working directory and with two positional arguments passed being software and version.

    Here are example scripts shipping with the respository:

    Conclusion

    Solve your own problems and you might just solve some of others in the meantime.