debmaker/lib/function.sh

108 lines
3.8 KiB
Bash
Raw Normal View History

2022-01-23 21:49:01 +01:00
#!/bin/bash
LANGUAGE=C
LC_ALL=C
LANG=C
2022-02-24 00:02:53 +01:00
DEBOOTSTRAP_DIR=cache/debootstrap/
MOUNT_PATH=/mnt/debmaker
2022-02-23 21:25:03 +01:00
zdebmaker_getDep(){
sudo sleep 0
2022-02-25 00:16:47 +01:00
[ -d cache ] || mkdir cache
[ -d dist ] || mkdir dist
2022-02-23 21:25:03 +01:00
[ -d ${DEBOOTSTRAP_DIR} ] || debmaker_debootstrapUpdate
}
2022-02-24 00:02:53 +01:00
zdebmaker_createOS(){
zdebmaker_getDep
2022-02-24 00:02:53 +01:00
dd if=/dev/zero of=cache/${DEBIAN_VERSION_CODENAME}.tmp bs=100M count=5
sudo mkfs.ext4 cache/${DEBIAN_VERSION_CODENAME}.tmp
2022-02-25 00:16:47 +01:00
[ -d ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME}/ ] || sudo mkdir -p ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME}/
2022-02-24 00:02:53 +01:00
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}
2022-01-23 21:49:01 +01:00
}
2022-02-24 00:02:53 +01:00
zdebmaker_createAppOS(){
zdebmaker_getDep
2022-02-24 00:02:53 +01:00
[ -f cache/${DEBIAN_VERSION_CODENAME} ] || zdebmaker_createOS
2022-03-28 22:42:52 +02:00
2022-02-20 15:02:18 +01:00
[ "${IMAGE_SIZE}" == "" ] && IMAGE_SIZE=2
2022-02-24 00:02:53 +01:00
dd if=/dev/zero of=cache/${APP}.tmp bs=1G count=${IMAGE_SIZE}
sudo mkfs.ext4 cache/${APP}.tmp
2022-03-28 22:42:52 +02:00
2022-02-25 00:16:47 +01:00
[ -d ${MOUNT_PATH}/${APP}/ ] || sudo mkdir -p ${MOUNT_PATH}/${APP}/
[ -d ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME}/ ] || sudo mkdir -p ${MOUNT_PATH}/${DEBIAN_VERSION_CODENAME}/
2022-02-24 00:02:53 +01:00
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}
2022-02-20 15:02:18 +01:00
}
2022-02-24 00:02:53 +01:00
zdebmaker_inject(){
zdebmaker_getDep
2022-02-24 00:02:53 +01:00
sudo mount cache/${APP} ${MOUNT_PATH}/${APP}/
[ -d ${MOUNT_PATH}/${APP}/tmp/dist ] && sudo rm -fr ${MOUNT_PATH}/${APP}/tmp/dist/
sudo mkdir ${MOUNT_PATH}/${APP}/tmp/dist/
2022-02-24 00:02:53 +01:00
[ -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 {} \;
2022-02-24 00:02:53 +01:00
sudo umount ${MOUNT_PATH}/${APP}/
2022-02-20 15:02:18 +01:00
}
2022-02-24 00:02:53 +01:00
debmaker_mount_proc_sys(){
OPEN_FILE=$1
OPEN_DIR=$2
zdebmaker_getDep
2022-02-24 00:02:53 +01:00
[ -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
2022-02-20 15:02:18 +01:00
}
2022-02-24 00:02:53 +01:00
debmaker_umount_proc_sys(){
OPEN_DIR=$1
zdebmaker_getDep
2022-02-24 00:02:53 +01:00
sudo umount ${OPEN_DIR}/sys
sudo umount ${OPEN_DIR}/proc
sudo umount ${OPEN_DIR}
2022-02-20 15:02:18 +01:00
}
2022-02-24 00:02:53 +01:00
debmaker_chroot() {
2022-03-28 22:42:52 +02:00
OPEN_FILE=cache/$2${APP}
zdebmaker_getDep
[ -f cache/${APP} ] || zdebmaker_createAppOS
zdebmaker_inject
2022-02-24 00:02:53 +01:00
debmaker_mount_proc_sys ${OPEN_FILE} ${MOUNT_PATH}/${APP}/
sudo chroot ${MOUNT_PATH}/${APP}/
debmaker_umount_proc_sys ${MOUNT_PATH}/${APP}/
2022-02-20 15:02:18 +01:00
}
2022-03-28 22:42:52 +02:00
2022-02-24 00:02:53 +01:00
debmaker_run(){
zdebmaker_getDep
2022-02-24 00:02:53 +01:00
[ -f cache/${APP} ] || zdebmaker_createAppOS
zdebmaker_inject
debmaker_mount_proc_sys cache/${APP} ${MOUNT_PATH}/${APP}/
for CURRENT_STEP in ${STEP}
2022-02-20 15:02:18 +01:00
do
sudo chroot ${MOUNT_PATH}/${APP}/ /tmp/src/exec_in_chroot.sh ${CURRENT_STEP}
2022-02-20 15:02:18 +01:00
done
rm -fr dist/${APP}*
find ${MOUNT_PATH}/${APP}/tmp/dist/ -name *.deb -exec cp -v {} dist/ \;
2022-02-24 00:02:53 +01:00
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}
2022-02-03 22:51:24 +01:00
}