Hi,
I’ve been searching the webs for a solution to my issue and have not come across something solid that works for me. Any help is appreciated.
I would like to install a package (In this case openconnect) using a script that will install it on any linux distribution depending on the OS type.
I know in Debian derivatives I can issue apt-get install openconnect
I know in RHEL derivatives I can issue yum install openconnect
In Fedora I can issue dnf install openconnect
However, I’d like my script to identify the distribution it is running on and use the appropriate package management tool to install it. I do not want my script to work on every distribution, just Debian, Kali, Ubuntu, Fedora, and CentOS.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Here’s an idea — hopefully you can make use of it.
You can create a Bash script containing OS check. Probably the best idea would be to parse /etc/os-release file which contains many information about your OS.
You can run an cat command to check file’s content.
- cat /etc/os-release
Output form Fedora 27NAME=Fedora
VERSION="27 (Workstation Edition)"
ID=fedora
VERSION_ID=27
PRETTY_NAME="Fedora 27 (Workstation Edition)"
ANSI_COLOR="0;34"
...
The best idea is to parse either Name or ID, as Pretty Name is prone to change when upgrading.
There are several ways to parse key-value pairs. For example, check out awk.
Once you have distro extracted, you can put it in a if statement:
# parsing /etc/os-release...
if [ $os = "ubuntu" ]; then
# install packages
fi
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.