#!/usr/bin/bash # Copyright (C) 2020 Jean-Baptiste Biernacki # # This program 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,dnf or # (at your option) any later version. # # This program 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 this program. If not, see . #Change the local to the most global export LC_ALL=C CMD_LINE="${@}" CMDNAME="$(/usr/bin/basename "${0}")" PROG_DIR="$(/usr/bin/dirname "$(readlink -f ${0})")" source "${PROG_DIR}/functions.sh" source "${PROG_DIR}/build_all.cfg" CONFIG_FILE="/etc/mageia4arm.conf.json" CONFIG_FILE_NOT_FOUND=-1 CONFIG_FILE_ERROR=-1 unset exit function help() { echo -e "${CMDNAME} [option]\n" echo -e "Synopsis:" echo -e "\tGenerates Mageia images for all SBC defined in the mageia4arm.conf.json file.\n" echo -e "Options:" echo -e "\t--config file Specify a config file, by default /etc/mageia4arm.conf.json" } case $(hostname) in *.mageia.org) sudo_root="sudo -u draklive sudo"; sudo_bcd="sudo -u bcd";; *) sudo_root="su -c"; sudo_bcd="su -c";; esac print_info ${0} # parsing commandline TEMP=$(getopt -o c:,h --long config:,help -n ${CMDNAME} -- "${@}") if [ ${?} -ne 0 ] ; then error "line ${LINENO} Failed parsing options." >&2 ; exit ${ERR_1} ; fi eval set -- "${TEMP}" # echo "${TEMP}" while true; do case "${1}" in -c|--config) if [ "x" != "x${2}" ]; then #check file in cmdline if [ -e ${2} ]; then #check if exists CONFIG_FILE="${2}" fi fi shift 2 ;; -h|--help) help exit 0 ;; --) shift break;; *) error "Parameter ${1} does not exists " exit ${ERR_1};; esac done if [ ! -e "${CONFIG_FILE}" ]; then error "Config file (${CONFIG_FILE}) not found !" exit ${CONFIG_FILE_NOT_FOUND} fi # If SBCs is not defined in the config file, take ALL board in the platforms directory. SBCs="$(cat ${CONFIG_FILE} | jq -c ".SBCs[]")" if [ 0 -ne "${?}" ]; then error "Config file (${CONFIG_FILE}) is not json or contains syntax error!" exit ${CONFIG_FILE_ERROR} fi vendor="$(cat ${CONFIG_FILE} | jq -c ".vendor")" distro="$(cat ${CONFIG_FILE} | jq -c ".distro")" release="$(cat ${CONFIG_FILE} | jq -c ".release")" region="$(cat ${CONFIG_FILE} | jq -c ".region")" repository="$(cat ${CONFIG_FILE} | jq -c ".repository")" workdir="$(cat ${CONFIG_FILE} | jq -c ".workdir")" destdir="$(cat ${CONFIG_FILE} | jq -c ".destdir")" for SBC_config in ${SBCs}; do SBC="$(echo ${SBC_config} | jq -r '.board')" DESKTOP_STEP="$(echo ${SBC_config} | jq '.desktop')" if [ "null" != "${DESKTOP_STEP}" ]; then DESKTOP="--desktop $(echo ${SBC_config} | jq '.desktop')" else unset DESKTOP fi NONFREE_STEP="$(echo ${SBC_config} | jq '.nonfree')" if [ "true" = "${NONFREE_STEP}" ]; then NONFREE="--nonfree" else unset NONFREE fi SIZE="$(echo ${SBC_config} | jq -r '.size')" print_info "Start build for ${SBC}" $sudo_root "MIRROR=${repository} ${PROG_DIR}/create_arm_image.sh --all --build-path ${workdir} --config ${SBC} ${DESKTOP} ${NONFREE} --mga-version ${release} --size ${SIZE} --compress --add-checksum 2>&1 | tee -a ${workdir}/$(date "+%Y-%m-%d_%H:%M")-${SBC}.log" $sudo_bcd "mkdir -p ${destdir}/${SBC}" $sudo_bcd "mv ${workdir}/* ${destdir}/${SBC}/" # not enough space on rabbit's RAM disk for all four variants, so delete as we go $sudo_root "${PROG_DIR}/create_arm_image.sh --clean --build-path ${workdir} --config ${SBC}" done exit 0