2020-01-28 13:40:30 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-01-29 13:51:37 +00:00
|
|
|
|
2022-03-27 04:18:33 +00:00
|
|
|
source $(dirname $(realpath $0))/utils.sh
|
2020-01-29 13:51:37 +00:00
|
|
|
|
2020-01-28 13:40:30 +00:00
|
|
|
function unbox_outer_stage(){
|
2021-03-12 13:35:16 +00:00
|
|
|
echo "-----------FIRST STAGE-----------"
|
|
|
|
|
|
|
|
apt install git util-linux
|
|
|
|
|
2020-01-31 21:39:18 +00:00
|
|
|
if [ -e .repo_cache ]; then
|
|
|
|
select chosen_repo in other $(cat .repo_cache | sort | uniq); do
|
|
|
|
if [ "${chosen_repo}" = "other" ]; then
|
|
|
|
echo -n "git repository url: "
|
|
|
|
read REMOTE
|
|
|
|
else
|
|
|
|
REMOTE=$chosen_repo
|
|
|
|
fi
|
|
|
|
break
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo -n "git repository url: "
|
|
|
|
read REMOTE
|
|
|
|
fi
|
2021-03-12 13:35:16 +00:00
|
|
|
|
2020-01-31 21:39:18 +00:00
|
|
|
echo $REMOTE
|
2021-03-12 13:35:16 +00:00
|
|
|
URL_CACHE=$( ( cat .repo_cache; echo $REMOTE;) )
|
|
|
|
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
|
|
|
|
echo no entry found;
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
source repo/entry.sh
|
|
|
|
|
|
|
|
mkdir -p target
|
|
|
|
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
|
2022-03-28 00:22:59 +00:00
|
|
|
(first_stage) || (echo first_stage failed; bash)
|
2021-03-12 13:35:16 +00:00
|
|
|
else
|
|
|
|
echo first stage not found
|
|
|
|
fi
|
|
|
|
|
|
|
|
if type -t chroot > /dev/null; then
|
|
|
|
if type -t arch-chroot > /dev/null; then
|
|
|
|
CHROOT=arch-chroot
|
|
|
|
else
|
|
|
|
CHROOT=chroot
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo ERROR: no chroot found 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p target/root/unbox
|
|
|
|
mount -o bind . target/root/unbox
|
2022-03-27 23:36:20 +00:00
|
|
|
mkdir -p target/root/unbox_data
|
|
|
|
mount -o bind /data target/root/unbox_data
|
2021-03-12 13:35:16 +00:00
|
|
|
$CHROOT target /root/unbox/unbox.sh unbox_inner_stage
|
2022-03-27 23:36:20 +00:00
|
|
|
umount target/root/unbox target/root/unbox_data
|
2021-03-12 13:35:16 +00:00
|
|
|
|
|
|
|
if type -t post_install_stage > /dev/null; then
|
2022-03-28 00:22:59 +00:00
|
|
|
(post_install_stage) || (echo post_install_stage failed; bash)
|
2021-03-12 13:35:16 +00:00
|
|
|
else
|
|
|
|
echo no post_install_stage found
|
|
|
|
fi
|
|
|
|
if [ -e ${UNBOX_ENV_FILE} ]; then
|
|
|
|
rm ${UNBOX_ENV_FILE}
|
|
|
|
fi
|
|
|
|
exit 0
|
2020-01-28 13:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function unbox_inner_stage(){
|
2021-03-12 13:35:16 +00:00
|
|
|
echo "-----------SECOND STAGE-----------"
|
|
|
|
export UNBOX_ENV_FILE=$(pwd)/.env
|
|
|
|
if [ -e ${UNBOX_ENV_FILE} ]; then
|
|
|
|
source ${UNBOX_ENV_FILE}
|
|
|
|
fi
|
|
|
|
if [ -e repo/entry.sh ]; then
|
|
|
|
source repo/entry.sh
|
|
|
|
else
|
|
|
|
echo chosen repository does not contain entry.sh file
|
|
|
|
fi
|
|
|
|
if type -t second_stage > /dev/null; then
|
2022-03-28 00:22:59 +00:00
|
|
|
(second_stage) || (echo second_stage failed; bash)
|
2021-03-12 13:35:16 +00:00
|
|
|
else
|
|
|
|
echo second stage not found
|
|
|
|
fi
|
|
|
|
if [ -e ${UNBOX_ENV_FILE} ]; then
|
|
|
|
rm ${UNBOX_ENV_FILE}
|
|
|
|
fi
|
|
|
|
exit 0
|
2020-01-28 13:40:30 +00:00
|
|
|
}
|
|
|
|
|
2022-03-27 04:14:16 +00:00
|
|
|
cd $(dirname $(realpath $0))
|
2020-01-28 13:40:30 +00:00
|
|
|
if [[ $# -ge 1 ]]; then
|
2021-03-12 13:35:16 +00:00
|
|
|
CMD=$1
|
|
|
|
shift
|
|
|
|
if type -t $CMD > /dev/null; then
|
|
|
|
$CMD $@
|
|
|
|
else
|
|
|
|
echo command $CMD found
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-01-28 13:40:30 +00:00
|
|
|
else
|
2020-01-29 13:44:57 +00:00
|
|
|
git pull
|
2021-03-12 13:35:16 +00:00
|
|
|
$0 unbox_outer_stage
|
2020-01-28 13:40:30 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|