#!/usr/bin/env bash
set -e

source $(dirname $0)/env.sh

cd $LUNA_ROOT

fakeroot -u -s $LUNA_ROOT/.fakeroot -- tools/install.sh

disk_space=$(du -s base | awk '{ print $1 }')
min_blocks=$(($disk_space / 4)) # This is just the blocks needed for all the files in the file system: this excludes space for the inode table, block group descriptors, etc.
blocks=$(($min_blocks + 1024)) # This is the actual number of blocks we're using.

fakeroot -u -i $LUNA_ROOT/.fakeroot -- genext2fs -d base -B 4096 -b $blocks -L luna-rootfs -N 1024 build/ext2fs.bin

mkbootimg luna.json Luna.iso