diff --git a/Dockerfile.d/Dockerfile.tpl b/Dockerfile.d/Dockerfile.tpl index 2aa6c00..fd7942d 100644 --- a/Dockerfile.d/Dockerfile.tpl +++ b/Dockerfile.d/Dockerfile.tpl @@ -2,25 +2,24 @@ ARG BASE_IMAGE FROM $BASE_IMAGE ARG BASE_IMAGE -ARG SYSADMIN_PW ARG VERBOSE +ARG REBUILD ARG LINUX_DISTRO=alpine WORKDIR /build -# PACKAGES -RUN --mount=type=bind,source=.src/packages,target=/build/packages \ +# CORE +RUN --mount=type=bind,source=./core,target=/build \ < /dev/null || return 1 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 diff --git a/Dockerfile.d/init.run b/Dockerfile.d/init.run new file mode 100644 index 0000000..06f984e --- /dev/null +++ b/Dockerfile.d/init.run @@ -0,0 +1,5 @@ +# INITIALIZATION +RUN --mount=type=bind,source=.src/init,target=/build \ +<> /tmp/profile -echo 'export PATH=$BIN_DIR:$PATH' >> /tmp/profile +export BUILD_DIR=/build +echo Distro is $LINUX_DISTRO +source /opt/lib/verbose.lib -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 sourcing core-run.env +quiet cat /opt/core_run.env +source /opt/core_run.env -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 copying source init/opt directory to image /opt directory +quiet ls -la opt/ + /bin/cp -R -f -p opt/. /opt -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 + [[ -f ./build.env ]] && source ./build.env && echo loaded build.env at /init/build.env in source 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 env quiet echo "----- env ------" @@ -65,15 +30,10 @@ if [[ -f ./init.sh ]]; then quiet cat ./init.sh quiet echo "-------------------------------------------------------------" # 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 #########################" 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 ***" diff --git a/Dockerfile.d/init/dirs.sh b/Dockerfile.d/init/dirs.sh deleted file mode 100644 index d5f2860..0000000 --- a/Dockerfile.d/init/dirs.sh +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Dockerfile.d/init/entrypoint.tpl b/Dockerfile.d/init/entrypoint.tpl deleted file mode 100644 index 0dbbb57..0000000 --- a/Dockerfile.d/init/entrypoint.tpl +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Dockerfile.d/init/help.sh b/Dockerfile.d/init/help.sh deleted file mode 100644 index b3d52d9..0000000 --- a/Dockerfile.d/init/help.sh +++ /dev/null @@ -1,14 +0,0 @@ -cat < -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 \ No newline at end of file diff --git a/Dockerfile.d/init/image-info.sh b/Dockerfile.d/init/image-info.sh deleted file mode 100644 index 0fce780..0000000 --- a/Dockerfile.d/init/image-info.sh +++ /dev/null @@ -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 diff --git a/Dockerfile.d/init/map-host-id.sh b/Dockerfile.d/init/map-host-id.sh deleted file mode 100644 index 7814226..0000000 --- a/Dockerfile.d/init/map-host-id.sh +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Dockerfile.d/init/profile.sh b/Dockerfile.d/init/profile.sh deleted file mode 100644 index 2ab4521..0000000 --- a/Dockerfile.d/init/profile.sh +++ /dev/null @@ -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 "%%%%%%%%%%%%%%%%%%%%%%%%%%%" \ No newline at end of file diff --git a/Dockerfile.d/init/start.sh b/Dockerfile.d/init/start.sh deleted file mode 100644 index 2628408..0000000 --- a/Dockerfile.d/init/start.sh +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Dockerfile.d/packages.run b/Dockerfile.d/packages.run new file mode 100644 index 0000000..9466946 --- /dev/null +++ b/Dockerfile.d/packages.run @@ -0,0 +1,5 @@ +# PACKAGES +RUN --mount=type=bind,source=.src/packages,target=/build \ +<" REPLY [[ $REPLY != "y" ]] && echo -e "\n" && return 2 - BUILD_SRC=$BDIR/src - echo -e "\n\e[1;31mNOTE: use '_default_' to explicitly use build source in uci-docker-build repo\e[1;37m" + BUILD_SRC="_core_" + echo -e "\n\e[1;31mNOTE: use '_core_' to explicitly build with only the UCI core\e[1;37m" fi fi TARGET=${TARGET:-default} [[ ! "${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 $@) @@ -184,6 +182,7 @@ export LINUX_DISTRO export BUILD_SRC export ARCH export VERBOSE +export REBUILD build_info @@ -209,30 +208,53 @@ if [[ $TARGET == "publish" ]]; then popd > /dev/null || return 4 fi -# copy or bind build source directory to temporary .src/ subdirectory in build repo -[[ -d $BDIR/.src ]] && rm -rf $BDIR/.src -if [[ $(which rsync 2> /dev/null ) ]]; then -rsync -aAru ${BUILD_SRC:-src}/ $BDIR/.src -else -echo no rsync copying with cp -/bin/cp -a ${BUILD_SRC:-src}/. $BDIR/.src > /dev/null 2>&1 -fi -if [[ -f $append_efile ]]; then -/bin/cp "$append_efile" "$BDIR/.src/init/env/_build.env_" -echo 'source $ENV_DIR/_build.env_' >> $BDIR/.src/init/build.env +if [[ ! $BUILD_SRC = "_core_" ]]; then + # copy or bind build source directory to temporary .src/ subdirectory in build repo + [[ -d $BDIR/.src ]] && rm -rf $BDIR/.src + if [[ $(which rsync 2> /dev/null ) ]]; then + rsync -aAru ${BUILD_SRC:-src}/ $BDIR/.src + else + echo no rsync copying with cp + /bin/cp -a ${BUILD_SRC:-src}/. $BDIR/.src > /dev/null 2>&1 + fi +fi + +if [[ -f $APPEND_BUILD_ENV ]]; then + echo "------ Including custom build environment at $APPEND_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 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 -e "#################################################################\e[1;37m" 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 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 echo trying newly built image in a container echo name before try $IMAGE_NAME diff --git a/core/core.sh b/core/core.sh new file mode 100644 index 0000000..3042424 --- /dev/null +++ b/core/core.sh @@ -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 <> /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 <> /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 ------------" \ No newline at end of file diff --git a/core/opt/bin/entrypoint b/core/opt/bin/entrypoint new file mode 100755 index 0000000..07d1d8b --- /dev/null +++ b/core/opt/bin/entrypoint @@ -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 \ No newline at end of file diff --git a/core/opt/bin/entrypoint-help b/core/opt/bin/entrypoint-help new file mode 100755 index 0000000..f1400a1 --- /dev/null +++ b/core/opt/bin/entrypoint-help @@ -0,0 +1,33 @@ +#!/bin/bash +cat < ${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 \ No newline at end of file diff --git a/core/opt/bin/image-info b/core/opt/bin/image-info new file mode 100755 index 0000000..03de68d --- /dev/null +++ b/core/opt/bin/image-info @@ -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 \ No newline at end of file diff --git a/core/opt/bin/map-host-id b/core/opt/bin/map-host-id new file mode 100755 index 0000000..95739af --- /dev/null +++ b/core/opt/bin/map-host-id @@ -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 \ No newline at end of file diff --git a/core/opt/bin/start b/core/opt/bin/start new file mode 100755 index 0000000..ea7e083 --- /dev/null +++ b/core/opt/bin/start @@ -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 -----" \ No newline at end of file diff --git a/core/opt/core_run.env b/core/opt/core_run.env new file mode 100644 index 0000000..5d233c0 --- /dev/null +++ b/core/opt/core_run.env @@ -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 diff --git a/core/opt/lib/distro.lib b/core/opt/lib/distro.lib new file mode 100755 index 0000000..c030533 --- /dev/null +++ b/core/opt/lib/distro.lib @@ -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 +} diff --git a/core/opt/lib/distros copy.csv b/core/opt/lib/distros copy.csv new file mode 100644 index 0000000..d309b8c --- /dev/null +++ b/core/opt/lib/distros copy.csv @@ -0,0 +1,7 @@ +# valid distros list +# the distro must be the name used in /etc/os-release +# ,,, +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 \ No newline at end of file diff --git a/core/opt/lib/distros.csv b/core/opt/lib/distros.csv new file mode 100644 index 0000000..d309b8c --- /dev/null +++ b/core/opt/lib/distros.csv @@ -0,0 +1,7 @@ +# valid distros list +# the distro must be the name used in /etc/os-release +# ,,, +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 \ No newline at end of file diff --git a/core/opt/lib/verbose.lib b/core/opt/lib/verbose.lib new file mode 100644 index 0000000..b6ec93b --- /dev/null +++ b/core/opt/lib/verbose.lib @@ -0,0 +1,10 @@ +quiet () { + if [ -n "$VERBOSE" ]; then $@; fi +} +silence() { + if [ -n "$VERBOSE" ] ; then + "$@" + else + "$@" > /dev/null + fi +} \ No newline at end of file diff --git a/core/packages.sh b/core/packages.sh new file mode 100644 index 0000000..173a78d --- /dev/null +++ b/core/packages.sh @@ -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 ------------" diff --git a/core/packages/alpine b/core/packages/alpine new file mode 100644 index 0000000..d8ecfa7 --- /dev/null +++ b/core/packages/alpine @@ -0,0 +1 @@ +shadow \ No newline at end of file diff --git a/src/packages/alpine/packages b/core/packages/arch similarity index 100% rename from src/packages/alpine/packages rename to core/packages/arch diff --git a/src/packages/common/packages b/core/packages/common similarity index 65% rename from src/packages/common/packages rename to core/packages/common index 0541c55..af3c08a 100644 --- a/src/packages/common/packages +++ b/core/packages/common @@ -1,9 +1,9 @@ +bash +bash-completion +coreutils wget curl git -rsync -sudo nano -coreutils -bash -bash-completion \ No newline at end of file +sudo + \ No newline at end of file diff --git a/src/packages/archlinux/packages b/core/packages/debian similarity index 100% rename from src/packages/archlinux/packages rename to core/packages/debian diff --git a/core/packages/ubuntu b/core/packages/ubuntu new file mode 100644 index 0000000..e69de29 diff --git a/core/uci-shell.sh b/core/uci-shell.sh new file mode 100755 index 0000000..89ef0ba --- /dev/null +++ b/core/uci-shell.sh @@ -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 ------" + diff --git a/core/user.sh b/core/user.sh new file mode 100755 index 0000000..11b308d --- /dev/null +++ b/core/user.sh @@ -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 <> /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 <> /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 + + + + diff --git a/distros.csv b/distros.csv new file mode 120000 index 0000000..c833237 --- /dev/null +++ b/distros.csv @@ -0,0 +1 @@ +./core/opt/lib/distros.csv \ No newline at end of file diff --git a/docker-bake.hcl b/docker-bake.hcl index 94ab768..29b36f8 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -11,10 +11,10 @@ variable "IMAGE_NAME" { variable "BASE_IMAGE" { // default = "alpine" } -variable "SYSADMIN_PW" { +variable "VERBOSE" { default = "" } -variable "VERBOSE" { +variable "REBUILD" { default = "" } variable "ARCH" { @@ -48,7 +48,7 @@ target "amd64" { BASE_IMAGE = "${BASE_IMAGE}" TAG = "${TAG}" VERBOSE = "${VERBOSE}" - SYSADMIN_PW = "${SYSADMIN_PW}" + REBUILD = "${REBUILD}" } tags = tag("amd64") platforms = ["linux/amd64"] diff --git a/examples/build b/example/build similarity index 100% rename from examples/build rename to example/build diff --git a/example/build.env b/example/build.env new file mode 100644 index 0000000..ccd515a --- /dev/null +++ b/example/build.env @@ -0,0 +1,2 @@ +export USER_PW=ucommandit +export UCI_SHELL=true \ No newline at end of file diff --git a/example/example.env b/example/example.env new file mode 100644 index 0000000..70ca70d --- /dev/null +++ b/example/example.env @@ -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//,../$PWD,../$PWD/ +# 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 + + + + diff --git a/example/image.info b/example/image.info new file mode 100644 index 0000000..9dd97dc --- /dev/null +++ b/example/image.info @@ -0,0 +1,3 @@ +This is an example image built from the +source found in example/ directory of +the uci-docker-build repo \ No newline at end of file diff --git a/examples/private.env b/example/private.env similarity index 100% rename from examples/private.env rename to example/private.env diff --git a/examples/publish.env b/example/publish.env similarity index 100% rename from examples/publish.env rename to example/publish.env diff --git a/example/shell b/example/shell new file mode 100755 index 0000000..fb71a80 --- /dev/null +++ b/example/shell @@ -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 diff --git a/example/src/init/build.env b/example/src/init/build.env new file mode 100644 index 0000000..86cf9f1 --- /dev/null +++ b/example/src/init/build.env @@ -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" \ No newline at end of file diff --git a/example/src/init/init.sh b/example/src/init/init.sh new file mode 100755 index 0000000..dadcab3 --- /dev/null +++ b/example/src/init/init.sh @@ -0,0 +1,7 @@ +#!/bin/bash +echo custom initialization script +echo "----- CONTAINER RUN ENVIRONMENT ---" +cat $ENV_DIR/run.env +echo -e "-n--------------------" + + diff --git a/example/src/init/opt/bin/mycmd b/example/src/init/opt/bin/mycmd new file mode 100755 index 0000000..1b02c99 --- /dev/null +++ b/example/src/init/opt/bin/mycmd @@ -0,0 +1,2 @@ +echo "this is my custom entrypoint command script, mycmd" +echo "arguments that were passed: $*" \ No newline at end of file diff --git a/example/src/init/opt/env/run.env b/example/src/init/opt/env/run.env new file mode 100644 index 0000000..e30fb4d --- /dev/null +++ b/example/src/init/opt/env/run.env @@ -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" \ No newline at end of file diff --git a/example/src/init/opt/env/run.env.example b/example/src/init/opt/env/run.env.example new file mode 100755 index 0000000..e30fb4d --- /dev/null +++ b/example/src/init/opt/env/run.env.example @@ -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" \ No newline at end of file diff --git a/src/init/image.info b/example/src/init/opt/image.info similarity index 52% rename from src/init/image.info rename to example/src/init/opt/image.info index 5e3b4bc..d716d7b 100644 --- a/src/init/image.info +++ b/example/src/init/opt/image.info @@ -1,5 +1,5 @@ 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. So this text comes from the default image.info file in the src/init folder of the default build source \ No newline at end of file diff --git a/example/src/packages/install-os-info.sh b/example/src/packages/install-os-info.sh new file mode 100644 index 0000000..2894cd6 --- /dev/null +++ b/example/src/packages/install-os-info.sh @@ -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 diff --git a/example/src/packages/packages.lst b/example/src/packages/packages.lst new file mode 100644 index 0000000..02b3e15 --- /dev/null +++ b/example/src/packages/packages.lst @@ -0,0 +1,2 @@ +rsync + \ No newline at end of file diff --git a/example/src/packages/packages.sh b/example/src/packages/packages.sh new file mode 100644 index 0000000..8ac579f --- /dev/null +++ b/example/src/packages/packages.sh @@ -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 \ No newline at end of file diff --git a/example/sysadmin-permits b/example/sysadmin-permits new file mode 100644 index 0000000..18406b4 --- /dev/null +++ b/example/sysadmin-permits @@ -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 diff --git a/examples/try b/example/try similarity index 56% rename from examples/try rename to example/try index 57e389b..b644f9b 100755 --- a/examples/try +++ b/example/try @@ -1,2 +1,2 @@ # invokes build with the example environment file -udbuild try -e example.env ${@:-shell} +udbuild try -e example.env $@ diff --git a/example/try-opt b/example/try-opt new file mode 100755 index 0000000..b883cce --- /dev/null +++ b/example/try-opt @@ -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} $@ diff --git a/examples/example.env b/examples/example.env deleted file mode 100644 index 8ad4e01..0000000 --- a/examples/example.env +++ /dev/null @@ -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 - - - - - diff --git a/lib/helpers.lib b/lib/build.lib similarity index 74% rename from lib/helpers.lib rename to lib/build.lib index 9934eed..9f04cde 100755 --- a/lib/helpers.lib +++ b/lib/build.lib @@ -113,26 +113,57 @@ source_env_file () { } -docker_image_distro() { -local temp=/tmp/os-release.tmp -docker create --name dummy $1 > /dev/null -docker cp -L dummy:/etc/os-release $temp -docker rm -f dummy > /dev/null -echo $(cat $temp | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq) -rm $temp +load_csv () { + # add newline, remove comments, remove empty lines, remove extra whitespace around , + if [[ -f $1 ]]; then + sed -e '$a\' "$1" | \ + sed -e '/\s*#.*$/d' | \ + sed -e '/^\s*$/d' | \ + 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 -quiet echo determining DISTRO of base image: $BASE_IMAGE -LINUX_DISTRO=$(docker_image_distro $BASE_IMAGE) - [[ ! $LINUX_DISTRO ]] && quiet echo "unable to get base image OS for: $BASE_IMAGE, aborting build" && return 5 - quiet echo $BASE_IMAGE is built from distro $LINUX_DISTRO + quiet echo determining DISTRO of base image: $BASE_IMAGE + if ! validate_image_distro $BASE_IMAGE; then + 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 else - BASE_IMAGE=$LINUX_DISTRO + echo unable to determine a base image, aborting build + return 6 fi } @@ -172,11 +203,13 @@ get_build_src () { # processing the build source directory local src; local spath; local spaths 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 == "_default_" ]] && src=${BDIR}/src +[[ $src == "_core_" ]] && return 0 src=${src:-src} unset BUILD_SRC @@ -185,10 +218,10 @@ if check_dir $src; then return 0 fi -echo build source path \'$src\' not initially found -echo looking in parent directories for a valid build source directory +echo build source path \'$src\' not initially found, echo looking +echo in \$PWD,\$PWD/src/,../\$PWD/src for valid build source 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 echo checking for source in: $spath if check_dir $spath; then @@ -205,8 +238,6 @@ done build_info () { - -echo "Build Command: docker buildx --builder ${builder} bake ${nocache} ${TARGET}" if [[ $VERBOSE ]]; then echo -e "\n!!!!!!!!!!!!!!!!EXTRA BUILD INFO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!" pushd "$BDIR" > /dev/null || return 3 @@ -222,11 +253,21 @@ fi echo -e "\e[1;37m**************BUILD PARAMETERS *******************************" echo "Architecture of this machine doing the building: $ARCH" -echo "Using scripts source directory at $BUILD_SRC" -echo "Building with base image: $BASE_IMAGE" +if [[ $BUILD_SRC="_core_" ]] ;then + echo Building ONLY the UCI core + else + echo "Using scripts source directory at $BUILD_SRC" +fi +echo "Building with base image: $BASE_IMAGE"$([[ "${BASE_IMAGE}" == *":"* ]] || echo :latest) echo "Build logs can be found in directory $log_dir" echo "Linux Distro of Image: $LINUX_DISTRO" 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 creating image case $TARGET in diff --git a/lib/cmds/01-image-name.sh b/lib/cmds/01-image-name.sh index d7e90b1..273fba1 100755 --- a/lib/cmds/01-image-name.sh +++ b/lib/cmds/01-image-name.sh @@ -42,7 +42,6 @@ TAG=${tag:-$TAG} name=${1%:*} shift -get_distro echo $(make_image_name $name $@)$([[ $suffix ]] && echo -$suffix):${TAG:-latest} } diff --git a/lib/cmds/try.sh b/lib/cmds/try.sh index 4dea849..9ef9246 100755 --- a/lib/cmds/try.sh +++ b/lib/cmds/try.sh @@ -86,7 +86,6 @@ try_container () { if [[ ! ( $build && $image ) ]]; then echo attempting to getting image name from environment file - get_distro source_env_file $efile image=$(make_image_name) fi @@ -141,7 +140,7 @@ END if [[ ! $dry_run ]]; then 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 dcmd=$( tr "\n" " " <<-END docker run -i $([[ ! $script ]] && echo -t) @@ -160,7 +159,7 @@ END $([[ -f $script ]] && echo cat || echo "echo") "$script" | $dcmd else $dcmd - echo "done with session, removing containter try-$name" + echo -e "\ndone with session, removing containter try-$name" if [[ $mp ]] ; then echo removing volume $vname used for mapping docker volume rm $vname > /dev/null diff --git a/lib/distros.csv b/lib/distros.csv new file mode 120000 index 0000000..b390fbf --- /dev/null +++ b/lib/distros.csv @@ -0,0 +1 @@ +../core/opt/lib/distros.csv \ No newline at end of file diff --git a/lib/load.sh b/lib/load.sh index 6d150dd..f58ddb2 100755 --- a/lib/load.sh +++ b/lib/load.sh @@ -1,7 +1,7 @@ #!/bin/bash declare libdir libdir=$(dirname "$(realpath "$BASH_SOURCE")") -source $libdir/helpers.lib +source $libdir/build.lib for f in $libdir/cmds/*.sh; do # echo sourcing: $f >&2 source "$f" diff --git a/lib/tester b/lib/tester new file mode 100755 index 0000000..6424236 --- /dev/null +++ b/lib/tester @@ -0,0 +1,6 @@ +declare -A distros +. ./build.lib +LINUX_DISTRO=arch +BDIR=../ +get_distro +echo $BASE_IMAGE \ No newline at end of file diff --git a/src/init/alpine/init.sh b/src/init/alpine/init.sh deleted file mode 100644 index 0dd2fa0..0000000 --- a/src/init/alpine/init.sh +++ /dev/null @@ -1 +0,0 @@ -echo initialization script for alpine distro \ No newline at end of file diff --git a/src/init/archlinux/init.sh b/src/init/archlinux/init.sh deleted file mode 100644 index 6b021b8..0000000 --- a/src/init/archlinux/init.sh +++ /dev/null @@ -1 +0,0 @@ -echo initialization script for archlinux distro \ No newline at end of file diff --git a/src/init/build.env b/src/init/build.env deleted file mode 100644 index 33b333a..0000000 --- a/src/init/build.env +++ /dev/null @@ -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" diff --git a/src/init/common/init.sh b/src/init/common/init.sh deleted file mode 100644 index ebb7b9d..0000000 --- a/src/init/common/init.sh +++ /dev/null @@ -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 diff --git a/src/init/common/install-os-info.sh b/src/init/common/install-os-info.sh deleted file mode 100644 index 9a87fcf..0000000 --- a/src/init/common/install-os-info.sh +++ /dev/null @@ -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 diff --git a/src/init/debian/init.sh b/src/init/debian/init.sh deleted file mode 100644 index a66a1c5..0000000 --- a/src/init/debian/init.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -echo initialization script for debian distro diff --git a/src/init/env/run.env b/src/init/env/run.env deleted file mode 100644 index ab6827c..0000000 --- a/src/init/env/run.env +++ /dev/null @@ -1,3 +0,0 @@ -# added /opt/run.env to the end of /etc/profile -export SHELL=/bin/bash -export INITIAL_DIR=/opt \ No newline at end of file diff --git a/src/init/init.sh b/src/init/init.sh deleted file mode 100755 index c663528..0000000 --- a/src/init/init.sh +++ /dev/null @@ -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 .. diff --git a/src/init/ubuntu/add-ppa.sh b/src/init/ubuntu/add-ppa.sh deleted file mode 100755 index 1b8c2c3..0000000 --- a/src/init/ubuntu/add-ppa.sh +++ /dev/null @@ -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 package/branch (e.g. git-core/ppa)" - echo "available options -v ; -p " - ;; - 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 $@ \ No newline at end of file diff --git a/src/init/ubuntu/init.sh b/src/init/ubuntu/init.sh deleted file mode 100644 index 6532972..0000000 --- a/src/init/ubuntu/init.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -echo intialization script for ubuntu distro diff --git a/src/packages/alpine/packages.sh b/src/packages/alpine/packages.sh deleted file mode 100644 index 41aba57..0000000 --- a/src/packages/alpine/packages.sh +++ /dev/null @@ -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) - - diff --git a/src/packages/archlinux/packages.sh b/src/packages/archlinux/packages.sh deleted file mode 100644 index 30ab8fe..0000000 --- a/src/packages/archlinux/packages.sh +++ /dev/null @@ -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 - diff --git a/src/packages/debian/packages b/src/packages/debian/packages deleted file mode 100644 index a8bfc18..0000000 --- a/src/packages/debian/packages +++ /dev/null @@ -1,2 +0,0 @@ -ca-certificates -gpg \ No newline at end of file diff --git a/src/packages/debian/packages.sh b/src/packages/debian/packages.sh deleted file mode 100644 index e246157..0000000 --- a/src/packages/debian/packages.sh +++ /dev/null @@ -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 diff --git a/src/packages/packages.sh b/src/packages/packages.sh deleted file mode 100644 index ef33932..0000000 --- a/src/packages/packages.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - echo "installing packages.... for $LINUX_DISTRO" - cd ${LINUX_DISTRO} || exit 1 -/bin/sh packages.sh - cd .. - \ No newline at end of file diff --git a/src/packages/ubuntu/add-ppa.sh b/src/packages/ubuntu/add-ppa.sh deleted file mode 100755 index 1b8c2c3..0000000 --- a/src/packages/ubuntu/add-ppa.sh +++ /dev/null @@ -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 package/branch (e.g. git-core/ppa)" - echo "available options -v ; -p " - ;; - 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 $@ \ No newline at end of file diff --git a/src/packages/ubuntu/packages b/src/packages/ubuntu/packages deleted file mode 100644 index a8bfc18..0000000 --- a/src/packages/ubuntu/packages +++ /dev/null @@ -1,2 +0,0 @@ -ca-certificates -gpg \ No newline at end of file diff --git a/src/packages/ubuntu/packages.sh b/src/packages/ubuntu/packages.sh deleted file mode 100644 index 3d2c6cc..0000000 --- a/src/packages/ubuntu/packages.sh +++ /dev/null @@ -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