This commit is contained in:
j3d1 2021-03-12 14:35:16 +01:00
parent 5a010aec09
commit deb2c57e5a

150
unbox.sh
View file

@ -4,9 +4,9 @@
source $(dirname $0)/utils.sh source $(dirname $0)/utils.sh
function unbox_outer_stage(){ function unbox_outer_stage(){
echo "-----------FIRST STAGE-----------" echo "-----------FIRST STAGE-----------"
apt install git util-linux apt install git util-linux
if [ -e .repo_cache ]; then if [ -e .repo_cache ]; then
select chosen_repo in other $(cat .repo_cache | sort | uniq); do select chosen_repo in other $(cat .repo_cache | sort | uniq); do
@ -24,98 +24,98 @@ function unbox_outer_stage(){
fi fi
echo $REMOTE echo $REMOTE
URL_CACHE=$( ( cat .repo_cache; echo $REMOTE;) | sort | uniq ) URL_CACHE=$( ( cat .repo_cache; echo $REMOTE;) )
echo $URL_CACHE > .repo_cache for LINE in $URL_CACHE; do echo $LINE; done | sort | uniq > .repo_cache
if [ -e repo ]; then if [ -e repo ]; then
(cd repo; git pull) (cd repo; git pull)
else else
git clone "$REMOTE" repo git clone "$REMOTE" repo
fi fi
if [[ ! -e repo/entry.sh ]]; then if [[ ! -e repo/entry.sh ]]; then
echo no entry found; echo no entry found;
exit 1; exit 1;
fi fi
source repo/entry.sh source repo/entry.sh
mkdir -p target mkdir -p target
export TARGET=$(pwd)/target export TARGET=$(pwd)/target
export UNBOX_ENV_FILE=$(pwd)/.env export UNBOX_ENV_FILE=$(pwd)/.env
if [ -e .env ]; then if [ -e .env ]; then
rm .env rm .env
fi fi
if type -t first_stage > /dev/null; then if type -t first_stage > /dev/null; then
first_stage first_stage
else else
echo first stage not found echo first stage not found
fi fi
if type -t chroot > /dev/null; then if type -t chroot > /dev/null; then
if type -t arch-chroot > /dev/null; then if type -t arch-chroot > /dev/null; then
CHROOT=arch-chroot CHROOT=arch-chroot
else else
CHROOT=chroot CHROOT=chroot
fi fi
else else
echo ERROR: no chroot found 1>&2 echo ERROR: no chroot found 1>&2
exit 1 exit 1
fi fi
mkdir -p target/root/unbox mkdir -p target/root/unbox
mount -o bind . target/root/unbox mount -o bind . target/root/unbox
$CHROOT target /root/unbox/unbox.sh unbox_inner_stage $CHROOT target /root/unbox/unbox.sh unbox_inner_stage
if type -t post_install_stage > /dev/null; then if type -t post_install_stage > /dev/null; then
post_install_stage post_install_stage
else else
echo no post_install_stage found echo no post_install_stage found
fi fi
if [ -e ${UNBOX_ENV_FILE} ]; then if [ -e ${UNBOX_ENV_FILE} ]; then
rm ${UNBOX_ENV_FILE} rm ${UNBOX_ENV_FILE}
fi fi
exit 0 exit 0
} }
function unbox_inner_stage(){ function unbox_inner_stage(){
echo "-----------SECOND STAGE-----------" echo "-----------SECOND STAGE-----------"
export UNBOX_ENV_FILE=$(pwd)/.env export UNBOX_ENV_FILE=$(pwd)/.env
if [ -e ${UNBOX_ENV_FILE} ]; then if [ -e ${UNBOX_ENV_FILE} ]; then
source ${UNBOX_ENV_FILE} source ${UNBOX_ENV_FILE}
fi fi
if [ -e repo/entry.sh ]; then if [ -e repo/entry.sh ]; then
source repo/entry.sh source repo/entry.sh
else else
echo chosen repository does not contain entry.sh file echo chosen repository does not contain entry.sh file
fi fi
if type -t second_stage > /dev/null; then if type -t second_stage > /dev/null; then
second_stage second_stage
else else
echo second stage not found echo second stage not found
fi fi
if [ -e ${UNBOX_ENV_FILE} ]; then if [ -e ${UNBOX_ENV_FILE} ]; then
rm ${UNBOX_ENV_FILE} rm ${UNBOX_ENV_FILE}
fi fi
exit 0 exit 0
} }
cd $(dirname $0) cd $(dirname $0)
if [[ $# -ge 1 ]]; then if [[ $# -ge 1 ]]; then
CMD=$1 CMD=$1
shift shift
if type -t $CMD > /dev/null; then if type -t $CMD > /dev/null; then
$CMD $@ $CMD $@
else else
echo command $CMD found echo command $CMD found
exit 1 exit 1
fi fi
else else
git pull git pull
$0 unbox_outer_stage $0 unbox_outer_stage
fi fi