unbox/unbox.sh

117 lines
2.2 KiB
Bash
Raw Normal View History

2020-01-28 13:40:30 +00:00
#!/bin/bash
2020-01-29 13:51:37 +00:00
source $(dirname $0)/utils.sh
2020-01-28 13:40:30 +00:00
function unbox_outer_stage(){
echo "-----------FIRST STAGE-----------"
2020-01-29 13:40:46 +00:00
2020-01-31 10:16:17 +00:00
apt install git util-linux
2020-01-29 13:40:46 +00:00
2020-01-31 20:30:11 +00:00
touch .repo_cache
2020-01-31 20:23:21 +00:00
select chosen_repo in other $(cat .repo_cache | sort | uniq); do
if [ "${chosen_repo}" = "other" ]; then
2020-01-31 20:24:31 +00:00
echo -n "git repository url: "
2020-01-31 20:23:21 +00:00
read REMOTE
else
REMOTE=$chosen_repo
fi
2020-01-31 20:30:11 +00:00
echo $REMOTE
echo $REMOTE >> .repo_cache
2020-01-31 20:26:16 +00:00
break
2020-01-31 20:23:21 +00:00
done
2020-01-28 13:40:30 +00:00
if [ -e repo ]; then
(cd repo; git pull)
else
2020-01-31 20:23:21 +00:00
git clone "$REMOTE" repo
2020-01-28 13:40:30 +00:00
fi
if [[ ! -e repo/entry.sh ]]; then
echo no entry found;
exit 1;
fi
source repo/entry.sh
mkdir -p target
2020-01-31 09:49:01 +00:00
export TARGET=$(pwd)/target
2020-01-31 14:29:45 +00:00
export UNBOX_ENV_FILE=$(pwd)/.env
if [ -e .env ]; then
rm .env
fi
2020-01-28 13:40:30 +00:00
if type -t first_stage > /dev/null; then
first_stage
else
echo first stage not found
fi
if type -t chroot > /dev/null; then
2020-01-29 21:00:16 +00:00
if type -t arch-chroot > /dev/null; then
CHROOT=arch-chroot
else
2020-01-28 13:40:30 +00:00
CHROOT=chroot
2020-01-29 21:00:16 +00:00
fi
2020-01-28 13:40:30 +00:00
else
echo ERROR: no chroot found 1>&2
exit 1
fi
mkdir -p target/root/unbox
mount -o bind . target/root/unbox
$CHROOT target /root/unbox/unbox.sh unbox_inner_stage
2020-01-31 09:49:01 +00:00
if type -t post_install_stage > /dev/null; then
post_install_stage
else
echo no post_install_stage found
fi
2020-01-31 14:29:45 +00:00
if [ -e ${UNBOX_ENV_FILE} ]; then
rm ${UNBOX_ENV_FILE}
fi
2020-01-28 13:40:30 +00:00
exit 0
}
function unbox_inner_stage(){
echo "-----------SECOND STAGE-----------"
2020-01-31 14:29:45 +00:00
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
2020-01-28 13:40:30 +00:00
if type -t second_stage > /dev/null; then
second_stage
else
echo second stage not found
fi
2020-01-31 14:29:45 +00:00
if [ -e ${UNBOX_ENV_FILE} ]; then
rm ${UNBOX_ENV_FILE}
fi
2020-01-28 13:40:30 +00:00
exit 0
}
cd $(dirname $0)
if [[ $# -ge 1 ]]; then
CMD=$1
shift
if type -t $CMD > /dev/null; then
$CMD $@
else
echo command $CMD found
exit 1
fi
else
2020-01-29 13:44:57 +00:00
git pull
$0 unbox_outer_stage
2020-01-28 13:40:30 +00:00
fi