0

I am trying to create an install script for my program that runs on Linux systems. I am choosing Bash for the install script, and I am wondering if there is any efficient way of installing a package independent of the system's package manager. I know that Debian uses aptitude, Redhat uses yellow dog updater, etc. Given this diversity of package managers, it seems like a lot of if statements will be required, of which check the distribution and match it with the default package manager.

The only thing I can think of apart from checking the distro is having the script manually download the package sources and building them. I'm not sure how popular projects do this, but I would be interested to know.

2 Answers2

1

Your question seems inside out. Just make your script install things in /usr/local/bin with an option for those who want to create a package wrapper for their distro to easily override the destination (typically to use /usr/bin instead, ideally simply by setting DESTDIR). The Linux Standard Base should tell you where to similarly install auxiliary files, libraries, etc.

As an aside, the core package manager on Debian is dpkg and on Red Hat it's rpm.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • So are you saying that I should manually install them inside /usr/loca/bin using the sources? I'll need to make sure python2.7 is installed it (and if not install it), install pip if not already, and then manually install a C++ library. –  Jan 22 '18 at 21:33
  • The package manager will handle this through dependencies anyway - leave it to the packager to figure out how to satisfy your dependencies on their platform. – tripleee Jan 22 '18 at 21:35
  • The typical installation procedure will build anything in the current directory tree, and separately `make install` or similar to copy the necessary artefacts to system-wide locations. Compilation and testing should not require root privileges, or, if you have a component which really cannot work without them, absolutely minimize the scope and duration of privileged operations. – tripleee Jan 22 '18 at 21:39
0

You are not the first to encounter this issue. Basically, there are two differnt solutions to that.

Use a package manager

Examples:

Docker detects your OS and adds its own repository to the local package manager. This might be an option for you, depending on your project size.

Standard compile and install approach

You might have heard of the following 3 lines:

./configure
make
make install

Make is not the only option, there are other build systems, that do essentially the same.

There are still a lot of open source projects out there, where compiling locally and then moving/copying the files to the correct location is the preferred method of installation (sometimes only the development builds)

Examples:

rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38
  • Thanks I'll try Docker out. My project is less than 1,000 lines of code so it's not that big, I'll just need something that can install the packages on the main Linux distros. –  Jan 22 '18 at 21:38
  • What this means is that Docker knows how to package their stuff for a number of distros, and simply create `.deb`, `.rpm` etc packages straight out of their own sources as part of their build process. All the user needs is to add Docker's repository to their Apt/Yum/whatever sources (as in, repos they pull from), and then use that package manager to install and manage these third-party packages from Docker, too. – tripleee Jan 22 '18 at 21:44
  • And "project size" here I think refers to available personnel or volunteers, rather than source bytes. – tripleee Jan 22 '18 at 21:46