From c854436cdfe05fbac098ccc2007bf35b26deeffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ant=C3=B4nio?= Date: Fri, 24 Dec 2021 05:46:05 -0300 Subject: [PATCH] feat.: realpath'd everything (for avoiding possible errors from happening), created a new function that only generates chroot.mit and finally updated the subshell syntax entirely. Merry Christmas, folks! The 'TODO' stills the same from the last commit on this file. Sorry, I hadn't enough time to do all of it yet. docs: Happy new year (in advance)! --- LICENSE | 2 +- mitzune.sh | 37 +++++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/LICENSE b/LICENSE index ba7c1dc..deb779c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Luiz Antônio Rangel +Copyright (c) 2022 Luiz Antônio Rangel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/mitzune.sh b/mitzune.sh index 2e9c3c5..4ecbfb1 100644 --- a/mitzune.sh +++ b/mitzune.sh @@ -29,13 +29,13 @@ function main { function check_doas { # doas will be necessary for now since i don't really know how to # work with namespaces in Linux for chroot'ing without root rights - if `grep "$USER" "$DOAS_CONF" &>/dev/null`; then + if $(grep "$USER" "$DOAS_CONF" &>/dev/null); then function elevate { doas "$@"; } export -f elevate return elif [ $UID == 0 ]; then printerr 'Warning: running as root. This isn'\''t recommended.' - elif `id -nG $USER | grep 'wheel'`; then + elif $(id -nG $USER | grep 'wheel'); then printerr 'Warning: %s can log directly as root, although using doas is better.' \ "$USER" function elevate { su -c "$@"; } @@ -47,14 +47,16 @@ function check_doas { } function create_prefix { - newPrefix="$MITZUNE_PREFIX/$prefixName" - + newPrefix="$(realpath "$MITZUNE_PREFIX/$prefixName")" + mkdir "$newPrefix" && \ if [ -z "$rootfsTarball" ]; then printerr 'Warning: no rootfs declared, creating empty rootfs directory.' mkdir -v "$newPrefix/rootfs" else - copy2prefix "$rootfsTarball" "$newPrefix" + realpathRootfsTarball="$(realpath "$rootfsTarball")" + copy2prefix "$realpathRootfsTarball" "$newPrefix" + unset realpathRootfsTarball fi if [ -z "$chrootOptions" ]; then printerr 'Warning: no chroot options informed, creating an empty file.' @@ -63,6 +65,11 @@ function create_prefix { write_prefix_config "$chrootOptions" "$prefixName" "$newPrefix" fi + # This function generates chroot.mit, independently from chrootOptions + # being NULL or not, since this file is essential to initialize the chroot + # prefix. + write_chroot_mitzune "$newPrefix" + # Unfortunately we can't trust lines() when the file is empty installedPrefixes="$(sed '/#/d' "$MITZUNE_PREFIX/prefixes" | wc -l | awk '{print $1}')" @@ -77,7 +84,7 @@ function create_prefix { function delete_prefix { # Remove the prefix itself rm -rvI $MITZUNE_PREFIX/$prefixName || \ - oh_mist "Fatal: Couldn'\''t remove $prefixName directory ($MITZUNE_PREFIX/$prefixName)." 6 + oh_mist "Fatal: Couldn't remove $prefixName directory ($MITZUNE_PREFIX/$prefixName)." 6 # Create a safe temporary file TMPFILE="$(mktemp -t mitzune.XXXXXX)" || oh_mist 'Fatal: Couldn'\''t create temporary file.' 10 @@ -118,7 +125,6 @@ function write_prefix_config { prefixName="$2" newPrefix="$3" prefixProfile="$newPrefix/$prefixName.rc" - prefixMit="$newPrefix/chroot.mit" printf '%s' "$chrootOptions" > "$prefixProfile" && \ if [ $OVERWRITE_CHROOT_PROFILE == true ]; then @@ -130,7 +136,13 @@ function write_prefix_config { test -e "$(dirname $chrootProfile)" \ || mkdir -p "$(dirname $chrootProfile)" cp -vf "$prefixProfile" "$chrootProfile" + + export prefixProfile chrootProfile +} +function write_chroot_mitzune { + newPrefix="$1" + prefixMit="$newPrefix/chroot.mit" cat > $prefixMit <