uci-docker-build/Dockerfile.d/init.tpl

86 lines
2.5 KiB
Smarty

#!/bin/bash
%
if [[ $REBUILD == "init" ]]; then
echo "## Busting Cache, Forcing Rebuild $(date)"
fi
%
quiet () {
if [[ $VERBOSE ]]; then $@; fi
}
quiet echo -e "\n ************************************************* \n"
quiet echo "****** Initializing Image with build source ******"
cd init
pwd; quiet ls -la
export BUILDING=true
export BUILD_DIR=$PWD
export SHELL=/bin/bash
export BIN_DIR=/opt/bin
mkdir -p $BIN_DIR
echo "export BIN_DIR=${BIN_DIR}" >> /tmp/profile
echo 'export PATH=$BIN_DIR:$PATH' >> /tmp/profile
echo " ##### creating entrypoint script ###"
cat << EOE >$BIN_DIR/entrypoint
.INCLUDE ./init/entrypoint.tpl
EOE
chmod +x $BIN_DIR/entrypoint
quiet echo '------ default entrypoint -----'
quiet ls -la $BIN_DIR/entrypoint
quiet cat $BIN_DIR/entrypoint
quiet echo "------------"
echo " ##### creating default start script ###"
cat << "EOS" >$BIN_DIR/start
.INCLUDE ./init/start.sh
EOS
chmod -R +x $BIN_DIR/start
quiet echo "--- DEFAULT START SCRIPT in $BIN_DIR/start ---"
quiet cat $BIN_DIR/start
quiet echo "-----------------------------------"
echo " ##### creating map host id script ###"
cat << "EOM" >$BIN_DIR/map-host-id
.INCLUDE ./init/map-host-id.sh
EOM
chmod +x $BIN_DIR/map-host-id
[[ -f image.info ]] && cp image.info /opt
.INCLUDE ./init/dirs.sh
if [[ -f build.env ]]; then
echo "-- sourcing /build/build.env --"
quiet ls -la
quiet cat build.env
quiet echo "----------------------"
source build.env
fi
if [[ -f ./init.sh ]]; then
echo "############## Running Script init.sh of build source #################"
quiet echo "----- build environment ------"
quiet env
quiet echo "----- env ------"
quiet echo "-------------------- init.sh ------------------------------"
quiet cat ./init.sh
quiet echo "-------------------------------------------------------------"
# init.sh must have shebang and be executable
if ! $SHELL ./init.sh; then return 1; fi
echo "############## Finished running init.sh build script #########################"
fi
.INCLUDE ./init/profile.sh
echo "****** creating user and group 'host' with ids 1000 *****"
groupadd -g 1000 host
useradd -r -g host -u 1000 host
# map host id now based on build environment
if [[ $VOLUME_DIRS ]]; then
echo "*** creating and configuring volume directories ***"
echo $VOLUME_DIRS
mkdir -p $VOLUME_DIRS
$BIN_DIR/map-host-id
chmod -R g+rw $VOLUME_DIRS
fi
echo -e "\n ************* End Initialzation ************************"