diff --git a/distro/distros.csv b/distro/distros.csv new file mode 120000 index 0000000..454dec4 --- /dev/null +++ b/distro/distros.csv @@ -0,0 +1 @@ +/data/Hacking/computing/docker/uci-docker-build/core/rootfs/opt/lib/distros.csv \ No newline at end of file diff --git a/modules/distro.lib b/modules/distro.lib new file mode 100644 index 0000000..1221a8c --- /dev/null +++ b/modules/distro.lib @@ -0,0 +1,65 @@ +#!/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 +# ,,, + +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\ +" +} + + + diff --git a/modules/host-utils.mod b/modules/host-utils.mod index 3ce186a..b448719 100644 --- a/modules/host-utils.mod +++ b/modules/host-utils.mod @@ -43,51 +43,3 @@ hostinfo () { [[ -f /etc/upstream-release/lsb-release ]] && cat /etc/upstream-release/lsb-release } - -# function get_distro() { -# source /etc/os-release -# declare distros=${@:-"arch alpine debian ubuntu"} -# # echo $ID $ID_LIKE -# for distro in $distros; do -# echo $distro $ID $ID_LIKE -# [[ $ID =~ $distro ]] && echo $distro && return 0 -# [[ $ID_LIKE =~ $distro ]] && echo $distro && return 0 -# done -# return 1 -# } - -# function get_release() { - -# } - -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 -} - -# function get_distro() { -# /bin/cp /etc/os-release /tmp/os-release.tmp -# if [[ $1 == "-d" ]]; then -# shift 1 -# # docker run -it --name get_container_os --rm --entrypoint cat $1 /etc/os-release -# docker create --name dummy $1 > /dev/null -# docker cp -L dummy:/etc/os-release /tmp/os-release.tmp -# docker rm -f dummy > /dev/null -# # docker run -it --name get_container_os --rm --entrypoint cat $1 /etc/os-release > /tmp/container-os.tmp 2> /dev/null -# shift 1 -# fi -# source /tmp/os-release.tmp -# declare valid=${@:-"alpine debian ubuntu"} -# # echo $ID $ID_LIKE -# [[ "${valid}" =~ $ID ]] && echo $ID && return 0 -# [[ "${valid}" =~ $ID_LIKE ]] && echo $ID_LIKE && return 0 -# return 1 -# }