mirror of
https://github.com/fsquillace/junest.git
synced 2026-07-20 17:59:38 +00:00
Merge pull request #291 from fsquillace/create-wrappers
Create wrappers
This commit is contained in:
commit
e7d7056e9c
6 changed files with 140 additions and 72 deletions
|
|
@ -111,7 +111,7 @@ Run JuNest installed programs directly from host OS
|
|||
---------------------------------------
|
||||
|
||||
Installed programs can be accessible directly from host without
|
||||
calling `junest` command.
|
||||
entering directly into a JuNest session (no need to call `junest` command).
|
||||
For instance, supposing the host OS is an Ubuntu distro you can directly
|
||||
run `pacman` by simply updating the `PATH` variable:
|
||||
|
||||
|
|
|
|||
24
bin/junest
24
bin/junest
|
|
@ -68,6 +68,9 @@ 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 " -f, --force Create the wrapper files even if they already exist"
|
||||
echo
|
||||
}
|
||||
|
||||
version() {
|
||||
|
|
@ -78,6 +81,7 @@ function parse_arguments(){
|
|||
# Actions
|
||||
ACT_SETUP=false
|
||||
ACT_BUILD=false
|
||||
ACT_CREATE_WRAPPERS=false
|
||||
ACT_NAMESPACE=false
|
||||
ACT_PROOT=false
|
||||
ACT_GROOT=false
|
||||
|
|
@ -88,6 +92,7 @@ function parse_arguments(){
|
|||
case "$1" in
|
||||
s|setup) ACT_SETUP=true ; shift ;;
|
||||
b|build) ACT_BUILD=true ; shift ;;
|
||||
create-bin-wrappers) ACT_CREATE_WRAPPERS=true ; shift ;;
|
||||
n|ns) ACT_NAMESPACE=true ; shift ;;
|
||||
p|proot) ACT_PROOT=true ; shift ;;
|
||||
g|groot) ACT_GROOT=true ; shift ;;
|
||||
|
|
@ -103,6 +108,9 @@ function parse_arguments(){
|
|||
elif $ACT_BUILD
|
||||
then
|
||||
_parse_build_opts "$@"
|
||||
elif $ACT_CREATE_WRAPPERS
|
||||
then
|
||||
_parse_create_wrappers_opts "$@"
|
||||
elif $ACT_NAMESPACE
|
||||
then
|
||||
_parse_ns_opts "$@"
|
||||
|
|
@ -204,6 +212,17 @@ function _parse_build_opts() {
|
|||
done
|
||||
}
|
||||
|
||||
function _parse_create_wrappers_opts() {
|
||||
OPT_FORCE=false
|
||||
while [[ -n "$1" ]]
|
||||
do
|
||||
case "$1" in
|
||||
-f|--force) OPT_FORCE=true ; shift ;;
|
||||
*) die "Invalid option $1" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function _parse_setup_opts() {
|
||||
OPT_FROM_FILE=false
|
||||
IMAGE_FILE=""
|
||||
|
|
@ -256,6 +275,11 @@ function execute_operation() {
|
|||
die "Error: The image is still not installed in $JUNEST_HOME. Run this first: $CMD setup"
|
||||
fi
|
||||
|
||||
if $ACT_CREATE_WRAPPERS; then
|
||||
create_wrappers $OPT_FORCE
|
||||
exit
|
||||
fi
|
||||
|
||||
local run_env
|
||||
if $ACT_NAMESPACE; then
|
||||
if $OPT_FAKEROOT; then
|
||||
|
|
|
|||
|
|
@ -22,4 +22,5 @@ $JUNEST_SCRIPT ns --backend-command "$JUNEST_HOME/usr/bin/bwrap" -- exit
|
|||
sudo -E $JUNEST_SCRIPT groot -- "$CHECK_SCRIPT" --run-root-tests --skip-aur-tests
|
||||
|
||||
# Test the wrappers work
|
||||
$JUNEST_SCRIPT create-bin-wrappers --force
|
||||
$JUNEST_HOME/usr/bin_wrappers/pacman --help
|
||||
|
|
|
|||
|
|
@ -1,13 +1,32 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Dependencies:
|
||||
# None
|
||||
#
|
||||
# vim: ft=sh
|
||||
|
||||
|
||||
#######################################
|
||||
# Create bin wrappers
|
||||
#
|
||||
# Globals:
|
||||
# JUNEST_HOME (RO) : The JuNest home directory.
|
||||
# Arguments:
|
||||
# force ($1?) : Create bin wrappers even if the bin file exists.
|
||||
# Defaults to false.
|
||||
# Returns:
|
||||
# None
|
||||
# Output:
|
||||
# None
|
||||
#######################################
|
||||
function create_wrappers() {
|
||||
local force=${1:-false}
|
||||
mkdir -p "${JUNEST_HOME}/usr/bin_wrappers"
|
||||
|
||||
cd "${JUNEST_HOME}/usr/bin" || return 1
|
||||
for file in *
|
||||
do
|
||||
[[ -x $file ]] || continue
|
||||
if [[ -e ${JUNEST_HOME}/usr/bin_wrappers/$file ]]
|
||||
if [[ -e ${JUNEST_HOME}/usr/bin_wrappers/$file ]] && ! $force
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -12,75 +12,74 @@ function oneTimeSetUp(){
|
|||
}
|
||||
|
||||
function setUp(){
|
||||
## Mock functions ##
|
||||
function usage(){
|
||||
echo "usage"
|
||||
}
|
||||
function version(){
|
||||
echo "version"
|
||||
}
|
||||
function build_image_env(){
|
||||
local disable_check=$1
|
||||
echo "build_image_env($disable_check)"
|
||||
}
|
||||
function delete_env(){
|
||||
echo "delete_env"
|
||||
}
|
||||
function setup_env_from_file(){
|
||||
echo "setup_env_from_file($1)"
|
||||
}
|
||||
function setup_env(){
|
||||
echo "setup_env($1)"
|
||||
}
|
||||
function run_env_as_proot_fakeroot(){
|
||||
local backend_command="$1"
|
||||
local backend_args="$2"
|
||||
local no_copy_files="$3"
|
||||
shift 3
|
||||
echo "run_env_as_proot_fakeroot($backend_command,$backend_args,$no_copy_files,$@)"
|
||||
}
|
||||
function run_env_as_groot(){
|
||||
local backend_command="$1"
|
||||
local backend_args="$2"
|
||||
local no_copy_files="$3"
|
||||
shift 3
|
||||
echo "run_env_as_groot($backend_command,$backend_args,$no_copy_files,$@)"
|
||||
}
|
||||
function run_env_as_chroot(){
|
||||
local backend_command="$1"
|
||||
local backend_args="$2"
|
||||
local no_copy_files="$3"
|
||||
shift 3
|
||||
echo "run_env_as_chroot($backend_command,$backend_args,$no_copy_files,$@)"
|
||||
}
|
||||
function run_env_as_proot_user(){
|
||||
local backend_command="$1"
|
||||
local backend_args="$2"
|
||||
local no_copy_files="$3"
|
||||
shift 3
|
||||
echo "run_env_as_proot_user($backend_command,$backend_args,$no_copy_files,$@)"
|
||||
}
|
||||
function run_env_as_bwrap_fakeroot(){
|
||||
local backend_command="$1"
|
||||
local backend_args="$2"
|
||||
local no_copy_files="$3"
|
||||
shift 3
|
||||
echo "run_env_as_bwrap_fakeroot($backend_command,$backend_args,$no_copy_files,$@)"
|
||||
}
|
||||
function run_env_as_bwrap_user(){
|
||||
local backend_command="$1"
|
||||
local backend_args="$2"
|
||||
local no_copy_files="$3"
|
||||
shift 3
|
||||
echo "run_env_as_bwrap_user($backend_command,$backend_args,$no_copy_files,$@)"
|
||||
}
|
||||
function is_env_installed(){
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
## Mock functions ##
|
||||
function usage(){
|
||||
echo "usage"
|
||||
}
|
||||
function version(){
|
||||
echo "version"
|
||||
}
|
||||
function build_image_env(){
|
||||
local disable_check=$1
|
||||
echo "build_image_env($disable_check)"
|
||||
}
|
||||
function delete_env(){
|
||||
echo "delete_env"
|
||||
}
|
||||
function create_wrappers(){
|
||||
:
|
||||
}
|
||||
function setup_env_from_file(){
|
||||
echo "setup_env_from_file($1)"
|
||||
}
|
||||
function setup_env(){
|
||||
echo "setup_env($1)"
|
||||
}
|
||||
function run_env_as_proot_fakeroot(){
|
||||
local backend_command="$1"
|
||||
local backend_args="$2"
|
||||
local no_copy_files="$3"
|
||||
shift 3
|
||||
echo "run_env_as_proot_fakeroot($backend_command,$backend_args,$no_copy_files,$@)"
|
||||
}
|
||||
function run_env_as_groot(){
|
||||
local backend_command="$1"
|
||||
local backend_args="$2"
|
||||
local no_copy_files="$3"
|
||||
shift 3
|
||||
echo "run_env_as_groot($backend_command,$backend_args,$no_copy_files,$@)"
|
||||
}
|
||||
function run_env_as_chroot(){
|
||||
local backend_command="$1"
|
||||
local backend_args="$2"
|
||||
local no_copy_files="$3"
|
||||
shift 3
|
||||
echo "run_env_as_chroot($backend_command,$backend_args,$no_copy_files,$@)"
|
||||
}
|
||||
function run_env_as_proot_user(){
|
||||
local backend_command="$1"
|
||||
local backend_args="$2"
|
||||
local no_copy_files="$3"
|
||||
shift 3
|
||||
echo "run_env_as_proot_user($backend_command,$backend_args,$no_copy_files,$@)"
|
||||
}
|
||||
function run_env_as_bwrap_fakeroot(){
|
||||
local backend_command="$1"
|
||||
local backend_args="$2"
|
||||
local no_copy_files="$3"
|
||||
shift 3
|
||||
echo "run_env_as_bwrap_fakeroot($backend_command,$backend_args,$no_copy_files,$@)"
|
||||
}
|
||||
function run_env_as_bwrap_user(){
|
||||
local backend_command="$1"
|
||||
local backend_args="$2"
|
||||
local no_copy_files="$3"
|
||||
shift 3
|
||||
echo "run_env_as_bwrap_user($backend_command,$backend_args,$no_copy_files,$@)"
|
||||
function create_wrappers(){
|
||||
:
|
||||
}
|
||||
}
|
||||
|
||||
function test_help(){
|
||||
|
|
@ -106,6 +105,18 @@ function test_build_image_env(){
|
|||
assertEquals "build_image_env(true)" "$(cat $STDOUTF)"
|
||||
}
|
||||
|
||||
function test_create_wrappers(){
|
||||
function create_wrappers(){
|
||||
local force=$1
|
||||
echo "create_wrappers($force)"
|
||||
}
|
||||
assertCommandSuccess main create-bin-wrappers
|
||||
assertEquals "create_wrappers(false)" "$(cat $STDOUTF)"
|
||||
|
||||
assertCommandSuccess main create-bin-wrappers --force
|
||||
assertEquals "create_wrappers(true)" "$(cat $STDOUTF)"
|
||||
}
|
||||
|
||||
function test_delete_env(){
|
||||
assertCommandSuccess main s -d
|
||||
assertEquals "delete_env" "$(cat $STDOUTF)"
|
||||
|
|
|
|||
|
|
@ -45,13 +45,26 @@ function test_create_wrappers_already_exist(){
|
|||
touch $JUNEST_HOME/usr/bin/myfile
|
||||
chmod +x $JUNEST_HOME/usr/bin/myfile
|
||||
mkdir -p $JUNEST_HOME/usr/bin_wrappers
|
||||
touch $JUNEST_HOME/usr/bin_wrappers/myfile
|
||||
echo "original" > $JUNEST_HOME/usr/bin_wrappers/myfile
|
||||
chmod +x $JUNEST_HOME/usr/bin_wrappers/myfile
|
||||
assertCommandSuccess create_wrappers
|
||||
assertCommandSuccess create_wrappers false
|
||||
assertEquals "" "$(cat $STDOUTF)"
|
||||
assertTrue "bin_wrappers should exist" "[ -e $JUNEST_HOME/usr/bin_wrappers ]"
|
||||
assertTrue "myfile wrapper should exist" "[ -x $JUNEST_HOME/usr/bin_wrappers/myfile ]"
|
||||
assertEquals "" "$(touch $JUNEST_HOME/usr/bin_wrappers/myfile)"
|
||||
assertEquals "original" "$(cat $JUNEST_HOME/usr/bin_wrappers/myfile)"
|
||||
}
|
||||
|
||||
function test_create_wrappers_forced_already_exist(){
|
||||
echo "new" > $JUNEST_HOME/usr/bin/myfile
|
||||
chmod +x $JUNEST_HOME/usr/bin/myfile
|
||||
mkdir -p $JUNEST_HOME/usr/bin_wrappers
|
||||
echo "original" > $JUNEST_HOME/usr/bin_wrappers/myfile
|
||||
chmod +x $JUNEST_HOME/usr/bin_wrappers/myfile
|
||||
assertCommandSuccess create_wrappers true
|
||||
assertEquals "" "$(cat $STDOUTF)"
|
||||
assertTrue "bin_wrappers should exist" "[ -e $JUNEST_HOME/usr/bin_wrappers ]"
|
||||
assertTrue "myfile wrapper should exist" "[ -x $JUNEST_HOME/usr/bin_wrappers/myfile ]"
|
||||
assertNotEquals "original" "$(cat $JUNEST_HOME/usr/bin_wrappers/myfile)"
|
||||
}
|
||||
|
||||
function test_create_wrappers_executable_no_longer_exist(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue