diff --git a/README.md b/README.md index 3ee8e32..38eb5e3 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,6 @@ COMMANDS: -m - mount the container before start stop [-u] [NAME ...] - stop all included or only specified components -u - unmount the container after stop - sync URL - synchronize with the operating environment with server status [NAME ...] - display the status of the container and components help [NAME ...] - show this help or help of components diff --git a/cli.sh b/cli.sh index 5cbdc2e..1c455ed 100755 --- a/cli.sh +++ b/cli.sh @@ -6,7 +6,7 @@ # ################################################################################ -VERSION="2.4.1" +VERSION="2.5.0" ################################################################################ # Common @@ -57,24 +57,6 @@ get_platform() esac } -get_qemu() -{ - local arch="$1" - local qemu="" - local host_platform=$(get_platform) - local guest_platform=$(get_platform "${arch}") - if [ "${host_platform}" != "${guest_platform}" ]; then - case "${guest_platform}" in - arm) qemu="qemu-arm-static" ;; - arm_64) qemu="qemu-aarch64-static" ;; - x86) qemu="qemu-i386-static" ;; - x86_64) qemu="qemu-x86_64-static" ;; - *) qemu="" ;; - esac - fi - echo ${qemu} -} - get_uuid() { cat /proc/sys/kernel/random/uuid @@ -241,9 +223,6 @@ chroot_exec() mounts="${mounts} -b ${MOUNTS// / -b }" fi local emulator - if [ -z "${EMULATOR}" ]; then - EMULATOR=$(get_qemu ${ARCH}) - fi if [ -n "${EMULATOR}" ]; then emulator="-q ${EMULATOR}" fi @@ -260,16 +239,6 @@ chroot_exec() esac } -sync_env() -{ - local env_url="$1" - [ -n "${env_url}" ] || return 1 - msg -n "Synchronization with server ... " - [ -e "${ENV_DIR}" ] || mkdir -p "${ENV_DIR}" - wget -q -O - "${env_url}" | tar xz -C "${ENV_DIR}" 1>&2 - is_ok "fail" "done" -} - ################################################################################ # Params ################################################################################ @@ -944,8 +913,6 @@ container_status() local supported_fs=$(printf '%s ' $(grep -v nodev /proc/filesystems | sort)) msg "${supported_fs}" - [ -n "${CHROOT_DIR}" ] || return 0 - msg -n "Installed system: " local linux_version=$([ -r "${CHROOT_DIR}/etc/os-release" ] && . "${CHROOT_DIR}/etc/os-release"; [ -n "${PRETTY_NAME}" ] && echo "${PRETTY_NAME}" || echo "unknown") msg "${linux_version}" @@ -955,53 +922,11 @@ container_status() component_exec "${INCLUDE}" msg "Mounted parts: " - local is_mnt=0 local item for item in $(grep "${CHROOT_DIR%/}" /proc/mounts | awk '{print $2}' | sed "s|${CHROOT_DIR%/}/*|/|g") do msg "* ${item}" - local is_mnt=1 - done - [ "${is_mnt}" -ne 1 ] && msg " ...nothing mounted" - - msg "Available mount points: " - local is_mountpoints=0 - local mp - for mp in $(grep -v "${CHROOT_DIR%/}" /proc/mounts | grep ^/ | awk '{print $2":"$3}') - do - local part=$(echo ${mp} | awk -F: '{print $1}') - local fstype=$(echo ${mp} | awk -F: '{print $2}') - local block_size=$(stat -c '%s' -f ${part}) - local available=$(stat -c '%a' -f ${part} | awk '{printf("%.1f",$1*'${block_size}'/1024/1024/1024)}') - local total=$(stat -c '%b' -f ${part} | awk '{printf("%.1f",$1*'${block_size}'/1024/1024/1024)}') - if [ -n "${available}" -a -n "${total}" ]; then - msg "* ${part} ${available}/${total} GB (${fstype})" - is_mountpoints=1 - fi - done - [ "${is_mountpoints}" -ne 1 ] && msg " ...no mount points" - - msg "Available partitions: " - local is_partitions=0 - local dev - for dev in /sys/block/*/dev - do - if [ -f ${dev} ]; then - local devname=$(echo ${dev} | sed -e 's@/dev@@' -e 's@.*/@@') - [ -e "/dev/${devname}" ] && local devpath="/dev/${devname}" - [ -e "/dev/block/${devname}" ] && local devpath="/dev/block/${devname}" - [ -n "${devpath}" ] && local parts=$(fdisk -l ${devpath} 2>/dev/null | grep ^/dev/ | awk '{print $1}') - local part - for part in ${parts} - do - local size=$(fdisk -l ${part} 2>/dev/null | grep 'Disk.*bytes' | awk '{ sub(/,/,""); print $3" "$4}') - local type=$(fdisk -l ${devpath} 2>/dev/null | grep ^${part} | tr -d '*' | awk '{str=$6; for (i=7;i<=10;i++) if ($i!="") str=str" "$i; printf("%s",str)}') - msg "* ${part} ${size} (${type})" - local is_partitions=1 - done - fi done - [ "${is_partitions}" -ne 1 ] && msg " ...no available partitions" } helper() @@ -1041,7 +966,6 @@ COMMANDS: -m - mount the container before start stop [-u] [NAME ...] - stop all included or only specified components -u - unmount the container after stop - sync URL - synchronize with the operating environment with server status [NAME ...] - display the status of the container and components help [NAME ...] - show this help or help of components @@ -1086,6 +1010,9 @@ fi if [ -z "${CHROOT_DIR}" ]; then CHROOT_DIR="${ENV_DIR}/mnt" fi +if [ -z "${METHOD}" ]; then + METHOD="chroot" +fi # parse options OPTIND=1 @@ -1133,14 +1060,6 @@ WITHOUT_CHECK="false" WITHOUT_DEPENDS="false" REVERSE_DEPENDS="false" EXCLUDE_COMPONENTS="" -case "${METHOD}" in -proot) - CHROOT_DIR="${TARGET_PATH}" -;; -*) - METHOD="chroot" -;; -esac # make dirs [ -d "${CONFIG_DIR}" ] || mkdir "${CONFIG_DIR}" @@ -1314,9 +1233,6 @@ stop) container_umount fi ;; -sync) - sync_env "$@" -;; status) if [ $# -gt 0 ]; then DO_ACTION='do_status' diff --git a/include/bootstrap/docker/deploy.conf b/include/bootstrap/docker/deploy.conf new file mode 100644 index 0000000..98c795e --- /dev/null +++ b/include/bootstrap/docker/deploy.conf @@ -0,0 +1,6 @@ +# Linux Deploy Component +# (c) Anton Skshidlevsky , GPLv3 + +NAME="docker" +DESC="Bootstrap for Docker containers" +DEPENDS="bootstrap" diff --git a/include/bootstrap/docker/deploy.sh b/include/bootstrap/docker/deploy.sh new file mode 100644 index 0000000..bd4d668 --- /dev/null +++ b/include/bootstrap/docker/deploy.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# Linux Deploy Component +# (c) Anton Skshidlevsky , GPLv3 + +[ -n "${SUITE}" ] || SUITE="linux" + +if [ -z "${ARCH}" ] +then + case "$(get_platform)" in + x86) ARCH="386" ;; + x86_64) ARCH="amd64" ;; + arm) ARCH="arm" ;; + arm_64) ARCH="arm64" ;; + esac +fi + +[ -n "${SOURCE_PATH}" ] || SOURCE_PATH="library/ubuntu:18.04" + +do_install() +{ + msg ":: Installing ${COMPONENT} ... " + + local image="${SOURCE_PATH%%:*}" + local tag="${SOURCE_PATH##*:}" + msg -n "Authorization in Docker repository ... " + local token=$(wget -q -O - "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${image}:pull" | grep -oE '"token":"[.a-zA-Z0-9_-]+"' | tr -d '"' | awk -F':' '{print $2}') + test -n "${token}" + is_ok "fail" "done" || return 1 + msg -n "Fetching manifests from the repository ... " + local manifest=$(wget -q -O - --header "Authorization: Bearer ${token}" --header "Accept: application/vnd.docker.distribution.manifest.list.v2+json" "https://registry-1.docker.io/v2/${image}/manifests/${tag}" | sed 's/},{/\n/g' | grep "\"${ARCH}\".*\"${SUITE}\"" | grep -oE 'sha256:[a-f0-9]{64}') + test -n "${manifest}" + is_ok "fail" "done" || return 1 + msg "Retrieving rootfs blobs: " + wget -q -O - --header "Authorization: Bearer ${token}" "https://registry-1.docker.io/v2/${image}/manifests/${manifest}" | tr '\n' ' ' | tr '{}' '\n' | grep 'tar.gzip.*digest' | grep -oE 'sha256:[0-9a-f]{64}' | while read digest + do + msg -n " * ${digest} ... " + wget -q -O - --header "Authorization: Bearer ${token}" "https://registry-1.docker.io/v2/${image}/blobs/${digest}" | tar xz -C "${CHROOT_DIR}" + is_ok "fail" "done" + done + + return 0 +} + +do_help() +{ +cat <, GPLv3 +get_qemu() +{ + local arch="$1" + local qemu="" + local host_platform=$(get_platform) + local guest_platform=$(get_platform "${arch}") + if [ "${host_platform}" != "${guest_platform}" ]; then + case "${guest_platform}" in + arm) qemu="qemu-arm-static" ;; + arm_64) qemu="qemu-aarch64-static" ;; + x86) qemu="qemu-i386-static" ;; + x86_64) qemu="qemu-x86_64-static" ;; + *) qemu="" ;; + esac + fi + echo ${qemu} +} + [ -n "${EMULATOR}" ] || EMULATOR=$(get_qemu ${ARCH}) do_configure() @@ -90,6 +108,14 @@ do_stop() msg "skip" fi ;; + qemu-x86_64*) + if [ -e "/proc/sys/fs/binfmt_misc/qemu-x86_64" ]; then + echo -1 > /proc/sys/fs/binfmt_misc/qemu-x86_64 + is_ok "fail" "done" + else + msg "skip" + fi + ;; qemu-arm*) if [ -e "/proc/sys/fs/binfmt_misc/qemu-arm" ]; then echo -1 > /proc/sys/fs/binfmt_misc/qemu-arm @@ -98,9 +124,9 @@ do_stop() msg "skip" fi ;; - qemu-mipsel*) - if [ -e "/proc/sys/fs/binfmt_misc/qemu-mipsel" ]; then - echo -1 > /proc/sys/fs/binfmt_misc/qemu-mipsel + qemu-aarch64*) + if [ -e "/proc/sys/fs/binfmt_misc/qemu-aarch64" ]; then + echo -1 > /proc/sys/fs/binfmt_misc/qemu-aarch64 is_ok "fail" "done" else msg "skip"