From: Stefano Stabellini Date: Tue, 31 Mar 2015 17:48:50 +0000 (+0000) Subject: Use rpm and deb to install and uninstall the components on the system X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;p=people%2Fgdunlap%2Fraisin.git%2F.git Use rpm and deb to install and uninstall the components on the system Rather than copying files to / and manually maintain a list of installed files, simply repackage the content of INST_DIR into a deb or rpm. Install the simple package use dpkg or rpm. Signed-off-by: Stefano Stabellini --- diff --git a/README b/README index 3658857..f18db4c 100644 --- a/README +++ b/README @@ -18,7 +18,8 @@ Set your configuration parameters in the "config" file, then run ./raise.sh Go and grab a coffee. When the script completes, you'll have a full -Xen system installation under DESTDIR. +Xen system installation under DESTDIR and a deb or rpm package +(depending on your distro) containing all the necessary binaries. raise.sh takes care of: @@ -26,12 +27,16 @@ raise.sh takes care of: - installing all the dependencies needed to build each components (requires sudo) - building them - installing them under DESTDIR (the "dist" sub-directory by default) +- creating a deb or rpm package with all the content raise.sh can optionally perform the installation under / and fully configure the system for you. If you want this behaviour run ./raise.sh -i +raise.sh performs the installation by installing the deb or rpm package, +hence it can be easily uninstalled by unraise.sh or manually by the +user. = Adding new components = @@ -53,12 +58,11 @@ git clones, builds and installs the new component under DESTDIR cleans the build * component_configure -The component has already been installed under /, now configure the -system for it +The component has already been installed, now configure the system for +it * component_unconfigure -The component has already been uninstalled from /, now remove the -configuration +The component has already been uninstalled, now remove the configuration These functions are called by raise.sh automatically if the component is enabled in the config. diff --git a/common-functions.sh b/common-functions.sh index df88f67..c67650c 100644 --- a/common-functions.sh +++ b/common-functions.sh @@ -183,3 +183,39 @@ function for_each_component () { fi done } + +function build_package() { + if test $DISTRO = "Debian" + then + ./mkdeb "$1" + elif test $DISTRO = "Fedora" + then + ./mkrpm "$1" + else + echo "Don't know how to create packages for $DISTRO" + fi +} + +function install_package() { + if test $DISTRO = "Debian" + then + $SUDO dpkg -i "$1".deb + elif test $DISTRO = "Fedora" + then + $SUDO rpm -i --force "$1"-`git show --oneline | head -1 | cut -d " " -f 1`-0.$ARCH.rpm + else + echo "Don't know how to install packages on $DISTRO" + fi +} + +function uninstall_package() { + if test $DISTRO = "Debian" + then + $SUDO dpkg -r "$1" + elif test $DISTRO = "Fedora" + then + $SUDO rpm -e "$1" + else + echo "Don't know how to uninstall packages on $DISTRO" + fi +} diff --git a/mkdeb b/mkdeb new file mode 100755 index 0000000..fd147a7 --- /dev/null +++ b/mkdeb @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +# +# mkdeb: package $INST_DIR output in a .deb +# +# Takes 1 argument: the package name +# It relies on ARCH and INST_DIR being set correctly + +set -e + +if test -z "$1" +then + echo "usage: $0 package_name" + exit 1 +fi + +name=$1 + +# map the architecture, if necessary +case "$ARCH" in + x86_32|x86_32p) arch=i386 ;; + x86_64) arch=amd64 ;; + arm32) arch=armhf ;; + arm64) arch=$ARCH;; + *) echo "Unknown ARCH $ARCH" >&2 + exit 1 + ;; +esac + +# Prepare the directory to package +rm -rf deb +cp -a "$INST_DIR" deb + +# Debian doesn't use /usr/lib64 for 64-bit libraries +if test -d deb/usr/lib64 ; then + cp -a deb/usr/lib64/* deb/usr/lib/ + rm -rf deb/usr/lib64 +fi + +# Fill in the debian boilerplate +mkdir -p deb/DEBIAN +cat >deb/DEBIAN/control <deb/DEBIAN/conffiles + + +# Package it up +chown -R root:root deb +dpkg --build deb $name.deb + +# Tidy up after ourselves +rm -rf deb diff --git a/mkrpm b/mkrpm new file mode 100755 index 0000000..47e1814 --- /dev/null +++ b/mkrpm @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# +# mkrpm: package INST_DIR in an .rpm +# +# Takes 1 argument: the package name +# It relies on ARCH and INST_DIR being set correctly + +set -e + +if test -z "$1" +then + echo "usage: $0 package_name" + exit 1 +fi + +name="$1" + +# Prepare the directory to package +rm -rf rpm + +# Fill in the rpm boilerplate +mkdir -p rpm/{BUILD,RPMS,SOURCES,SPECS,SRPMS} +cat >rpm/SPECS/xen.spec </dev/null install_dependencies git +if test $DISTRO = "Fedora" +then + install_dependencies rpm-build +fi # build and install under $DESTDIR for_each_component clean for_each_component build +build_package xen-system + if test -z "$INST" || test "$INST" -eq 0 then exit 0 fi -# install under / -TMPFILE=`mktemp` -cd "$INST_DIR" -find . > $TMPFILE -$SUDO mv -f $TMPFILE /var/log/raisin.log -$SUDO cp -ar * / || true + +install_package xen-system # configure for_each_component configure diff --git a/unraise.sh b/unraise.sh index 88d49cc..3b49f05 100755 --- a/unraise.sh +++ b/unraise.sh @@ -10,23 +10,8 @@ source common-functions.sh common_init for_each_component clean -for_each_component unconfigure -for i in `cat /var/log/raisin.log 2>/dev/null` -do - if test ! -d /"$i" - then - rm -f /"$i" - fi -done -for i in `cat /var/log/raisin.log 2>/dev/null` -do - if test -d /"$i" - then - rmdir --ignore-fail-on-non-empty /"$i" &> /dev/null || true - fi -done +uninstall_package xen-system +for_each_component unconfigure -rm -rf /var/log/raisin.log rm -rf "$INST_DIR" -