diff options
author | Thomas Haller <thaller@redhat.com> | 2014-06-30 17:43:17 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-06-30 17:43:17 +0200 |
commit | d44d526c00ce7aff7443c783e1c80dbbc94dff04 (patch) | |
tree | 8d7fab983818a8ee7e2b777eccb4924993fbd4c6 | |
parent | 2469601a0ef9a158ad1363044ca5e558169ab86c (diff) | |
parent | 031142000a7b1861043c44972e8c81f714dc6fef (diff) | |
download | NetworkManager-d44d526c00ce7aff7443c783e1c80dbbc94dff04.tar.gz |
contrib/nm-live-vm: merge branch 'contrib/nm-live-vm'
Merge script to create a VM image with NetworkManager.
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | contrib/fedora/nm-live-vm/.gitignore | 4 | ||||
-rw-r--r-- | contrib/fedora/nm-live-vm/README | 20 | ||||
-rwxr-xr-x | contrib/fedora/nm-live-vm/build.sh | 154 | ||||
-rwxr-xr-x | contrib/fedora/nm-live-vm/nm-make-script.sh | 79 | ||||
-rwxr-xr-x | contrib/fedora/nm-live-vm/run.sh | 43 | ||||
-rw-r--r-- | contrib/fedora/nm-live-vm/self-extract.sh | 17 |
6 files changed, 317 insertions, 0 deletions
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/README b/contrib/fedora/nm-live-vm/README new file mode 100644 index 0000000000..75cff68a07 --- /dev/null +++ b/contrib/fedora/nm-live-vm/README @@ -0,0 +1,20 @@ +NetworkManager live VM scripts +------------------------------ + +This set of scripts can be used to build a live initramfs image suitable for +testing NetworkManager in a virtual environment. The scripts themselves are +intended to be used by a power user who can adapt them to their needs. The +result, on the contrary, is intended to be used by anyone who wants to play +with NetworkManager on the command line. + +Building the initramfs image: + +sudo ./build.sh [-n name] [-b branch/commit] + +You may have to update ./build.sh to suit your distribution. The included +version is prepared for Fedora 20 and the image is also build using Fedora 20 +repositories. + +Then you can distribute the self-extracting archive and run it on other machines: + +./nm-live-vm-bundle.sh diff --git a/contrib/fedora/nm-live-vm/build.sh b/contrib/fedora/nm-live-vm/build.sh new file mode 100755 index 0000000000..e31d021b9a --- /dev/null +++ b/contrib/fedora/nm-live-vm/build.sh @@ -0,0 +1,154 @@ +#!/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" +if [[ $INSIDE_GIT ]]; then + NM_BRANCH="HEAD" +else + NM_BRANCH=master +fi + +BUILD_PACKAGES="qemu febootstrap mock rpmdevtools" +ARCH=i386 +ROOT="${ROOT:-"fedora-20-$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 newt-devel libndp-devel + readline-devel + gobject-introspection-devel + pygobject3 + dhclient dnsmasq + bash-completion man-db man-pages vim-minimal + firewald + vim + wget + gdb valgrind lsof strace nmap-ncat tcpdump + net-tools bridge-utils vconfig + openssh-server + teamd libteam" +KERNEL_URL=http://kojipkgs.fedoraproject.org/packages/kernel/3.12.9/301.fc20/i686/kernel-3.12.9-301.fc20.i686.rpm +KERNEL=`basename "${KERNEL_URL%.rpm}"` +#RELEASE="http://kojipkgs.fedoraproject.org/packages/fedora-release/20/1/noarch/fedora-release-20-1.noarch.rpm" +#PACKAGES="systemd bash" + +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 +} + +do_chroot() { + echo "Building the chroot..." + mock -r "$ROOT" --init || exit 1 + mock -r "$ROOT" --install $PACKAGES || exit 1 + #mock -r "$ROOT" --installdeps NetworkManager || exit 1 + mock -r "$ROOT" --chroot cp /sbin/init /init || exit 1 + echo +} + +do_build() { + echo "Building NetworkManager..." + + 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 +} + +do_live_vm() { + echo "Preparing kernel and initrd..." || exit 1 + mkdir -p $NAME || exit 1 + cp $TREE/boot/vmlinuz* $NAME/vmlinuz || exit 1 + mock -r "$ROOT" --chroot "{ ( cd / ; \ + echo '/dev/sda1 /mnt/sda1 vfat defaults 0 0' >> /etc/fstab ; \ + find -not \( \ + -path ./tmp/initramfs.img -o \ + -path './var/cache/yum/*' -o \ + -path './boot' \ + \) -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 +} + +do_archive() { + echo "Creating the archive..." + tar -czvf $NAME.tar.gz $NAME || exit 1 + EXTRACT_SCRIPT=$(sed -e "s/__NAME_PLACEHOLDER__/$NAME/g" < self-extract.sh) + echo "$EXTRACT_SCRIPT" | cat - ${NAME}.tar.gz > ${NAME}-bundle.sh || exit 1 + chmod +x ${NAME}-bundle.sh || exit 1 + echo "Successfully completed" + echo + echo "Now you can run and/or distribute: ${NAME}-bundle.sh" +} + + +if [ "$1" = "-n" ]; then + test -n "$2" || { echo "Name for initramfs is expected"; exit 1; } + NAME=$2 + shift 2 +fi + +if [ "$1" = "-b" ]; then + test -n "$2" || { echo "NM branch (commit) is expected"; exit 1; } + NM_BRANCH=$2 + 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 + check_root && do_prepare + do_chroot + do_build + do_live_vm + do_archive + exit 0 +fi + +while [ $# -gt 0 ]; do + do_$1; shift + exit 0 +done + +echo "Wrong number of arguments." +exit 1 diff --git a/contrib/fedora/nm-live-vm/nm-make-script.sh b/contrib/fedora/nm-live-vm/nm-make-script.sh new file mode 100755 index 0000000000..f987842eff --- /dev/null +++ b/contrib/fedora/nm-live-vm/nm-make-script.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +set -vx + +die() { + echo "$@" >&2 + exit 1 +} + +COMMIT=${1:-origin/master} + +URL="${2:-"git://anongit.freedesktop.org/NetworkManager/NetworkManager"}" + +passwd -d root +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 +git clean -fdx +export CFLAGS='-g -Og' +export CXXFLAGS='-g -Og' +./autogen.sh --prefix=/usr \ + --exec-prefix=/usr \ + --libdir=/usr/lib \ + --sysconfdir=/etc \ + --localstatedir=/var \ + --with-nmtui=yes \ + --enable-gtk-doc || exit 1 +make || exit 1 +#make check || exit 1 +make install || exit 1 +cat <<EOF > /etc/NetworkManager/NetworkManager.conf +[main] +plugins=ifcfg-rh +debug=RLIMIT_CORE +[logging] +level=DEBUG +domains=ALL +EOF +/bin/systemctl enable NetworkManager.service || exit 1 +/bin/systemctl enable sshd.service || exit 1 + +git config --global user.name "NetworkManager Test VM" +git config --global user.email "networkmanager-maint@gnome.bugs" + +cat <<EOF > /root/.vimrc +EOF + +cat <<EOF > /root/.bashrc +LS_OPTIONS='--color=auto -Q' +alias l='ls \$LS_OPTIONS -la' +alias ll='ls \$LS_OPTIONS -l' +EOF + +# allow login for root via SSH, without password!! +sed -e 's/^#\?\(PermitRootLogin *\).*/\1yes/' \ + -e 's/^#\?\(PermitEmptyPasswords *\).*/\1yes/' \ + -i /etc/ssh/sshd_config + +# disable rate limiting of the journal +sed -e 's/^#\?\(RateLimitInterval *= *\).*/\10/' \ + -e 's/^#\?\(RateLimitBurst *= *\).*/\10/' \ + -i /etc/systemd/journald.conf + +mkdir /mnt/sda1 + +git gc diff --git a/contrib/fedora/nm-live-vm/run.sh b/contrib/fedora/nm-live-vm/run.sh new file mode 100755 index 0000000000..cd9f7c238a --- /dev/null +++ b/contrib/fedora/nm-live-vm/run.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# Three network interfaces +NET_OPTIONS="-net nic -net user,hostfwd=tcp:127.0.0.1:10022-:22 -net nic -net user -net nic -net user" + +OS="Linux" +if [ -f /etc/redhat-release ]; then + OS=`cat /etc/redhat-release | cut -d" " -f1,2,3,4` +fi + +DIR="$(dirname "$(readlink -f "$0")")" +SDIR="$DIR/share" +MEMORY=$((3*1024)) + +mkdir "$SDIR" + +cd "$DIR" + +if [ "$OS" == "Red Hat Enterprise Linux" ]; then + # qemu-kvm is installed in /usr/libexec on RHEL6 + # and redirects its output to VNC server + + rpm -q qemu-kvm tigervnc >&2 || exit 1 + + PATH=$PATH:/usr/libexec + + qemu-kvm -vnc :0 -m $MEMORY $NET_OPTIONS -kernel vmlinuz -append "video=1024x768 rootfstype=ramfs" -initrd initramfs.img & + + sleep 1 + vncviewer localhost + +else + # all other distros + + QEMU="qemu-kvm" + which $QEMU &>2 || { + ARCH=`uname -m` + which qemu-system-$ARCH &>2 || { echo "Neither '$QEMU' nor 'qemu-system-$ARCH' available"; exit 1; } + QEMU="qemu-system-$ARCH -enable-kvm" + } + + $QEMU -m $MEMORY -net nic $NET_OPTIONS -drive "file=fat:rw:$SDIR,cache=none" -kernel vmlinuz -append "video=1024x768 rootfstype=ramfs" -initrd initramfs.img +fi diff --git a/contrib/fedora/nm-live-vm/self-extract.sh b/contrib/fedora/nm-live-vm/self-extract.sh new file mode 100644 index 0000000000..754e98337d --- /dev/null +++ b/contrib/fedora/nm-live-vm/self-extract.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +NAME=__NAME_PLACEHOLDER__ +BUNDLE=`readlink -f "$0"` || exit 1 +TEMP=`mktemp -d "$PWD/$NAME.XXXXXXXXXX"` || exit 1 + +echo "Extracting to: $TEMP" +cd "$TEMP" || exit 1 +sed '1,/^__MARK__$/d' "$BUNDLE" > $NAME.tar.gz || exit 1 +tar -xvf $NAME.tar.gz || exit 1 +cd $NAME || exit 1 + +./run.sh || exit 1 + +#rm -rf "$TEMP" +exit 0 +__MARK__ |