#!/bin/bash function prepare_generation { local config_file="./rs-config" local copy_dest=$1 if [[ ! -f "${config_file}" ]]; then echo "There is no config file(${config_file})." exit 1 fi sed -i 's@^export BUILD_REQUIRED_INSTALLED_PATH=.*$@export BUILD_REQUIRED_INSTALLED_PATH="/"@' "${config_file}" sed -i 's@^export GBS_BUILDROOT=.*$@export GBS_BUILDROOT="'${copy_dest}'"@' "${config_file}" } function generate_rootstrap_ix86 { ./script/convert32.sh if [[ $? -ne 0 ]]; then echo "Failed to convert .xml files into 32-bit." return $? fi ./make_rootstrap.sh -C rs-config ./rs_resource --emulator -A i686 RET=$? if [[ ${RET} -ne 0 ]]; then echo "Failed to create rootstrap." fi return ${RET} } function generate_rootstrap_x86_64 { ./script/convert64.sh if [[ $? -ne 0 ]]; then echo "Failed to convert .xml files into 64-bit" return $? fi ./make_rootstrap_64.sh -C rs-config ./rs_resource --emulator -A x86_64 RET=$? if [[ ${RET} -ne 0 ]]; then echo "Failed to create rootstrap." fi return ${RET} } function generate_rootstrap_arm { ./script/convert32.sh if [[ $? -ne 0 ]]; then echo "Failed to convert .xml files into 32-bit." return $? fi ./make_rootstrap.sh -C rs-config ./rs_resource --target -A arm RET=$? if [[ ${RET} -ne 0 ]]; then echo "Failed to create rootstrap." fi return ${RET} } function generate_rootstrap_aarch64 { ./script/convert64.sh if [[ $? -ne 0 ]]; then echo "Failed to convert .xml files into 64-bit" return $? fi ./make_rootstrap_64.sh -C rs-config ./rs_resource --target -A aarch64 RET=$? if [[ ${RET} -ne 0 ]]; then echo "Failed to create rootstrap." fi return ${RET} } function generate_rootstrap_riscv64 { ./script/convert64.sh if [[ $? -ne 0 ]]; then echo "Failed to convert .xml files into 64-bit" return $? fi ./make_rootstrap_64.sh -C rs-config ./rs_resource --target -A riscv64 RET=$? if [[ ${RET} -ne 0 ]]; then echo "Failed to create rootstrap." fi return ${RET} } function generate_rootstrap { local arch=$1 local rootstrap_type=$2 local rootstrap_resource_dir="./rs_resource" rm -rf "${rootstrap_resource_dir}" cp -r "/tmp/rs_resource/${ROOTSTRAP_TYPE}" "${rootstrap_resource_dir}" case "${arch}" in "arm") generate_rootstrap_arm return $? ;; "aarch64") generate_rootstrap_aarch64 return $? ;; "i386") generate_rootstrap_ix86 return $? ;; "x86_64") generate_rootstrap_x86_64 return $? ;; "riscv64") generate_rootstrap_riscv64 return $? ;; *) echo "Architecture not supported: ${arch}" exit 1 ;; esac } ARCH=$1 ROOTSTRAP_TYPE=$2 COPY_DEST=$3 if [[ -z "${ARCH}" ]] || [[ -z "${ROOTSTRAP_TYPE}" ]] || [[ -z "${COPY_DEST}" ]]; then echo "3 parameters are required: " exit 1 fi prepare_generation "${COPY_DEST}" generate_rootstrap "${ARCH}" "${ROOTSTRAP_TYPE}"