Files
LibreELEC.tv/scripts/checkdeps
2017-11-23 00:32:16 +02:00

172 lines
5.2 KiB
Bash
Executable File

#!/bin/bash
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv)
#
# OpenELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# OpenELEC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
. config/options $1
get_deps() {
need=()
need_pkg=()
for i in "${!deps[@]}"; do
dep=${deps[$i]}
dep_pkg=${deps_pkg[$i]}
[ -z "`which $dep 2>/dev/null`" ] && need+=($dep) && need_pkg+=("$dep_pkg")
done
for i in "${!files[@]}"; do
file=${files[$i]}
file_pkg=${files_pkg[$i]}
installed=N
[ $installed == N -a -f "$file" ] && installed=Y
[ $installed == N ] && need+=($file) && need_pkg+=("$file_pkg")
done
for i in "${!perl_mod[@]}"; do
mod=${perl_mod[$i]}
pkg=${perl_pkg[$i]}
if ! perl -M"$mod" -e exit 2>/dev/null; then
need+=(perl::$mod)
need_pkg+=($pkg)
fi
done
}
get_yes_no()
{
local ans
read -p "Would you like to install the needed tools ? (y/n) " ans
[ "${ans,,}" == "y" ] && return 0
[ "${ans,,}" == "yes" ] && return 0
return 1
}
if [ -f /etc/lsb-release ]; then
DISTRO=$(grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr A-Z a-z)
fi
if [ -f /etc/os-release ]; then
DISTRO=$(grep ^ID= /etc/os-release | cut -d "=" -f 2 | tr A-Z a-z)
fi
deps=(wget bash bc gcc sed patch lsdiff tar bzip2 gzip perl gawk gperf zip unzip diff lzop)
deps_pkg=(wget bash bc gcc sed patch patchutils tar bzip2 gzip perl gawk gperf zip unzip diffutils lzop)
files=(/usr/include/stdio.h /usr/include/ncurses.h)
files_pkg=(libc6-dev libncurses5-dev)
perl_mod=(JSON)
case "$DISTRO" in
fedora|centos|rhel)
deps+=(g++ mkfontscale mkfontdir bdftopcf xsltproc java python)
deps_pkg+=(gcc-c++ xorg-x11-font-utils xorg-x11-font-utils xorg-x11-font-utils libxslt java-1.7.0-openjdk python2)
[[ ! `rpm -qa glibc-static` ]] && deps+=(glibc-static) && deps_pkg+=(glibc-static)
[[ ! `rpm -qa libstdc++-static` ]] && deps+=(libstdc++-static) && deps_pkg+=(libstdc++-static)
files_pkg=(glibc-headers ncurses-devel)
perl_pkg=(perl-JSON)
;;
gentoo)
deps+=(g++ mkfontscale mkfontdir bdftopcf xsltproc java python)
deps_pkg+=("gcc[cxx]" mkfontscale mkfontdir bdftopcf libxslt virtual/jre python)
files_pkg=(glibc ncurses)
perl_pkg=(JSON)
;;
arch)
deps+=(g++ mkfontscale mkfontdir bdftopcf xsltproc java python)
deps_pkg+=(g++ xorg-mkfontscale xorg-mkfontdir xorg-bdftopcf libxslt "java-runtime-common jdk8-openjdk" python2)
perl_pkg=(perl-json)
;;
opensuse)
deps+=( g++ mkfontscale mkfontdir bdftopcf xsltproc java python)
deps_pkg+=(gcc-c++ mkfontscale mkfontdir bdftopcf libxslt-tools java-1_8_0-openjdk python)
[[ ! `rpm -qa glibc-devel-static` ]] && deps+=(glibc-devel-static) && deps_pkg+=(glibc-devel-static)
perl_pkg=(perl-JSON)
;;
*)
deps+=(g++ mkfontscale mkfontdir bdftopcf xsltproc java python)
deps_pkg+=(g++ xfonts-utils xfonts-utils xfonts-utils xsltproc default-jre python)
perl_pkg=(libjson-perl)
;;
esac
# project specific dependencies
if [ -n "$EXTRA_DEPS" ] ; then
deps+=($EXTRA_DEPS)
fi
if [ -n "$EXTRA_DEPS_PKG" ] ; then
deps_pkg+=($EXTRA_DEPS_PKG)
fi
# distro specific dependencies
if [ -n "$DISTRO_DEPS" ] ; then
deps+=($DISTRO_DEPS)
fi
if [ -n "$DISTRO_DEPS_PKG" ] ; then
deps_pkg+=($DISTRO_DEPS_PKG)
fi
get_deps
if [ "${#need[@]}" -gt 0 ]; then
echo "**** Your system lacks the following tools needed to build $DISTRONAME ****"
for i in "${!need[@]}"; do
echo "${need[$i]} provided by ${need_pkg[$i]}"
done
echo "**** You seem to use a $DISTRO system ****"
case "$DISTRO" in
ubuntu|debian|linuxmint|\"elementary\")
get_yes_no && sudo apt-get install "${need_pkg[@]}"
;;
fedora|centos|rhel)
if [ `which dnf` ]; then YUM=dnf; else YUM=yum; fi
get_yes_no && sudo $YUM install "${need_pkg[@]}"
;;
gentoo)
get_yes_no && sudo emerge --ask --deep "${need_pkg[@]}"
;;
mageia)
get_yes_no && sudo urpmi "${need_pkg[@]}"
;;
arch)
get_yes_no && sudo pacman -Sy "${need_pkg[@]}"
;;
opensuse)
get_yes_no && sudo zypper install -y --no-recommends "${need_pkg[@]}"
;;
*)
echo "**** unsupported distro $DISTRO ****"
exit 1
;;
esac
fi
get_deps
if [ "${#need[@]}" -gt 0 ]; then
echo "**** The following packages were not installed correctly ****"
for i in "${!need[@]}"; do
echo "${need[$i]} provided by ${need_pkg[$i]}"
done
echo "********"
exit 1
fi