#!/bin/bash source ressources/${APP}/${APP} DEBOOTSTRAP_DIR=cache/debootstrap/ MOUNT_PATH=/mnt/debmaker zdebmaker_getDep(){ [ -d ${DEBOOTSTRAP_DIR} ] || debmaker_debootstrapUpdate } zdebmaker_createOS(){ dd if=/dev/zero of=cache/${DEBIAN_VERSION_CODENAME}.tmp bs=100M count=5 sudo mkfs.ext4 cache/${DEBIAN_VERSION_CODENAME}.tmp sudo mount cache/${DEBIAN_VERSION_CODENAME}.tmp ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME} sudo DEBOOTSTRAP_DIR=cache/debootstrap/ ${DEBOOTSTRAP_DIR}/debootstrap ${DEBIAN_VERSION_CODENAME} ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME}/ sudo umount ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME} mv cache/${DEBIAN_VERSION_CODENAME}.tmp cache/${DEBIAN_VERSION_CODENAME} } zdebmaker_createAppOS(){ [ -f cache/${DEBIAN_VERSION_CODENAME} ] || zdebmaker_createOS [ "${IMAGE_SIZE}" == "" ] && IMAGE_SIZE=2 dd if=/dev/zero of=cache/${APP}.tmp bs=1G count=${IMAGE_SIZE} sudo mkfs.ext4 cache/${APP}.tmp sudo mount cache/${APP}.tmp ${MOUNT_PATH}/${APP}/ sudo mount cache/${DEBIAN_VERSION_CODENAME} ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME} sudo rsync -h -X -A --numeric-ids -aH --no-whole-file --inplace --one-file-system ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME}/* ${MOUNT_PATH}/${APP}/ sudo umount ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME} sudo umount ${MOUNT_PATH}/${APP}/ mv cache/${APP}.tmp cache/${APP} } zdebmaker_inject(){ sudo mount cache/${APP} ${MOUNT_PATH}/${APP}/ [ -d ${MOUNT_PATH}/${APP}/tmp/dist ] || sudo mkdir ${MOUNT_PATH}/${APP}/tmp/dist/ [ -d ${MOUNT_PATH}/${APP}/tmp/src ] && sudo rm -rf ${MOUNT_PATH}/${APP}/tmp/src/ sudo mkdir -p ${MOUNT_PATH}/${APP}/tmp/src sudo cp -fr ressources/${APP}/* ${MOUNT_PATH}/${APP}/tmp/src sudo cp -fr lib/exec_in_chroot.sh ${MOUNT_PATH}/${APP}/tmp/src sudo umount ${MOUNT_PATH}/${APP}/ } debmaker_mount_proc_sys(){ OPEN_FILE=$1 OPEN_DIR=$2 [ -d ${OPEN_FILE} ] || sudo mkdir -p ${OPEN_DIR} sudo mount ${OPEN_FILE} ${OPEN_DIR} [ -d ${OPEN_DIR}/proc ] || sudo mkdir -p ${OPEN_DIR}/proc sudo mount -t proc proc ${OPEN_DIR}/proc [ -d ${OPEN_DIR}/sys ] || sudo mkdir -p ${OPEN_DIR}/sys sudo mount -t sysfs sys ${OPEN_DIR}/sys } debmaker_umount_proc_sys(){ OPEN_DIR=$1 sudo umount ${OPEN_DIR}/sys sudo umount ${OPEN_DIR}/proc sudo umount ${OPEN_DIR} } debmaker_chroot() { OPEN_FILE=$1 debmaker_mount_proc_sys ${OPEN_FILE} ${MOUNT_PATH}/${APP}/ sudo chroot ${MOUNT_PATH}/${APP}/ debmaker_umount_proc_sys ${MOUNT_PATH}/${APP}/ } debmaker_run(){ [ -f cache/${APP} ] || zdebmaker_createAppOS zdebmaker_inject debmaker_mount_proc_sys cache/${APP} ${MOUNT_PATH}/${APP}/ for CURRENT_STEP in ${STEP} do sudo chroot ${MOUNT_PATH}/${APP}/ /tmp/src/exec_in_chroot.sh ${APP} ${CURRENT_STEP} ${GIT_VERSION} ${DEB_VERSION} done find ${MOUNT_PATH}/${APP}/tmp/dist/ -name *.deb -exec cp {} dist/ \; debmaker_umount_proc_sys ${MOUNT_PATH}/${APP}/ } debmaker_debootstrapUpdate(){ [ -d ${DEBOOTSTRAP_DIR} ] || mkdir ${DEBOOTSTRAP_DIR} URL=https://salsa.debian.org/installer-team/debootstrap/-/archive/master/debootstrap-master.tar.gz FILES="debootstrap-master/debootstrap debootstrap-master/scripts/ debootstrap-master/functions" wget -qO - ${URL} | tar -C ${DEBOOTSTRAP_DIR} --strip-components=1 -zx ${FILES} } zdebmaker_getDep