debmaker/lib/function.sh

102 lines
3.6 KiB
Bash

#!/bin/bash
DEBOOTSTRAP_DIR=cache/debootstrap/
MOUNT_PATH=/mnt/debmaker
zdebmaker_getDep(){
sudo sleep 0
[ -d cache ] || mkdir cache
[ -d dist ] || mkdir dist
[ -d ${DEBOOTSTRAP_DIR} ] || debmaker_debootstrapUpdate
}
zdebmaker_createOS(){
zdebmaker_getDep
dd if=/dev/zero of=cache/${DEBIAN_VERSION_CODENAME}.tmp bs=100M count=5
sudo mkfs.ext4 cache/${DEBIAN_VERSION_CODENAME}.tmp
[ -d ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME}/ ] || sudo mkdir -p ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME}/
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(){
zdebmaker_getDep
[ -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
[ -d ${MOUNT_PATH}/${APP}/ ] || sudo mkdir -p ${MOUNT_PATH}/${APP}/
[ -d ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME}/ ] || sudo mkdir -p ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME}/
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(){
zdebmaker_getDep
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 -pfr ressources/${APP}/* ${MOUNT_PATH}/${APP}/tmp/src
sudo cp lib/exec_in_chroot.sh ${MOUNT_PATH}/${APP}/tmp/src
sudo find ${MOUNT_PATH}/${APP}/tmp/src -name .gitkeep -exec rm {} \;
sudo umount ${MOUNT_PATH}/${APP}/
}
debmaker_mount_proc_sys(){
OPEN_FILE=$1
OPEN_DIR=$2
zdebmaker_getDep
[ -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
zdebmaker_getDep
sudo umount ${OPEN_DIR}/sys
sudo umount ${OPEN_DIR}/proc
sudo umount ${OPEN_DIR}
}
debmaker_chroot() {
OPEN_FILE=cache/$2${APP}
zdebmaker_getDep
debmaker_mount_proc_sys ${OPEN_FILE} ${MOUNT_PATH}/${APP}/
sudo chroot ${MOUNT_PATH}/${APP}/
debmaker_umount_proc_sys ${MOUNT_PATH}/${APP}/
}
debmaker_run(){
zdebmaker_getDep
[ -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 ${CURRENT_STEP}
done
find ${MOUNT_PATH}/${APP}/tmp/dist/ -name *.deb -exec cp {} dist/ \;
debmaker_umount_proc_sys ${MOUNT_PATH}/${APP}/
}
debmaker_debootstrapUpdate(){
zdebmaker_getDep
[ -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}
}