diff --git a/_home/dot_sz.shrc.d/01_util.functions b/_home/dot_sz.shrc.d/01_util.functions new file mode 100644 index 0000000..4ca5064 --- /dev/null +++ b/_home/dot_sz.shrc.d/01_util.functions @@ -0,0 +1,28 @@ +error() { + (>&2 printf '\E[31mERROR:\E[0m %s\n' "$@" ) +} + +require_root() { + if [[ $EUID -ne 0 ]]; then + error "This script should only be run using sudo or as the root user" + exit 1 + fi +} + +function setacl() { + if [[ $# -lt 4 ]]; then + error "setacl missing arguments, called with '$1' ${@:2}" + return 1 + fi + local Options=${1} + local Ownership=${2} + local Permissions=${3} + + [[ -n "${SZ_DEBUG}" ]] \ + && echo "chown $Options $Ownership \"${@:4}\"" + chown $Options $Ownership "${@:4}" + [[ -n "${SZ_DEBUG}" ]] \ + && echo "chmod $Options $Permissions \"${@:4}\"" + chmod $Options $Permissions "${@:4}" +} + diff --git a/_home/private_dot_local/bin/executable_sz-prep-docker-system.sh b/_home/private_dot_local/bin/executable_sz-prep-docker-system.sh new file mode 100644 index 0000000..07b6d85 --- /dev/null +++ b/_home/private_dot_local/bin/executable_sz-prep-docker-system.sh @@ -0,0 +1,53 @@ +#! /usr/bin/env bash +. ~/.sz.shrc.d/01_util.functions + +require_root + +if [[ ! -r "/etc/apt/sources.list.d/download.docker.com.list" ]]; then + error "Docker sources are not installed yet, please run 'sz-add-my-apt-repos' script first" + exit 1 +fi + +[[ -z "$(getent group szdocker)" ]] \ + && groupadd --gid 2001 szdocker +[[ -z "$(getent passwd szdocker)" ]] \ + && useradd --gid szdocker --uid 2001 szdocker +[[ -z "$(type -fP docker)" ]] \ + && DEBIAN_FRONTEND=noninteractive apt-get install --yes docker-ce docker-ce-cli containerd.io docker-compose-plugin \ + && printf "\n\ndocker installed\n\n" +CUR_USER=$USER +[[ -n "$SUDO_USER" ]] \ + && CUR_USER=$SUDO_USER +echo $CUR_USER +sudo usermod --groups docker,szdocker --append $CUR_USER +sudo usermod --groups docker --append szdocker + +if [[ ! -x /usr/local/bin/compose-switch ]]; then + curl -fL https://raw.githubusercontent.com/docker/compose-switch/master/install_on_linux.sh | sh + update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/local/bin/compose-switch 99 +fi + +CTSZ_ROOT=/srv/containeriszed +[[ -n "${SZ_DEBUG}" ]] \ + && echo "Creating $CTSZ_ROOT/docker-compose/0.template.off..." +mkdir -p $CTSZ_ROOT/docker-compose/0.template.off +[[ -n "${SZ_DEBUG}" ]] \ + && echo "Creating $CTSZ_ROOT/0.local/0.shared..." +mkdir -p $CTSZ_ROOT/0.local/0.shared + +setacl -R szdocker:szdocker 775 $CTSZ_ROOT + +[[ -n "${SZ_DEBUG}" ]] \ + && echo "Creating $CTSZ_ROOT/docker-compose/.env..." +touch $CTSZ_ROOT/docker-compose/.env +pushd $CTSZ_ROOT/docker-compose/0.template.off > /dev/null +[[ -r ".env" ]] || ln -s ../.env . +chown szdocker:szdocker $CTSZ_ROOT/docker-compose/0.template.off/.env +setacl '' szdocker:szdocker 660 $CTSZ_ROOT/docker-compose/.env +popd > /dev/null +[[ -n "${SZ_DEBUG}" ]] \ + && echo "Template created with .env as a symbloiv link" + +[[ -n "type tree" ]] \ + && echo "Containerized Directory Tree initialized:" \ + && tree -Fapug --dirsfirst --noreport $CTSZ_ROOT