From: Stefano Stabellini Date: Thu, 26 Mar 2015 05:15:17 +0000 (+0000) Subject: Introduce common_init fuction X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=83616e4cad22180237fc1c7d530802c78ca9d8e3;p=raisin.git Introduce common_init fuction Move common variable initializations from raise.sh and unraise.sh to common_init in common_functions.sh. Signed-off-by: Stefano Stabellini --- diff --git a/common-functions.sh b/common-functions.sh index c68a373..706d332 100644 --- a/common-functions.sh +++ b/common-functions.sh @@ -1,5 +1,35 @@ #!/usr/bin/env bash +function common_init() { + export BASEDIR=`pwd` + export GIT=${GIT-git} + export SUDO=${SUDO-sudo} + export MAKE=${MAKE-make} + export PREFIX=${PREFIX-/usr} + export INST_DIR=${DESTDIR-dist} + + INST_DIR=`readlink -f $INST_DIR` + + # execution + if test $EUID -eq 0 + then + export SUDO="" + elif test ! -f `which sudo 2>/dev/null` + then + echo "Raixen requires sudo to install build dependencies for you." + echo "Please install sudo, then run this script again." + exit 1 + fi + + get_distro + get_arch + + for f in `cat "$BASEDIR"/components/series` + do + source "$BASEDIR"/components/"$f" + done +} + function get_distro() { if test -x "`which lsb_release 2>/dev/null`" then diff --git a/raise.sh b/raise.sh index b96e0df..887779b 100755 --- a/raise.sh +++ b/raise.sh @@ -5,16 +5,6 @@ set -e source config source common-functions.sh -export BASEDIR=`pwd` -export GIT=${GIT-git} -export SUDO=${SUDO-sudo} -export MAKE=${MAKE-make} -export PREFIX=${PREFIX-/usr} -export INST_DIR=${DESTDIR-dist} - -INST_DIR=`readlink -f $INST_DIR` -mkdir -p "$INST_DIR" &>/dev/null - help() { echo "Usage: ./build.sh " echo "where options are:" @@ -23,16 +13,7 @@ help() { echo " -i | --install Install under / and configure the system" } -# execution -if test $EUID -eq 0 -then - export SUDO="" -elif test ! -f `which sudo 2>/dev/null` -then - echo "Raixen requires sudo to install build dependencies for you." - echo "Please install sudo, then run this script again." - exit 1 -fi +common_init # parameters check INST=0 @@ -58,17 +39,9 @@ do fi done - -get_distro -get_arch - +mkdir -p "$INST_DIR" &>/dev/null install_dependencies git -for f in `cat "$BASEDIR"/components/series` -do - source "$BASEDIR"/components/"$f" -done - # build and install under $DESTDIR ($BASEDIR/dist by default) for_each_component clean for_each_component build @@ -86,5 +59,3 @@ $SUDO cp -ar * / || true # configure for_each_component configure - -rm -rf "$INST_DIR" diff --git a/unraise.sh b/unraise.sh index 43b8d1e..f973846 100644 --- a/unraise.sh +++ b/unraise.sh @@ -5,32 +5,7 @@ set -e source config source common-functions.sh -export BASEDIR=`pwd` -export GIT=${GIT-git} -export SUDO=${SUDO-sudo} -export MAKE=${MAKE-make} -export PREFIX=${PREFIX-/usr} -export INST_DIR=${DESTDIR-dist} - -INST_DIR=`readlink -f $INST_DIR` - -if test $EUID -eq 0 -then - export SUDO="" -elif test ! -f `which sudo 2>/dev/null` -then - echo "Raixen requires sudo to install build dependencies for you." - echo "Please install sudo, then run this script again." - exit 1 -fi - -get_distro -get_arch - -for f in `cat "$BASEDIR"/components/series` -do - source "$BASEDIR"/components/"$f" -done +common_init for_each_component clean for_each_component unconfigure