Commit 78a94c80 authored by Daniel Bissani Furlin's avatar Daniel Bissani Furlin

SCRUM#263: Add heandler

parent 23bb473e
......@@ -70,6 +70,15 @@ function create_stub() {
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() {
......
......@@ -82,18 +82,20 @@ export LOG_FILE="${LOG_PATH}/create-iso-${TIME_STAMP}.log"
mkdir --parents ${TMP}
source common.sh
source lib/mktmpfs.sh
source lib/overlay.sh
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")
apt-get install isolinux syslinux squashfs-tools genisoimage xorriso \
|| log ERROR "Failed to install basic tools: \"${_DIST}\""
mountTmpfs ${TMPFS}
mountOverlay ${CHROOTDIR} ${TMPFS}
for script in `ls ${SCRIPTSDIR}`; do
if [ -x "$SCRIPTSDIR/$script" ] && egrep --quiet '^[0-9]{2}-[A-Za-z]+' <<< "$script"; then
echo "Running `basename $script`..."
pinfo "Running `basename $script`..."
if ! "${SCRIPTSDIR}/${script}"\
${_DIST} \
${_ARCH} \
......@@ -130,9 +132,8 @@ done
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} \
. ||\
log ERROR "Failed to generate iso 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
cleanup "${CHROOTDIR}" "${TMP}"
......
......@@ -2,13 +2,14 @@ readonly ERROR=1
readonly WARNING=2
readonly INFO=4
readonly DEBUG=8
readonly ALL=15
VERBOSE_FLAGS=$ERROR
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" 1>&2
echo -e "\033[38;5;9m[error]\033[0m $@" >> "$LOG_FILE"
fi
}
......@@ -20,16 +21,16 @@ pwarning () {
}
pinfo () {
if [ $(($VERBOSE_FLAGS & $INFO)) -eq $WARNING ]; then
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" 1>&2
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" 1>&2
echo -e "\033[38;5;6m[debug]\033[0m $@" >> "$LOG_FILE"
fi
}
......
......@@ -41,7 +41,7 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
source ${PREFIX}/common.sh
type genErrHandle >/dev/null 2>&1 || source ${PREFIX}/common.sh
#########################################
# WARNING:
......@@ -60,9 +60,7 @@ if mountpoint --quiet "${CHROOTDIR}/proc"; then
umount "${CHROOTDIR}/proc"
fi
mksquashfs ${CHROOTDIR} ${TMP}/image/casper/filesystem.squashfs -b 1M -no-recovery -processors $(nproc) ||\
log ERROR "Failed to compress ${CHROOTDIR}."
(cd ${TMP}/image && find . -type f -print0 | xargs -0 md5sum | grep --invert-match "\./md5sum.txt" > md5sum.txt) ||\
log ERROR "Failed to generate md5sum."
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
......@@ -41,7 +41,7 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
source ${PREFIX}/common.sh
type addToChrootFile >/dev/null 2>&1 || source ${PREFIX}/common.sh
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)
......@@ -51,19 +51,19 @@ if test -z ${fingerprint}; then
fi
cp --recursive --archive ${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
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 --invert-match '^#' | 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/
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"
......
......@@ -20,8 +20,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
type addToChrootFile >/dev/null 2>&1 || . common.sh
_DIST=$1
_ARCH=$2
_REPO=$3
......@@ -43,11 +41,11 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} 'export PATH=/fakebin:${PATH}'
type addToChrootFile >/dev/null 2>&1 || source ${PREFIX}/common.sh
cat ${DPLIST} | grep --invert-match '^#' | 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 install $(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 0
......@@ -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 ${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"
#addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get update && apt-get --quiet --yes --target-release ${_REPO} install $(cat ${INSTLIST} | grep --invert-match '^#' | tr '\n' ' ')"
#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
......@@ -41,9 +41,10 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
source ${PREFIX}/common.sh
type genErrHandle >/dev/null 2>&1 || source ${PREFIX}/common.sh
type pinfo >/dev/null 2>&1 || source ${PREFIX}/helper/logging.incsh
cp ${PREFIX}/vmlinuz-*-generic ${TMP}/image/casper/vmlinuz || exit 1
cp ${PREFIX}/vmlinuz-*-generic ${TMP}/image/casper/vmlinuz; $(genErrHandle "Unable to copy kernel to image")
if ! test -f initrd.lz; then
initname=$(ls "${PREFIX}/" | grep "initrd.*-generic")
if [ ! -d ${PREFIX}/initrd ]; then
......@@ -51,11 +52,12 @@ if ! test -f initrd.lz; then
else
rm --recursive --force ${PREFIX}/initrd/*
fi
echo "initname = '${initname}'"
cd ${PREFIX}/initrd
gzip --decompress --stdout ${PREFIX}/${initname} | cpio --extract
find . | cpio --quiet --create -H newc | lzma -7 > ../initrd.lz
cd ..
pinfo "Using '${initname}'"
pushd ${PREFIX}/initrd
gzip --decompress --stdout ${PREFIX}/${initname} | cpio --extract; $(genErrHandle "Unable to decompress initrd")
find . | cpio --quiet --create -H newc | lzma -7 > ../initrd.lz; $(genErrHandle "Unable to compress initrd")
popd
fi
cp initrd.lz ${TMP}/image/casper/initrd.lz || exit 1
cp initrd.lz ${TMP}/image/casper/initrd.lz; $(genErrHandle "Unable to copy initrd to image")
exit 0
......@@ -41,15 +41,17 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
source common.sh
type genErrHandle >/dev/null 2>&1 || source ${PREFIX}/common.sh
type pwarning >/dev/nul 2>&1 || source ${PREFIX}/helper/logging.incsh
#This packages must not appear in the manifest
cp ${TMP}/image/casper/filesystem.manifest ${TMP}/image/casper/filesystem.manifest-desktop
cp ${TMP}/image/casper/filesystem.manifest ${TMP}/image/casper/filesystem.manifest-desktop; $(genErrHandle 'Unable to create desktop manifest')
IFS_OLD=${IFS}
IFS=$'\n'
for package in $(cat ${RMDSKT})
do
sed --in-place "/${package}/d" ${TMP}/image/casper/filesystem.manifest-desktop
sed --in-place "/${package}/d" ${TMP}/image/casper/filesystem.manifest-desktop; pwarning "Unable to remove package ${package} from desktop manifest"
done
IFS=${IFS_OLD}
exit 0
......@@ -41,6 +41,4 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
source common.sh
exit 0
......@@ -41,8 +41,8 @@ TMPFS=${18}
REPOPKGS=${19}
export PREFIX=$PWD
source common.sh
type genErrHandle >/dev/null 2>&1 || source ${PREFIX}/common.sh
chroot ${CHROOTDIR} dpkg-query --show --showformat='${Package} ${Version}\n' > ${TMP}/image/casper/filesystem.manifest
chroot ${CHROOTDIR} dpkg-query --show --showformat='${Package} ${Version}\n' > ${TMP}/image/casper/filesystem.manifest; $(genErrHandle 'Unable to create manifest')
exit 0
......@@ -41,9 +41,9 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
source ${PREFIX}/common.sh
type addToChrootFile >/dev/null 2>&1 || source ${PREFIX}/common.sh
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get --yes purge $(cat ${RMLIST} | grep --invert-match "^#")"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get --yes autoremove"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get --yes purge $(cat ${RMLIST} | grep --invert-match "^#"); $(genErrHandleInChroot)"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get --yes autoremove; $(genErrHandleInChroot)"
exit 0
......@@ -41,35 +41,39 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
type genErrHandle >/dev/null 2>&1 || source ${PREFIX}/common.sh
type perror >/dev/null 2>&1 || source ${PREFIX}/helper/logging.incsh
if test -z ${CHROOTDIR}; then
echo "Variavel CHROOTDIR vazia!!"
echo "CHROOTDIR=\"${CHROOTDIR}\""
exit 1
fi
mkdir --parents ${TMP}/image/{casper,isolinux,install,preseed}
cp /usr/lib/ISOLINUX/isolinux.bin ${TMP}/image/isolinux/ || exit 1
cp /usr/lib/syslinux/modules/bios/ldlinux.c32 ${TMP}/image/isolinux/ || exit 1
cp src/isolinux/* ${TMP}/image/isolinux/ || exit 1
cp src/preseed/preseed.cfg ${TMP}/image/preseed/
cp src/keyboard ${CHROOTDIR}/etc/default/
du --summarize --one-file-system --block-size=1 ${CHROOTDIR} | cut --fields=1 > "${TMP}/image/casper/filesystem.size"
cp src/README.diskdefines-${_ARCH} ${TMP}/image/README.diskdefines || exit 1
mkdir --parents ${TMP}/image/{casper,isolinux,install,preseed,.disk}; $(genErrHandle "Unable to create necessarily directories")
cp /usr/lib/ISOLINUX/isolinux.bin ${TMP}/image/isolinux/; $(genErrHandle "Unable to copy isolinux.bin to image")
cp /usr/lib/syslinux/modules/bios/ldlinux.c32 ${TMP}/image/isolinux/; $(genErrHandle "Unable toi ldlinux.c32 to image")
cp ${PREFIX}/src/isolinux/* ${TMP}/image/isolinux/; $(genErrHandle "Unable to copy isolinux files to image")
cp ${PREFIX}/src/preseed/preseed.cfg ${TMP}/image/preseed/; $(genErrHandle "Unable to copy preseed to image")
cp ${PREFIX}/src/keyboard ${CHROOTDIR}/etc/default/ || \
pwarning "Unable to copy default keyboard layout"
du --summarize --one-file-system --block-size=1 ${CHROOTDIR} | cut --fields=1 > "${TMP}/image/casper/filesystem.size"; $(genErrHandle "Unable to get the size of chroot")
cp ${PREFIX}/src/README.diskdefines-${_ARCH} ${TMP}/image/README.diskdefines; $(genErrHandle "Unable to copy README.diskdefines to image")
pushd ${TMP}/image/
ln --symbolic . ubuntu
ln --symbolic . ubuntu; $(genErrHandle "Unable to create ${TMP}/image/ubuntu symbolic link")
popd
mkdir ${TMP}/image/.disk
touch ${TMP}/image/.disk/base_installable || exit 1
echo "full_cd/single" > ${TMP}/image/.disk/cd_type || exit 1
echo "Linux-Educacional 6.1.0" > ${TMP}/image/.disk/info || exit 1
echo "https://linuxeducacional.c3sl.ufpr.br" > ${TMP}/image/.disk/release_notes_url || exit 1
touch ${TMP}/image/.disk/base_installable; $(genErrHandle "Unable to create ${TMP}/image/.disk/base_installable")
echo "full_cd/single" > ${TMP}/image/.disk/cd_type; $(genErrHandle "Unable to set ${TMP}/image/.disk/cd_type")
echo "Linux-Educacional 6.1.0" > ${TMP}/image/.disk/info; $(genErrHandle "Unable to set ${TMP}/image/.disk/info")
echo "https://linuxeducacional.c3sl.ufpr.br" > ${TMP}/image/.disk/release_notes_url; $(genErrHandle "Unable to set ${TMP}/image/.disk/release_notes/url")
#Change label on grub menu
sed --in-place "s/GRUB_DISTRIBUTOR=.*/GRUB_DISTRIBUTOR=\"${DISTRO//_/ }\"/" ${CHROOTDIR}/etc/default/grub
sed --in-place "s/GRUB_DISTRIBUTOR=.*/GRUB_DISTRIBUTOR=\"${DISTRO//_/ }\"/" ${CHROOTDIR}/etc/default/grub || \
pwarning "Unable to change distributor in grub default file"
sed --in-place "s/PRETTY_NAME=.*/PRETTY_NAME=\"${DISTRO//_/ }\"/" ${CHROOTDIR}/usr/lib/os-release
sed --in-place "s/PRETTY_NAME=.*/PRETTY_NAME=\"${DISTRO//_/ }\"/" ${CHROOTDIR}/usr/lib/os-release || \
pwarning "Unable to change pretty name in os-release file"
cp src/lsb-release ${CHROOTDIR}/etc/
# Disable apport
sed --in-place 's/enabled=.*/enabled=0/' ${CHROOTDIR}/etc/default/apport
cp ${PREFIX}/src/lsb-release ${CHROOTDIR}/etc/ || \
pwarning "Unable to copy lsb-release file to chroot"
exit 0
......@@ -41,17 +41,18 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
source ${PREFIX}/common.sh
type addToChrootFile >/dev/null 2>&1 || source ${PREFIX}/common.sh
type pwarning >/dev/null 2>&1 || source ${PREFIX}/helper/logging.incsh
cp ${SOURCESLISTDEFAULT} ${CHROOTDIR}/etc/apt/sources.list
cp ${SOURCESLISTDEFAULT} ${CHROOTDIR}/etc/apt/sources.list || pwarning "Unable to copy default sources.list"
if [ ! -d "${CHROOTDIR}/etc/apt/sources.list.d" ]; then
mkdir "${CHROOTDIR}/etc/apt/sources.list.d"
fi
cp ${OURSOURCESLIST} ${CHROOTDIR}/etc/apt/sources.list.d/
cp ${OURSOURCESLIST} ${CHROOTDIR}/etc/apt/sources.list.d/; $(genErrHandle "Unable to copy custom sources.list")
sed --in-place "s/##CODENAME##/${_REPO}/g" ${CHROOTDIR}/etc/apt/sources.list.d/$(basename ${OURSOURCESLIST})
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "wget -O- http://repo.c3sl.ufpr.br/le6/le.c3sl.ufpr.br.key | apt-key add -"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "wget -O- http://repo.c3sl.ufpr.br/le6/le.c3sl.ufpr.br.key | apt-key add -; $(genErrHandleInChroot 'Unable to add a key to custom repository')"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get update"
#addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get --yes upgrade"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get update; $(genErrHandleInChroot 'Unable to reash all repositories')"
#addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get --yes upgrade; $(genErrHandleInChroot 'Unable to upgrade packages')"
exit 0
../../../scripts-available/post-epilogue.sh
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment