debmaker/lib/function.sh

109 lines
2.7 KiB
Bash

#!/bin/bash
source ressources/${APP}/${APP}
CACHE_APP=cache/${APP}/
MOUNT_APP=/mnt/debmaker/${APP}/
[ -d ${CACHE_APP} ] || mkdir -p ${CACHE_APP}
########################## SUB FUNCTION ##########################
valideStep(){
CURRENT_STEP=$1
RESULT=0
for tmp in ${STEP}
do
if [ $tmp == ${CURRENT_STEP} ] ; then
RESULT=1
break
fi
done
if [ $RESULT -eq 0 ]
then
echo invalid step
fi
}
getSizeImage(){
[ "${IMAGE_SIZE}" == "" ] && IMAGE_SIZE=2
}
createImage(){
dd if=/dev/zero of=${CACHE_APP}/os bs=1G count=${IMAGE_SIZE}
sudo mkfs.ext4 ${CACHE_APP}/os
}
previousStep(){
CURRENT_STEP=$1
TMP_STEP=os;
for tmp in ${STEP}
do
PREV=${TMP_STEP}
TMP_STEP=$tmp
if [ $tmp == $CURRENT_STEP ] ; then
break
fi
done
echo $PREV
}
########################## FUNCTION ##########################
debmake_mountStep(){
CURRENT_STEP=$1
[ -d ${MOUNT_APP}/${CURRENT_STEP} ] || sudo mkdir -p ${MOUNT_APP}/${CURRENT_STEP}
sudo mount ${CACHE_APP}/${CURRENT_STEP} ${MOUNT_APP}/${CURRENT_STEP}
[ -d ${MOUNT_APP}/${CURRENT_STEP}/proc ] || sudo mkdir -p ${MOUNT_APP}/${CURRENT_STEP}/proc
sudo mount -t proc proc ${MOUNT_APP}/${CURRENT_STEP}/proc
[ -d ${MOUNT_APP}/${CURRENT_STEP}/sys ] || sudo mkdir -p ${MOUNT_APP}/${CURRENT_STEP}/sys
sudo mount -t sysfs sys ${MOUNT_APP}/${CURRENT_STEP}/sys
sleep 2
}
debmake_umountStep(){
CURRENT_STEP=$1
sudo umount ${MOUNT_APP}/${CURRENT_STEP}/sys
sudo umount ${MOUNT_APP}/${CURRENT_STEP}/proc
sudo umount ${MOUNT_APP}/${CURRENT_STEP}
}
debmake_chrootStep(){
CURRENT_STEP=$1
debmake_mountStep ${CURRENT_STEP}
[ -d ${MOUNT_APP}/${CURRENT_STEP}/tmp/dist/${APP} ] && sudo rm -rf ${MOUNT_APP}/${CURRENT_STEP}/tmp/dist/
sudo mkdir -p ${MOUNT_APP}/${CURRENT_STEP}/tmp/dist
sudo cp -fr ressources/${APP}/* ${MOUNT_APP}/${CURRENT_STEP}/tmp/dist
sudo cp -fr lib/exec_in_chroot.sh ${MOUNT_APP}/${CURRENT_STEP}/tmp/dist
shift
sudo chroot ${MOUNT_APP}${CURRENT_STEP}/ $*
find ${MOUNT_APP}${CURRENT_STEP}/tmp/dist/ -name *.deb -exec cp {} dist/ \;
debmake_umountStep ${CURRENT_STEP}
}
########################## FUNCTION ##########################
debmake_runStepOS() {
CURRENT_STEP=os
getSizeImage
createImage
debmake_mountStep ${CURRENT_STEP}
sudo debootstrap ${DEBIAN_VERSION_CODENAME} ${MOUNT_APP}/os/
debmake_umountStep ${CURRENT_STEP}
}
debmake_runStepCustom() {
CURRENT_STEP=$1
valideStep ${CURRENT_STEP}
PREVIOUS=$(previousStep ${CURRENT_STEP})
echo -n copy $PREVIOUS in $CURRENT_STEP ...
cp ${CACHE_APP}/${PREVIOUS} ${CACHE_APP}/${CURRENT_STEP}
echo ": OK"
debmake_chrootStep $1 /tmp/dist/exec_in_chroot.sh ${APP} ${CURRENT_STEP} ${GIT_VERSION} ${DEB_VERSION}
}
debmake_runAllStep(){
debmake_runStepOS
for tmp in ${STEP}
do
debmake_runStepCustom $tmp
done
}