From ebe7a345071bd753ba6284ed1b4512c7e5cfd0e0 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 4 Nov 2014 17:42:53 +0000 Subject: [PATCH] Add support for ARM --- bin/juju | 28 +++++++++++++++------------- lib/core.sh | 46 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/bin/juju b/bin/juju index 84502b3..b6bdd7d 100755 --- a/bin/juju +++ b/bin/juju @@ -28,22 +28,24 @@ source "$(dirname $0)/../lib/core.sh" ################################### usage() { - echo -e "JuJu: The portable GNU/Linux distribution" - echo -e "Usage: $NAME [options]" - echo -e "Options:" - echo -e "-i, --setup-from-file Setup the JuJu image in ${JUJU_HOME}" - echo -e "-f, --fakeroot Run JuJu with fakeroot privileges" - echo -e "-r, --root Run JuJu with root privileges" - echo -e "-b, --build-image Build a JuJu image (must run in ArchLinux only)" - echo -e "-d, --delete Delete JuJu from ${JUJU_HOME}" - echo -e "-h, --help Show this help message" - echo -e "-v, --version Show the $NAME version" + echo -e "JuJu: The portable GNU/Linux distribution" + echo -e "Usage: $NAME [options]" + echo -e "Options:" + echo -e "-i, --setup-from-file Setup the JuJu image in ${JUJU_HOME}" + echo -e "-f, --fakeroot Run JuJu with fakeroot privileges" + echo -e "-r, --root Run JuJu with root privileges" + echo -e "-b, --build-image Build a JuJu image (must run in ArchLinux + with base-devel, package-query + and arch-install-scripts installed)" + echo -e "-d, --delete Delete JuJu from ${JUJU_HOME}" + echo -e "-h, --help Show this help message" + echo -e "-v, --version Show the $NAME version" } version() { - echo -e "JuJu ($VERSION): The portable GNU/Linux distribution" - echo -e "Copyright (c) 2012-2014 Filippo Squillace " - echo -e "Homepage: http://github.com/fsquillace/juju" + echo -e "JuJu ($VERSION): The portable GNU/Linux distribution" + echo -e "Copyright (c) 2012-2014 Filippo Squillace " + echo -e "Homepage: http://github.com/fsquillace/juju" } diff --git a/lib/core.sh b/lib/core.sh index 9c72066..2d4e7dc 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -28,7 +28,14 @@ set -e source "$(dirname ${BASH_ARGV[0]})/util.sh" ################################# VARIABLES ############################## -[ -z ${JUJU_HOME} ] && JUJU_HOME=~/.juju +if [ -z ${JUJU_HOME} ] || [ ! -d ${JUJU_HOME} ] +then + JUJU_HOME=~/.juju +fi +if [ -z ${JUJU_TEMPDIR} ] || [ ! -d ${JUJU_TEMPDIR} ] +then + JUJU_TEMPDIR=/tmp +fi JUJU_REPO=https://bitbucket.org/fsquillace/juju-repo/raw/master ORIGIN_WD=$(pwd) @@ -45,6 +52,9 @@ else fi TAR=tar +ARCH=$(uname -m | grep -oE "^armv[567]") +[ "$ARCH" == "" ] && ARCH=$(uname -m) + PROOT="${JUJU_HOME}/lib64/ld-linux-x86-64.so.2 --library-path ${JUJU_HOME}/usr/lib:${JUJU_HOME}/lib ${JUJU_HOME}/usr/bin/proot" ################################# MAIN FUNCTIONS ############################## @@ -75,12 +85,12 @@ function _setup_juju(){ function setup_juju(){ # Setup the JuJu environment - local maindir=$(TMPDIR=/tmp mktemp -d -t juju.XXXXXXXXXX) + local maindir=$(TMPDIR=$JUJU_TEMPDIR mktemp -d -t juju.XXXXXXXXXX) prepare_build_directory info "Downloading JuJu..." builtin cd ${maindir} - local imagefile=juju-$(uname -m).tar.gz + local imagefile=juju-${ARCH}.tar.gz $WGET ${JUJU_REPO}/${imagefile} info "Installing JuJu..." @@ -154,17 +164,34 @@ function delete_juju(){ } +function _check_package(){ + if ! pacman -Qq $1 > /dev/null + then + error "Package $1 must be installed" + exit 1 + fi +} + function build_image_juju(){ # The function must runs on ArchLinux # The dependencies are: # arch-install-scripts # base-devel # package-query - local maindir=$(TMPDIR=/tmp mktemp -d -t juju.XXXXXXXXXX) + _check_package arch-install-scripts + _check_package gcc + _check_package package-query + local maindir=$(TMPDIR=$JUJU_TEMPDIR mktemp -d -t juju.XXXXXXXXXX) mkdir -p ${maindir}/root prepare_build_directory info "Installing pacman and its dependencies..." - pacstrap -d ${maindir}/root pacman arch-install-scripts binutils + pacstrap -d ${maindir}/root pacman arch-install-scripts binutils libunistring + + info "Generating the locales..." + ln -sf /usr/share/zoneinfo/posix/UTC ${maindir}/root/etc/localtime + echo "en_US.UTF-8 UTF-8" >> ${maindir}/root/etc/locale.gen + arch-chroot ${maindir}/root locale-gen + echo 'LANG = "en_US.UTF-8"' >> ${maindir}/root/etc/locale.conf info "Compiling and installing yaourt..." mkdir -p ${maindir}/packages/{package-query,yaourt,proot} @@ -182,18 +209,15 @@ function build_image_juju(){ info "Compiling and installing proot..." builtin cd ${maindir}/packages/proot $WGET https://aur.archlinux.org/packages/pr/proot/PKGBUILD + sed "s/arch=\(.*\)/arch=('any')/" PKGBUILD > PKGBUILD.1 + mv PKGBUILD.1 PKGBUILD makepkg -sfc --asroot pacman --noconfirm --root ${maindir}/root -U proot*.pkg.tar.xz - ln -sf /usr/share/zoneinfo/posix/UTC ${maindir}/root/etc/localtime - echo "en_US.UTF-8 UTF-8" >> ${maindir}/root/etc/locale.gen - arch-chroot ${maindir}/root locale-gen - echo 'LANG = "en_US.UTF-8"' >> ${maindir}/root/etc/locale.conf - rm ${maindir}/root/var/cache/pacman/pkg/* builtin cd ${ORIGIN_WD} - local imagefile="juju-$(uname -m).tar.gz" + local imagefile="juju-${ARCH}.tar.gz" info "Compressing image to ${imagefile}..." tar -zcpf ${imagefile} -C ${maindir}/root . cleanup_build_directory ${maindir}