Merge pull request #4945 from antonlacon/checkdeps

checkdeps: cleanup
This commit is contained in:
CvH 2021-01-23 09:27:07 +01:00 committed by GitHub
commit 3c1d308418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,35 +4,31 @@
# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv) # Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv)
# Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv) # Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv)
set -e
# set up variables
declare -A dep_map file_map perl_map need_map
DEBUG="false"
get_deps() { get_deps() {
need=() # start from a blank slate
need_pkg=() need_map=()
for i in "${!deps[@]}"; do for key in "${!dep_map[@]}"; do
dep=${deps[${i}]} if ! command -v "${key}" >/dev/null; then
dep_pkg=${deps_pkg[${i}]} need_map["${key}"]="${dep_map[${key}]}"
if ! command -v "${dep}" >/dev/null; then
need+=(${dep})
need_pkg+=("${dep_pkg}")
fi fi
done done
for i in "${!files[@]}"; do for key in "${!file_map[@]}"; do
file=${files[${i}]} if [ ! -f "${key}" ]; then
file_pkg=${files_pkg[${i}]} need_map["${key}"]="${file_map[${key}]}"
if [ ! -f "${file}" ]; then
need+=(${file})
need_pkg+=("${file_pkg}")
fi fi
done done
for i in "${!perl_mod[@]}"; do for key in "${!perl_map[@]}"; do
mod=${perl_mod[${i}]} if ! perl -M"${key}" -e exit 2>/dev/null; then
pkg=${perl_pkg[${i}]} need_map["perl::${key}"]="${perl_map[${key}]}"
if ! perl -M"${mod}" -e exit 2>/dev/null; then
need+=(perl::${mod})
need_pkg+=(${pkg})
fi fi
done done
} }
@ -40,12 +36,13 @@ get_deps() {
get_yes_no() get_yes_no()
{ {
local ans local ans
read -p "Would you like to install the needed tools? (y/n) " ans read -p "Would you like to install the needed tools? (y/n)" ans
[ "${ans,,}" = "y" ] && return 0 [ "${ans,,}" = "y" ] && return 0
[ "${ans,,}" = "yes" ] && return 0 [ "${ans,,}" = "yes" ] && return 0
return 1 return 1
} }
if [ -f /etc/lsb-release ]; then if [ -f /etc/lsb-release ]; then
DISTRO=$(grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2) DISTRO=$(grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2)
fi fi
@ -56,115 +53,219 @@ fi
DISTRO=${DISTRO,,} DISTRO=${DISTRO,,}
deps=(wget bash bc gcc sed patch lsdiff tar bzip2 gzip xz perl gawk gperf zip unzip diff lzop make file) # [program]=package
deps_pkg=(wget bash bc gcc sed patch patchutils tar bzip2 gzip xz-utils perl gawk gperf zip unzip diffutils lzop make file) dep_map=(
[bash]=bash
[bc]=bc
[bzip2]=bzip2
[diff]=diffutils
[gawk]=gawk
[gcc]=gcc
[gperf]=gperf
[gzip]=gzip
[file]=file
[lsdiff]=patchutils
[lzop]=lzop
[make]=make
[patch]=patch
[perl]=perl
[sed]=sed
[tar]=tar
[unzip]=unzip
[wget]=wget
[xz]=xz-utils
[zip]=zip
)
files=(/usr/include/stdio.h /usr/include/ncurses.h) # [file]=package
files_pkg=(libc6-dev libncurses5-dev) file_map=(
[/usr/include/ncurses.h]=libncurses5-dev
[/usr/include/stdio.h]=libc6-dev
)
perl_mod=(JSON XML::Parser Thread::Queue Parse::Yapp::Driver) # [module]=package
perl_map=(
[JSON]=libjson-perl
[Parse::Yapp::Driver]=libparse-yapp-perl
[Thread::Queue]=perl
[XML::Parser]=libxml-parser-perl
)
### PROJECT SPECIFIC REQUIREMENTS ###
# Extend build scripts to look for distro/project/device checkdep scripts before adding further checks here
# Native aarch64 on debian(?) host Rockchip needs to support rkbin
if [ "$(uname -m)" = "aarch64" -a "${PROJECT}" = "Rockchip" ]; then
dep_map[qemu-x86_64]=qemu-user-binfmt
if [ ! -f /lib64/ld-linux-x86-64.so.2 -o ! -f /lib/x86_64-linux-gnu/libc.so.6 ]; then
echo -e "Copy from a working x86_64 system:\n\t/lib64/ld-linux-x86-64.so.2\n\t/lib/x86_64-linux-gnu/libc.so.6"
fi
file_map[/lib64/ld-linux-x86-64.so.2]="libc6:amd64"
file_map[/lib/x86_64-linux-gnu/libc.so.6]="libc6:amd64"
fi
# remap or add [depend]=package needs based on host distro
case "${DISTRO}" in case "${DISTRO}" in
fedora|centos|rhel) fedora|centos|rhel)
deps+=(g++ mkfontscale mkfontdir bdftopcf xsltproc java python3 rpcgen) dep_map+=(
deps_pkg+=(gcc-c++ xorg-x11-font-utils xorg-x11-font-utils xorg-x11-font-utils libxslt java-1.7.0-openjdk python3 rpcgen) [g++]=gcc-c++
[mkfontscale]=xorg-x11-font-utils
[mkfontdir]=xorg-x11-font-utils
[bdftopcf]=xorg-x11-font-utils
[xsltproc]=libxslt
[java]=java-1.7.0-openjdk
[python3]=python3
[rpcgen]=rpcgen
)
if [[ ! $(rpm -qa glibc-static) ]]; then if [[ ! $(rpm -qa glibc-static) ]]; then
deps+=(glibc-static) dep_map+=(
deps_pkg+=(glibc-static) [glibc-static]=glibc-static
)
fi fi
if [[ ! $(rpm -qa libstdc++-static) ]]; then if [[ ! $(rpm -qa libstdc++-static) ]]; then
deps+=(libstdc++-static) dep_map+=(
deps_pkg+=(libstdc++-static) [libstdc++-static]=libstdc++-static
)
fi fi
files_pkg=(glibc-headers ncurses-devel) file_map+=(
perl_pkg=(perl-JSON perl-XML-Parser perl-Thread-Queue perl-Parse-Yapp) [/usr/include/ncurses.h]=ncurses-devel
[/usr/inculde/stdio.h]=glibc-headers
)
perl_map+=(
[JSON]=perl-JSON
[Parse::Yapp::Driver]=perl-Parse-Yapp
[Thread::Queue]=perl-Thread-Queue
[XML::Parser]=perl-XML-Parser
)
;; ;;
gentoo|sabayon) gentoo|sabayon)
deps+=(g++ mkfontscale mkfontdir bdftopcf xsltproc java python3 rpcgen) dep_map+=(
deps_pkg+=("gcc[cxx]" mkfontscale mkfontdir bdftopcf libxslt virtual/jre python3 net-libs/rpcsvc-proto) [g++]="gcc[cxx]"
files_pkg=(glibc ncurses) [mkfontscale]=mkfontscale
perl_pkg=(JSON XML-Parser perl-Thread-Queue perl-Parse-Yapp) [bdftopcf]=bdftopcf
[xsltproc]=libxslt
[java]=virtual/jre
[python3]=python
[rpcgen]=net-libs/rpcsvc-proto
)
file_map+=(
[/usr/inculde/stdio.h]=glibc
[/usr/include/ncurses.h]=ncurses
)
perl_map+=(
[JSON]=JSON
[Parse::Yapp::Driver]=perl-Parse-Yapp
[Thread::Queue]=perl-Thread-Queue
[XML::Parser]=XML-Parser
)
;; ;;
arch) arch)
deps+=(g++ mkfontscale mkfontdir bdftopcf xsltproc java python3 rpcgen) dep_map+=(
deps_pkg+=(g++ xorg-mkfontscale xorg-mkfontdir xorg-bdftopcf libxslt "java-runtime-common jdk8-openjdk" python3 rpcsvc-proto) [g++]=g++
perl_pkg=(perl-json perl-xml-parser perl perl-parse-yapp) [mkfontscale]=xorg-mkfontscale
[mkfontdir]=xorg-mkfontdir
[bdftopcf]=xorg-bdftopcf
[xsltproc]=libxslt
[java]="java-runtime-common jdk8-openjdk"
[python3]=python3
[rpcgen]=rpcsvc-proto
)
perl_map+=(
[JSON]=perl-json
[XML::Parser]=perl-xml-parser
[Thread::Queue]=perl
[Parse::Yapp::Driver]=perl-parse-yapp
)
;; ;;
opensuse) opensuse)
deps+=( g++ mkfontscale mkfontdir bdftopcf xsltproc java python3) dep_map+=(
deps_pkg+=(gcc-c++ mkfontscale mkfontdir bdftopcf libxslt-tools java-1_8_0-openjdk python3) [g++]=gcc-c++
[mkfontscale]=mkfontscale
[mkfontdir]=mkfontdir
[bdftopcf]=bdftopcf
[xsltproc]=libxslt-tools
[java]=java-1_8_0-openjdk
[python3]=python3
)
if [[ ! $(rpm -qa glibc-devel-static) ]]; then if [[ ! $(rpm -qa glibc-devel-static) ]]; then
deps+=(glibc-devel-static) dep_map+=(
deps_pkg+=(glibc-devel-static) [glibc-devel-static]=glibc-devel-static
)
fi fi
perl_pkg=(perl-JSON perl-XML-Parser perl perl-Parse-Yapp) perl_map+=(
[JSON]=perl-JSON
[XML::Parser]=perl-XML-Parser
[Thread::Queue]=perl
[Parse::Yapp::Driver]=perl-Parse-Yapp
)
;; ;;
*) *)
deps+=(g++ mkfontscale mkfontdir bdftopcf xsltproc java python3) dep_map+=(
deps_pkg+=(g++ xfonts-utils xfonts-utils xfonts-utils xsltproc default-jre python3) [g++]=g++
perl_pkg=(libjson-perl libxml-parser-perl perl libparse-yapp-perl) [mkfontscale]=xfonts-utils
[mkfontdir]=xfonts-utils
[bdftopcf]=xfonts-utils
[xsltproc]=xsltproc
[java]=default-jre
[python3]=python3
)
;; ;;
esac esac
# project specific dependencies if [ "${DEBUG}" = "true" ]; then
if [ -n "${EXTRA_DEPS}" ] ; then echo "DEP MAP"
deps+=(${EXTRA_DEPS}) for key in "${!dep_map[@]}"; do
fi echo "${key}:${dep_map[${key}]}"
if [ -n "${EXTRA_DEPS_PKG}" ] ; then done
deps_pkg+=(${EXTRA_DEPS_PKG}) echo "FILE MAP"
fi for key in "${!file_map[@]}"; do
echo "${key}:${file_map[${key}]}"
# distro specific dependencies done
if [ -n "${DISTRO_DEPS}" ] ; then echo "PERL MAP"
deps+=(${DISTRO_DEPS}) for key in "${!perl_map[@]}"; do
fi echo "${key}:${perl_map[${key}]}"
if [ -n "${DISTRO_DEPS_PKG}" ] ; then done
deps_pkg+=(${DISTRO_DEPS_PKG})
fi
# aarch64 dependencies
if [ "$(uname -m)" = "aarch64" ]; then
if [ ! -f /lib64/ld-linux-x86-64.so.2 -a ! -f /lib/x86_64-linux-gnu/libc.so.6 ]; then
printf "Copy from a working x86_64 system:\n\t/lib64/libc.so.6\n\t/lib/x86_64-linux-gnu/libc.so.6\n"
fi
files+=(/lib64/ld-linux-x86-64.so.2 /lib/x86_64-linux-gnu/libc.so.6)
files_pkg+=(libc6:amd64 libc6:amd64)
deps+=(qemu-x86_64)
deps_pkg+=(qemu-user-binfmt)
fi fi
### DEPENDENCY CHECKING AND INSTALLATION ###
get_deps get_deps
if [ "${#need[@]}" -gt 0 ]; then if [ "${DEBUG}" = "true" ]; then
echo "**** Your system lacks the following tools needed to build ${DISTRONAME} ****" echo "NEED MAP"
for i in "${!need[@]}"; do for key in "${!need_map[@]}"; do
echo "${need[${i}]} provided by ${need_pkg[${i}]}" echo "${key}:${need_map[${key}]}"
done done
echo "**** You seem to use a ${DISTRO} system ****" fi
if [ "${#need_map[@]}" -gt 0 ]; then
echo "**** This system lacks the following tools needed to build ${DISTRONAME} ****"
for key in "${!need_map[@]}"; do
echo "${key} provided by ${need_map[${key}]}"
done
echo "**** The system appears to be a ${DISTRO} system ****"
if command -v sudo >/dev/null; then if command -v sudo >/dev/null; then
case "${DISTRO}" in case "${DISTRO}" in
ubuntu|debian|linuxmint|\"elementary\") ubuntu|debian|linuxmint|\"elementary\")
get_yes_no && sudo apt-get install "${need_pkg[@]}" get_yes_no && sudo apt-get install "${need_map[@]}"
;; ;;
fedora|centos|rhel) fedora|centos|rhel)
command -v dnf >/dev/null && YUM=dnf || YUM=yum command -v dnf >/dev/null && YUM=dnf || YUM=yum
get_yes_no && sudo ${YUM} install "${need_pkg[@]}" get_yes_no && sudo ${YUM} install "${need_map[@]}"
;; ;;
gentoo) gentoo)
get_yes_no && sudo emerge --ask --deep "${need_pkg[@]}" get_yes_no && sudo emerge --ask --deep "${need_map[@]}"
;; ;;
sabayon) sabayon)
get_yes_no && sudo equo install --ask "${need_pkg[@]}" get_yes_no && sudo equo install --ask "${need_map[@]}"
;; ;;
mageia) mageia)
get_yes_no && sudo urpmi "${need_pkg[@]}" get_yes_no && sudo urpmi "${need_map[@]}"
;; ;;
arch) arch)
get_yes_no && sudo pacman -Sy "${need_pkg[@]}" get_yes_no && sudo pacman -Sy "${need_map[@]}"
;; ;;
opensuse) opensuse)
get_yes_no && sudo zypper install -y --no-recommends "${need_pkg[@]}" get_yes_no && sudo zypper install -y --no-recommends "${need_map[@]}"
;; ;;
*) *)
echo "**** unsupported distro ${DISTRO} ****" echo "**** unsupported distro ${DISTRO} ****"
@ -173,15 +274,17 @@ if [ "${#need[@]}" -gt 0 ]; then
esac esac
else else
echo "The command 'sudo' was not found. Please install necessary packages manually." echo "The command 'sudo' was not found. Please install necessary packages manually."
exit 1
fi fi
fi fi
# check if installed packages satisifed deps
get_deps get_deps
if [ "${#need[@]}" -gt 0 ]; then if [ "${#need_map[@]}" -gt 0 ]; then
echo "**** The following packages were not installed correctly ****" echo "**** The following packages were not installed correctly ****"
for i in "${!need[@]}"; do for key in "${!need_map[@]}"; do
echo "${need[${i}]} provided by ${need_pkg[${i}]}" echo "${key} provided by ${need_map[${key}]}"
done done
echo "********" echo "********"
exit 1 exit 1