shell-host/modules/distro.lib

66 lines
1.4 KiB
Bash

#!/bin/bash
load_distros () {
# $BASH_SHELL_HOST/distro/distros.csv
if [ -f "$1" ]; then
sed -e '$a\' "$1";
else
sed -e '$a\' <<< $(valid_distros)
fi |
sed -e '/\s*#.*$/d' |
sed -e '/^\s*$/d' |
sed 's/\s*,\s*/,/g'
}
set_distro () {
_distro="$(echo "$(load_distros)" | grep $(get_distro))"
INSTALL_PKGS=$(echo $_distro | cut -d',' -f3)
UPDATE_PKGS=$(echo $_distro | cut -d',' -f4)
export INSTALL_PKGS
export UPDATE_PKGS
[ "$1" = "-v" ] && env | grep _PKGS
}
get_distro_install () {
set_distro
echo $INSTALL_PKGS
}
get_distro_update () {
set_distro
echo $UPDATE_PKGS
}
get_distro() {
local file=/etc/upstream-release/lsb-release
if [[ -f $file ]]; then
echo $(cat $file | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq)
return 0
else
file=/etc/os-release
if [[ -f $file ]]; then
echo $(cat $file | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq)
fi
fi
}
# get_distro_install
valid_distros () {
# valid distros list
# the distro must be the name used in /etc/os-release
# <distro>,<core image name>,<install command>,<update command>
echo -e "\
alpine,alpine, apk add --no-cache, apk update \n\
debian,debian, apt-get install -y, apt-get update \n\
arch, archlinux,pacman -S --noconfirm --needed, pacman -Syu \n\
ubuntu, ubuntu, apt-get install -y, apt-get update \n\
"
}