create-iso.sh 5.39 KB
Newer Older
1
#!/bin/bash
2
# shellcheck disable=SC1090
3 4 5 6 7 8
#
# Copyright (C) 2017 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of create-iso
#
9
# create-iso is free software; you can redistribute it and/or
10 11 12 13 14 15 16 17 18 19 20 21 22 23
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.

24 25
export PREFIX="${PWD}"
source "${PREFIX}/conf/pre.conf"
26

27
while true; do
28
    case "${1}" in
29
        -h | --help   ) _HELP=true; shift ;;
30 31 32
        -d | --distro ) _DIST="${2}"; shift; shift ;;
        -a | --arch   ) _ARCH="${2}"; shift; shift ;;
        -r | --repo   ) _REPO="${2}"; shift; shift ;;
33 34 35 36 37
        -* )            echo "Unrecognized option. Try with --help."; exit 1 ;;
        *  )            break ;;
    esac
done

38 39
if [ "${_HELP}" = true ]; then
    echo "Usage: ${0} [OPTION] [ARGUMENT]..."
40 41
    echo ""
    echo "Examples:"
42 43
    echo "    sudo ${0} --distro le6/testing             # Generate default arch (amd64) le6 iso image"
    echo "    sudo ${0} -d le6/testing -a i386           # Generate i386 architecture le6 iso image"
44 45
    echo ""
    echo "Options:"
46 47 48 49
    echo "    -h, --help                                 Show this help list"
    echo "    -d, --distro [DIST]                        Select iso image's distro"
    echo "    -a, --arch [amd64 | i386]                  Select iso image's architecture"
    echo "    -r, --repo [stable | testing | unstable]   Select remote repository codename to download packages from"
50
    exit 2
51
fi
52

53
if [ -z "${_DIST}" ]; then
54
    echo "No distro specified. Try with --help."
55 56
    exit 1
fi
57

58
if [ "${_ARCH}" != "amd64" ] && [ "${_ARCH}" != "i386" ]; then
59 60
    echo "Unrecognized architecture. Try with --help."
    exit 1
61 62
fi

63
if [ "${_REPO}" != "stable" ] && [ "${_REPO}" != "testing" ] && [ "${_REPO}" != "unstable" ]; then
64 65 66 67
    echo "Unrecognized remote repository codename. Try with --help."
    exit 1
fi

68 69 70
if [ "$(id -u)" != "0" ]; then
    echo "You must have more power to run this script. Are you root?"
    exit -1
71
fi
72

73
source "${PREFIX}/conf/${_DIST}/create-iso.conf"
74

75
TIME_STAMP="$(date +'%Y-%m-%dT%H:%M:%S')"
76
export LOG_FILE="${LOG_PATH}/create-iso-${TIME_STAMP}.log"
77

78 79
exec 1<&-
exec 2<&-
80
exec 1<> "${LOG_FILE}"
81
exec 1>&1
82 83 84 85 86 87 88 89 90
mkdir --parents "${TMP}"

source "${PREFIX}/common.sh"
source "${PREFIX}/helper/logging.incsh"
source "${PREFIX}/lib/mktmpfs.sh"
source "${PREFIX}/lib/overlay.sh"

# Installation of create-iso's dependencies
apt-get install isolinux syslinux squashfs-tools genisoimage xorriso --yes || \
Lucas Sulzbach's avatar
Lucas Sulzbach committed
91
createIsoLogger --message "Failed to install basic tools" --tag "apt-get"
92 93 94 95 96 97 98

mountTmpfs "${TMPFS}"
mountOverlay "${CHROOTDIR}" "${TMPFS}"

# Each one of the available scripts is executed in numeric order
for script in "${SCRIPTSDIR}"/*; do
    if [ -x "${script}" ] && grep -E --quiet '^[0-9]{2}-[A-Za-z]+' <<< "$(basename "${script}")"; then
Lucas Sulzbach's avatar
Lucas Sulzbach committed
99
        createIsoLogger --message "Running $(basename "${script}")..." --type info
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
        if ! "${script}"\
             "${_DIST}" \
             "${_ARCH}" \
             "${_REPO}" \
             "${CHROOTDIR}" \
             "${SCRIPT_NAME}" \
             "${DISTRO}" \
             "${DPLIST}" \
             "${INSTLIST}" \
             "${ISOLINUX}" \
             "${MOUNTLIST}" \
             "${OURSOURCESLIST}" \
             "${RMDSKT}" \
             "${RMLIST}" \
             "${SCRIPTSDIR}" \
             "${SHORTNAME}" \
             "${SOURCESLISTDEFAULT}" \
             "${TMP}" \
             "${TMPFS}" \
             "${REPOPKGS}" \
             "${LOG_FILE}"; then
			cleanup "${CHROOTDIR}" "${TMP}"
122 123 124
            exit 1
        fi

125 126 127 128 129
        # If the script is marked as 'chroot', it means it performs changes in the overlayed chroot filesystem,
        # therefore, the 'chroot script', filled with the required commands by the marked script, is executed
        # This warning is disabled because the literal '-' is actually needed:
        # shellcheck disable=SC1001
        if [[ "$(basename "${script}")" =~ [0-9]+\-chroot\.* ]]; then
Daniel Bissani Furlin's avatar
Daniel Bissani Furlin committed
130
            initChroot "${CHROOTDIR}" "${LOG_FILE}"
131
            execChroot "${CHROOTDIR}" "${SCRIPT_NAME}"
Daniel Bissani Furlin's avatar
Daniel Bissani Furlin committed
132
            closeChroot "${CHROOTDIR}" "${LOG_FILE}"
133 134 135 136
        fi
    fi
done

137 138
# Finally generates the resulting iso image
NAME="LinuxEducacional6-$(echo "${_DIST}" | cut --delimiter='/' --fields=2).iso"
Lucas Sulzbach's avatar
Lucas Sulzbach committed
139
pushd "${TMP}/image" || createIsoLogger --message "Unable to change directory" --tag "pushd"
140 141
xorriso -as mkisofs -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin -c isolinux/boot.cat -b isolinux/isolinux.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -no-emul-boot -isohybrid-gpt-basdat \
Lucas Sulzbach's avatar
Lucas Sulzbach committed
142 143
-o "${PREFIX}/iso/${NAME}" . || createIsoLogger --message "Failed to generate iso image." --tag "xorriso"
popd || createIsoLogger --message "Unable to change directory" --tag "popd"
144

145
cleanup "${CHROOTDIR}" "${TMP}"
146 147
umountOverlay "${CHROOTDIR}" "${TMPFS}"
umountTmpfs "${TMPFS}"
148 149

exit 0