new: add core RUN step
refactored: Dockefile template refactor: example and move src/ there a simple example new: distros.csv holds table of valid distros, their images and install/update commands refactor: various fixes and adjustment in response to above refactor: help vastly improved and updatedmaster
parent
efe8d0fa2d
commit
ca857a032a
|
@ -2,25 +2,24 @@
|
||||||
ARG BASE_IMAGE
|
ARG BASE_IMAGE
|
||||||
FROM $BASE_IMAGE
|
FROM $BASE_IMAGE
|
||||||
ARG BASE_IMAGE
|
ARG BASE_IMAGE
|
||||||
ARG SYSADMIN_PW
|
|
||||||
ARG VERBOSE
|
ARG VERBOSE
|
||||||
|
ARG REBUILD
|
||||||
ARG LINUX_DISTRO=alpine
|
ARG LINUX_DISTRO=alpine
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
|
|
||||||
# PACKAGES
|
# CORE
|
||||||
RUN --mount=type=bind,source=.src/packages,target=/build/packages \
|
RUN --mount=type=bind,source=./core,target=/build \
|
||||||
<<eot
|
<<eot
|
||||||
.INCLUDE packages.tpl
|
.INCLUDE core.tpl
|
||||||
eot
|
|
||||||
# END PACKAGES
|
|
||||||
|
|
||||||
# INITIALIZATION
|
|
||||||
RUN --mount=type=bind,source=.src/init,target=/build/init \
|
|
||||||
<<eot
|
|
||||||
.INCLUDE init.tpl
|
|
||||||
eot
|
eot
|
||||||
|
|
||||||
# END INITIALIZATION
|
% if [[ ( "$_packages_" && ! $BUILD_SRC = "_core_" ) ]]; then
|
||||||
|
.INCLUDE packages.run
|
||||||
|
% fi
|
||||||
|
|
||||||
|
% if [[ ( "$BUILD_SRC" && ! $BUILD_SRC = "_core_" ) ]]; then
|
||||||
|
.INCLUDE init.run
|
||||||
|
% fi
|
||||||
|
|
||||||
# default command
|
# default command
|
||||||
ENTRYPOINT ["/opt/bin/entrypoint"]
|
ENTRYPOINT ["/opt/bin/entrypoint"]
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/sh
|
||||||
|
%
|
||||||
|
if [ "$REBUILD" = "core" ]; then
|
||||||
|
echo "## Busting Cache, Forcing Rebuild starting at core RUN "
|
||||||
|
echo $(date)
|
||||||
|
fi
|
||||||
|
%
|
||||||
|
if ! { [ "$VERBOSE" = "core" ] || [ "$VERBOSE" = "all" ]; }; then unset VERBOSE; fi
|
||||||
|
|
||||||
|
mkdir -p /opt
|
||||||
|
/bin/cp -R -f -p opt/. /opt
|
||||||
|
. /opt/lib/verbose.lib
|
||||||
|
|
||||||
|
echo "**************************************"
|
||||||
|
echo "****** Building UCI Image Core ******"
|
||||||
|
quiet echo core build directory
|
||||||
|
quiet pwd
|
||||||
|
quiet ls -la
|
||||||
|
quiet echo "--------------------------------------"
|
||||||
|
. /opt/lib/distro.lib
|
||||||
|
if validate_distro; then
|
||||||
|
echo distro $LINUX_DISTRO was validated...continuing
|
||||||
|
set_distro
|
||||||
|
/bin/sh ./packages.sh
|
||||||
|
/bin/bash -l ./core.sh
|
||||||
|
echo
|
||||||
|
echo "************* End UCI CORE build ********************"
|
||||||
|
else
|
||||||
|
echo !!! FATAL ERROR: distro of base image $BASE_IMAGE does not match linux distro $LINUX_DISTRO !!!
|
||||||
|
exit 1
|
||||||
|
fi
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
|
# echo build source?: $BUILD_SRC packages? $packages
|
||||||
pushd $(dirname "$(realpath "$BASH_SOURCE")") > /dev/null || return 1
|
pushd $(dirname "$(realpath "$BASH_SOURCE")") > /dev/null || return 1
|
||||||
source <(../lib/bash-tpl Dockerfile.tpl ) | grep -v '^# ' > ../Dockerfile
|
source <(../lib/bash-tpl Dockerfile.tpl ) | grep -v '^# ' > ../Dockerfile
|
||||||
echo " ************* uci build Dockerfile created *****************"
|
echo "------------ Created Dockfile from template in Dockerfile.d -------------"
|
||||||
popd > /dev/null || return 2
|
popd > /dev/null || return 2
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
# INITIALIZATION
|
||||||
|
RUN --mount=type=bind,source=.src/init,target=/build \
|
||||||
|
<<eot
|
||||||
|
.INCLUDE init.tpl
|
||||||
|
eot
|
|
@ -4,60 +4,25 @@
|
||||||
echo "## Busting Cache, Forcing Rebuild $(date)"
|
echo "## Busting Cache, Forcing Rebuild $(date)"
|
||||||
fi
|
fi
|
||||||
%
|
%
|
||||||
quiet () {
|
echo "************* BUILD INITIALZATION ***********************"
|
||||||
if [[ $VERBOSE ]]; then $@; fi
|
if ! { [ "$VERBOSE" = "init" ] || [ "$VERBOSE" = "all" ]; }; then unset VERBOSE; fi
|
||||||
}
|
|
||||||
quiet echo -e "\n ************************************************* \n"
|
|
||||||
quiet echo "****** Initializing Image with build source ******"
|
|
||||||
cd init
|
|
||||||
pwd; quiet ls -la
|
|
||||||
export BUILDING=true
|
export BUILDING=true
|
||||||
export BUILD_DIR=$PWD
|
export BUILD_DIR=/build
|
||||||
export SHELL=/bin/bash
|
echo Distro is $LINUX_DISTRO
|
||||||
export BIN_DIR=/opt/bin
|
source /opt/lib/verbose.lib
|
||||||
mkdir -p $BIN_DIR
|
|
||||||
echo "export BIN_DIR=${BIN_DIR}" >> /tmp/profile
|
|
||||||
echo 'export PATH=$BIN_DIR:$PATH' >> /tmp/profile
|
|
||||||
|
|
||||||
echo " ##### creating entrypoint script ###"
|
echo sourcing core-run.env
|
||||||
cat << EOE >$BIN_DIR/entrypoint
|
quiet cat /opt/core_run.env
|
||||||
.INCLUDE ./init/entrypoint.tpl
|
source /opt/core_run.env
|
||||||
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 ###"
|
echo copying source init/opt directory to image /opt directory
|
||||||
cat << "EOS" >$BIN_DIR/start
|
quiet ls -la opt/
|
||||||
.INCLUDE ./init/start.sh
|
/bin/cp -R -f -p opt/. /opt
|
||||||
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 ###"
|
[[ -f ./build.env ]] && source ./build.env && echo loaded build.env at /init/build.env in source
|
||||||
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
|
if [[ -f ./init.sh ]]; then
|
||||||
echo "############## Running Script init.sh of build source #################"
|
echo "### Running Script init.sh of $BUILD_NAME build source with ${SHELL:-/bin/bash} ####"
|
||||||
quiet echo "----- build environment ------"
|
quiet echo "----- build environment ------"
|
||||||
quiet env
|
quiet env
|
||||||
quiet echo "----- env ------"
|
quiet echo "----- env ------"
|
||||||
|
@ -65,15 +30,10 @@ if [[ -f ./init.sh ]]; then
|
||||||
quiet cat ./init.sh
|
quiet cat ./init.sh
|
||||||
quiet echo "-------------------------------------------------------------"
|
quiet echo "-------------------------------------------------------------"
|
||||||
# init.sh must have shebang and be executable
|
# init.sh must have shebang and be executable
|
||||||
if ! $SHELL ./init.sh; then return 1; fi
|
if ! ${SHELL:-/bin/bash} ./init.sh; then return 1; fi
|
||||||
echo "############## Finished running init.sh build script #########################"
|
echo "############## Finished running init.sh build script #########################"
|
||||||
fi
|
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
|
# map host id now based on build environment
|
||||||
if [[ $VOLUME_DIRS ]]; then
|
if [[ $VOLUME_DIRS ]]; then
|
||||||
echo "*** creating and configuring volume directories ***"
|
echo "*** creating and configuring volume directories ***"
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
if [[ -d env/ ]]; then
|
|
||||||
export ENV_DIR=/opt/env
|
|
||||||
echo "############## Adding Environment Directroy $ENV_DIR #################"
|
|
||||||
echo "export ENV_DIR=${ENV_DIR}" >> /tmp/profile
|
|
||||||
quiet echo "copying env/ to $ENV_DIR"
|
|
||||||
/bin/cp -R -p env/. $ENV_DIR
|
|
||||||
quiet ls -la $ENV_DIR
|
|
||||||
fi
|
|
||||||
if [[ -d bin/ ]]; then
|
|
||||||
echo "############## Copying to Binary Directroy $BIN_DIR #################"
|
|
||||||
quiet echo "copying bin/ to $BIN_DIR"
|
|
||||||
/bin/cp -R -p bin/. $BIN_DIR
|
|
||||||
# chmod -R +x $BIN_DIR
|
|
||||||
quiet ls -la $BIN_DIR
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -d lib/ ]]; then
|
|
||||||
export LIB_DIR=/opt/lib
|
|
||||||
echo "############## Adding Library Directroy $LIB_DIR #################"
|
|
||||||
echo "export LIB_DIR=${LIB_DIR}" >> /tmp/profile
|
|
||||||
quiet echo "copying lib/ to $LIB_DIR"
|
|
||||||
/bin/cp -R -p lib/. $LIB_DIR
|
|
||||||
chmod -R +x $LIB_DIR
|
|
||||||
quiet ls -la $LIB_DIR
|
|
||||||
fi
|
|
|
@ -1,29 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
# to maintain variable $ in container script espcape with \$
|
|
||||||
# otherwise subtitution will happen during build
|
|
||||||
case "\$1" in
|
|
||||||
maphostid)
|
|
||||||
shift 1
|
|
||||||
/bin/bash -l -c '\$BIN_DIR/map-host-id \$@' \$0 "\$@"
|
|
||||||
;;
|
|
||||||
shell)
|
|
||||||
/bin/bash -c "cd \${INITIAL_DIR:-/opt}; exec bash -l"
|
|
||||||
;;
|
|
||||||
help)
|
|
||||||
.INCLUDE ./init/help.sh
|
|
||||||
;;
|
|
||||||
image)
|
|
||||||
.INCLUDE ./init/image-info.sh
|
|
||||||
;;
|
|
||||||
script)
|
|
||||||
shift 1
|
|
||||||
cat | /bin/bash -l
|
|
||||||
;;
|
|
||||||
${ENTRYPOINT_CMD:-start})
|
|
||||||
shift 1
|
|
||||||
/bin/bash -l -c '${ENTRYPOINT_CMD_PATH:-$BIN_DIR/start} \$@' \$0 "\$@"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
/bin/bash -l -c '"\$@"' \$0 "\$@"
|
|
||||||
;;
|
|
||||||
esac
|
|
|
@ -1,14 +0,0 @@
|
||||||
cat <<HELP
|
|
||||||
--------- ENTRYPOINT HELP ----------
|
|
||||||
commands are shell,maphostid,help,image and a custom command <start>
|
|
||||||
otherwise you can pass any shell command such as 'ls -la'
|
|
||||||
the current container custom command is > ${ENTRYPOINT_CMD:-start}
|
|
||||||
and the script for that command is in ${ENTRYPOINT_CMD_PATH:-$BIN_DIR/start}
|
|
||||||
-----
|
|
||||||
you can replace this start script with your own
|
|
||||||
your own script in $BIN_DIR/start in your build source directory
|
|
||||||
or set the \$ENTRYPOINT_CMD and \$ENTRYPOINT_CMD_PATH variables
|
|
||||||
It is possible to override the container entrypoint with your own
|
|
||||||
but is not recommmended as then a login shell will not be used
|
|
||||||
and critical environment variables will not be set
|
|
||||||
HELP
|
|
|
@ -1,5 +0,0 @@
|
||||||
if [[ -f /opt/image.info ]]; then
|
|
||||||
echo -e "\n--------- image info found at /opt/image.info----------"
|
|
||||||
cat /opt/image.info
|
|
||||||
echo -e "\n****************************"
|
|
||||||
fi
|
|
|
@ -1,9 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
if [[ $VOLUME_DIRS ]]; then
|
|
||||||
echo changing ownership of directories $VOLUME_DIRS
|
|
||||||
echo to ${HOST_MAP:-"host:host"}
|
|
||||||
declare usesudo
|
|
||||||
[[ ! $EUID -eq 0 ]] && usesudo=sudo
|
|
||||||
$usesudo chown -R ${HOST_MAP:-"host:host"} $VOLUME_DIRS
|
|
||||||
ls -la $VOLUME_DIRS
|
|
||||||
fi
|
|
|
@ -1,12 +0,0 @@
|
||||||
[[ -f $ENV_DIR/run.env ]] && echo 'source $ENV_DIR/run.env' >> /tmp/profile
|
|
||||||
|
|
||||||
while read line; do
|
|
||||||
if ! grep -q "$line" /etc/profile; then
|
|
||||||
quiet echo added $line to /etc/profile
|
|
||||||
echo $line >> /etc/profile
|
|
||||||
fi
|
|
||||||
done < /tmp/profile
|
|
||||||
# echo "echo /etc/profile has been sourced" >> /etc/profile
|
|
||||||
quiet echo "&&&&&&& last 10 of /etc/profile &&&&&"
|
|
||||||
quiet tail /etc/profile
|
|
||||||
quiet echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%"
|
|
|
@ -1,17 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
#***** CONTAINER DEFAULT CUSTOM SCRIPT ******************"
|
|
||||||
case "$1" in
|
|
||||||
sub1)
|
|
||||||
echo this would be a subcommand #1
|
|
||||||
echo with arguments $@
|
|
||||||
;;
|
|
||||||
sub2)
|
|
||||||
shift 1
|
|
||||||
echo this would be a subcommand #1
|
|
||||||
echo with arguments $@
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "running this command $*"
|
|
||||||
echo within login shell
|
|
||||||
/bin/bash -c '"$@"' $0 "$@"
|
|
||||||
esac
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
# PACKAGES
|
||||||
|
RUN --mount=type=bind,source=.src/packages,target=/build \
|
||||||
|
<<eot
|
||||||
|
.INCLUDE packages.tpl
|
||||||
|
eot
|
|
@ -1,20 +1,32 @@
|
||||||
|
#!/bin/bash
|
||||||
%
|
%
|
||||||
if [[ $REBUILD == "packages" ]]; then
|
if [[ $REBUILD == "packages" ]]; then
|
||||||
echo "## Busting Cache, Forcing Rebuild $(date)"
|
echo "## Busting Cache, Forcing Rebuild $(date)"
|
||||||
fi
|
fi
|
||||||
%
|
%
|
||||||
echo -e "\n ************************************************* \n"
|
echo "************* PACKAGE INSTALLATION ***********************"
|
||||||
echo "Building Image from Base: $BASE_IMAGE"
|
if ! { [ "$VERBOSE" = "packages" ] || [ "$VERBOSE" = "all" ]; }; then unset VERBOSE; fi
|
||||||
echo "Distro: $LINUX_DISTRO"
|
source /opt/lib/verbose.lib
|
||||||
echo " ---- running packages install script ---"
|
source /opt/core_run.env
|
||||||
if [[ $LINUX_DISTRO == "alpine" ]]; then
|
echo Distro is $LINUX_DISTRO
|
||||||
echo "-------------------------------"
|
echo package installer command for this build: "$INSTALL_PKGS"
|
||||||
echo "adding shadow bash and bash completion coreutils for alpine"
|
echo package update command for this build: "$UPDATE_PKGS"
|
||||||
echo "to be compatible with other distros"
|
if [[ -f ./packages.lst || -f ./packages.sh ]]; then
|
||||||
apk add --no-cache shadow bash bash-completion coreutils
|
if [[ -f ./packages.lst ]]; then
|
||||||
echo "-------------------------------"
|
echo "----- Installing Packages ---------------"
|
||||||
|
_pkgs=$(< ./packages.lst)
|
||||||
|
echo $_pkgs
|
||||||
|
echo ....
|
||||||
|
silence ${INSTALL_PKGS} ${_pkgs}
|
||||||
|
echo "done ----- Installing Packages ---------------"
|
||||||
fi
|
fi
|
||||||
cd packages
|
if [[ -f ./packages.sh ]]; then
|
||||||
/bin/sh ./packages.sh
|
echo "---- Running package installation script packages.sh -----"
|
||||||
cd ..
|
/bin/bash -l ./packages.sh
|
||||||
echo -e "\n********************************************************"
|
echo "done ---- Running package installation script packages.sh -----"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo neither packages.lst, nor packages.sh in source
|
||||||
|
echo nothing to install!
|
||||||
|
fi
|
||||||
|
echo "********************************"
|
136
build
136
build
|
@ -3,8 +3,9 @@
|
||||||
udbuild () {
|
udbuild () {
|
||||||
|
|
||||||
local targets=(dev arm64 amd64 publish multi default)
|
local targets=(dev arm64 amd64 publish multi default)
|
||||||
local log_dir; local no_prompt
|
local log_dir; local no_prompt; local packages
|
||||||
local append_efile
|
declare -A dimage; declare -A dinstall; declare -A dupdate
|
||||||
|
|
||||||
declare OPTION; declare OPTARG; declare OPTIND
|
declare OPTION; declare OPTARG; declare OPTIND
|
||||||
|
|
||||||
BDIR=$(dirname "$(realpath "$BASH_SOURCE")")
|
BDIR=$(dirname "$(realpath "$BASH_SOURCE")")
|
||||||
|
@ -54,81 +55,78 @@ case "$1" in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
exit_abnormal() { # Function: Exit with error.
|
|
||||||
usage
|
|
||||||
return ${1:-1}
|
|
||||||
}
|
|
||||||
|
|
||||||
[[ -z "$PS1" ]] || no_prompt=true
|
[[ -z "$PS1" ]] || no_prompt=true
|
||||||
overwrite=true
|
overwrite=true
|
||||||
|
|
||||||
while getopts 'fg:e:b:d:t:nc:r:u:lhs:a:voi:p' OPTION; do
|
while getopts 'a:b:c:d:e:f:g:hi:lnopr:s:t:u:v:' OPTION; do
|
||||||
# echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND}
|
# echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND}
|
||||||
case "$OPTION" in
|
case "$OPTION" in
|
||||||
i)
|
|
||||||
IMAGE_INFO=$OPTARG
|
|
||||||
;;
|
|
||||||
e)
|
|
||||||
BUILD_EFILE=$OPTARG
|
|
||||||
if ! source_env_file $BUILD_EFILE; then return 2; fi
|
|
||||||
;;
|
|
||||||
o)
|
|
||||||
unset overwrite
|
|
||||||
;;
|
|
||||||
v)
|
|
||||||
VERBOSE=true
|
|
||||||
;;
|
|
||||||
a)
|
a)
|
||||||
append_efile=$OPTARG
|
APPEND_BUILD_ENV=$OPTARG
|
||||||
;;
|
|
||||||
f)
|
|
||||||
REBUILD=init
|
|
||||||
;;
|
|
||||||
p)
|
|
||||||
echo "build script will be run WITHOUT user prompts (i.e. non-interactive)"
|
|
||||||
no_prompt=true
|
|
||||||
;;
|
;;
|
||||||
b)
|
b)
|
||||||
# CUSTOM BASE IMAGE
|
# CUSTOM BASE IMAGE
|
||||||
BASE_IMAGE=$OPTARG
|
BASE_IMAGE=$OPTARG
|
||||||
;;
|
;;
|
||||||
s)
|
c)
|
||||||
# building source from which to bind into build, default is src/ in current directory
|
TRY_CMD=$OPTARG
|
||||||
BUILD_SRC=$OPTARG
|
|
||||||
;;
|
;;
|
||||||
d)
|
d)
|
||||||
# LINUX_DISTRO=$OPTARG
|
# LINUX_DISTRO=$OPTARG
|
||||||
LINUX_DISTRO=$OPTARG
|
LINUX_DISTRO=$OPTARG
|
||||||
;;
|
;;
|
||||||
l)
|
e)
|
||||||
# append distro name to image name
|
BUILD_EFILE=$OPTARG
|
||||||
APPEND_DISTRO=true
|
if ! source_env_file $BUILD_EFILE; then return 2; fi
|
||||||
;;
|
;;
|
||||||
t)
|
f)
|
||||||
TARGET=$OPTARG
|
REBUILD=$OPTARG
|
||||||
;;
|
;;
|
||||||
g)
|
g)
|
||||||
TAG=$OPTARG
|
TAG=$OPTARG
|
||||||
;;
|
;;
|
||||||
u)
|
h)
|
||||||
RUSER=$OPTARG
|
usage
|
||||||
|
return 0
|
||||||
;;
|
;;
|
||||||
c)
|
i)
|
||||||
TRY_CMD=$OPTARG
|
IMAGE_INFO=$OPTARG
|
||||||
|
;;
|
||||||
|
|
||||||
|
o)
|
||||||
|
unset overwrite
|
||||||
|
;;
|
||||||
|
v)
|
||||||
|
VERBOSE=$OPTARG
|
||||||
|
;;
|
||||||
|
l)
|
||||||
|
# append distro name to image name
|
||||||
|
APPEND_DISTRO=true
|
||||||
;;
|
;;
|
||||||
n)
|
n)
|
||||||
nocache="--no-cache"
|
nocache="--no-cache"
|
||||||
;;
|
;;
|
||||||
|
p)
|
||||||
|
echo "build script will be run WITHOUT user prompts (i.e. non-interactive)"
|
||||||
|
no_prompt=true
|
||||||
|
;;
|
||||||
r)
|
r)
|
||||||
REPO=$OPTARG
|
REPO=$OPTARG
|
||||||
;;
|
;;
|
||||||
h)
|
s)
|
||||||
exit_abnormal 0
|
# building source from which to bind into build, default is src/ in current directory
|
||||||
return 0
|
BUILD_SRC=$OPTARG
|
||||||
|
;;
|
||||||
|
t)
|
||||||
|
TARGET=$OPTARG
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
RUSER=$OPTARG
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "unknown $0 option -$OPTARG"
|
echo "unknown $0 option -$OPTARG"
|
||||||
exit_abnormal 1
|
usage
|
||||||
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
@ -140,22 +138,22 @@ shift $((OPTIND - 1))
|
||||||
if ! get_build_src; then
|
if ! get_build_src; then
|
||||||
if [[ $no_prompt ]] ; then
|
if [[ $no_prompt ]] ; then
|
||||||
echo aborting the build...
|
echo aborting the build...
|
||||||
echo -e "\e[1;31mNOTE: use '_default_' to explicitly use build source in uci-docker-build repo\e[1;37m"
|
echo -e "\e[1;31mNOTE: use '_core_' to explicitly build with only the UCI core repo\e[1;37m"
|
||||||
return 2
|
return 2
|
||||||
else
|
else
|
||||||
echo "Do you want to use the uci-docker-build default build source"
|
echo "Do you want to build with only the UCI core"
|
||||||
echo "at $BDIR/src "
|
|
||||||
read -n 1 -p "instead? [y]=>" REPLY
|
read -n 1 -p "instead? [y]=>" REPLY
|
||||||
[[ $REPLY != "y" ]] && echo -e "\n" && return 2
|
[[ $REPLY != "y" ]] && echo -e "\n" && return 2
|
||||||
BUILD_SRC=$BDIR/src
|
BUILD_SRC="_core_"
|
||||||
echo -e "\n\e[1;31mNOTE: use '_default_' to explicitly use build source in uci-docker-build repo\e[1;37m"
|
echo -e "\n\e[1;31mNOTE: use '_core_' to explicitly build with only the UCI core\e[1;37m"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TARGET=${TARGET:-default}
|
TARGET=${TARGET:-default}
|
||||||
[[ ! "${targets[@]}" =~ $TARGET ]] && echo $TARGET is not a valid target && echo valid targets are: ${targets[@]} && exit 4
|
[[ ! "${targets[@]}" =~ $TARGET ]] && echo $TARGET is not a valid target && echo valid targets are: ${targets[@]} && exit 4
|
||||||
|
|
||||||
get_distro
|
LINUX_DISTRO=${LINUX_DISTRO:-alpine}
|
||||||
|
if ! get_base_image; then return $?; fi
|
||||||
|
|
||||||
IMAGE_NAME=$(make_image_name $@)
|
IMAGE_NAME=$(make_image_name $@)
|
||||||
|
|
||||||
|
@ -184,6 +182,7 @@ export LINUX_DISTRO
|
||||||
export BUILD_SRC
|
export BUILD_SRC
|
||||||
export ARCH
|
export ARCH
|
||||||
export VERBOSE
|
export VERBOSE
|
||||||
|
export REBUILD
|
||||||
|
|
||||||
build_info
|
build_info
|
||||||
|
|
||||||
|
@ -209,6 +208,8 @@ if [[ $TARGET == "publish" ]]; then
|
||||||
popd > /dev/null || return 4
|
popd > /dev/null || return 4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [[ ! $BUILD_SRC = "_core_" ]]; then
|
||||||
# copy or bind build source directory to temporary .src/ subdirectory in build repo
|
# copy or bind build source directory to temporary .src/ subdirectory in build repo
|
||||||
[[ -d $BDIR/.src ]] && rm -rf $BDIR/.src
|
[[ -d $BDIR/.src ]] && rm -rf $BDIR/.src
|
||||||
if [[ $(which rsync 2> /dev/null ) ]]; then
|
if [[ $(which rsync 2> /dev/null ) ]]; then
|
||||||
|
@ -217,22 +218,43 @@ else
|
||||||
echo no rsync copying with cp
|
echo no rsync copying with cp
|
||||||
/bin/cp -a ${BUILD_SRC:-src}/. $BDIR/.src > /dev/null 2>&1
|
/bin/cp -a ${BUILD_SRC:-src}/. $BDIR/.src > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -f $append_efile ]]; then
|
if [[ -f $APPEND_BUILD_ENV ]]; then
|
||||||
/bin/cp "$append_efile" "$BDIR/.src/init/env/_build.env_"
|
echo "------ Including custom build environment at $APPEND_BUILD_ENV -------"
|
||||||
echo 'source $ENV_DIR/_build.env_' >> $BDIR/.src/init/build.env
|
cat $APPEND_BUILD_ENV
|
||||||
|
echo -e "\n--------------------"
|
||||||
|
echo | tee -a "$BDIR/.src/init/build.env" > /dev/null
|
||||||
|
tee -a "$BDIR/.src/init/build.env" > /dev/null < "$APPEND_BUILD_ENV"
|
||||||
|
cat "$APPEND_BUILD_ENV" > "$BDIR/core/build.env"
|
||||||
|
# run in subshell to not affect $USER
|
||||||
|
/bin/bash <<"EOF"
|
||||||
|
unset USER
|
||||||
|
source "$BDIR/core/build.env"
|
||||||
|
[[ $USER_PW ]] && USER=${USER:-sysadmin}
|
||||||
|
if [[ $USER ]]; then
|
||||||
|
if [[ -f $PWD/$USER-permits ]]; then
|
||||||
|
echo sudo permits file: \'$USER-permits\' added to core build
|
||||||
|
/bin/cp -f $PWD/$USER-permits $BDIR/core
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pushd "$BDIR" > /dev/null || return 3
|
pushd "$BDIR" > /dev/null || return 3
|
||||||
|
|
||||||
######### RUNNING THE DOCKER BUILD COMMAND ######################
|
echo -e "\n\e[1;31m######### RUNNING THE DOCKER BUILD COMMAND ######################"
|
||||||
echo running build command: docker buildx --builder ${builder} bake ${nocache} ${TARGET}
|
echo running build command: docker buildx --builder ${builder} bake ${nocache} ${TARGET}
|
||||||
|
echo -e "#################################################################\e[1;37m"
|
||||||
docker buildx --builder ${builder} bake ${nocache} ${TARGET} 2>&1 | tee "$log_dir/${IMAGE_NAME//\//-}build.log"
|
docker buildx --builder ${builder} bake ${nocache} ${TARGET} 2>&1 | tee "$log_dir/${IMAGE_NAME//\//-}build.log"
|
||||||
[[ $? == 0 ]] && echo succcess building image $IMAGE_NAME || exit_abnormal 5
|
[[ $? == 0 ]] && echo succcess building image $IMAGE_NAME || exit_abnormal 5
|
||||||
popd > /dev/null || return 4
|
popd > /dev/null || return 4
|
||||||
|
|
||||||
rm -rf $BDIR/.src
|
# cleanup
|
||||||
|
echo cleaning up..
|
||||||
|
rm -rf $BDIR/.src $BDIR/core/build.env $BDIR/core/*-permits > /dev/null 2<&1
|
||||||
|
echo done cleaning
|
||||||
|
# try in container
|
||||||
if [[ ($TRY_CMD || $TARGET == "dev") ]]; then
|
if [[ ($TRY_CMD || $TARGET == "dev") ]]; then
|
||||||
echo trying newly built image in a container
|
echo trying newly built image in a container
|
||||||
echo name before try $IMAGE_NAME
|
echo name before try $IMAGE_NAME
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/bin/bash
|
||||||
|
echo "------------- CORE INSTALLATION ------------"
|
||||||
|
source /opt/core_run.env
|
||||||
|
if [[ -f ./build.env ]]; then
|
||||||
|
echo sourcing a custom core build enviornment
|
||||||
|
cat ./build.env
|
||||||
|
echo "--------"
|
||||||
|
source ./build.env
|
||||||
|
fi
|
||||||
|
source $LIB_DIR/verbose.lib
|
||||||
|
echo appending pkg commands to core_run.env
|
||||||
|
echo appending sourcing of $ENV_DIR/run.env if it exists
|
||||||
|
cat <<ENV >> /opt/core_run.env
|
||||||
|
|
||||||
|
export INSTALL_PKGS="$INSTALL_PKGS"
|
||||||
|
export UPDATE_PKGS="$UPDATE_PKGS"
|
||||||
|
[ -f "\$ENV_DIR/run.env" ] && [ -z "\$BUILDING" ] && source \$ENV_DIR/run.env
|
||||||
|
ENV
|
||||||
|
quiet cat /opt/core_run.env
|
||||||
|
mkdir -p /etc/profile.d
|
||||||
|
echo creating login sourcing file for core_run.env in /etc/profile.d
|
||||||
|
echo "source /opt/core_run.env" > /etc/profile.d/01-core-run-env.sh
|
||||||
|
quiet ls -la /etc/profile.d
|
||||||
|
|
||||||
|
echo "--------- creating user and group 'host' with ids 1000 -----"
|
||||||
|
echo "done --------- creating user and group 'host' with ids 1000 -----"
|
||||||
|
cat <<DOC >> /etc/login.defs
|
||||||
|
SYS_UID_MAX 1001"
|
||||||
|
SYS_GID_MAX 1001"
|
||||||
|
DOC
|
||||||
|
groupadd -g 1000 host
|
||||||
|
echo "SYS_UID_MAX 1001" >> /etc/login.defs
|
||||||
|
useradd -r -g host -u 1000 host
|
||||||
|
[[ $USER_PW ]] && export USER=${USER:-sysadmin}
|
||||||
|
[[ $USER ]] && /bin/bash user.sh
|
||||||
|
[[ $UCI_SHELL ]] && /bin/bash uci-shell.sh
|
||||||
|
$BIN_DIR/map-host-id /opt
|
||||||
|
ls -la /opt
|
||||||
|
echo "done ------------- CORE INSTALLATION ------------"
|
|
@ -0,0 +1,41 @@
|
||||||
|
#!/bin/bash
|
||||||
|
source /opt/core_run.env
|
||||||
|
case "$1" in
|
||||||
|
maphostid)
|
||||||
|
shift 1
|
||||||
|
/bin/bash -l -c '$BIN_DIR/map-host-id $@' $0 "$@"
|
||||||
|
;;
|
||||||
|
image)
|
||||||
|
shift 1
|
||||||
|
/bin/bash -l -c '$BIN_DIR/image-info $@' $0 "$@"
|
||||||
|
;;
|
||||||
|
shell)
|
||||||
|
shift 1
|
||||||
|
_shell_=/bin/bash
|
||||||
|
[[ $1 ]] && _shell_="/bin/su $1"
|
||||||
|
$_shell_ -c "cd ${INITIAL_DIR:-/opt}; exec bash -l"
|
||||||
|
;;
|
||||||
|
help)
|
||||||
|
$BIN_DIR/entrypoint-help
|
||||||
|
;;
|
||||||
|
script)
|
||||||
|
shift 1
|
||||||
|
cat | /bin/bash -l
|
||||||
|
;;
|
||||||
|
${ENTRYPOINT_CMD:-start})
|
||||||
|
shift 1
|
||||||
|
/bin/bash -l -c '${ENTRYPOINT_CMD_PATH:-$BIN_DIR/start} $@' $0 "$@"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo command passed to container "$*"
|
||||||
|
if [ -n "$*" ]; then
|
||||||
|
if ! /bin/bash -l -c '$@' $0 "$@" ; then
|
||||||
|
$BIN_DIR/entrypoint-help
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo no command was passed to entrypoint
|
||||||
|
echo
|
||||||
|
$BIN_DIR/entrypoint-help
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/bin/bash
|
||||||
|
cat <<HELP
|
||||||
|
--------- ENTRYPOINT HELP ----------
|
||||||
|
entrypoint commands are shell, maphostid, help, image, script and a custom command (start, by default)
|
||||||
|
otherwise you can pass any shell command such as 'ls -la'
|
||||||
|
|
||||||
|
----- Custom Command (start) -------------
|
||||||
|
|
||||||
|
the current container custom command is > ${ENTRYPOINT_CMD:-start}
|
||||||
|
and the script/binary that command runs is ${ENTRYPOINT_CMD_PATH:-$BIN_DIR/start}
|
||||||
|
|
||||||
|
you can replace this start script with your own or any binary
|
||||||
|
placed at init/opt/bin/start in your build source directory
|
||||||
|
or set the \$ENTRYPOINT_CMD_PATH and (optionally) the \$ENTRYPOINT_CMD variables
|
||||||
|
|
||||||
|
---------- script ---------------
|
||||||
|
you can pipe a script from the host to container with this command
|
||||||
|
|
||||||
|
script < test.sh
|
||||||
|
|
||||||
|
if you use a heredoc you can delay variable substition
|
||||||
|
until the command is run in container.
|
||||||
|
|
||||||
|
script << "SCRIPT"
|
||||||
|
echo $BIN_DIR
|
||||||
|
SCRIPT
|
||||||
|
|
||||||
|
----- Overwrite Entrypoint
|
||||||
|
It is also possible to completely override the container entrypoint with your own
|
||||||
|
$BIN_DIR/entrypoint script but is not recommmended as then a bash login shell is
|
||||||
|
assured (unless you see to it) and thus critical runtime environment variables
|
||||||
|
will not be set
|
||||||
|
HELP
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
if [[ -f /opt/image.info ]]; then
|
||||||
|
echo -e "\n--------- image info found at /opt/image.info----------"
|
||||||
|
cat /opt/image.info
|
||||||
|
echo -e "\n****************************"
|
||||||
|
else
|
||||||
|
echo no image information found at /opt/image.info
|
||||||
|
echo "you can place one at 'init/image.info' in your source (src) directory"
|
||||||
|
echo "to be included in the image"
|
||||||
|
fi
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/bash
|
||||||
|
vdirs=${1:-$VOLUME_DIRS}
|
||||||
|
if [[ $vdirs ]]; then
|
||||||
|
echo changing ownership of directories $vdirs
|
||||||
|
vgroup=host
|
||||||
|
[[ ! $USER = "root" && $USER ]]; vgroup=$USER
|
||||||
|
vmap=${HOST_MAP:-host:$vgroup}
|
||||||
|
echo to $vmap
|
||||||
|
declare usesudo
|
||||||
|
[[ ! $USER = "root" ]] && usesudo=sudo
|
||||||
|
$usesudo chown -R $vmap $vdirs
|
||||||
|
fi
|
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#***** CONTAINER DEFAULT CUSTOM SCRIPT ******************"
|
||||||
|
echo "------ EXAMPLE 'start' command script -----"
|
||||||
|
echo replace with your /opt/bin/start or use
|
||||||
|
echo "export ENTRYPOINT_CMD=mycmd"
|
||||||
|
echo "export ENTRYPOINT_CMD_PATH=\$BIN_DIR/mycmd"
|
||||||
|
echo and supply a init/opt/mycmd in your source
|
||||||
|
echo "---------------"
|
||||||
|
case "$1" in
|
||||||
|
sub1)
|
||||||
|
echo "this is the 'start' subcommand 'sub2' "
|
||||||
|
echo with arguments $@
|
||||||
|
;;
|
||||||
|
sub2)
|
||||||
|
shift 1
|
||||||
|
echo "this is the 'start' subcommand 'sub2' "
|
||||||
|
echo with arguments $@
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo
|
||||||
|
echo "running this command $*"
|
||||||
|
echo "via the 'start' command"
|
||||||
|
echo within a login shell
|
||||||
|
/bin/bash -l -c '"$@"' $0 "$@"
|
||||||
|
esac
|
||||||
|
echo "done------ EXAMPLE 'start' command script -----"
|
|
@ -0,0 +1,5 @@
|
||||||
|
export ENV_DIR=/opt/env
|
||||||
|
export BIN_DIR=/opt/bin
|
||||||
|
export LIB_DIR=/opt/lib
|
||||||
|
export SHELL=/bin/bash
|
||||||
|
PATH=$BIN_DIR:$PATH
|
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/sh
|
||||||
|
load_csv () (
|
||||||
|
# add newline, remove comments, remove empty lines, remove extra whitespace around ,
|
||||||
|
csv=${1:-/opt/lib/distros.csv}
|
||||||
|
if [ -f $csv ]; then
|
||||||
|
sed -e '$a\' "$csv" | \
|
||||||
|
sed -e '/\s*#.*$/d' | \
|
||||||
|
sed -e '/^\s*$/d' | \
|
||||||
|
sed 's/\s*,\s*/,/g'
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
|
||||||
|
validate_distro () (
|
||||||
|
release=${1:-/etc/os-release}
|
||||||
|
distros=$(echo $(echo "$(load_csv)" | grep -Eo "^[^,]+") | sed "s/\s/|/g")
|
||||||
|
#echo valids:$distros
|
||||||
|
distro=$(cat $release | tr [:upper:] [:lower:] | grep -Eio -m 1 $distros)
|
||||||
|
# echo debug: c $distro p $LINUX_DISTRO
|
||||||
|
if [ "$LINUX_DISTRO" = "$distro" ]; then
|
||||||
|
echo $distro
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
|
||||||
|
set_distro () {
|
||||||
|
|
||||||
|
_distro="$(echo "$(load_csv)" | grep $LINUX_DISTRO)"
|
||||||
|
INSTALL_PKGS=$(echo $_distro | cut -d',' -f3)
|
||||||
|
UPDATE_PKGS=$(echo $_distro | cut -d',' -f4)
|
||||||
|
export INSTALL_PKGS
|
||||||
|
export UPDATE_PKGS
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
# valid distros list
|
||||||
|
# the distro must be the name used in /etc/os-release
|
||||||
|
# <distro>,<core image name>,<install command>,<update command>
|
||||||
|
alpine,alpine, apk add --no-cache, apk update
|
||||||
|
debian,debian, apt-get install -y, apt-get update
|
||||||
|
arch, archlinux,pacman -S --noconfirm --needed,pacman -Syu
|
||||||
|
ubuntu, ubuntu, apt-get install -y, apt-get update
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
# valid distros list
|
||||||
|
# the distro must be the name used in /etc/os-release
|
||||||
|
# <distro>,<core image name>,<install command>,<update command>
|
||||||
|
alpine,alpine, apk add --no-cache, apk update
|
||||||
|
debian,debian, apt-get install -y, apt-get update
|
||||||
|
arch, archlinux,pacman -S --noconfirm --needed,pacman -Syu
|
||||||
|
ubuntu, ubuntu, apt-get install -y, apt-get update
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
quiet () {
|
||||||
|
if [ -n "$VERBOSE" ]; then $@; fi
|
||||||
|
}
|
||||||
|
silence() {
|
||||||
|
if [ -n "$VERBOSE" ] ; then
|
||||||
|
"$@"
|
||||||
|
else
|
||||||
|
"$@" > /dev/null
|
||||||
|
fi
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo "------------- CORE PACKAGE INSTALLATION ------------"
|
||||||
|
echo UPDATING PACKAGE REGISTRY....
|
||||||
|
. /opt/lib/verbose.lib
|
||||||
|
silence $UPDATE_PKGS
|
||||||
|
echo .... DONE!
|
||||||
|
if [ -f ./packages/$LINUX_DISTRO ]; then
|
||||||
|
echo INSTALLING $LINUX_DISTRO DISTRO SPECIFIC PACKAGES
|
||||||
|
_pkgs=$(cat ./packages/$LINUX_DISTRO)
|
||||||
|
echo $_pkgs
|
||||||
|
echo ....
|
||||||
|
silence $INSTALL_PKGS $_pkgs
|
||||||
|
echo "DONE INSTALLING $LINUX_DISTRO SPECIFIC PACKAGES"
|
||||||
|
fi
|
||||||
|
echo INSTALLING COMMON PACKAGES FOR ANY DISTRO
|
||||||
|
quiet this is a test of quiet
|
||||||
|
_pkgs=$(cat ./packages/common)
|
||||||
|
echo $_pkgs
|
||||||
|
echo ....
|
||||||
|
silence $INSTALL_PKGS $_pkgs
|
||||||
|
echo "DONE INSTALLING COMMON PACKAGES"
|
||||||
|
echo "done ------------- CORE PACKAGE INSTALLATION ------------"
|
|
@ -0,0 +1 @@
|
||||||
|
shadow
|
|
@ -1,9 +1,9 @@
|
||||||
|
bash
|
||||||
|
bash-completion
|
||||||
|
coreutils
|
||||||
wget
|
wget
|
||||||
curl
|
curl
|
||||||
git
|
git
|
||||||
rsync
|
|
||||||
sudo
|
|
||||||
nano
|
nano
|
||||||
coreutils
|
sudo
|
||||||
bash
|
|
||||||
bash-completion
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/bash
|
||||||
|
echo -e "\n------------ ADD UCI-SHELL ---------------"
|
||||||
|
mkdir -p /shell
|
||||||
|
_url=https://git.kebler.net/bash/shell-base.git
|
||||||
|
git clone $_url /shell
|
||||||
|
source /shell/install/install.sh
|
||||||
|
[[ $USER ]] && mkdir -p /home/$USER/shell
|
||||||
|
uci_bash_shell_install $USER
|
||||||
|
|
||||||
|
if [[ $USER ]]; then
|
||||||
|
chown -R $USER:$USER /shell
|
||||||
|
chmod -R g+rw /shell
|
||||||
|
setfacl -d --set u::rwx,g::rwx,o::- /shell
|
||||||
|
chown -R :host /home/$USER/shell
|
||||||
|
chmod -R g+rw /home/$USER/shell
|
||||||
|
setfacl -d --set u::rwx,g::rwx,o::- /home/$USER/shell
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "----------- uci shell install complete ------"
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/bin/bash
|
||||||
|
USER=${1:-$USER}
|
||||||
|
USER_PW=${2-$USER_PW}
|
||||||
|
if [[ $USER ]]; then
|
||||||
|
echo "------- Adding USER: $USER ------"
|
||||||
|
source $LIB_DIR/verbose.lib
|
||||||
|
echo loading acl package
|
||||||
|
silence $INSTALL_PKGS acl
|
||||||
|
echo "------- Adding User: $USER ------"
|
||||||
|
groupadd -g 1001 $USER
|
||||||
|
useradd -rm -s /bin/bash -G host,$([[ $(getent group sudo) ]] && echo sudo || echo wheel) -g $USER -u 1001 $USER
|
||||||
|
echo $USER groups: $(groups $USER)
|
||||||
|
chpasswd <<< "sysadmin:${USER_PW:-$USER}"
|
||||||
|
# SUDOERS Setup
|
||||||
|
cat <<SUDO >> /etc/sudoers.d/01-sudo-wheel
|
||||||
|
Defaults lecture = never
|
||||||
|
%wheel ALL=(ALL:ALL) ALL
|
||||||
|
%sudo ALL=(ALL:ALL) ALL
|
||||||
|
SUDO
|
||||||
|
chmod 440 /etc/sudoers.d/01-sudo-wheel
|
||||||
|
cat <<USER >> /etc/sudoers.d/02-$USER
|
||||||
|
$USER ALL = NOPASSWD:/bin/chown
|
||||||
|
$USER ALL = NOPASSWD:/bin/chmod
|
||||||
|
USER
|
||||||
|
chmod 440 /etc/sudoers.d/02-$USER
|
||||||
|
if [[ -f $USER-permits ]]; then
|
||||||
|
echo "--- $USER-permits file supplied copying to /etc/sudoers.d ---"
|
||||||
|
cat $USER-permits
|
||||||
|
cat $USER-permits >> /etc/sudoers.d/02-$USER
|
||||||
|
fi
|
||||||
|
|
||||||
|
chmod g+rw /opt
|
||||||
|
setfacl -d --set u::rwx,g::rwx,o::- /opt
|
||||||
|
echo "done------- Adding USER: $USER ------"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
./core/opt/lib/distros.csv
|
|
|
@ -11,10 +11,10 @@ variable "IMAGE_NAME" {
|
||||||
variable "BASE_IMAGE" {
|
variable "BASE_IMAGE" {
|
||||||
// default = "alpine"
|
// default = "alpine"
|
||||||
}
|
}
|
||||||
variable "SYSADMIN_PW" {
|
variable "VERBOSE" {
|
||||||
default = ""
|
default = ""
|
||||||
}
|
}
|
||||||
variable "VERBOSE" {
|
variable "REBUILD" {
|
||||||
default = ""
|
default = ""
|
||||||
}
|
}
|
||||||
variable "ARCH" {
|
variable "ARCH" {
|
||||||
|
@ -48,7 +48,7 @@ target "amd64" {
|
||||||
BASE_IMAGE = "${BASE_IMAGE}"
|
BASE_IMAGE = "${BASE_IMAGE}"
|
||||||
TAG = "${TAG}"
|
TAG = "${TAG}"
|
||||||
VERBOSE = "${VERBOSE}"
|
VERBOSE = "${VERBOSE}"
|
||||||
SYSADMIN_PW = "${SYSADMIN_PW}"
|
REBUILD = "${REBUILD}"
|
||||||
}
|
}
|
||||||
tags = tag("amd64")
|
tags = tag("amd64")
|
||||||
platforms = ["linux/amd64"]
|
platforms = ["linux/amd64"]
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
export USER_PW=ucommandit
|
||||||
|
export UCI_SHELL=true
|
|
@ -0,0 +1,44 @@
|
||||||
|
|
||||||
|
# UCI Build Script environment file
|
||||||
|
# for easy use copy this file to .env and it will be sourced
|
||||||
|
# using a filename of just .env in pwd will load it by default
|
||||||
|
# otherwise invoke `udbuild -e example.env`
|
||||||
|
|
||||||
|
# Default base images are set in distros.csv
|
||||||
|
# if BASE_IMAGE is unset then the default for LINUX_DISTRO will
|
||||||
|
# be used and the default LINUX_DISTRO is alpine
|
||||||
|
# BASE_IMAGE="dockerhubuser/mybase"
|
||||||
|
# a set LINUX_DISTRO is over written by distro of BASE_IMAGE if set
|
||||||
|
# LINUX_DISTRO=alpine
|
||||||
|
|
||||||
|
# tag of created image will be 'latest' by default
|
||||||
|
# TAG=1.0.0
|
||||||
|
|
||||||
|
# RUSER will be prepended to image name with /, and is used mostly for publishing
|
||||||
|
RUSER=example
|
||||||
|
|
||||||
|
# remote repository for pushing, default is hub.docker.com
|
||||||
|
# REPO=my.priviate.repo.net
|
||||||
|
|
||||||
|
# default target is "default" , other targets, dev, publish, amd64, arm64
|
||||||
|
# TARGET=publish
|
||||||
|
|
||||||
|
# if unset BUILD_SRC will be determined by a search
|
||||||
|
# Search looks for looks for /init and /packages
|
||||||
|
# in $PWD,$PWD/<src>/,../$PWD,../$PWD/<src>
|
||||||
|
# otherwise you can set an absolute or relative path, or use _core_'
|
||||||
|
# If BUILD_SRC can not be determined or is unset
|
||||||
|
# you will be given the option to build just with the uci core
|
||||||
|
# BUILD_SRC=../src
|
||||||
|
|
||||||
|
# For a custom container build environment
|
||||||
|
# create an environment file and then set
|
||||||
|
# this file will sourced by the "core" RUN of the build
|
||||||
|
# and also the "init" RUN
|
||||||
|
# Otherwise you can "hard code" build container envirnomnet
|
||||||
|
# at /init/build.env which is only sourced by the "init" RUN
|
||||||
|
APPEND_BUILD_ENV=./build.env
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
This is an example image built from the
|
||||||
|
source found in example/ directory of
|
||||||
|
the uci-docker-build repo
|
|
@ -0,0 +1,3 @@
|
||||||
|
echo invoking a shell in container image for a non root user ${1:-sysadmin}
|
||||||
|
echo assuming one was added in build
|
||||||
|
udbuild try -e example.env shell $1
|
|
@ -0,0 +1,8 @@
|
||||||
|
# anything in here will be sourced ONLY during build
|
||||||
|
# allows easy custom environment variables
|
||||||
|
# /opt/core_run.env is always sourced before this file
|
||||||
|
# /opt/env/run.env is NOT sourced by default during build but you
|
||||||
|
# can explicity add it there
|
||||||
|
# [ -f "$ENV_DIR/run.env" ] && $ENV_DIR/run.env
|
||||||
|
export SOMEBUILDONLYVALUE="yes!"
|
||||||
|
export VOLUME_DIRS="/opt"
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/bash
|
||||||
|
echo custom initialization script
|
||||||
|
echo "----- CONTAINER RUN ENVIRONMENT ---"
|
||||||
|
cat $ENV_DIR/run.env
|
||||||
|
echo -e "-n--------------------"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
echo "this is my custom entrypoint command script, mycmd"
|
||||||
|
echo "arguments that were passed: $*"
|
|
@ -0,0 +1,7 @@
|
||||||
|
# set these to customize the "custom" entrypoint command
|
||||||
|
export ENTRYPOINT_CMD=mycmd
|
||||||
|
export ENTRYPOINT_CMD_PATH=$BIN_DIR/mycmd
|
||||||
|
# here you could put specific exports
|
||||||
|
# or source another file, whatever. this is sourced at shell login
|
||||||
|
export INITIAL_DIR=/opt/bin
|
||||||
|
export NONSENSE="this is from the run.env file"
|
|
@ -0,0 +1,7 @@
|
||||||
|
# set these to customize the "custom" entrypoint command
|
||||||
|
export ENTRYPOINT_CMD=mycmd
|
||||||
|
export ENTRYPOINT_CMD_PATH=$BIN_DIR/mycmd
|
||||||
|
# here you could put specific exports
|
||||||
|
# or source another file, whatever. this is sourced at shell login
|
||||||
|
export INITIAL_DIR=/opt/bin
|
||||||
|
export NONSENSE="this is from the run.env file"
|
|
@ -1,5 +1,5 @@
|
||||||
If you create/edit a image.info file in your source
|
If you create/edit a image.info file in your source
|
||||||
at the init/ subfolder then it will be including in the build
|
at the init/opt subfolder then it will be including in the build
|
||||||
as /opt/image.info.
|
as /opt/image.info.
|
||||||
So this text comes from the default image.info file
|
So this text comes from the default image.info file
|
||||||
in the src/init folder of the default build source
|
in the src/init folder of the default build source
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/bash
|
||||||
|
echo env
|
||||||
|
_url=https://raw.githubusercontent.com/KittyKatt/screenFetch/master/screenfetch-dev
|
||||||
|
wget --quiet -O $BIN_DIR/os-info $_url > /dev/null
|
||||||
|
if [[ -f $BIN_DIR/os-info ]]; then
|
||||||
|
chmod +x $BIN_DIR/os-info
|
||||||
|
else
|
||||||
|
echo Failed to download
|
||||||
|
echo $_url
|
||||||
|
echo info screen not available
|
||||||
|
fi
|
|
@ -0,0 +1,2 @@
|
||||||
|
rsync
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/bash
|
||||||
|
echo custom package installer script
|
||||||
|
echo "--------HERE IS THE ENVIRONMENT-------"
|
||||||
|
env
|
||||||
|
echo "--------------------"
|
||||||
|
echo "installing a fancy OS info script"
|
||||||
|
/bin/bash ./install-os-info.sh
|
||||||
|
echo now running the os-info script, a command in PATH at $BIN_DIR/os-info
|
||||||
|
os-info
|
|
@ -0,0 +1,10 @@
|
||||||
|
# allow admins to change group and user ids
|
||||||
|
# sysadmin ALL = NOPASSWD : ALL
|
||||||
|
# or specify
|
||||||
|
sysadmin ALL = NOPASSWD:/bin/cp
|
||||||
|
# sysadmin ALL = NOPASSWD:/sbin/groupmod
|
||||||
|
# sysadmin ALL = NOPASSWD:/sbin/usermod
|
||||||
|
# sysadmin ALL = NOPASSWD:/sbin/adduser
|
||||||
|
# sysadmin ALL = NOPASSWD:/sbin/addgroup
|
||||||
|
# sysadmin ALL = NOPASSWD:/sbin/useradd
|
||||||
|
# sysadmin ALL = NOPASSWD:/sbin/groudadd
|
|
@ -1,2 +1,2 @@
|
||||||
# invokes build with the example environment file
|
# invokes build with the example environment file
|
||||||
udbuild try -e example.env ${@:-shell}
|
udbuild try -e example.env $@
|
|
@ -0,0 +1,3 @@
|
||||||
|
# invokes build with the example environment file
|
||||||
|
echo mounting /opt from container to ./mnt/opt in PWD
|
||||||
|
udbuild try -e example.env -m opt ${@:-shell} $@
|
|
@ -1,29 +0,0 @@
|
||||||
|
|
||||||
# for easy use copy this file to .env and it will be sourced
|
|
||||||
# otherwise invoke `udbuild -e example.env`
|
|
||||||
# using a filename of just .env will load it by default
|
|
||||||
# LINUX_DISTRO ignored if BASE_IMAGE is set
|
|
||||||
# LINUX_DISTRO=alpine
|
|
||||||
# BASE_IMAGE="dockerhubuser/mybase"
|
|
||||||
# tag is 'latest' by default
|
|
||||||
# TAG=1.0.0
|
|
||||||
# will be prepended to image name with /, used mostly for publishing
|
|
||||||
RUSER=testing
|
|
||||||
# default is hub.docker.com
|
|
||||||
# REPO=my.priviate.repo.net
|
|
||||||
# if using base source this will set the pw for the sysadmin user in the image
|
|
||||||
SYSADMIN_PW=ucommandit
|
|
||||||
# default target is "default"
|
|
||||||
# TARGET=publish
|
|
||||||
BUILD_SRC=../src
|
|
||||||
# looks for /init and /packages in present directory by default
|
|
||||||
# also looks in src/ subdirectory
|
|
||||||
# relate paths work
|
|
||||||
# use '_base_' to force using the uci-docker-build build source
|
|
||||||
# BUILD_SRC=._base_
|
|
||||||
# in the image where the build scripts are put /build by default
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -113,26 +113,57 @@ source_env_file () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
docker_image_distro() {
|
load_csv () {
|
||||||
local temp=/tmp/os-release.tmp
|
# add newline, remove comments, remove empty lines, remove extra whitespace around ,
|
||||||
docker create --name dummy $1 > /dev/null
|
if [[ -f $1 ]]; then
|
||||||
docker cp -L dummy:/etc/os-release $temp
|
sed -e '$a\' "$1" | \
|
||||||
docker rm -f dummy > /dev/null
|
sed -e '/\s*#.*$/d' | \
|
||||||
echo $(cat $temp | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq)
|
sed -e '/^\s*$/d' | \
|
||||||
rm $temp
|
sed 's/\s*,\s*/,/g'
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_distro() {
|
get_default_distro_image () {
|
||||||
|
local distro
|
||||||
|
distro="$(echo "$(load_csv $BDIR/distros.csv)" | grep $LINUX_DISTRO)"
|
||||||
|
echo $distro | cut -d',' -f2
|
||||||
|
}
|
||||||
|
|
||||||
LINUX_DISTRO=${LINUX_DISTRO:-alpine}
|
validate_image_distro() {
|
||||||
|
local temp=/tmp/os-release.tmp
|
||||||
|
local distro; local distros
|
||||||
|
if docker create --name dummy $1 > /dev/null; then
|
||||||
|
if docker cp -L dummy:/etc/os-release $temp > /dev/null; then
|
||||||
|
docker rm -f dummy > /dev/null
|
||||||
|
distros=$(echo $(echo "$(load_csv $BDIR/distros.csv)" | grep -Eo "^[^,]+") | sed "s/\s/|/g")
|
||||||
|
distro=$(cat $temp | tr [:upper:] [:lower:] | grep -Eio -m 1 $distros)
|
||||||
|
rm $temp
|
||||||
|
[[ ! $distro ]] && echo "image $1 is not a valid distro ($distros)" && return 1
|
||||||
|
[[ ! "$distro" == "${2:-$LINUX_DISTRO}" ]] && echo "image ${1}'s distro ($distro) is NOT build distro (${2:-$LINUX_DISTRO})" && return 1
|
||||||
|
quiet echo "base image $1 distro ($distro) has been validated"
|
||||||
|
else
|
||||||
|
echo "unable to retreive /etc/os-release from image $1, unable to determine image distro"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "there is no image $1 locally or at docker hub, can't set the base image"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
get_base_image() {
|
||||||
|
|
||||||
|
[[ ! $BASE_IMAGE ]] && BASE_IMAGE=$(get_default_distro_image)
|
||||||
if [[ $BASE_IMAGE ]]; then
|
if [[ $BASE_IMAGE ]]; then
|
||||||
quiet echo determining DISTRO of base image: $BASE_IMAGE
|
quiet echo determining DISTRO of base image: $BASE_IMAGE
|
||||||
LINUX_DISTRO=$(docker_image_distro $BASE_IMAGE)
|
if ! validate_image_distro $BASE_IMAGE; then
|
||||||
[[ ! $LINUX_DISTRO ]] && quiet echo "unable to get base image OS for: $BASE_IMAGE, aborting build" && return 5
|
echo "unable to get or use base image: $BASE_IMAGE, aborting build" && return 5
|
||||||
|
fi
|
||||||
quiet echo $BASE_IMAGE is built from distro $LINUX_DISTRO
|
quiet echo $BASE_IMAGE is built from distro $LINUX_DISTRO
|
||||||
else
|
else
|
||||||
BASE_IMAGE=$LINUX_DISTRO
|
echo unable to determine a base image, aborting build
|
||||||
|
return 6
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,11 +203,13 @@ get_build_src () {
|
||||||
# processing the build source directory
|
# processing the build source directory
|
||||||
local src; local spath; local spaths
|
local src; local spath; local spaths
|
||||||
check_dir () {
|
check_dir () {
|
||||||
[[ ( -d $1/packages && -d $1/init ) ]] || return 1
|
[[ -f $1/init/init.sh ]] || return 1
|
||||||
|
[[ ( -f $1/packages/packages.lst || -f $1/packages/packages.sh ) ]] && _packages_=true
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
src=${1:-$BUILD_SRC}
|
src=${1:-$BUILD_SRC}
|
||||||
[[ $src == "_default_" ]] && src=${BDIR}/src
|
[[ $src == "_core_" ]] && return 0
|
||||||
src=${src:-src}
|
src=${src:-src}
|
||||||
unset BUILD_SRC
|
unset BUILD_SRC
|
||||||
|
|
||||||
|
@ -185,10 +218,10 @@ if check_dir $src; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo build source path \'$src\' not initially found
|
echo build source path \'$src\' not initially found, echo looking
|
||||||
echo looking in parent directories for a valid build source directory
|
echo in \$PWD,\$PWD/src/,../\$PWD/src for valid build source
|
||||||
echo to avoid this search use BUILD_SRC= in an environment file
|
echo to avoid this search use BUILD_SRC= in an environment file
|
||||||
spaths="$PWD $(dirname $PWD)/$src $(dirname $PWD)"
|
spaths="$PWD $PWD/src $(dirname $PWD)/$src $(dirname $PWD)"
|
||||||
for spath in $spaths; do
|
for spath in $spaths; do
|
||||||
echo checking for source in: $spath
|
echo checking for source in: $spath
|
||||||
if check_dir $spath; then
|
if check_dir $spath; then
|
||||||
|
@ -205,8 +238,6 @@ done
|
||||||
|
|
||||||
build_info () {
|
build_info () {
|
||||||
|
|
||||||
|
|
||||||
echo "Build Command: docker buildx --builder ${builder} bake ${nocache} ${TARGET}"
|
|
||||||
if [[ $VERBOSE ]]; then
|
if [[ $VERBOSE ]]; then
|
||||||
echo -e "\n!!!!!!!!!!!!!!!!EXTRA BUILD INFO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
echo -e "\n!!!!!!!!!!!!!!!!EXTRA BUILD INFO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
pushd "$BDIR" > /dev/null || return 3
|
pushd "$BDIR" > /dev/null || return 3
|
||||||
|
@ -222,11 +253,21 @@ fi
|
||||||
|
|
||||||
echo -e "\e[1;37m**************BUILD PARAMETERS *******************************"
|
echo -e "\e[1;37m**************BUILD PARAMETERS *******************************"
|
||||||
echo "Architecture of this machine doing the building: $ARCH"
|
echo "Architecture of this machine doing the building: $ARCH"
|
||||||
|
if [[ $BUILD_SRC="_core_" ]] ;then
|
||||||
|
echo Building ONLY the UCI core
|
||||||
|
else
|
||||||
echo "Using scripts source directory at $BUILD_SRC"
|
echo "Using scripts source directory at $BUILD_SRC"
|
||||||
echo "Building with base image: $BASE_IMAGE"
|
fi
|
||||||
|
echo "Building with base image: $BASE_IMAGE"$([[ "${BASE_IMAGE}" == *":"* ]] || echo :latest)
|
||||||
echo "Build logs can be found in directory $log_dir"
|
echo "Build logs can be found in directory $log_dir"
|
||||||
echo "Linux Distro of Image: $LINUX_DISTRO"
|
echo "Linux Distro of Image: $LINUX_DISTRO"
|
||||||
echo "Using build target: ${TARGET}"
|
echo "Using build target: ${TARGET}"
|
||||||
|
if [[ -f $APPEND_BUILD_ENV ]]; then
|
||||||
|
echo "Will append contents of $APPEND_BUILD_ENV to build envionrment"
|
||||||
|
echo "-------"
|
||||||
|
cat $APPEND_BUILD_ENV
|
||||||
|
echo "-------"
|
||||||
|
fi
|
||||||
echo "----- output --------"
|
echo "----- output --------"
|
||||||
echo creating image
|
echo creating image
|
||||||
case $TARGET in
|
case $TARGET in
|
|
@ -42,7 +42,6 @@ TAG=${tag:-$TAG}
|
||||||
name=${1%:*}
|
name=${1%:*}
|
||||||
shift
|
shift
|
||||||
|
|
||||||
get_distro
|
|
||||||
echo $(make_image_name $name $@)$([[ $suffix ]] && echo -$suffix):${TAG:-latest}
|
echo $(make_image_name $name $@)$([[ $suffix ]] && echo -$suffix):${TAG:-latest}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,6 @@ try_container () {
|
||||||
|
|
||||||
if [[ ! ( $build && $image ) ]]; then
|
if [[ ! ( $build && $image ) ]]; then
|
||||||
echo attempting to getting image name from environment file
|
echo attempting to getting image name from environment file
|
||||||
get_distro
|
|
||||||
source_env_file $efile
|
source_env_file $efile
|
||||||
image=$(make_image_name)
|
image=$(make_image_name)
|
||||||
fi
|
fi
|
||||||
|
@ -141,7 +140,7 @@ END
|
||||||
|
|
||||||
if [[ ! $dry_run ]]; then
|
if [[ ! $dry_run ]]; then
|
||||||
echo starting container with image: $image, and name $name
|
echo starting container with image: $image, and name $name
|
||||||
echo at container prompt type \'exit\' to exit from shell and remove trial container
|
echo -e "at container prompt type 'exit' to exit from shell and remove trial container\n"
|
||||||
fi
|
fi
|
||||||
dcmd=$( tr "\n" " " <<-END
|
dcmd=$( tr "\n" " " <<-END
|
||||||
docker run -i $([[ ! $script ]] && echo -t)
|
docker run -i $([[ ! $script ]] && echo -t)
|
||||||
|
@ -160,7 +159,7 @@ END
|
||||||
$([[ -f $script ]] && echo cat || echo "echo") "$script" | $dcmd
|
$([[ -f $script ]] && echo cat || echo "echo") "$script" | $dcmd
|
||||||
else
|
else
|
||||||
$dcmd
|
$dcmd
|
||||||
echo "done with session, removing containter try-$name"
|
echo -e "\ndone with session, removing containter try-$name"
|
||||||
if [[ $mp ]] ; then
|
if [[ $mp ]] ; then
|
||||||
echo removing volume $vname used for mapping
|
echo removing volume $vname used for mapping
|
||||||
docker volume rm $vname > /dev/null
|
docker volume rm $vname > /dev/null
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
../core/opt/lib/distros.csv
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
declare libdir
|
declare libdir
|
||||||
libdir=$(dirname "$(realpath "$BASH_SOURCE")")
|
libdir=$(dirname "$(realpath "$BASH_SOURCE")")
|
||||||
source $libdir/helpers.lib
|
source $libdir/build.lib
|
||||||
for f in $libdir/cmds/*.sh; do
|
for f in $libdir/cmds/*.sh; do
|
||||||
# echo sourcing: $f >&2
|
# echo sourcing: $f >&2
|
||||||
source "$f"
|
source "$f"
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
declare -A distros
|
||||||
|
. ./build.lib
|
||||||
|
LINUX_DISTRO=arch
|
||||||
|
BDIR=../
|
||||||
|
get_distro
|
||||||
|
echo $BASE_IMAGE
|
|
@ -1 +0,0 @@
|
||||||
echo initialization script for alpine distro
|
|
|
@ -1 +0,0 @@
|
||||||
echo initialization script for archlinux distro
|
|
|
@ -1,7 +0,0 @@
|
||||||
# anything in here will be sourced during build
|
|
||||||
# allows easy custom environment variables
|
|
||||||
|
|
||||||
# by sourcing run.env in build will available in build
|
|
||||||
[[ $ENV_DIR && -f $ENV_DIR/run.env ]] && source $ENV_DIR/run.env
|
|
||||||
|
|
||||||
# export VOLUME_DIRS="/opt"
|
|
|
@ -1,24 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
echo -e "\n##################################"
|
|
||||||
# which groupadd
|
|
||||||
# which useradd
|
|
||||||
# which /bin/bash
|
|
||||||
# echo SHELL $SHELL
|
|
||||||
# groupadd -g 1000 host
|
|
||||||
# useradd -r -g host -u 1000 host
|
|
||||||
# git clone https://git.kebler.net/bash/shell-base.git /shell/base
|
|
||||||
# export SHELL=/bin/bash
|
|
||||||
# mkdir -p /home/sysadmin/shell
|
|
||||||
# /bin/bash /shell/base/install/install.sh sysadmin
|
|
||||||
# echo "******** uci shell install complete **********"
|
|
||||||
# # make essential directories
|
|
||||||
# mkdir -p $VOLUME_DIRS /opt/bin
|
|
||||||
# chown -R :host /home/sysadmin/shell
|
|
||||||
# chown -R host:host $VOLUME_DIRS
|
|
||||||
# chmod -R g+rw /home/sysadmin/shell $VOLUME_DIRS
|
|
||||||
# ls -la /home/sysadmin/shell $VOLUME_DIRS
|
|
||||||
|
|
||||||
echo installing and running image distro info
|
|
||||||
/bin/bash install-os-info.sh
|
|
||||||
/opt/bin/os-info
|
|
|
@ -1,9 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
wget --quiet -O /opt/bin/os-info https://git.io/vaHfR > /dev/null
|
|
||||||
if [[ -f /opt/bin/os-info ]]; then
|
|
||||||
chmod +x /opt/bin/os-info
|
|
||||||
else
|
|
||||||
echo Failed to download
|
|
||||||
echo "https://raw.githubusercontent.com/KittyKatt/screenFetch/master/screenfetch-dev"
|
|
||||||
echo info screen not available
|
|
||||||
fi
|
|
|
@ -1,2 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
echo initialization script for debian distro
|
|
|
@ -1,3 +0,0 @@
|
||||||
# added /opt/run.env to the end of /etc/profile
|
|
||||||
export SHELL=/bin/bash
|
|
||||||
export INITIAL_DIR=/opt
|
|
|
@ -1,21 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
echo "running base init.sh script in /build"
|
|
||||||
# remove other distro files
|
|
||||||
# find $PWD -maxdepth 1 -type d ! -path $PWD ! -name ${LINUX_DISTRO} ! -name common -exec rm -rf {} +
|
|
||||||
cd ${LINUX_DISTRO} || exit 1
|
|
||||||
echo " ----- Running ${LINUX_DISTRO} specific init script ----- ";
|
|
||||||
/bin/bash init.sh
|
|
||||||
cd ..
|
|
||||||
cd common || exit 1
|
|
||||||
echo " ***** Running common initialzation script *****"
|
|
||||||
ls -la;
|
|
||||||
/bin/bash init.sh;
|
|
||||||
cd ..
|
|
||||||
cd ${LINUX_DISTRO} || exit 1
|
|
||||||
echo " ----- Running ${LINUX_DISTRO} specific post commont script ----- ";
|
|
||||||
if [[ -f post_common.sh ]]; then
|
|
||||||
echo "running distro specific commands after common install in post_common.sh"
|
|
||||||
/bin/bash post_common.sh
|
|
||||||
echo returned from ${LINUX_DISTRO} post common script
|
|
||||||
fi
|
|
||||||
cd ..
|
|
|
@ -1,117 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
add-ppa () {
|
|
||||||
|
|
||||||
if [ $EUID != 0 ]; then
|
|
||||||
sudo bash -c "$(declare -f add-ppa); add-ppa $*"
|
|
||||||
else
|
|
||||||
VERSION=jammy
|
|
||||||
KEYSDIR=/etc/apt/trusted.gpg.d
|
|
||||||
KEYSERVER=keyserver.ubuntu.com
|
|
||||||
|
|
||||||
declare OPTION; declare OPTARG; declare OPTIND
|
|
||||||
while getopts 'v:p:s:k:c:d:oi' OPTION; do
|
|
||||||
echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND}
|
|
||||||
case "$OPTION" in
|
|
||||||
i)
|
|
||||||
INSTALL=true
|
|
||||||
;;
|
|
||||||
v)
|
|
||||||
VERSION=$OPTARG
|
|
||||||
;;
|
|
||||||
p)
|
|
||||||
PACKAGE=$OPTARG
|
|
||||||
;;
|
|
||||||
c)
|
|
||||||
CMD=$OPTARG
|
|
||||||
;;
|
|
||||||
d)
|
|
||||||
KEYSDIR=$OPTARG
|
|
||||||
;;
|
|
||||||
s)
|
|
||||||
KEYSERVER=$OPTARG
|
|
||||||
;;
|
|
||||||
o)
|
|
||||||
# overwrite any exising public key
|
|
||||||
KEYOVERWRITE=true
|
|
||||||
;;
|
|
||||||
*) echo unknown run option -$OPTARG
|
|
||||||
echo "USAGE: add-ppa <options> package/branch (e.g. git-core/ppa)"
|
|
||||||
echo "available options -v <ubnutu version name - default Jammy>; -p <apt install package name if not the same>"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
shift $((OPTIND - 1))
|
|
||||||
|
|
||||||
#check input
|
|
||||||
if [ -z ${1+x} ]; then
|
|
||||||
echo "No ppa provided!"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
LAUNCHPAD="https://ppa.launchpadcontent.net"
|
|
||||||
DEV=$(echo $1 | cut -d ':' -f 2 | cut -d '/' -f1 )
|
|
||||||
PACKAGE=${PACKAGE:-$DEV}
|
|
||||||
CMD=${CMD:-$PACKAGE}
|
|
||||||
BRANCH=${2:-$(echo $1| cut -d '/' -f 2)}
|
|
||||||
URL="$LAUNCHPAD/$DEV/$BRANCH/ubuntu $VERSION main"
|
|
||||||
|
|
||||||
echo "*********** Adding PPA Repository ************"
|
|
||||||
echo DEVELOPER: $DEV
|
|
||||||
echo BRANCH: $BRANCH
|
|
||||||
echo PACKAGE: $PACKAGE
|
|
||||||
echo COMMAND: $CMD
|
|
||||||
echo URL: $URL
|
|
||||||
|
|
||||||
if [[ -t 0 ]]; then
|
|
||||||
read -n 1 -p "do you want to continue [y]=>" REPLY
|
|
||||||
[[ $REPLY != "y" ]] && return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "\n*********************************************"
|
|
||||||
#create source list file
|
|
||||||
echo "deb $URL" > /etc/apt/sources.list.d/$DEV.list
|
|
||||||
echo "***** added /etc/apt/sources.list.d/$DEV.list with****"
|
|
||||||
cat /etc/apt/sources.list.d/$DEV.list
|
|
||||||
echo "*********************************************"
|
|
||||||
|
|
||||||
KEYFILE=$KEYSDIR/$DEV.gpg
|
|
||||||
|
|
||||||
[[ $KEYOVERWRITE ]] && rm $KEYFILE
|
|
||||||
if [ ! -f $KEYFILE ]; then
|
|
||||||
# using an update error to grab key id
|
|
||||||
KEY_ERROR=/tmp/${DEV}_key_error
|
|
||||||
touch $KEY_ERROR
|
|
||||||
apt-get update > /dev/null 2> $KEY_ERROR
|
|
||||||
cat $KEY_ERROR
|
|
||||||
KEY=$(sed -n 's/^.*NO_PUBKEY //p' "$KEY_ERROR" | head -1)
|
|
||||||
# echo Reposity Public Key Settings
|
|
||||||
# echo KEYS DIRECTORY: $KEYSDIR
|
|
||||||
# echo KEY SERVER: $KEYSERVER
|
|
||||||
# echo KEY: $KEY
|
|
||||||
if [ ! $KEY ]; then
|
|
||||||
echo can not determine $DEV/$BRANCH key sign
|
|
||||||
echo "removing file: /etc/apt/sources.list.d/$DEV.list and aborting"
|
|
||||||
rm /etc/apt/sources.list.d/$DEV.list
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
echo downloading and saving public key $KEY for $DEV/$BRANCH to $KEYFILE
|
|
||||||
gpg --keyserver $KEYSERVER --recv $KEY
|
|
||||||
gpg --export $KEY > $KEYFILE
|
|
||||||
else
|
|
||||||
echo " >>>>>> $KEYFILE already exists, using that key $KEY <<<<<"
|
|
||||||
fi
|
|
||||||
echo ppa repo $DEV/$BRANCH for package $PACKAGE now registered, updating...
|
|
||||||
apt-get update 1> /dev/null
|
|
||||||
if [[ $INSTALL ]]; then
|
|
||||||
echo installing $PACKAGE
|
|
||||||
[[ -t 0 ]] && apt policy $PACKAGE
|
|
||||||
apt-get install $PACKAGE -y
|
|
||||||
$CMD --version
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
# # if script was executed then call the function
|
|
||||||
(return 0 2>/dev/null) || add-ppa $@
|
|
|
@ -1,2 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
echo intialization script for ubuntu distro
|
|
|
@ -1,8 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
echo install packages for alpine distro
|
|
||||||
apk update; apk upgrade;
|
|
||||||
pwd; ls -la
|
|
||||||
echo ">>>> installing packages => alpine: $(cat ./packages); common: $(cat ../common/packages)"
|
|
||||||
apk add --no-cache $(cat ./packages) $(cat ../common/packages)
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
echo install packages for archlinux distro
|
|
||||||
pacman -Syu
|
|
||||||
pwd; ls -la
|
|
||||||
echo ">>>> installing packages => arch: $(cat ./packages); common: $(cat ../common/packages)"
|
|
||||||
pacman -S --needed --noconfirm $(cat ./packages) $(cat ../common/packages)
|
|
||||||
pacman -Scc --noconfirm
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
ca-certificates
|
|
||||||
gpg
|
|
|
@ -1,5 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
echo install packages for ubuntu distro
|
|
||||||
apt-get update
|
|
||||||
echo ">>>> installing packages => $(cat packages) $(cat ../common/packages)"
|
|
||||||
apt-get install $(cat packages) $(cat ../common/packages) -y
|
|
|
@ -1,6 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
echo "installing packages.... for $LINUX_DISTRO"
|
|
||||||
cd ${LINUX_DISTRO} || exit 1
|
|
||||||
/bin/sh packages.sh
|
|
||||||
cd ..
|
|
||||||
|
|
|
@ -1,117 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
add-ppa () {
|
|
||||||
|
|
||||||
if [ $EUID != 0 ]; then
|
|
||||||
sudo bash -c "$(declare -f add-ppa); add-ppa $*"
|
|
||||||
else
|
|
||||||
VERSION=jammy
|
|
||||||
KEYSDIR=/etc/apt/trusted.gpg.d
|
|
||||||
KEYSERVER=keyserver.ubuntu.com
|
|
||||||
|
|
||||||
declare OPTION; declare OPTARG; declare OPTIND
|
|
||||||
while getopts 'v:p:s:k:c:d:oi' OPTION; do
|
|
||||||
echo processing: option:$OPTION argument:$OPTARG index:$OPTIND remaining:${@:$OPTIND}
|
|
||||||
case "$OPTION" in
|
|
||||||
i)
|
|
||||||
INSTALL=true
|
|
||||||
;;
|
|
||||||
v)
|
|
||||||
VERSION=$OPTARG
|
|
||||||
;;
|
|
||||||
p)
|
|
||||||
PACKAGE=$OPTARG
|
|
||||||
;;
|
|
||||||
c)
|
|
||||||
CMD=$OPTARG
|
|
||||||
;;
|
|
||||||
d)
|
|
||||||
KEYSDIR=$OPTARG
|
|
||||||
;;
|
|
||||||
s)
|
|
||||||
KEYSERVER=$OPTARG
|
|
||||||
;;
|
|
||||||
o)
|
|
||||||
# overwrite any exising public key
|
|
||||||
KEYOVERWRITE=true
|
|
||||||
;;
|
|
||||||
*) echo unknown run option -$OPTARG
|
|
||||||
echo "USAGE: add-ppa <options> package/branch (e.g. git-core/ppa)"
|
|
||||||
echo "available options -v <ubnutu version name - default Jammy>; -p <apt install package name if not the same>"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
shift $((OPTIND - 1))
|
|
||||||
|
|
||||||
#check input
|
|
||||||
if [ -z ${1+x} ]; then
|
|
||||||
echo "No ppa provided!"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
LAUNCHPAD="https://ppa.launchpadcontent.net"
|
|
||||||
DEV=$(echo $1 | cut -d ':' -f 2 | cut -d '/' -f1 )
|
|
||||||
PACKAGE=${PACKAGE:-$DEV}
|
|
||||||
CMD=${CMD:-$PACKAGE}
|
|
||||||
BRANCH=${2:-$(echo $1| cut -d '/' -f 2)}
|
|
||||||
URL="$LAUNCHPAD/$DEV/$BRANCH/ubuntu $VERSION main"
|
|
||||||
|
|
||||||
echo "*********** Adding PPA Repository ************"
|
|
||||||
echo DEVELOPER: $DEV
|
|
||||||
echo BRANCH: $BRANCH
|
|
||||||
echo PACKAGE: $PACKAGE
|
|
||||||
echo COMMAND: $CMD
|
|
||||||
echo URL: $URL
|
|
||||||
|
|
||||||
if [[ -t 0 ]]; then
|
|
||||||
read -n 1 -p "do you want to continue [y]=>" REPLY
|
|
||||||
[[ $REPLY != "y" ]] && return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "\n*********************************************"
|
|
||||||
#create source list file
|
|
||||||
echo "deb $URL" > /etc/apt/sources.list.d/$DEV.list
|
|
||||||
echo "***** added /etc/apt/sources.list.d/$DEV.list with****"
|
|
||||||
cat /etc/apt/sources.list.d/$DEV.list
|
|
||||||
echo "*********************************************"
|
|
||||||
|
|
||||||
KEYFILE=$KEYSDIR/$DEV.gpg
|
|
||||||
|
|
||||||
[[ $KEYOVERWRITE ]] && rm $KEYFILE
|
|
||||||
if [ ! -f $KEYFILE ]; then
|
|
||||||
# using an update error to grab key id
|
|
||||||
KEY_ERROR=/tmp/${DEV}_key_error
|
|
||||||
touch $KEY_ERROR
|
|
||||||
apt-get update > /dev/null 2> $KEY_ERROR
|
|
||||||
cat $KEY_ERROR
|
|
||||||
KEY=$(sed -n 's/^.*NO_PUBKEY //p' "$KEY_ERROR" | head -1)
|
|
||||||
# echo Reposity Public Key Settings
|
|
||||||
# echo KEYS DIRECTORY: $KEYSDIR
|
|
||||||
# echo KEY SERVER: $KEYSERVER
|
|
||||||
# echo KEY: $KEY
|
|
||||||
if [ ! $KEY ]; then
|
|
||||||
echo can not determine $DEV/$BRANCH key sign
|
|
||||||
echo "removing file: /etc/apt/sources.list.d/$DEV.list and aborting"
|
|
||||||
rm /etc/apt/sources.list.d/$DEV.list
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
echo downloading and saving public key $KEY for $DEV/$BRANCH to $KEYFILE
|
|
||||||
gpg --keyserver $KEYSERVER --recv $KEY
|
|
||||||
gpg --export $KEY > $KEYFILE
|
|
||||||
else
|
|
||||||
echo " >>>>>> $KEYFILE already exists, using that key $KEY <<<<<"
|
|
||||||
fi
|
|
||||||
echo ppa repo $DEV/$BRANCH for package $PACKAGE now registered, updating...
|
|
||||||
apt-get update 1> /dev/null
|
|
||||||
if [[ $INSTALL ]]; then
|
|
||||||
echo installing $PACKAGE
|
|
||||||
[[ -t 0 ]] && apt policy $PACKAGE
|
|
||||||
apt-get install $PACKAGE -y
|
|
||||||
$CMD --version
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
# # if script was executed then call the function
|
|
||||||
(return 0 2>/dev/null) || add-ppa $@
|
|
|
@ -1,2 +0,0 @@
|
||||||
ca-certificates
|
|
||||||
gpg
|
|
|
@ -1,6 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
echo install packages for ubuntu distro
|
|
||||||
apt-get update
|
|
||||||
echo ">>>> installing packages => $(cat packages) $(cat ../common/packages)"
|
|
||||||
apt-get install $(cat packages) $(cat ../common/packages) -y
|
|
||||||
./add-ppa.sh -i -p git git-core/ppa
|
|
Loading…
Reference in New Issue