diff --git a/.travis.yml b/.travis.yml index 5a5f7f7..d3273b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,20 +4,9 @@ sudo: required install: - PATH=$PWD/bin:$PATH - - junest -f echo 'Installing junest' - - sed -i -e "s/#Server/Server/" ~/.junest/etc/pacman.d/mirrorlist - - junest -f pacman --noconfirm -Syy - - junest -f pacman --noconfirm -S base-devel + - junest --fakeroot echo 'Installing junest' script: - ./tests/test_all.sh -# Test on installing package from AUR - - junest -f yaourt --noconfirm -S tcptraceroute - - sudo $PWD/bin/junest -r tcptraceroute localhost -# Test on installing package from official repo - - junest -f pacman --noconfirm -S tree - - junest -f tree -# Test on installing package from official repo with root access - - junest -f pacman --noconfirm -S iftop - - sudo bin/junest -r iftop -t -s 5 - - yes | junest -d + - junest --check ./bin/junest + - yes | junest --delete diff --git a/bin/junest b/bin/junest index d24ab4a..d00167e 100755 --- a/bin/junest +++ b/bin/junest @@ -44,6 +44,8 @@ usage() { echo -e "Building options:" echo -e "-b, --build-image Build a $NAME image (must run in ArchLinux)" echo -e "-n, --disable-validation Disable the $NAME image validation" + echo -e "-c, --check <${CMD}_script> Validate the env located in ${JUNEST_HOME}" + echo -e " using ${CMD}_script. This will alterate the environment." echo echo -e "General options:" echo -e "-h, --help Show this help message" @@ -60,15 +62,23 @@ check_cli(){ if $OPT_BUILD_IMAGE then if $OPT_DELETE || $OPT_HELP || $OPT_VERSION || $OPT_SETUP_FROM_FILE || \ - $OPT_FAKEROOT || $OPT_ROOT + $OPT_FAKEROOT || $OPT_ROOT || $OPT_CHECK then die "The build image option must be used exclusively" fi fi + if $OPT_CHECK + then + if $OPT_DELETE || $OPT_HELP || $OPT_VERSION || $OPT_SETUP_FROM_FILE || \ + $OPT_FAKEROOT || $OPT_ROOT || $OPT_BUILD_IMAGE + then + die "The validation image option must be used exclusively" + fi + fi if $OPT_DISABLE_VALIDATION then if $OPT_DELETE || $OPT_HELP || $OPT_VERSION || $OPT_SETUP_FROM_FILE || \ - $OPT_FAKEROOT || $OPT_ROOT + $OPT_FAKEROOT || $OPT_ROOT || $OPT_CHECK then die "The disable validation option must be used with the build image option only" fi @@ -76,7 +86,7 @@ check_cli(){ if $OPT_DELETE then if $OPT_BUILD_IMAGE || $OPT_HELP || $OPT_VERSION || $OPT_SETUP_FROM_FILE || \ - $OPT_FAKEROOT || $OPT_ROOT || $OPT_DISABLE_VALIDATION + $OPT_FAKEROOT || $OPT_ROOT || $OPT_DISABLE_VALIDATION || $OPT_CHECK then die "The $NAME delete option must be used exclusively" fi @@ -84,7 +94,7 @@ check_cli(){ if $OPT_HELP then if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_VERSION || $OPT_SETUP_FROM_FILE || \ - $OPT_FAKEROOT || $OPT_ROOT || $OPT_DISABLE_VALIDATION + $OPT_FAKEROOT || $OPT_ROOT || $OPT_DISABLE_VALIDATION || $OPT_CHECK then die "The $NAME help option must be used exclusively" fi @@ -92,7 +102,7 @@ check_cli(){ if $OPT_VERSION then if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_HELP || $OPT_SETUP_FROM_FILE || \ - $OPT_FAKEROOT || $OPT_ROOT || $OPT_DISABLE_VALIDATION + $OPT_FAKEROOT || $OPT_ROOT || $OPT_DISABLE_VALIDATION || $OPT_CHECK then die "The $NAME version option must be used exclusively" fi @@ -104,7 +114,7 @@ check_cli(){ if $OPT_PROOT_ARGS || $OPT_ARCH then if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_HELP || \ - $OPT_ROOT || $OPT_VERSION || $OPT_DISABLE_VALIDATION + $OPT_ROOT || $OPT_VERSION || $OPT_DISABLE_VALIDATION || $OPT_CHECK then die "Invalid syntax: Proot and arch args are not allowed with the other options" fi @@ -112,7 +122,7 @@ check_cli(){ if [ "$ARGS" != "" ] then if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_HELP || $OPT_SETUP_FROM_FILE || \ - $OPT_VERSION || $OPT_DISABLE_VALIDATION + $OPT_VERSION || $OPT_DISABLE_VALIDATION || $OPT_CHECK then die "No arguments are needed. For the CLI syntax run: $CMD --help" fi @@ -133,6 +143,8 @@ function parse_arguments(){ ARCH_ARG="" OPT_BUILD_IMAGE=false OPT_DISABLE_VALIDATION=false + OPT_CHECK=false + CHECK_ARG="" OPT_DELETE=false OPT_HELP=false OPT_VERSION=false @@ -146,6 +158,7 @@ function parse_arguments(){ -a|--arch) OPT_ARCH=true ; shift ; ARCH_ARG=$1; shift ;; -b|--build-image) OPT_BUILD_IMAGE=true ; shift ;; -n|--disable-validation) OPT_DISABLE_VALIDATION=true ; shift ;; + -c|--check) OPT_CHECK=true ; shift ; CHECK_ARG=$1; shift ;; -d|--delete) OPT_DELETE=true ; shift ;; -h|--help) OPT_HELP=true ; shift ;; -v|--version) OPT_VERSION=true ; shift ;; @@ -172,6 +185,9 @@ function execute_operation(){ elif $OPT_DELETE; then delete_env return + elif $OPT_CHECK; then + check_env "${JUNEST_HOME}" "${CHECK_ARG}" + return fi if ! is_env_installed diff --git a/lib/core.sh b/lib/core.sh index e21b3e1..97c81f8 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -395,8 +395,12 @@ function build_image_env(){ info "Compressing image to ${imagefile}..." sudo $TAR -zcpf ${imagefile} -C ${maindir}/root . - mkdir -p ${maindir}/root_test - $disable_validation || validate_image "${maindir}/root_test" "${imagefile}" + if ! $disable_validation + then + mkdir -p ${maindir}/root_test + $TAR -zxpf ${imagefile} -C "${maindir}/root_test" + check_env "${maindir}/root_test" "${maindir}/root_test/opt/${CMD}/bin/${CMD}" + fi sudo cp ${maindir}/output/${imagefile} ${ORIGIN_WD} @@ -405,35 +409,36 @@ function build_image_env(){ sudo rm -fr "$maindir" } -function validate_image(){ +function check_env(){ local testdir=$1 - local imagefile=$2 - info "Validating ${NAME} image..." - $TAR -zxpf ${imagefile} -C ${testdir} - mkdir -p ${testdir}/run/lock - sed -i -e "s/#Server/Server/" ${testdir}/etc/pacman.d/mirrorlist - JUNEST_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -Syy + local cmd=$2 + info "Validating ${NAME} located in ${testdir} using the ${cmd} script..." + echo "Server = ${DEFAULT_MIRROR}" >> ${testdir}/etc/pacman.d/mirrorlist + JUNEST_HOME=${testdir} ${cmd} -f pacman --noconfirm -Syy # Check most basic executables work - JUNEST_HOME=${testdir} sudo -E ${testdir}/opt/${CMD}/bin/${CMD} -r pacman -Qi pacman 1> /dev/null - JUNEST_HOME=${testdir} sudo -E ${testdir}/opt/${CMD}/bin/${CMD} -r yaourt -V 1> /dev/null - JUNEST_HOME=${testdir} sudo -E ${testdir}/opt/${CMD}/bin/${CMD} -r /opt/proot/proot-$ARCH --help 1> /dev/null + JUNEST_HOME=${testdir} sudo -E ${cmd} -r pacman -Qi pacman 1> /dev/null + JUNEST_HOME=${testdir} sudo -E ${cmd} -r yaourt -V 1> /dev/null + JUNEST_HOME=${testdir} sudo -E ${cmd} -r /opt/proot/proot-$ARCH --help 1> /dev/null - local repo_package=sysstat + local repo_package=tree info "Installing ${repo_package} package from official repo using proot..." - JUNEST_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -S ${repo_package} - JUNEST_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} iostat - JUNEST_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f iostat + JUNEST_HOME=${testdir} ${cmd} -f pacman --noconfirm -S ${repo_package} + JUNEST_HOME=${testdir} ${cmd} tree + JUNEST_HOME=${testdir} ${cmd} -f tree local repo_package=iftop info "Installing ${repo_package} package from official repo using root..." - JUNEST_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -S ${repo_package} - JUNEST_HOME=${testdir} sudo -E ${testdir}/opt/${CMD}/bin/${CMD} -r iftop -t -s 5 + JUNEST_HOME=${testdir} ${cmd} -f pacman --noconfirm -S ${repo_package} + JUNEST_HOME=${testdir} sudo -E ${cmd} -r iftop -t -s 5 - JUNEST_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -S base-devel + JUNEST_HOME=${testdir} ${cmd} -f pacman --noconfirm -S base-devel local yaourt_package=tcptraceroute info "Installing ${yaourt_package} package from AUR repo using proot..." - JUNEST_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f sh --login -c "yaourt -A --noconfirm -S ${yaourt_package}" - JUNEST_HOME=${testdir} sudo -E ${testdir}/opt/${CMD}/bin/${CMD} -r tcptraceroute localhost + JUNEST_HOME=${testdir} ${cmd} -f -- yaourt -A --noconfirm -S ${yaourt_package} + JUNEST_HOME=${testdir} sudo -E ${cmd} -r tcptraceroute localhost + + info "Removing the previous packages..." + JUNEST_HOME=${testdir} ${cmd} -f pacman --noconfirm -Rsn tcptraceroute tree iftop } diff --git a/tests/test_cli.sh b/tests/test_cli.sh index a0ddf58..f78c487 100755 --- a/tests/test_cli.sh +++ b/tests/test_cli.sh @@ -14,6 +14,9 @@ function version(){ function build_image_env(){ echo "build_image_env" } +function check_env(){ + echo "check_env" +} function delete_env(){ echo "delete_env" } @@ -64,6 +67,12 @@ function test_build_image_env(){ local output=$(wrap_env --build-image) assertEquals $output "build_image_env" } +function test_check_env(){ + local output=$(wrap_env -c) + assertEquals $output "check_env" + local output=$(wrap_env --check) + assertEquals $output "check_env" +} function test_delete_env(){ local output=$(wrap_env -d) assertEquals $output "delete_env" @@ -109,6 +118,8 @@ function test_run_env_as_root(){ function test_check_cli(){ $(wrap_env -b -h 2> /dev/null) assertEquals $? 1 + $(wrap_env -b -c 2> /dev/null) + assertEquals $? 1 $(wrap_env -n -v 2> /dev/null) assertEquals $? 1 $(wrap_env -d -r 2> /dev/null)