aboutsummaryrefslogtreecommitdiffstats
path: root/build_all.sh
blob: 502347a9a79d6a775274b01b95d2a17df05f5270 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/bash

# Copyright (C) 2020      Jean-Baptiste Biernacki   <j.biernacki@free.fr>
#
# 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 <http://www.gnu.org/licenses/>.

#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