Commit b9f48326 authored by Alessandro Elias's avatar Alessandro Elias

Merge branch 'issue/263/log' into 'develop'

Issue/263/log: Add Handle and error message

See merge request !13
parents e84b0820 01ec84e1
#!/bin/bash
cleanTmpFiles() {
rm -rf ${TMP}
local tmp="$1"
rm --recursive --force ${TMP}
closeChroot
}
emergency_shell() {
cleanTmpFiles
local tmp="$1"
cleanTmpFiles ${tmp}
echo "FATAL ERROR!"
exit 1
}
log() {
local _TYPE=$1
local _TXT=$(echo $@ | cut -d' ' -f2-)
local _FILE=${PREFIX}/log/${DIST}/${_TYPE}-create-iso.log
if [ "$_TXT" ]; then
if [ "$LOGINFO" ]; then
echo "${_TYPE}: ${_TXT}" | tee -a $_FILE
else
echo "${_TYPE}: ${_TXT}"
fi
fi
if [ "${_TYPE}" == "ERROR" ]; then
emergency_shell
fi
}
function log() {
local type=$1
local msg=$2
removeMountList() {
grep -v "$1" ${MOUNTLIST} > ${MOUNTLIST}.tmp
mv -f ${MOUNTLIST}.tmp ${MOUNTLIST}
echo "$msg" 1>&2 >> "$LOG_FILE"
}
initChroot() {
local _DIST=$1
local chrootdir="$1"
mkdir -p ${CHROOTDIR}/var/log/create-iso/
if [ ! -d ${PREFIX}/log/${_DIST} ]; then
mkdir -p ${PREFIX}/log/${_DIST}
fi
# Create the log file; this file will be bind to appear in $VARLOG
# directory in the target machine that generates the iso.
touch "${chrootdir}/${LOG_FILE}"
touch "$LOG_FILE"
cp /etc/resolv.conf ${CHROOTDIR}/etc/
cp /etc/hosts ${CHROOTDIR}/etc/
mount --bind /dev "${chrootdir}/dev"
mount --bind /dev/pts "${chrootdir}/dev/pts"
mount --bind /proc "${chrootdir}/proc"
mount --bind /sys "${chrootdir}/sys"
mount --bind /dev ${CHROOTDIR}/dev && echo "${CHROOTDIR}/dev" >> ${MOUNTLIST}
mount --bind /sys ${CHROOTDIR}/sys && echo "${CHROOTDIR}/sys" >> ${MOUNTLIST}
mount --bind /dev/pts ${CHROOTDIR}/dev/pts && echo "${CHROOTDIR}/dev/pts" \
>> ${MOUNTLIST}
mount --bind ${PREFIX}/log/${_DIST}/ ${CHROOTDIR}/var/log/create-iso/ && \
echo "${CHROOTDIR}/var/log/create-iso/" >> ${MOUNTLIST} || \
log ERROR "Failed to mount log dir."
mount --bind /proc ${CHROOTDIR}/proc && echo "${CHROOTDIR}/proc" >> ${MOUNTLIST}
mount --bind "${LOG_FILE}" "${chrootdir}/${LOG_FILE}" ||
log ERROR "Failed to bind log file from: '${LOG_FILE}' to '${chrootdir}/${LOG_FILE}'."
# chroot ${CHROOTDIR} dbus-uuidgen > ${CHROOTDIR}/var/lib/dbus/machine-id
mount --bind "/etc/resolv.conf" "${chrootdir}/etc/resolv.conf"
# Prevent services from being started in the chrooted environment
rm -rf ${CHROOTDIR}/fakebin
chroot ${CHROOTDIR} mkdir /fakebin
chroot ${CHROOTDIR} ln -s /bin/true /fakebin/initctl
chroot ${CHROOTDIR} ln -s /bin/true /fakebin/invoke-rc.d
chroot ${CHROOTDIR} ln -s /bin/true /fakebin/restart
chroot ${CHROOTDIR} ln -s /bin/true /fakebin/start
chroot ${CHROOTDIR} ln -s /bin/true /fakebin/stop
chroot ${CHROOTDIR} ln -s /bin/true /fakebin/service
chroot ${CHROOTDIR} ln -s /bin/true /fakebin/start-stop-daemon
rm -rf ${chrootdir}/fakebin
chroot ${chrootdir} mkdir /fakebin
chroot ${chrootdir} ln -s /bin/true /fakebin/initctl
chroot ${chrootdir} ln -s /bin/true /fakebin/invoke-rc.d
chroot ${chrootdir} ln -s /bin/true /fakebin/restart
chroot ${chrootdir} ln -s /bin/true /fakebin/start
chroot ${chrootdir} ln -s /bin/true /fakebin/stop
chroot ${chrootdir} ln -s /bin/true /fakebin/service
chroot ${chrootdir} ln -s /bin/true /fakebin/start-stop-daemon
}
closeChroot() {
chroot ${CHROOTDIR} apt-get clean
local chrootdir="$1"
rm -rf ${CHROOTDIR}/fakebin
rm -rf ${CHROOTDIR}/root/.bash_history ${CHROOTDIR}/var/lib/dbus/machine-id
rm -rf ${CHROOTDIR}/tmp/*
umount --lazy "${chrootdir}/etc/resolv.conf"
umount --lazy "${chrootdir}/${LOG_FILE}"
umount --lazy ${chrootdir}/{dev/pts,proc,sys,dev}
}
if grep -qs ${CHROOTDIR}/dev/pts ${MOUNTLIST}; then
umount -l ${CHROOTDIR}/dev/pts && removeMountList ${CHROOTDIR}/dev/pts
fi
echo "1"
if grep -qs ${CHROOTDIR}/sys ${MOUNTLIST}; then
umount -l ${CHROOTDIR}/sys && removeMountList ${CHROOTDIR}/sys
fi
if grep -qs ${CHROOTDIR}/proc ${MOUNTLIST}; then
umount -l ${CHROOTDIR}/proc && removeMountList ${CHROOTDIR}/proc
fi
if grep -qs ${CHROOTDIR}/dev ${MOUNTLIST}; then
umount -l ${CHROOTDIR}/dev && removeMountList ${CHROOTDIR}/dev
fi
if grep -qs ${CHROOTDIR}/var/log/create-iso/ ${MOUNTLIST}; then
umount -l ${CHROOTDIR}/var/log/create-iso/ \
&& removeMountList ${CHROOTDIR}/var/log/create-iso/
fi
rm -rf ${CHROOTDIR}/var/log/create-iso/
function create_stub() {
local script=$1
cat << EOF > "$script"
#!/usr/bin/env bash
# THIS SCRIPT WAS GENERATE DINAMICALLY BY CREATE-ISO
# DO NOT EDIT IT.
EOF
cat ${PREFIX}/helper/logging.incsh >> ${script}
}
genErrHandle() {
echo "eval if test $? -ne 0; then perror ${BASH_SOURCE[1]}: line ${BASH_LINENO} $@; /bin/bash;fi"
}
genErrHandleInChroot() {
echo "if test \$? -ne 0; then perror ${BASH_SOURCE[1]}: line ${BASH_LINENO} $@; /bin/bash;fi"
}
addToChrootFile() {
local _FILE=$1
local _CMD=$2
echo "$_CMD \\ || /bin/bash" add no arquivo
echo "$_CMD \\" >> "$_FILE"
echo '|| /bin/bash' >> "$_FILE"
local chrootdir="$1"
local script_name="$2"
local cmd="$3"
if [ ! -f "${chrootdir}/tmp/${script_name}" ]; then
create_stub "${chrootdir}/tmp/${script_name}"
fi
echo ${cmd} >> "${chrootdir}/tmp/${script_name}"
}
execChroot() {
_FILE=$1
_DIR=$2
chmod +x $_FILE
cp $_FILE ${CHROOTDIR}/tmp/exec.sh
rm $_FILE
chroot $_DIR /tmp/exec.sh
local chrootdir="$1"
local script_name="$2"
[ ! -x "${chrootdir}/tmp/${script_name}" ] && chmod +x "${chrootdir}/tmp/${script_name}"
chroot "${chrootdir}" "/tmp/${script_name}"
rm --recursive --force "${chrootdir}/tmp/${script_name}" &>/dev/null
return $?
}
function cleanup() {
local chrootdir="$1"
local tmp="$2"
if mountpoint --quiet "${chrootdir}/etc/resolv.conf"; then
umount --lazy "${chrootdir}/etc/resolv.conf"
fi
if mountpoint --quiet "${chrootdir}/${LOG_FILE}"; then
umount --lazy "${chrootdir}/$LOG_FILE"
fi
if mountpoint --quiet "${chrootdir}/dev/pts"; then
umount --lazy "${chrootdir}/dev/pts"
fi
if mountpoint --quiet "${chrootdir}/dev"; then
umount --lazy "${chrootdir}/dev"
fi
if mountpoint --quiet "${chrootdir}/sys"; then
umount --lazy "${chrootdir}/sys"
fi
if mountpoint --quiet "${chrootdir}/proc"; then
umount --lazy "${chrootdir}/proc"
fi
rm --recursive --force "$tmp"
}
SHORTNAME=le6
TMP=/home/${SUDO_USER}/${_DIST}/
CHROOTDIR=/home/${SUDO_USER}/overlay
TMPFS=/home/${SUDO_USER}/tmp
CHROOTFILE=${TMP}/todo.sh
TMP=${PREFIX}/${_DIST}
CHROOTDIR=${PREFIX}/overlay
TMPFS=${PREFIX}/tmp
DISTRO=Linux_Educacional_6.1.0
DPLIST=${PREFIX}/pkg-list/${_DIST}/dependencies.list
INSTLIST=${PREFIX}/pkg-list/${_DIST}/install.list
ISOLINUX=${PREFIX}/src/isolinux/
ISOLINUX=${PREFIX}/src/isolinux
MOUNTLIST=${TMP}/mountlist
OURSOURCESLIST=${PREFIX}/sources-list/${_DIST}/${SHORTNAME}.list
RMDSKT=${PREFIX}/pkg-list/${_DIST}/remove-desktop.list
RMLIST=${PREFIX}/pkg-list/${_DIST}/remove.list
REPOPKGS=${PREFIX}/pkg-list/${_DIST}/repo-local.list
SCRIPTSDIR=${PREFIX}/scripts-enabled/${_DIST}/
SCRIPTSDIR=${PREFIX}/scripts-enabled/${_DIST}
SOURCESLISTDEFAULT=${PREFIX}/sources-list/${_DIST}/default.list
SCRIPT_NAME="exec.sh"
LOG_PATH="/var/log"
......@@ -20,6 +20,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
if [ "$(id -u)" != "0" ]; then
echo You must have more power to run this script
exit -1
fi
export PREFIX=$(pwd)
source ${PREFIX}/conf/pre.conf \
|| log ERROR "Preconfiguration file not found"
......@@ -70,38 +74,73 @@ if [ "$(id -u)" != "0" ]; then
exit -1
fi
source ${PREFIX}/conf/$_DIST/create-iso.conf \
|| log ERROR "Configuration file not found for dist: \"${_DIST}\""
source "${PREFIX}/conf/$_DIST/create-iso.conf" \
|| log ERROR "configuration file not found for dist: \"${_DIST}\""
TIME_STAMP="`date +'%Y-%m-%dT%H:%M:%S'`"
export LOG_FILE="${LOG_PATH}/create-iso-${TIME_STAMP}.log"
source common.sh
source lib/mktmpfs.sh
source lib/overlay.sh
exec 1<&-
exec 2<&-
exec 1<> ${LOG_FILE}
exec 1>&1
mkdir --parents ${TMP}
sudo apt-get install syslinux squashfs-tools genisoimage xorriso \
|| log ERROR "Failed to install basic tools: \"${_DIST}\""
source ${PREFIX}/common.sh
source ${PREFIX}/helper/logging.incsh
source ${PREFIX}/lib/mktmpfs.sh
source ${PREFIX}/lib/overlay.sh
apt-get install isolinux syslinux squashfs-tools genisoimage xorriso
$(genErrHandle "Failed to install basic tools")
mountTmpfs ${TMPFS}
mountOverlay ${CHROOTDIR} ${TMPFS}
mkdir -p ${TMP}
for file in $(ls ${SCRIPTSDIR}); do
if [ -x "${SCRIPTSDIR}/${file}" ] && egrep -q '^[0-9]{2}-[a-z-]+' <<< "$file"; then
echo "$file"
if ! "${SCRIPTSDIR}/${file}" ${_DIST} ${_ARCH} ${_REPO} ${CHROOTDIR} ${CHROOTFILE} ${DISTRO} ${DPLIST} ${INSTLIST} ${ISOLINUX} ${MOUNTLIST} ${OURSOURCESLIST} ${RMDSKT} ${RMLIST} ${SCRIPTSDIR} ${SHORTNAME} ${SOURCESLISTDEFAULT} ${TMP} ${TMPFS} ${REPOPKGS}; then
log ERROR "While running \"${SCRIPTSDIR}/${file}\""
for script in `ls ${SCRIPTSDIR}`; do
if [ -x "$SCRIPTSDIR/$script" ] && egrep --quiet '^[0-9]{2}-[A-Za-z]+' <<< "$script"; then
pinfo "Running `basename $script`..."
if ! "${SCRIPTSDIR}/${script}"\
${_DIST} \
${_ARCH} \
${_REPO} \
${CHROOTDIR} \
${SCRIPT_NAME} \
${DISTRO} \
${DPLIST} \
${INSTLIST} \
${ISOLINUX} \
${MOUNTLIST} \
${OURSOURCESLIST} \
${RMDSKT} \
${RMLIST} \
${SCRIPTSDIR} \
${SHORTNAME} \
${SOURCESLISTDEFAULT} \
${TMP} \
${TMPFS} \
${REPOPKGS} \
${LOG_FILE}; then
log ERROR "While running \"${SCRIPTSDIR}/${script}\""
cleanup "$CHROOTDIR" "$TMP"
exit 1
fi
if [[ "$script" =~ [0-9]+\-chroot\.* ]]; then
initChroot "${CHROOTDIR}" "${LOG_FILE}"
execChroot "$CHROOTDIR" "${SCRIPT_NAME}"
closeChroot "${CHROOTDIR}" "${LOG_FILE}"
fi
fi
done
NAME="LinuxEducacional6-$(echo ${_DIST} | cut -d'/' -f2).iso"
cd ${TMP}/image
sudo 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 -o ${PREFIX}/iso/${_DIST}/${NAME} \
. ||\
log ERROR "Failed to generate iso image."
cd -
NAME="LinuxEducacional6-$(echo ${_DIST} | cut --delimiter='/' --fields=2).iso"
pushd ${TMP}/image
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 -o ${PREFIX}/iso/${NAME} .
$(genErrHandle "Failed to generate iso image.")
popd
cleanTmpFiles
cleanup "${CHROOTDIR}" "${TMP}"
umountOverlay ${CHROOTDIR} ${TMPFS}
umountTmpfs ${TMPFS}
......
readonly ERROR=1
readonly WARNING=2
readonly INFO=4
readonly DEBUG=8
readonly ALL=15
VERBOSE_FLAGS=$ALL
perror () {
if [ $(($VERBOSE_FLAGS & $ERROR)) -eq $ERROR ]; then
echo -e "\033[38;5;9m[error]\033[0m $@" 1>&2
echo -e "\033[38;5;9m[error]\033[0m $@" >> "$LOG_FILE"
fi
}
pwarning () {
if [ $(($VERBOSE_FLAGS & $WARNING)) -eq $WARNING ]; then
echo -e "\033[38;5;11m[warning]\033[0m $@"
echo -e "\033[38;5;11m[warning]\033[0m $@" >> "$LOG_FILE"
fi
}
pinfo () {
if [ $(($VERBOSE_FLAGS & $INFO)) -eq $INFO ]; then
echo -e "\033[38;5;10m[info]\033[0m $@"
echo -e "\033[38;5;10m[info]\033[0m $@" >> "$LOG_FILE"
fi
}
pdebug () {
if [ $(($VERBOSE_FLAGS & $DEBUG)) -eq $DEBUG ]; then
echo -e "\033[38;5;6m[debug]\033[0m $@"
echo -e "\033[38;5;6m[debug]\033[0m $@" >> "$LOG_FILE"
fi
}
true
......@@ -21,23 +21,23 @@
# USA.
mountTmpfs() {
local TMPFS=$1
local tmpfs=$1
if mount | grep -q ${TMPFS}; then
if mountpoint --quiet ${tmpfs}; then
return 1
fi
mkdir -p ${TMPFS}
if [ ! -d "${TMPFS}" ]; then
echo "overlay path: '${TMPFS}' has not been found."
mkdir --parents ${tmpfs}
if [ ! -d "${tmpfs}" ]; then
echo "overlay path: '${tmpfs}' has not been found."
exit 1
fi
mount -t tmpfs tmpfs -o suid,dev,size=6291456k ${TMPFS}
mount --types tmpfs tmpfs --options suid,dev,size=6291456k ${tmpfs}
}
umountTmpfs() {
local TMPFS=$1
if mountpoint -q ${TMPFS}; then
umount ${TMPFS}
local tmpfs=$1
if mountpoint --quiet ${tmpfs}; then
umount ${tmpfs}
fi
rm -r ${TMPFS}
rm --recursive --force ${tmpfs}
}
......@@ -21,52 +21,53 @@
# USA.
mountOverlay() {
local CHROOTDIR=$1
local TMPFS=$2
local PREFIX=$(pwd)
local chrootdir=$1
local tmpfs=$2
local prefix=$(pwd)
mkdir -p "${TMPFS}/upper"
mkdir -p "${TMPFS}/work"
mkdir -p ${CHROOTDIR}
mkdir --parents "${tmpfs}/upper"
mkdir --parents "${tmpfs}/work"
mkdir --parents ${chrootdir}
if [ ! -d "${TMPFS}" ]; then
echo "overlay path: '${TMPFS}' has not been found."
if [ ! -d "${tmpfs}" ]; then
echo "overlay path: '${tmpfs}' has not been found."
exit 1
fi
if [ ! -d "${TMPFS}/upper" ]; then
echo "upperdir path: '${TMPFS}/upper' has not been found."
if [ ! -d "${tmpfs}/upper" ]; then
echo "upperdir path: '${tmpfs}/upper' has not been found."
exit 1
fi
if [ ! -d "${TMPFS}/work" ]; then
echo "workdir path: '${TMPFS}/work' has not been found."
if [ ! -d "${tmpfs}/work" ]; then
echo "workdir path: '${tmpfs}/work' has not been found."
exit 1
fi
if [ ! -d "${CHROOTDIR}" ]; then
echo "merge point path: '${CHROOTDIR}' has not been found."
if [ ! -d "${chrootdir}" ]; then
echo "merge point path: '${chrootdir}' has not been found."
exit 1
fi
if [ ! -d "${PREFIX}/chroot" ]; then
echo "chroot path: '${PREFIX}/chroot' has not been found."
if [ ! -d "${prefix}/chroot" ]; then
echo "chroot path: '${prefix}/chroot' has not been found."
exit 1
fi
if ! mountpoint -q ${CHROOTDIR}; then
if ! mount -t overlay overlay -o rw,lowerdir="${PREFIX}/chroot",upperdir="${TMPFS}"/upper,workdir="${TMPFS}"/work "${CHROOTDIR}"; then
if ! mountpoint --quiet ${chrootdir}; then
if ! mount --types overlay overlay --options rw,lowerdir="${prefix}/chroot",upperdir="${tmpfs}"/upper,workdir="${tmpfs}"/work "${chrootdir}"; then
echo "Overlay could not be mounted:" >&2
echo " lowerdir: '${PREFIX}/chroot'" >&2
echo " upperdir: '${TMPFS}/upper'" >&2
echo " workdir: '${TMPFS}/work'" >&2
echo "mount point: '${CHROOTDIR}'" >&2
echo " lowerdir: '${prefix}/chroot'" >&2
echo " upperdir: '${tmpfs}/upper'" >&2
echo " workdir: '${tmpfs}/work'" >&2
echo "mount point: '${chrootdir}'" >&2
exit 1
fi
fi
}
umountOverlay() {
local CHROOTDIR=$1
local TMPFS=$2
if mountpoint -q ${CHROOTDIR}; then
umount ${CHROOTDIR}
local chrootdir=$1
local tmpfs=$2
if mountpoint --quiet ${chrootdir}; then
umount ${chrootdir}
fi
rm -r ${TMPFS}/{upper,work}
rm --recursive --force ${tmpfs}/{upper,work}
rm --recursive --force "$chrootdir"
}
le-all
linux-generic-hwe-16.04
xserver-xorg-hwe-16.04
#!/bin/bash
#!/usr/bin/env bash
#set -x
_DIST=$1
PREFIX=$PWD
......
#!/bin/bash
#!/usr/bin/env bash
#
# Copyright (C) 2017 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
......@@ -24,7 +24,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......@@ -45,7 +45,7 @@ source ${PREFIX}/common.sh
initChroot $_DIST || \
log ERROR "failed to initialize chroot."
execChroot $CHROOTFILE $CHROOTDIR
execChroot $SCRIPT_NAME $CHROOTDIR
RET=$?
closeChroot || \
log ERROR "failed to close chroot."
......
#!/bin/bash
#!/usr/bin/env bash
#
# Copyright (C) 2017 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
......@@ -24,7 +24,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......@@ -41,12 +41,26 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
source ${PREFIX}/common.sh
type genErrHandle >/dev/null 2>&1 || source ${PREFIX}/common.sh
sudo mksquashfs $CHROOTDIR ${TMP}/image/casper/filesystem.squashfs -b 1M -no-recovery ||\
log ERROR "Failed to compress ${CHROOTDIR}."
(cd ${TMP}/image && find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt) ||\
log ERROR "Failed to generate md5sum."
#########################################
# WARNING:
# Sanity check if {dev,proc,sys} are mounted, cp from /proc will be recursive
# until run out RAM.
if mountpoint --quiet "${CHROOTDIR}/dev/pts"; then
umount "${CHROOTDIR}/dev/pts"
fi
if mountpoint --quiet "${CHROOTDIR}/dev"; then
umount "${CHROOTDIR}/dev"
fi
if mountpoint --quiet "${CHROOTDIR}/sys"; then
umount "${CHROOTDIR}/sys"
fi
if mountpoint --quiet "${CHROOTDIR}/proc"; then
umount "${CHROOTDIR}/proc"
fi
exit 0
mksquashfs ${CHROOTDIR} ${TMP}/image/casper/filesystem.squashfs -b 1M -no-recovery -processors $(nproc); $(genErrHandle "Failed to compress ${CHROOTDIR}.")
(pushd ${TMP}/image && find . -type f -print0 | xargs -0 md5sum | grep --invert-match "\./md5sum.txt" > md5sum.txt && popd); $(genErrHandle "Failed to generate md5sum.")
exit 0
......@@ -20,14 +20,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
set -u
set -e
_DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......@@ -44,28 +41,30 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
source ${PREFIX}/common.sh
type addToChrootFile >/dev/null 2>&1 || source ${PREFIX}/common.sh
fingerprint=$(gpg --list-keys --with-colons 'C3SL Live' | grep -m 1 'fpr' | cut -d':' -f10)
mount --bind "/etc/resolv.conf" "${CHROOTDIR}/etc/resolv.conf"
fingerprint=$(gpg --list-keys --with-colons 'C3SL Live' | grep --max-count=1 'fpr' | cut --delimiter=':' --fields=10)
if test -z ${fingerprint}; then
gpg --batch --no-tty --gen-key ${PREFIX}/src/gpg-key/gen-key-script
fingerprint=$(gpg --list-keys --with-colons 'C3SL Live' | grep -m 1 'fpr' | cut -d':' -f10)
fingerprint=$(gpg --list-keys --with-colons 'C3SL Live' | grep --max-count=1 'fpr' | cut --delimiter=':' --fields=10)
fi
cp -Ra ${PREFIX}/src/local-repository/ ${PREFIX}/repo/
sed -i "s/##ARCH##/ ${_ARCH}/" ${PREFIX}/repo/conf/distributions
sed -i "s/##GPGKEY##/ ${fingerprint}/" ${PREFIX}/repo/conf/distributions
sed -i "s/##CODENAME##/ ${_REPO}/" ${PREFIX}/repo/conf/distributions
cp --recursive --archive ${PREFIX}/src/local-repository/ ${PREFIX}/repo/
sed -i "s/##ARCH##/ ${_ARCH}/" ${PREFIX}/repo/conf/distributions || pwarning "Unable to setup architecture of local repository"
sed -i "s/##GPGKEY##/ ${fingerprint}/" ${PREFIX}/repo/conf/distributions || pwarning "Unable to setup the key of local repository"
sed -i "s/##CODENAME##/ ${_REPO}/" ${PREFIX}/repo/conf/distributions || pwarning "Unable to setup the codename of local repository"
chroot ${CHROOTDIR} apt-get clean
chroot ${CHROOTDIR} apt-get --download-only --yes install $(cat ${REPOPKGS} | grep -v '^#' | tr '\n' ' ')
reprepro --basedir ${PREFIX}/repo/ includedeb ${_REPO} ${CHROOTDIR}/var/cache/apt/archives/*.deb
chroot ${CHROOTDIR} apt-get --download-only --yes install $(cat ${REPOPKGS} | grep --invert-match '^#' | tr '\n' ' '); $(genErrHandle 'Unable to download packages to local repository')
reprepro --basedir ${PREFIX}/repo/ includedeb ${_REPO} ${CHROOTDIR}/var/cache/apt/archives/*.deb; $(genErrHandle 'Unable to include package to local repository')
chroot ${CHROOTDIR} apt-get clean
mv repo/{dists,pool} ${TMP}/image/
rm -rf ${PREFIX}/repo/
mv repo/{dists,pool} ${TMP}/image/; $(genErrHandle 'Unable to move local repository to image')
rm --recursive --force ${PREFIX}/repo/
gpg --armor --export 'C3SL Live' > ${CHROOTDIR}/tmp/public.key
chroot ${CHROOTDIR} apt-key add /tmp/public.key
gpg --armor --export 'C3SL Live' > ${CHROOTDIR}/tmp/public.key; $(genErrHandle)
chroot ${CHROOTDIR} apt-key add /tmp/public.key; $(genErrHandle 'Unable to add key of local repository')
rm ${CHROOTDIR}/tmp/public.key
umount "${CHROOTDIR}/etc/resolv.conf"
exit 0
#!/bin/bash
#!/usr/bin/env bash
#
# Copyright (C) 2017 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
......@@ -24,7 +24,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......@@ -41,17 +41,11 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
source ${PREFIX}/common.sh
type addToChrootFile >/dev/null 2>&1 || source ${PREFIX}/common.sh
cat ${DPLIST} | grep -v '^#' | tr '\n' ' '
addToChrootFile $CHROOTFILE "export PATH='/fakebin:${PATH}'"
addToChrootFile $CHROOTFILE "export DEBIAN_FRONTEND=noninteractive"
addToChrootFile $CHROOTFILE "apt-get update && apt-get -q -y install $(cat ${DPLIST} | grep -v '^#' | tr '\n' ' ')"
initChroot $_DIST || \
log ERROR "failed to initialize chroot."
execChroot $CHROOTFILE $CHROOTDIR
RET=$?
closeChroot || \
log ERROR "failed to close chroot."
cat ${DPLIST} | grep --invert-match '^#' | tr '\n' ' '
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "export PATH='/fakebin:${PATH}'; $(genErrHandleInChroot)"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "export DEBIAN_FRONTEND=noninteractive; $(genErrHandleInChroot)"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get update && apt-get --quiet --yes install $(cat ${DPLIST} | grep --invert-match '^#' | tr '\n' ' '); $(genErrHandleInChroot)"
exit $?
exit 0
#!/bin/bash
#!/usr/bin/env bash
#
# Copyright (C) 2017 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
......@@ -24,7 +24,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......@@ -41,11 +41,11 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
source ${PREFIX}/common.sh
type addToChrootFile >/dev/null 2>&1 || source ${PREFIX}/common.sh
addToChrootFile $CHROOTFILE "export PATH='/fakebin:${PATH}'"
addToChrootFile $CHROOTFILE "export DEBIAN_FRONTEND=noninteractive"
addToChrootFile $CHROOTFILE "apt-get update && apt-get -q -y -t ${_REPO} install le-live-all"
addToChrootFile $CHROOTFILE "apt-get update && apt-get -q -y -t ${_REPO} install $(cat ${INSTLIST} | grep -v '^#' | tr '\n' ' ')"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "export PATH='/fakebin:${PATH}'"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "export DEBIAN_FRONTEND=noninteractive"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get update && apt-get --quiet --yes --target-release ${_REPO} install le-live-all; $(genErrHandleInChroot)"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get update && apt-get --quiet --yes --target-release ${_REPO} install $(cat ${INSTLIST} | grep --invert-match '^#' | tr '\n' ' '); $(genErrHandleInChroot)"
exit 0