#!/bin/bash
source /etc/velvettools/config
if [ "$init_gen_hook" != "y" ];then
    exit 0
fi

unknown_error(){
  echo "WARNING. Something went wrong while building the image, please be careful while flashing it."
  exit 1
}

# don't run vtbuild if command was run by vtbuild
if [ ! -f /boot/norebuild ]; then
  /usr/bin/vtbuild $(cat /boot/to-update) noinitgen || unknown_error
  rm /boot/to-update
fi

# just in case somebody smart Ctrl + c out of vtbuild
rm /boot/norebuild 2> /dev/null

exit 0 # for whatever reason, it otherwise exits with error 1
