diff --git a/README.md b/README.md index 1f066d4..9ba7a95 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,11 @@ Advanced usage ### Build image ### You can build a new JuJu image from scratch by running the following command: - juju -b + juju -b [-n] -In this way the script will create a directory containing all the essentials +The script will create a directory containing all the essentials files in order to make JuJu working properly (such as pacman, yaourt, arch-chroot and proot). +The option `-n` will skip the final validation tests if they are not needed. Remember that the script to build the image must run in an Arch Linux OS with arch-install-scripts, package-query, git and the base-devel packages installed. To change the build directory just use the *JUJU_TEMPDIR* (by default /tmp). @@ -183,7 +184,7 @@ since JuJu will try to preserve the JuJu environment by assigning ownership of the files to the real user. ###No servers configured for repository### --**Q**: Why I cannot install packages? +- **Q**: Why I cannot install packages? ``` pacman -S lsof Packages (1): lsof-4.88-2 @@ -197,7 +198,7 @@ of the files to the real user. Errors occurred, no packages were upgraded. ``` --**A**: You need simply to update the mirrorlist file according to your location: +- **A**: You need simply to update the mirrorlist file according to your location: ``` # Uncomment the repository line according to your location nano /etc/pacman.d/mirrorlist diff --git a/bin/juju b/bin/juju index 41a37fa..8ff792b 100755 --- a/bin/juju +++ b/bin/juju @@ -42,6 +42,7 @@ usage() { echo -e "-r, --root Run $NAME with root privileges" echo -e "-p, --proot-args Proot arguments" 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 "-d, --delete Delete $NAME from ${JUJU_HOME}" echo -e "-h, --help Show this help message" echo -e "-v, --version Show the $NAME version" @@ -62,10 +63,18 @@ check_cli(){ die "The build 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 + then + die "The disable validation option must be used with the build image option only" + fi + fi if $OPT_DELETE then if $OPT_BUILD_IMAGE || $OPT_HELP || $OPT_VERSION || $OPT_SETUP_FROM_FILE || \ - $OPT_FAKEROOT || $OPT_ROOT + $OPT_FAKEROOT || $OPT_ROOT || $OPT_DISABLE_VALIDATION then die "The $NAME delete option must be used exclusively" fi @@ -73,7 +82,7 @@ check_cli(){ if $OPT_HELP then if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_VERSION || $OPT_SETUP_FROM_FILE || \ - $OPT_FAKEROOT || $OPT_ROOT + $OPT_FAKEROOT || $OPT_ROOT || $OPT_DISABLE_VALIDATION then die "The $NAME help option must be used exclusively" fi @@ -81,7 +90,7 @@ check_cli(){ if $OPT_VERSION then if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_HELP || $OPT_SETUP_FROM_FILE || \ - $OPT_FAKEROOT || $OPT_ROOT + $OPT_FAKEROOT || $OPT_ROOT || $OPT_DISABLE_VALIDATION then die "The $NAME version option must be used exclusively" fi @@ -93,7 +102,7 @@ check_cli(){ if $OPT_PROOT_ARGS then if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_HELP || $OPT_SETUP_FROM_FILE || \ - $OPT_ROOT || $OPT_VERSION + $OPT_ROOT || $OPT_VERSION || $OPT_DISABLE_VALIDATION then die "Invalid syntax: Proot args are not allowed with the other options" fi @@ -101,7 +110,7 @@ check_cli(){ if [ "$ARGS" != "" ] then if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_HELP || $OPT_SETUP_FROM_FILE || \ - $OPT_VERSION + $OPT_VERSION || $OPT_DISABLE_VALIDATION then die "No arguments are needed. For the CLI syntax run: $CMD --help" fi @@ -119,6 +128,7 @@ function parse_arguments(){ OPT_PROOT_ARGS=false PROOT_ARGS="" OPT_BUILD_IMAGE=false + OPT_DISABLE_VALIDATION=false OPT_DELETE=false OPT_HELP=false OPT_VERSION=false @@ -130,6 +140,7 @@ function parse_arguments(){ -r|--root) OPT_ROOT=true ; shift ;; -p|--proot-args) OPT_PROOT_ARGS=true ; shift ; PROOT_ARGS=$1; shift ;; -b|--build-image) OPT_BUILD_IMAGE=true ; shift ;; + -n|--disable-validation) OPT_DISABLE_VALIDATION=true ; shift ;; -d|--delete) OPT_DELETE=true ; shift ;; -h|--help) OPT_HELP=true ; shift ;; -v|--version) OPT_VERSION=true ; shift ;; @@ -151,7 +162,7 @@ function execute_operation(){ $OPT_VERSION && version && return if $OPT_BUILD_IMAGE; then - build_image_juju + build_image_juju $OPT_DISABLE_VALIDATION return elif $OPT_DELETE; then delete_juju diff --git a/lib/core.sh b/lib/core.sh index 8d070af..8580c1e 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -254,6 +254,9 @@ function build_image_juju(){ _check_package gcc _check_package package-query _check_package git + + local disable_validation=$1 + local maindir=$(TMPDIR=$JUJU_TEMPDIR mktemp -d -t juju.XXXXXXXXXX) sudo mkdir -p ${maindir}/root trap - QUIT EXIT ABRT KILL TERM INT @@ -312,6 +315,18 @@ function build_image_juju(){ info "Compressing image to ${imagefile}..." sudo $TAR -zcpf ${imagefile} -C ${maindir}/root . + $disable_validation || validate_image "${maindir}" "${imagefile}" + + sudo cp ${maindir}/output/${imagefile} ${ORIGIN_WD} + + builtin cd ${ORIGIN_WD} + trap - QUIT EXIT ABRT KILL TERM INT + sudo rm -fr "$maindir" +} + +function validate_image(){ + local maindir=$1 + local imagefile=$2 info "Validating JuJu image..." mkdir -p ${maindir}/root_test $TAR -zxpf ${imagefile} -C ${maindir}/root_test @@ -340,10 +355,4 @@ function build_image_juju(){ info "Installing ${repo_package} package from official repo using root..." ${maindir}/root/opt/proot/proot-$ARCH -S ${maindir}/root_test pacman --noconfirm -S ${repo_package} sudo ${maindir}/root/usr/bin/arch-chroot ${maindir}/root_test iftop -t -s 5 - - sudo cp ${maindir}/output/${imagefile} ${ORIGIN_WD} - - builtin cd ${ORIGIN_WD} - trap - QUIT EXIT ABRT KILL TERM INT - sudo rm -fr "$maindir" } diff --git a/tests/test_juju.sh b/tests/test_juju.sh index 0c2e748..6665432 100755 --- a/tests/test_juju.sh +++ b/tests/test_juju.sh @@ -117,6 +117,8 @@ function test_check_cli(){ export -f die bash -ic "wrap_juju -b -h" &> /dev/null is_equal $? 1 || return 1 + bash -ic "wrap_juju -n -v" &> /dev/null + is_equal $? 1 || return 1 bash -ic "wrap_juju -d -r" &> /dev/null is_equal $? 1 || return 1 bash -ic "wrap_juju -h -f" &> /dev/null