Commit 23bb473e authored by Daniel Bissani Furlin's avatar Daniel Bissani Furlin

SCRUM#263: Umount overlay and tmpfs

parent 57696c0f
#!/bin/bash
SCRIPT_NAME="exec.sh"
cleanTmpFiles() {
local tmp="$1"
rm --recursive --force ${TMP}
closeChroot
}
emergency_shell() {
cleanTmpFiles
local tmp="$1"
cleanTmpFiles ${tmp}
echo "FATAL ERROR!"
exit 1
}
......@@ -22,43 +23,39 @@ function log() {
initChroot() {
local chrootdir="$1"
local logfile="$2"
# Create the log file; this file will be bind to appear in $VARLOG
# directory in the target machine that generates the iso.
touch "${chrootdir}/${logfile}"
touch "$logfile"
touch "${chrootdir}/${LOG_FILE}"
touch "$LOG_FILE"
mount --bind /dev "${chrootdir}/dev"
mount --bind /dev/pts "${chrootdir}/dev/pts"
mount --bind /proc "${chrootdir}/proc"
mount --bind /sys "${chrootdir}/sys"
mount --bind "$logfile" "${chrootdir}/${logfile}" ||
log ERROR "Failed to bind log file from: '${logfile}' to '${chrootdir}/${logfile}'."
mount --bind "${LOG_FILE}" "${chrootdir}/${LOG_FILE}" ||
log ERROR "Failed to bind log file from: '${LOG_FILE}' to '${chrootdir}/${LOG_FILE}'."
mount --bind "/etc/resolv.conf" "${chrootdir}/etc/resolv.conf"
# chroot ${CHROOTDIR} dbus-uuidgen > ${CHROOTDIR}/var/lib/dbus/machine-id
# 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() {
local chrootdir="$1"
local logfile="$2"
umount --lazy "${chrootdir}/etc/resolv.conf"
umount --lazy "${chrootdir}/${logfile}"
umount --lazy "${chrootdir}/${LOG_FILE}"
umount --lazy ${chrootdir}/{dev/pts,proc,sys,dev}
}
......@@ -76,22 +73,24 @@ EOF
}
addToChrootFile() {
local chrootfile="$1"
local cmd="$2"
local chrootdir="$1"
local script_name="$2"
local cmd="$3"
if [ ! -f "$chrootfile" ]; then
create_stub "$chrootfile"
if [ ! -f "${chrootdir}/tmp/${script_name}" ]; then
create_stub "${chrootdir}/tmp/${script_name}"
fi
echo $cmd >> $chrootfile
echo ${cmd} >> "${chrootdir}/tmp/${script_name}"
}
execChroot() {
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
[ ! -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 $?
}
......@@ -100,10 +99,23 @@ function cleanup() {
local chrootdir="$1"
local tmp="$2"
umount --lazy "${chrootdir}/etc/resolv.conf"
umount --lazy "${chrootdir/$LOG_FILE"
umount --lazy "${chrootdir}/{dev/pts,proc,sys,dev}"
rm --recursive --force "$chrootdir"
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"
}
......@@ -2,7 +2,6 @@ SHORTNAME=le6
TMP=/home/${SUDO_USER}/${_DIST}
CHROOTDIR=/home/${SUDO_USER}/overlay
TMPFS=/home/${SUDO_USER}/tmp
CHROOTFILE=${CHROOTDIR}/tmp/exec.sh
DISTRO=Linux_Educacional_6.1.0
DPLIST=${PREFIX}/pkg-list/${_DIST}/dependencies.list
INSTLIST=${PREFIX}/pkg-list/${_DIST}/install.list
......@@ -14,4 +13,5 @@ RMLIST=${PREFIX}/pkg-list/${_DIST}/remove.list
REPOPKGS=${PREFIX}/pkg-list/${_DIST}/repo-local.list
SCRIPTSDIR=${PREFIX}/scripts-enabled/${_DIST}
SOURCESLISTDEFAULT=${PREFIX}/sources-list/${_DIST}/default.list
SCRIPT_NAME="exec.sh"
LOG_PATH="/var/log"
......@@ -99,7 +99,7 @@ for script in `ls ${SCRIPTSDIR}`; do
${_ARCH} \
${_REPO} \
${CHROOTDIR} \
${CHROOTFILE} \
${SCRIPT_NAME} \
${DISTRO} \
${DPLIST} \
${INSTLIST} \
......@@ -122,22 +122,21 @@ for script in `ls ${SCRIPTSDIR}`; do
if [[ "$script" =~ [0-9]+\-chroot\.* ]]; then
initChroot "${CHROOTDIR}" "${LOG_FILE}"
execChroot "$CHROOTDIR"
execChroot "$CHROOTDIR" "${SCRIPT_NAME}"
closeChroot "${CHROOTDIR}" "${LOG_FILE}"
fi
fi
done
NAME="LinuxEducacional6-$(echo ${_DIST} | cut --delimiter='/' --fields=f2).iso"
cd ${TMP}/image
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."
cd -
popd
#cleanTmpFiles
#umountOverlay ${CHROOTDIR} ${TMPFS}
#umountTmpfs ${TMPFS}
cleanup "${CHROOTDIR}" "${TMP}"
umountOverlay ${CHROOTDIR} ${TMPFS}
umountTmpfs ${TMPFS}
exit 0
......@@ -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"
}
......@@ -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."
......
......@@ -20,13 +20,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#set -x
_DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......@@ -49,21 +47,22 @@ source ${PREFIX}/common.sh
# WARNING:
# Sanity check if {dev,proc,sys} are mounted, cp from /proc will be recursive
# until run out RAM.
if chroot "$CHROOTDIR" mount | grep --quiet --only-matching 'on /dev/pts'; then
umount "$CHROOTDIR/dev/pts"
if mountpoint --quiet "${CHROOTDIR}/dev/pts"; then
umount "${CHROOTDIR}/dev/pts"
fi
if chroot "$CHROOTDIR" mount | grep --quiet --only-matching 'on /dev'; then
umount "$CHROOTDIR/dev"
if mountpoint --quiet "${CHROOTDIR}/dev"; then
umount "${CHROOTDIR}/dev"
fi
if chroot "$CHROOTDIR" mount | grep --quiet --only-matching 'on /sys'; then
umount "$CHROOTDIR/sys"
if mountpoint --quiet "${CHROOTDIR}/sys"; then
umount "${CHROOTDIR}/sys"
fi
if chroot "$CHROOTDIR" mount | grep --quiet --only-matching 'on /proc'; then
umount "$CHROOTDIR/proc"
if mountpoint --quiet "${CHROOTDIR}/proc"; then
umount "${CHROOTDIR}/proc"
fi
mksquashfs $CHROOTDIR ${TMP}/image/casper/filesystem.squashfs -b 1M -no-recovery -processors $(nproc) ||\
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."
exit 0
......@@ -20,13 +20,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
set -e
_DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......
......@@ -26,7 +26,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......@@ -43,11 +43,11 @@ TMPFS=${18}
REPOPKGS=${19}
PREFIX=$PWD
addToChrootFile $CHROOTFILE 'export PATH=/fakebin:${PATH}'
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} 'export PATH=/fakebin:${PATH}'
cat ${DPLIST} | grep --invert-match '^#' | tr '\n' ' '
addToChrootFile $CHROOTFILE "export PATH='/fakebin:${PATH}'"
addToChrootFile $CHROOTFILE "export DEBIAN_FRONTEND=noninteractive"
addToChrootFile $CHROOTFILE "apt-get update && apt-get --quiet --yes install $(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' ' ')"
exit 0
......@@ -24,7 +24,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......@@ -43,9 +43,9 @@ PREFIX=$PWD
source ${PREFIX}/common.sh
addToChrootFile $CHROOTFILE "export PATH='/fakebin:${PATH}'"
addToChrootFile $CHROOTFILE "export DEBIAN_FRONTEND=noninteractive"
#addToChrootFile $CHROOTFILE "apt-get update && apt-get --quiet --yes --target-release ${_REPO} install le-live-all"
#addToChrootFile $CHROOTFILE "apt-get update && apt-get --quiet --yes --target-release ${_REPO} install $(cat ${INSTLIST} | 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 --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' ' ')"
exit 0
......@@ -24,7 +24,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......
......@@ -24,7 +24,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......@@ -45,11 +45,11 @@ source common.sh
#This packages must not appear in the manifest
cp ${TMP}/image/casper/filesystem.manifest ${TMP}/image/casper/filesystem.manifest-desktop
IFS_OLD=$IFS
IFS_OLD=${IFS}
IFS=$'\n'
for package in $(cat ${RMDSKT})
do
sed --in-place "/${package}/d" ${TMP}/image/casper/filesystem.manifest-desktop
done
IFS=$IFS_OLD
IFS=${IFS_OLD}
exit 0
......@@ -24,7 +24,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......
......@@ -24,7 +24,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......@@ -43,6 +43,6 @@ export PREFIX=$PWD
source 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
exit 0
......@@ -24,7 +24,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......@@ -43,7 +43,7 @@ PREFIX=$PWD
source ${PREFIX}/common.sh
addToChrootFile $CHROOTFILE "apt-get --yes purge $(cat ${RMLIST} | grep --invert-match "^#")"
addToChrootFile $CHROOTFILE "apt-get --yes autoremove"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get --yes purge $(cat ${RMLIST} | grep --invert-match "^#")"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get --yes autoremove"
exit 0
......@@ -24,7 +24,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......
......@@ -24,7 +24,7 @@ _DIST=$1
_ARCH=$2
_REPO=$3
CHROOTDIR=$4
CHROOTFILE=$5
SCRIPT_NAME=$5
DISTRO=$6
DPLIST=$7
INSTLIST=$8
......@@ -49,9 +49,9 @@ if [ ! -d "${CHROOTDIR}/etc/apt/sources.list.d" ]; then
fi
cp ${OURSOURCESLIST} ${CHROOTDIR}/etc/apt/sources.list.d/
sed --in-place "s/##CODENAME##/${_REPO}/g" ${CHROOTDIR}/etc/apt/sources.list.d/$(basename ${OURSOURCESLIST})
addToChrootFile $CHROOTFILE "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 -"
addToChrootFile $CHROOTFILE "apt-get update"
#addToChrootFile $CHROOTFILE "apt-get --yes upgrade"
addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get update"
#addToChrootFile ${CHROOTDIR} ${SCRIPT_NAME} "apt-get --yes upgrade"
exit 0
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