diff --git a/bin/junest b/bin/junest index 442b31e..3b7eb87 100755 --- a/bin/junest +++ b/bin/junest @@ -39,8 +39,8 @@ usage() { echo -e " -d, --delete Delete $NAME from ${JUNEST_HOME}" echo echo -e " n[s] Access via Linux Namespaces using BubbleWrap (Default action)" - echo -e " -b, --backend-args Arguments for GRoot backend program" - echo -e " ($CMD groot -b \"--help\" to check out the bwrap options)" + echo -e " -b, --backend-args Arguments for bwrap backend program" + echo -e " ($CMD ns -b \"--help\" to check out the bwrap options)" echo -e " -n, --no-copy-files Do not copy common etc files into $NAME environment" echo echo -e " p[root] Access via PRoot" diff --git a/lib/checks/check.sh b/lib/checks/check.sh index e8bfc95..634044c 100755 --- a/lib/checks/check.sh +++ b/lib/checks/check.sh @@ -69,7 +69,8 @@ $SUDO pacman $PACMAN_OPTIONS -S $(pacman -Sg base-devel | cut -d ' ' -f 2 | grep info "Checking basic executables work..." $SUDO pacman -Qi pacman 1> /dev/null -/opt/proot/proot-$ARCH --help 1> /dev/null +/usr/bin/proot --help 1> /dev/null +/usr/bin/groot --help 1> /dev/null repo_package1=tree echo "Checking ${repo_package1} package from official repo..." diff --git a/lib/core/build.sh b/lib/core/build.sh index bd07c5b..a25cef6 100644 --- a/lib/core/build.sh +++ b/lib/core/build.sh @@ -23,8 +23,12 @@ function _install_pkg_from_aur(){ function _install_pkg(){ local maindir=$1 local pkgbuilddir=$2 - builtin cd ${pkgbuilddir} + # Generate a working directory because sources will be downloaded to there + working_dir=$(TMPDIR=/tmp mktemp -d -t junest-wd.XXXXXXXXXX) + cp -R "$pkgbuilddir"/* "$working_dir" + builtin cd ${working_dir} makepkg -sfcd + makepkg --printsrcinfo > ${pkgbuilddir}/.SRCINFO sudo pacman --noconfirm --root ${maindir}/root -U *.pkg.tar.xz } @@ -35,34 +39,6 @@ function _prepare() { sudo pacman -S --noconfirm git arch-install-scripts } -function _install_proot_and_qemu(){ - local maindir="$1" - local main_repo=https://s3-eu-west-1.amazonaws.com/${CMD}-repo - proot_link=${main_repo}/proot - qemu_link=${main_repo}/qemu - - info "Installing proot static binaries" - sudo bash -c " - mkdir -p '${maindir}/root/opt/proot/' - curl '$proot_link/proot-x86_64' > '${maindir}/root/opt/proot/proot-x86_64' - curl '$proot_link/proot-arm' > '${maindir}/root/opt/proot/proot-arm' - chmod -R 755 '${maindir}/root/opt/proot/' - " - - info "Installing qemu static binaries" - sudo bash -c " - mkdir -p '${maindir}/root/opt/qemu/' - if [[ $ARCH == 'arm' ]] - then - curl '${qemu_link}/arm/qemu-arm-static-x86_64' > '${maindir}/root/opt/qemu/qemu-arm-static-x86_64' - elif [[ $ARCH == 'x86_64' ]] - then - curl '${qemu_link}/x86_64/qemu-x86_64-static-arm' > '${maindir}/root/opt/qemu/qemu-x86_64-static-arm' - fi - chmod -R 755 '${maindir}/root/opt/qemu/' - " -} - function build_image_env(){ umask 022 @@ -84,7 +60,7 @@ function build_image_env(){ # bwrap command belongs to bubblewrap sudo pacstrap -G -M -d ${maindir}/root pacman coreutils bubblewrap - if [[ $(uname -m) != *"arm"* ]] + if [[ ${ARCH} != "arm" ]] then # x86_64 does not have any mirror set by default... sudo bash -c "echo 'Server = $DEFAULT_MIRROR' >> ${maindir}/root/etc/pacman.d/mirrorlist" @@ -92,13 +68,14 @@ function build_image_env(){ sudo mkdir -p ${maindir}/root/run/lock _install_pkg ${maindir} "$JUNEST_BASE/pkgs/sudo-fake" + _install_pkg ${maindir} "$JUNEST_BASE/pkgs/proot-static" + _install_pkg ${maindir} "$JUNEST_BASE/pkgs/qemu-static" + _install_pkg ${maindir} "$JUNEST_BASE/pkgs/groot-git" info "Installing yay..." sudo pacman --noconfirm -S go _install_pkg_from_aur ${maindir} "yay" - _install_proot_and_qemu "${maindir}" - echo "Generating the metadata info" sudo install -d -m 755 "${maindir}/root/etc/${CMD}" sudo bash -c "echo 'JUNEST_ARCH=$ARCH' > ${maindir}/root/etc/${CMD}/info" diff --git a/lib/core/common.sh b/lib/core/common.sh index fe43dde..eb728e9 100644 --- a/lib/core/common.sh +++ b/lib/core/common.sh @@ -21,7 +21,6 @@ NO_CONFIG_FOUND=108 UNPRIVILEGED_USERNS_DISABLED=109 JUNEST_HOME=${JUNEST_HOME:-~/.${CMD}} -JUNEST_BASE=${JUNEST_BASE:-${JUNEST_HOME}/opt/junest} JUNEST_TEMPDIR=${JUNEST_TEMPDIR:-/tmp} # The update of the variable PATH ensures that the executables are @@ -34,15 +33,17 @@ UNAME=uname ARCH_LIST=('x86_64' 'x86' 'arm') HOST_ARCH=$($UNAME -m) -if [ $HOST_ARCH == "i686" ] || [ $HOST_ARCH == "i386" ] +# To check all available architectures look here: +# https://wiki.archlinux.org/index.php/PKGBUILD#arch +if [[ $HOST_ARCH == "i686" ]] || [[ $HOST_ARCH == "i386" ]] then ARCH="x86" LD_LIB="${JUNEST_HOME}/lib/ld-linux.so.2" -elif [ $HOST_ARCH == "x86_64" ] +elif [[ $HOST_ARCH == "x86_64" ]] then ARCH="x86_64" LD_LIB="${JUNEST_HOME}/lib64/ld-linux-x86-64.so.2" -elif [[ $HOST_ARCH =~ .*(arm).* ]] +elif [[ $HOST_ARCH =~ .*(arm).* ]] || [[ $HOST_ARCH == "aarch64" ]] then ARCH="arm" LD_LIB="${JUNEST_HOME}/lib/ld-linux-armhf.so.3" @@ -66,8 +67,8 @@ ORIGIN_WD=$(pwd) SH=("/bin/sh" "--login") # List of executables that are run in the host OS: -PROOT="${JUNEST_HOME}/opt/proot/proot-${ARCH}" -GROOT=${JUNEST_BASE}/bin/groot +PROOT="${JUNEST_HOME}/usr/bin/proot" +GROOT="${JUNEST_HOME}/usr/bin/groot" CLASSIC_CHROOT=chroot WGET="wget --no-check-certificate" CURL="curl -L -J -O -k" diff --git a/lib/core/proot.sh b/lib/core/proot.sh index abf91df..d2bfd5f 100644 --- a/lib/core/proot.sh +++ b/lib/core/proot.sh @@ -33,7 +33,7 @@ function _run_env_with_qemu(){ warn "Emulating $NAME via QEMU..." [ -e ${qemu_symlink} ] || \ - ln_cmd -s ${JUNEST_HOME}/opt/qemu/${qemu_bin} ${qemu_symlink} + ln_cmd -s ${JUNEST_HOME}/bin/${qemu_bin} ${qemu_symlink} proot_args="-q ${qemu_symlink} $proot_args" fi shift diff --git a/pkgs/groot-git/PKGBUILD b/pkgs/groot-git/PKGBUILD new file mode 100644 index 0000000..015f9a2 --- /dev/null +++ b/pkgs/groot-git/PKGBUILD @@ -0,0 +1,58 @@ +# Maintainer: Filippo Squillace +# More details on how to change this file: +# https://wiki.archlinux.org/index.php/PKGBUILD +# https://wiki.archlinux.org/index.php/Creating_packages +# https://wiki.archlinux.org/index.php/Arch_User_Repository#Submitting_packages + +pkgname=groot-git +pkgver=1.0.1 +pkgrel=1 +pkgdesc="" +arch=('any') +url="https://github.com/fsquillace/groot" +license=('GPL') +groups=() +depends=('coreutils') +makedepends=() +provides=('groot') +conflicts=() +replaces=() +backup=() +options=() +#install= +noextract=() + + +source=('groot::git+https://github.com/fsquillace/groot.git#branch=master') +md5sums=('SKIP') + + +pkgver() { + cd "$srcdir/${pkgname%-git}" + +# The examples below are not absolute and need to be adapted to each repo. The +# primary goal is to generate version numbers that will increase according to +# pacman's version comparisons with later commits to the repo. The format +# VERSION='VER_NUM.rREV_NUM.HASH', or a relevant subset in case VER_NUM or HASH +# are not available, is recommended. + +# Git, tags available + printf "%s" "$(git describe --tags | sed 's/\([^-]*-\)g/r\1/;s/-/./g')" + +# Git, no tags available +# printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" + +} + +build() { + : +} + +package() { + cd "$srcdir/${pkgname%-git}" + + install -d -m 755 "${pkgdir}/usr/bin" + install -m 755 "${srcdir}/${pkgname%-git}/bin/groot" ${pkgdir}/usr/bin/groot +} + +# vim:set ts=2 sw=2 et: diff --git a/pkgs/proot-static/PKGBUILD b/pkgs/proot-static/PKGBUILD new file mode 100644 index 0000000..fad9291 --- /dev/null +++ b/pkgs/proot-static/PKGBUILD @@ -0,0 +1,43 @@ +# Maintainer: Filippo Squillace +# More details on how to change this file: +# https://wiki.archlinux.org/index.php/PKGBUILD +# https://wiki.archlinux.org/index.php/Creating_packages +# https://wiki.archlinux.org/index.php/Arch_User_Repository#Submitting_packages + +pkgname=proot-static +_pkgname=proot +pkgver=5.1.0 +pkgrel=1 +pkgdesc="chroot, mount --bind, and binfmt_misc without privilege/setup. Static binary only" +arch=('any') +url="https://proot-me.github.io/" +license=('GPL') +groups=() +depends=() +makedepends=() +provides=('proot') +conflicts=('proot' 'proot-bin') +backup=() +options=() +#install= +source=() +md5sums=() +noextract=() + +MAIN_REPO=https://s3-eu-west-1.amazonaws.com/junest-repo +PROOT_LINK=${MAIN_REPO}/proot + +source_x86_64=("${_pkgname}"::"$PROOT_LINK/proot-x86_64") +source_i686=("${_pkgname}"::"$PROOT_LINK/proot-x86") +source_arm=("${_pkgname}"::"$PROOT_LINK/proot-arm") +md5sums_x86_64=('14080705dd45a6bafa20e909a68072cb') +md5sums_i686=('b1c08236b56d121e04e9e29b197d0eeb') +md5sums_arm=('8218c5f00e77e2e6e04c372ced27c7e7') + +package() { + echo "Installing proot static binaries" + install -d -m 755 "${pkgdir}/usr/bin/" + install -m 755 "${srcdir}/${_pkgname}" ${pkgdir}/usr/bin/proot +} + +# vim:set ts=2 sw=2 et: diff --git a/pkgs/qemu-static/PKGBUILD b/pkgs/qemu-static/PKGBUILD new file mode 100644 index 0000000..3b7fc65 --- /dev/null +++ b/pkgs/qemu-static/PKGBUILD @@ -0,0 +1,50 @@ +# Maintainer: Filippo Squillace +# More details on how to change this file: +# https://wiki.archlinux.org/index.php/PKGBUILD +# https://wiki.archlinux.org/index.php/Creating_packages +# https://wiki.archlinux.org/index.php/Arch_User_Repository#Submitting_packages + +pkgname=qemu-static +pkgver=2.3.0 +pkgrel=1 +pkgdesc="Statically linked binaries of Qemu with user emulation. Useful for containers/chroot environment with binfmt." +arch=('any') +url="http://wiki.qemu.org" +license=('GPL2') +groups=() +depends=() +makedepends=() +provides=() +conflicts=() +backup=() +options=() +#install= +source=() +md5sums=() +noextract=() + +MAIN_REPO=https://s3-eu-west-1.amazonaws.com/junest-repo +QEMU_LINK=$MAIN_REPO/qemu + +source_x86_64=("${QEMU_LINK}/x86_64/qemu-x86_64-static-x86" "${QEMU_LINK}/x86_64/qemu-x86_64-static-arm") +source_i686=("${QEMU_LINK}/x86/qemu-x86-static-x86_64" "${QEMU_LINK}/x86/qemu-x86_64-static-arm") +md5sums_x86_64=('8a706d734f8c790743a8114dda4c344a' '3ced729c95d2514f35d4899e944a4582') +md5sums_x86=('c28d5049193dbce75efa0c8655d71427' 'f75fd15722fcc2914e3de0b0a46eb982') + +source_arm=("${QEMU_LINK}/arm/qemu-arm-static-x86_64" "${QEMU_LINK}/arm/qemu-arm-static-x86") +md5sums_arm=('bd9de1927aae4eb26dc0e5615159a616' 'a7c2b6ca53fa166f0c06ec76cc5edd7d') +source_armv6h=("${QEMU_LINK}/arm/qemu-arm-static-x86_64" "${QEMU_LINK}/arm/qemu-arm-static-x86") +md5sums_armv6h=('bd9de1927aae4eb26dc0e5615159a616' 'a7c2b6ca53fa166f0c06ec76cc5edd7d') +source_armv7h=("${QEMU_LINK}/arm/qemu-arm-static-x86_64" "${QEMU_LINK}/arm/qemu-arm-static-x86") +md5sums_armv7h=('bd9de1927aae4eb26dc0e5615159a616' 'a7c2b6ca53fa166f0c06ec76cc5edd7d') +source_aarch64=("${QEMU_LINK}/arm/qemu-arm-static-x86_64" "${QEMU_LINK}/arm/qemu-arm-static-x86") +md5sums_aarch64=('bd9de1927aae4eb26dc0e5615159a616' 'a7c2b6ca53fa166f0c06ec76cc5edd7d') + + +package() { + echo "Installing qemu static binaries" + install -d -m 755 "${pkgdir}/usr/bin" + install -m 755 "${srcdir}"/qemu-* ${pkgdir}/usr/bin +} + +# vim:set ts=2 sw=2 et: diff --git a/tests/unit-tests/test-proot.sh b/tests/unit-tests/test-proot.sh index 4463df7..8fa636f 100755 --- a/tests/unit-tests/test-proot.sh +++ b/tests/unit-tests/test-proot.sh @@ -153,7 +153,7 @@ function test_qemu() { } RANDOM=100 ARCH=x86_64 assertCommandSuccess _run_env_with_qemu "" - assertEquals "$(echo -e "-s $JUNEST_HOME/opt/qemu/qemu-arm-static-x86_64 /tmp/qemu-arm-static-x86_64-100\n-q /tmp/qemu-arm-static-x86_64-100")" "$(cat $STDOUTF)" + assertEquals "$(echo -e "-s $JUNEST_HOME/bin/qemu-arm-static-x86_64 /tmp/qemu-arm-static-x86_64-100\n-q /tmp/qemu-arm-static-x86_64-100")" "$(cat $STDOUTF)" } source $JUNEST_ROOT/tests/utils/shunit2