From 7b43e0526e61232b4262d17404ef2973f1d076c9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 5 Nov 2013 15:30:36 +0100 Subject: [PATCH] contrib/nm-live-vm: change scripts to be run by unprevileged user The user must still be member of the 'mock' group though. Also, hack something, that the current git repositoy will be reused, so that we don't have to fetch the entire repositoy from upstream. Signed-off-by: Thomas Haller --- contrib/fedora/nm-live-vm/.gitignore | 4 ++ contrib/fedora/nm-live-vm/build.sh | 63 ++++++++++++++++++--- contrib/fedora/nm-live-vm/nm-make-script.sh | 33 ++++++++--- 3 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 contrib/fedora/nm-live-vm/.gitignore diff --git a/contrib/fedora/nm-live-vm/.gitignore b/contrib/fedora/nm-live-vm/.gitignore new file mode 100644 index 0000000000..0f63e25c18 --- /dev/null +++ b/contrib/fedora/nm-live-vm/.gitignore @@ -0,0 +1,4 @@ +.build.log +nm-live-vm/ +nm-live-vm.tar.gz +nm-live-vm-bundle.sh diff --git a/contrib/fedora/nm-live-vm/build.sh b/contrib/fedora/nm-live-vm/build.sh index d0d071fcb8..b308076b03 100755 --- a/contrib/fedora/nm-live-vm/build.sh +++ b/contrib/fedora/nm-live-vm/build.sh @@ -1,10 +1,36 @@ #!/bin/bash + +set -vx + +die() { + echo "$@" >&2 + exit 1 +} + +BASEDIR="$(readlink -f "$(dirname "$0")")" +cd "$BASEDIR" || die "Could not switch directory." + +# copy output also to logfile +exec > >(tee ./.build.log) +exec 2>&1 + +if git rev-parse --git-dir 2> /dev/null; then + INSIDE_GIT=1 +else + INSIDE_GIT= +fi + NAME="nm-live-vm" -NM_BRANCH="master" +if [[ $INSIDE_GIT ]]; then + NM_BRANCH="HEAD" +else + NM_BRANCH=master +fi + BUILD_PACKAGES="qemu febootstrap mock rpmdevtools" ARCH=i386 -ROOT="fedora-18-$ARCH" +ROOT="${ROOT:-"fedora-18-$ARCH"}" TREE="/var/lib/mock/$ROOT/root" PACKAGES="kernel passwd git autoconf automake libtool intltool gtk-doc libnl3-devel dbus-glib-devel libgudev1-devel libuuid-devel nss-devel ppp-devel dhclient @@ -18,10 +44,13 @@ KERNEL=`basename "${KERNEL_URL%.rpm}"` #RELEASE="http://kojipkgs.fedoraproject.org/packages/fedora-release/18/1/noarch/fedora-release-18-1.noarch.rpm" #PACKAGES="systemd bash" -test "$EUID" -eq 0 || { echo "$0 must be run as root"; exit 1; } +check_root() { + test "$EUID" -eq 0 +} do_prepare() { echo "Installing build packages..." + check_root || die "$0 must be run as root" rpm -q $BUILD_PACKAGES || yum install $BUILD_PACKAGES || exit 1 echo } @@ -37,9 +66,22 @@ do_chroot() { do_build() { echo "Building NetworkManager..." - cp nm-make-script.sh $TREE/usr/local/sbin/nm-make-script || exit 1 - mock -r "$ROOT" --chroot "/usr/local/sbin/nm-make-script $NM_BRANCH" || exit 1 - test -f "$TREE/usr/sbin/NetworkManager" || ( echo "NetworkManager binary not found"; exit 1; ) + + if [[ $INSIDE_GIT ]]; then + # make first a local, bare clone of our git repository and copy it into the chroot. + # nm-make-script.sh will try to fetch from it first, to save bandwidth + GIT1="`git rev-parse --show-toplevel`" + GIT2="`mktemp --tmpdir -d nm.git-XXXXXXXXX`" + git clone --bare "$GIT1" "$GIT2" || die "Could not make local clone of git dir" + mock -r "$ROOT" --chroot 'rm -rf /NetworkManager-local.git' + mock -r "$ROOT" --copyin "$GIT2" "/NetworkManager-local.git" || die "Could not copy local repositoy" + rm -rf "$GIT2" + fi + + # run the make script in chroot. + mock -r "$ROOT" --copyin nm-make-script.sh "/usr/local/sbin/" || exit 1 + mock -r "$ROOT" --chroot "/usr/local/sbin/nm-make-script.sh \"$NM_BRANCH\"" || exit 1 + test -f "$TREE/usr/sbin/NetworkManager" || die "NetworkManager binary not found" echo } @@ -47,7 +89,8 @@ do_live_vm() { echo "Preparing kernel and initrd..." || exit 1 mkdir -p $NAME || exit 1 cp $TREE/boot/vmlinuz* $NAME/vmlinuz || exit 1 - { ( cd "$TREE" && find -print0 | cpio -o0c ) || exit 1; } | gzip > $NAME/initramfs.img || exit 1 + mock -r "$ROOT" --chroot "{ ( cd / ; find -not \( -path ./tmp/initramfs.img -o -path './var/cache/yum/*' -o -path './boot' -o -path './NetworkManager' \) -xdev -print0 | cpio -o0c ) || exit 1; } | gzip > /tmp/initramfs.img || exit 1" || die "error creating initramfs" + cp "$TREE/tmp/initramfs.img" "$NAME/" || exit 1 cp run.sh $NAME/run.sh } @@ -75,8 +118,12 @@ if [ "$1" = "-b" ]; then shift 2 fi +if [[ $INSIDE_GIT ]]; then + NM_BRANCH="$(git rev-parse -q --verify "$NM_BRANCH")" || die "Could not resolve branch $NM_BRANCH" +fi + if [ $# -eq 0 ]; then - do_prepare + check_root && do_prepare do_chroot do_build do_live_vm diff --git a/contrib/fedora/nm-live-vm/nm-make-script.sh b/contrib/fedora/nm-live-vm/nm-make-script.sh index d96e970301..bdd458db6b 100755 --- a/contrib/fedora/nm-live-vm/nm-make-script.sh +++ b/contrib/fedora/nm-live-vm/nm-make-script.sh @@ -1,14 +1,33 @@ #!/bin/bash -BRANCH=${1:-"master"} -COMMIT=origin/$BRANCH +set -vx + +die() { + echo "$@" >&2 + exit 1 +} + +COMMIT=${1:-origin/master} + +URL="${2:-"git://anongit.freedesktop.org/NetworkManager/NetworkManager"}" -cd / passwd -d root -test -d NetworkManager || git clone git://anongit.freedesktop.org/NetworkManager/NetworkManager || exit 1 -cd NetworkManager/ || exit 1 -git fetch -git checkout -f $COMMIT || exit 1 +test -d /NetworkManager || ( + git init /NetworkManager + cd /NetworkManager + + # check if there is a local git repository and fetch from it first (should be faster) + test -d "/NetworkManager-local.git" && ( + git remote add local "/NetworkManager-local.git" + git fetch local + git remote remove local + rm -rf "/NetworkManager-local.git" + ) + git remote add origin "$URL" +) +cd /NetworkManager/ || exit 1 +git fetch origin || die "Could not fetch $URL" +git checkout -f "$COMMIT" || exit 1 ./autogen.sh --prefix=/usr --exec-prefix=/usr --libdir=/usr/lib --sysconfdir=/etc --localstatedir=/var --enable-gtk-doc || exit 1 make || exit 1 #make check || exit 1