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

164
unbox.sh
View file

@ -4,10 +4,10 @@
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
if [ "${chosen_repo}" = "other" ]; then if [ "${chosen_repo}" = "other" ]; then
@ -22,100 +22,100 @@ function unbox_outer_stage(){
echo -n "git repository url: " echo -n "git repository url: "
read REMOTE read REMOTE
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
(cd repo; git pull)
else
git clone "$REMOTE" repo
fi
if [[ ! -e repo/entry.sh ]]; then if [ -e repo ]; then
echo no entry found; (cd repo; git pull)
exit 1; else
fi git clone "$REMOTE" repo
fi
source repo/entry.sh if [[ ! -e repo/entry.sh ]]; then
echo no entry found;
exit 1;
fi
mkdir -p target source repo/entry.sh
export TARGET=$(pwd)/target
export UNBOX_ENV_FILE=$(pwd)/.env
if [ -e .env ]; then
rm .env
fi
if type -t first_stage > /dev/null; then mkdir -p target
first_stage export TARGET=$(pwd)/target
else export UNBOX_ENV_FILE=$(pwd)/.env
echo first stage not found
fi if [ -e .env ]; then
rm .env
fi
if type -t chroot > /dev/null; then if type -t first_stage > /dev/null; then
if type -t arch-chroot > /dev/null; then first_stage
CHROOT=arch-chroot else
else echo first stage not found
CHROOT=chroot fi
fi
else
echo ERROR: no chroot found 1>&2
exit 1
fi
mkdir -p target/root/unbox if type -t chroot > /dev/null; then
mount -o bind . target/root/unbox if type -t arch-chroot > /dev/null; then
$CHROOT target /root/unbox/unbox.sh unbox_inner_stage CHROOT=arch-chroot
else
if type -t post_install_stage > /dev/null; then CHROOT=chroot
post_install_stage fi
else else
echo no post_install_stage found echo ERROR: no chroot found 1>&2
fi exit 1
if [ -e ${UNBOX_ENV_FILE} ]; then fi
rm ${UNBOX_ENV_FILE}
fi mkdir -p target/root/unbox
exit 0 mount -o bind . target/root/unbox
$CHROOT target /root/unbox/unbox.sh unbox_inner_stage
if type -t post_install_stage > /dev/null; then
post_install_stage
else
echo no post_install_stage found
fi
if [ -e ${UNBOX_ENV_FILE} ]; then
rm ${UNBOX_ENV_FILE}
fi
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