mirror of
https://github.com/fsquillace/junest.git
synced 2026-01-23 02:34:30 +00:00
Add create-bin-wrappers command
This commit is contained in:
parent
5630a0f035
commit
2b9f1839f1
4 changed files with 62 additions and 6 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 Replace 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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