Merge pull request #326 from fsquillace/wrapper-custom-path

Wrapper custom path
This commit is contained in:
Filippo Squillace 2023-05-07 16:26:22 +02:00 committed by GitHub
commit c440252f2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 14 deletions

View file

@ -110,9 +110,9 @@ used, see the [Usage](#usage) section below.
Run JuNest installed programs directly from host OS
---------------------------------------
Program installed within JuNest can be accessible directly from host machine
without entering directly into a JuNest session
(no need to call `junest` command first).
Programs installed within JuNest can be accessible directly from host machine
without entering into a JuNest session
(namely, no need to call `junest` command first).
For instance, supposing the host OS is an Ubuntu distro you can directly
run `pacman` by simply updating the `PATH` variable:
@ -123,7 +123,7 @@ htop
```
By default the wrappers use `ns` mode. To use the `ns --fakeroot` you can use the convenient command helper `sudoj`.
For more control on backend mode you can use the `JUNEST_ARGS` environment variable.
For more control on backend modes you can use the `JUNEST_ARGS` environment variable too.
For instance, if you want to run `iftop` with real root privileges:
```
@ -138,6 +138,22 @@ corrupted) with:
junest create-bin-wrappers -f
```
Bin wrappers are automatically generated each time they get installed inside JuNest.
This only works for executables located in `/usr/bin` path.
For executables in other locations (say `/usr/mybinpath`) you can only create
wrappers manually by executing the command:
```
junest create-bin-wrappers --bin-path /usr/mybinpath
```
Obviously, to get access to the corresponding bin wrappers you will need to
update your `PATH` variable accordingly:
```
export PATH="$PATH:~/.junest/usr/mybinpath_wrappers"
```
Install packages from AUR
-------------------------

View file

@ -69,8 +69,11 @@ usage() {
echo -e " b[uild] Build a $NAME image (must run in ArchLinux)"
echo -e " -n, --disable-check Disable the $NAME image check"
echo
echo -e " create-bin-wrappers Create bin wrappers in $JUNEST_HOME/usr/bin_wrappers"
echo -e " create-bin-wrappers Create a bin wrappers directory according to --bin-path option"
echo -e " Default path is $JUNEST_HOME/usr/bin_wrappers"
echo -e " -f, --force Create the wrapper files even if they already exist"
echo -e " -p, --bin-path The source directory where executable are located in JuNest"
echo -e " Default value is: /usr/bin"
echo
}
@ -215,10 +218,12 @@ function _parse_build_opts() {
function _parse_create_wrappers_opts() {
OPT_FORCE=false
OPT_BIN_PATH=""
while [[ -n "$1" ]]
do
case "$1" in
-f|--force) OPT_FORCE=true ; shift ;;
-p|--bin-path) shift ; OPT_BIN_PATH="$1" ; shift ;;
*) die "Invalid option $1" ;;
esac
done
@ -276,7 +281,7 @@ function execute_operation() {
fi
if $ACT_CREATE_WRAPPERS; then
create_wrappers $OPT_FORCE
create_wrappers $OPT_FORCE "$OPT_BIN_PATH"
exit
fi

View file

@ -24,4 +24,8 @@ sudo -E "$JUNEST_SCRIPT" groot -- "$CHECK_SCRIPT" --run-root-tests --skip-aur-te
# Test the wrappers work
"$JUNEST_SCRIPT" create-bin-wrappers --force
"$JUNEST_HOME"/usr/bin_wrappers/pacman --help
"$JUNEST_SCRIPT" create-bin-wrappers --force --bin-path /usr/bin/core_perl/
"$JUNEST_HOME"/usr/bin/core_perl_wrappers/shasum --help
"${JUNEST_BASE}/bin/sudoj" pacman -Syu

View file

@ -20,7 +20,9 @@
#######################################
function create_wrappers() {
local force=${1:-false}
mkdir -p "${JUNEST_HOME}/usr/bin_wrappers"
local bin_path=${2:-/usr/bin}
bin_path=${bin_path%/}
mkdir -p "${JUNEST_HOME}${bin_path}_wrappers"
# Arguments inside a variable (i.e. `JUNEST_ARGS`) separated by quotes
# are not recognized normally unless using `eval`. More info here:
# https://github.com/fsquillace/junest/issues/262
@ -33,26 +35,26 @@ junest "\${junest_args_array[@]}" -- \$(basename \${0}) "\$@"
EOF
chmod +x "${JUNEST_HOME}/usr/bin/junest_wrapper"
cd "${JUNEST_HOME}/usr/bin" || return 1
cd "${JUNEST_HOME}${bin_path}" || return 1
for file in *
do
[[ -d $file ]] && continue
# Symlinks outside junest appear as broken even though the are correct
# Symlinks outside junest appear as broken even though they are correct
# within a junest session. The following do not skip broken symlinks:
[[ -x $file || -L $file ]] || continue
if [[ -e ${JUNEST_HOME}/usr/bin_wrappers/$file ]] && ! $force
if [[ -e ${JUNEST_HOME}${bin_path}_wrappers/$file ]] && ! $force
then
continue
fi
rm -f "${JUNEST_HOME}/usr/bin_wrappers/$file"
ln -s "../bin/junest_wrapper" "${JUNEST_HOME}/usr/bin_wrappers/$file"
rm -f "${JUNEST_HOME}${bin_path}_wrappers/$file"
ln -s "${JUNEST_HOME}/usr/bin/junest_wrapper" "${JUNEST_HOME}${bin_path}_wrappers/$file"
done
# Remove wrappers no longer needed
cd "${JUNEST_HOME}/usr/bin_wrappers" || return 1
cd "${JUNEST_HOME}${bin_path}_wrappers" || return 1
for file in *
do
[[ -e ${JUNEST_HOME}/usr/bin/$file || -L ${JUNEST_HOME}/usr/bin/$file ]] || rm -f "$file"
[[ -e ${JUNEST_HOME}${bin_path}/$file || -L ${JUNEST_HOME}${bin_path}/$file ]] || rm -f "$file"
done
}

View file

@ -124,4 +124,15 @@ function test_create_wrappers_executable_no_longer_exist(){
assertTrue "myfile wrapper should not exist" "[ ! -x $JUNEST_HOME/usr/bin_wrappers/myfile ]"
}
function test_create_wrappers_custom_bin_path(){
mkdir -p "$JUNEST_HOME"/usr/mybindir
touch "$JUNEST_HOME"/usr/mybindir/myfile
chmod +x "$JUNEST_HOME"/usr/mybindir/myfile
assertCommandSuccess create_wrappers false /usr/mybindir/
assertEquals "" "$(cat "$STDOUTF")"
assertTrue "bin_wrappers should exist" "[ -e $JUNEST_HOME/usr/mybindir_wrappers ]"
assertTrue "myfile wrapper should exist" "[ -x $JUNEST_HOME/usr/mybindir_wrappers/myfile ]"
}
source "$(dirname "$0")"/../utils/shunit2