Clean up scripts, move burn image to tools

This commit is contained in:
fewtarius 2022-02-07 16:00:00 -05:00
parent 3978cbf69a
commit ac8ba30e1f
No known key found for this signature in database
GPG key ID: F4AE55305D1B8C1A
5 changed files with 49 additions and 378 deletions

View file

@ -6,8 +6,6 @@
. config/options ""
. config/multithread
${SCRIPTS}/checkdeps
# Setup both toolchain cmake configs to avoid potentially racy behaviour later.
# Use a fork for host to isolate any variable modifications.
( setup_toolchain host )

View file

@ -1,186 +0,0 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv)
# Copyright (C) 2018 Team LibreELEC (https://libreelec.tv)
# Copyright (C) 2018-present Team CoreELEC (https://coreelec.org)
. config/options ""
get_deps() {
need=()
need_pkg=()
for i in "${!deps[@]}"; do
dep=${deps[${i}]}
dep_pkg=${deps_pkg[${i}]}
if ! command -v "${dep}" >/dev/null; then
need+=(${dep})
need_pkg+=("${dep_pkg}")
fi
done
for i in "${!files[@]}"; do
file=${files[${i}]}
file_pkg=${files_pkg[${i}]}
if [ ! -f "${file}" ]; then
need+=(${file})
need_pkg+=("${file_pkg}")
fi
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)
fi
if [ -f /etc/os-release ]; then
DISTRO=$(grep ^ID= /etc/os-release | cut -d "=" -f 2)
fi
DISTRO=${DISTRO,,}
deps=(wget bash bc gcc sed patch lsdiff tar bzip2 gzip perl gawk gperf zip unzip diff lzop go)
deps_pkg=(wget bash bc gcc sed patch patchutils tar bzip2 gzip perl gawk gperf zip unzip diffutils lzop golang curl libssl-dev patchelf)
files=(/usr/include/stdio.h /usr/include/ncurses.h)
files_pkg=(libc6-dev libncurses5-dev)
perl_mod=(JSON XML::Parser)
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)
if [[ ! $(rpm -qa glibc-static) ]]; then
deps+=(glibc-static)
deps_pkg+=(glibc-static)
fi
if [[ ! $(rpm -qa libstdc++-static) ]]; then
deps+=(libstdc++-static)
deps_pkg+=(libstdc++-static)
fi
files_pkg=(glibc-headers ncurses-devel)
perl_pkg=(perl-JSON perl-XML-parser)
;;
gentoo|sabayon)
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 XML-Parser)
;;
arch|manjaro)
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 perl-xml-parser)
;;
opensuse)
deps+=( g++ mkfontscale mkfontdir bdftopcf xsltproc java python)
deps_pkg+=(gcc-c++ mkfontscale mkfontdir bdftopcf libxslt-tools java-1_8_0-openjdk python)
if [[ ! $(rpm -qa glibc-devel-static) ]]; then
deps+=(glibc-devel-static)
deps_pkg+=(glibc-devel-static)
fi
perl_pkg=(perl-JSON perl-XML-Parser)
;;
*)
deps+=(g++ mkfontscale mkfontdir bdftopcf xsltproc java python)
deps_pkg+=(g++ xfonts-utils xsltproc default-jre python)
perl_pkg=(libjson-perl libxml-parser-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
# aarch64 dependencies
if [ "$(uname -m)" == "aarch64" ]; then
deps+=(qemu-x86_64)
deps_pkg+=(qemu-user-binfmt)
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 ****"
if command -v sudo >/dev/null; then
case "${DISTRO}" in
ubuntu|debian|linuxmint|\"elementary\")
get_yes_no && sudo apt-get install "${need_pkg[@]}"
;;
fedora|centos|rhel)
command -v dnf >/dev/null && YUM=dnf || YUM=yum
get_yes_no && sudo ${YUM} install "${need_pkg[@]}"
;;
gentoo)
get_yes_no && sudo emerge --ask --deep "${need_pkg[@]}"
;;
sabayon)
get_yes_no && sudo equo install --ask "${need_pkg[@]}"
;;
mageia)
get_yes_no && sudo urpmi "${need_pkg[@]}"
;;
arch|manjaro)
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
else
echo "The command 'sudo' was not found. Please install necessary packages manually."
fi
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

View file

@ -1,188 +0,0 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2019-present Team LibreELEC (https://libreelec.tv)
. config/options ""
. config/multithread
usage() {
cat - >&2 <<EOF
SYNOPSIS
./script/create_addon [OPTION] [addons]...
DESCRIPTION
create_addon builds one or more addons.
--show-only
output the list of packages, which are intented to build
--help shows this message
[addons]
list of addons to build.
The addons can identified by:
- the name of the addon
- a group name of addons
* all - all addons found under packages and project/*/packages
* official - all addons found under packages/addons
* binary - all addons found under packages/mediacenter/kodi-binary-addons
- a regex term (grep styled), the term is automatic sorounded with string begin and end (^[term]$)
addons can removed from list with a leading minus.
EXAMPLE
build all addons
> ./script/create_addon all
build audio encoders and decoders, only
> ./script/create_addon audioencoder.* audiodecoder.*
build all, but not binary
> ./script/create_addon all -binary
EOF
exit ${1:-0}
}
# Get list of addon packages
get_addons() {
local paths filter
local pkgpath exited
local count=0 validpkg
case ${1} in
binary) paths="^${ROOT}/packages/mediacenter/kodi-binary-addons/";;
official) paths="^${ROOT}/packages/addons/";;
all) paths="^${ROOT}/packages/|^${ROOT}/projects/.*/packages/";;
*) paths="^${ROOT}/packages/|^${ROOT}/projects/.*/packages/"; filter="${1}";;
esac
exit() { exited=1; }
for pkgpath in $(cat "${_CACHE_PACKAGE_LOCAL}" "${_CACHE_PACKAGE_GLOBAL}" | grep -E "${paths}"); do
if [ -n "${filter}" ]; then
[[ ${pkgpath} =~ ^.*/${filter}@?+?@ ]] || continue
fi
exited=0
source_package "${pkgpath%%@*}/package.mk" &>/dev/null
[ ${exited} -eq 1 ] && continue
validpkg="no"
VERIFY_FAIL=
# Should only build embedded addons when they are explictly specified in the addon list
if [ "${PKG_IS_ADDON}" = "embedded" ]; then
if [ -n "${filter}" ]; then
verify_addon && validpkg="yes"
fi
elif [ "${PKG_IS_ADDON}" = "yes" ]; then
verify_addon && validpkg="yes"
fi
if [ "${validpkg}" = "yes" ]; then
echo "${PKG_NAME}"
count=$((count + 1))
elif [ -n "${VERIFY_FAIL}" -a -n "${filter}" ]; then
echo "$(print_color CLR_ERROR "${PKG_NAME}"): ${VERIFY_FAIL}" >&2
fi
done
unset -f exit
if [ ${count} -eq 0 -a -n "${filter}" ]; then
echo "$(print_color CLR_ERROR "ERROR: no addons matched for filter ${filter}")" >&2
echo "For more information type: ./scripts/create_addon --help" >&2
die
fi
}
# Return 0 if package is a suitable addon, 1 otherwise
verify_addon() {
if [ -n "${PKG_ARCH}" ]; then
VERIFY_FAIL="Incompatible arch: \"${TARGET_ARCH}\" not in [ ${PKG_ARCH} ]"
listcontains "${PKG_ARCH}" "!${TARGET_ARCH}" && return 1
listcontains "${PKG_ARCH}" "${TARGET_ARCH}" || listcontains "${PKG_ARCH}" "any" || return 1
fi
if [ -n "${PKG_ADDON_PROJECTS}" ]; then
[ "${DEVICE}" = "RPi" ] && _DEVICE="RPi1" || _DEVICE="${DEVICE}"
VERIFY_FAIL="Incompatible project or device: \"${_DEVICE:-${PROJECT}}\" not in [ ${PKG_ADDON_PROJECTS} ]"
if listcontains "${PKG_ADDON_PROJECTS}" "!${_DEVICE:-${PROJECT}}" ||
listcontains "${PKG_ADDON_PROJECTS}" "!${PROJECT}"; then
return 1
fi
if ! listcontains "${PKG_ADDON_PROJECTS}" "${_DEVICE:-${PROJECT}}" &&
! listcontains "${PKG_ADDON_PROJECTS}" "${PROJECT}" &&
! listcontains "${PKG_ADDON_PROJECTS}" "any"; then
return 1
fi
fi
return 0
}
# need parameter
if [ $# -eq 0 ]; then
usage 1
fi
# check environment and configure toolchains
${SCRIPTS}/checkdeps
(setup_toolchain host)
setup_toolchain target
# collect list of addons for building
addons=
addons_drop=
show_only="no"
# read addons from parameter list
while [ $# -gt 0 ]; do
case ${1} in
--help) usage 0;;
--show-only) show_only="yes";;
--*) usage 1;;
-*) addons_drop+=" $(get_addons ${1:1})";;
*) addons+=" $(get_addons ${1})";;
esac
shift
done
# Build a new list containing only those addons we want to build
wanted_addons=
for addon in $(echo ${addons} | tr ' ' '\n' | sort -u); do
listcontains "${addons_drop}" "${addon}" || wanted_addons+=" ${addon}"
done
if [ "${show_only}" = "yes" ]; then
for addon in ${wanted_addons}; do
echo ${addon}
done
exit 0
fi
# Build all addons at once using a single plan
if MTADDONBUILD=yes start_multithread_build "${wanted_addons:1}"; then
echo
echo "$(print_color CLR_INFO "ALL ADDONS BUILT SUCCESSFULLY")"
exit 0
elif [ -f "${THREAD_CONTROL}/addons.failed" ]; then
echo >&2
print_color CLR_ERROR "FAILED ADDONS:\n" >&2
while read -r addon logfile; do
if [ -n "${addon}" ]; then
if [ -n "${logfile}" ]; then
echo " $(print_color CLR_ERROR "${addon}"): ${logfile}" >&2
else
echo " $(print_color CLR_ERROR "${addon}")" >&2
fi
fi
done < "${THREAD_CONTROL}/addons.failed"
die
else
die "$(print_color CLR_ERROR "UNKNOWN BUILD FAILURE OR INABILITY TO GENERATE PLAN")"
fi

View file

@ -13,8 +13,6 @@ unset _CACHE_PACKAGE_LOCAL _CACHE_PACKAGE_GLOBAL _DEBUG_DEPENDS_LIST _DEBUG_PACK
show_config
${SCRIPTS}/checkdeps
# Setup both toolchain cmake configs to avoid potentially racy behaviour later.
# Use a fork for host to isolate any variable modifications.
( setup_toolchain host )

49
tools/burnimage Executable file
View file

@ -0,0 +1,49 @@
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2021-present Fewtarius (https://github.com/fewtarius)
export OS_VERSION=$(date +%Y%m%d)
if [ -z "${DISTRO}" ] || [ -z "${DEVICE}" ] || [ -z "${ARCH}" ]
then
echo "Environment variables DISTRO, DEVICE, and ARCH must be set. Aborting."
exit 1
fi
MAXSIZE="64000000"
SDDEVICES=($(awk '/sd*[a-z]$/ {print $3":"$4}' /proc/partitions))
for SDDEVICE in ${SDDEVICES[@]}
do
SIZE=${SDDEVICE%:*}
SDDEVICE=${SDDEVICE#*:}
if [ "${SIZE}" -le "${MAXSIZE}" ]
then
echo "Found SD Card @ ${SDDEVICE}"
break
fi
unset SDDEVICE
done
if [ ! -z "${SDDEVICE}" ]
then
if [ -d "cd release/aarch64/${DEVICE}" ]
then
cd release/aarch64/${DEVICE}
echo "Extracting ${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img.gz"
gunzip ${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img.gz
echo "Writing ${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img to ${SDDEVICE}"
sudo dd if=${DISTRO}-${DEVICE}.${ARCH}-${OS_VERSION}.img of=/dev/${SDDEVICE} bs=1M
sync
else
echo "Release directory not found, aborting."
exit 1
fi
else
echo "SD Card could not be found, aborting."
exit 1
fi