From: George Dunlap Date: Thu, 9 Apr 2015 14:45:37 +0000 (+0100) Subject: Import raise.sh and unraise.sh into library X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=deddbe60387caa85694cc39fe7e1e5473b6470c6;p=raisin.git Import raise.sh and unraise.sh into library Make as few changes as possible to begin with, just to separate code motion from changes. Signed-off-by: George Dunlap Signed-off-by: Stefano Stabellini --- diff --git a/lib/commands.sh b/lib/commands.sh new file mode 100755 index 0000000..5827565 --- /dev/null +++ b/lib/commands.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +build() { + if [[ $YES != "y" ]] + then + echo "Do you want Raisin to automatically install build time dependencies for you? (y/n)" + while read answer + do + if [[ "$answer" = "n" ]] + then + NO_DEPS=1 + break + elif [[ "$answer" = "y" ]] + then + break + else + echo "Reply y or n" + fi + done + fi + + mkdir -p "$INST_DIR" &>/dev/null + install_dependencies git + if [[ $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 +} + +unraise() { + for_each_component clean + + uninstall_package xen-system + for_each_component unconfigure + + rm -rf "$INST_DIR" +} + +install() { + # need single braces for filename matching expansion + if [ ! -f xen-sytem*rpm ] && [ ! -f xen-system*deb ] + then + echo You need to raise build first. + exit 1 + fi + install_package xen-system +} + +configure() { + if [[ $YES != "y" ]] + then + echo "Proceeding we'll make changes to the running system," + echo "are you sure that you want to continue? (y/n)" + while read answer + do + if [[ "$answer" = "n" ]] + then + exit 0 + elif [[ "$answer" = "y" ]] + then + break + else + echo "Reply y or n" + fi + done + fi + + for_each_component configure +} + diff --git a/raise b/raise new file mode 100755 index 0000000..37d1898 --- /dev/null +++ b/raise @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +set -e + +_help() { + echo "Usage: ./build.sh " + echo "where options are:" + echo " -n | --no-deps Do no install build-time dependencies" + echo " -v | --verbose Verbose" + echo " -y | --yes Do not ask questions and continue" + echo "where commands are:" + echo " build Build the components enabled in config" + echo " install Install binaries under / (requires sudo)" + echo " configure Configure the system (requires sudo)" + echo " unraise Uninstall and unconfigure the system (requires sudo)" +} + +# Include your defaults +if [[ -e "./config" ]] ; then + . ./config +fi + +# To use this as a library, set RAISIN_PATH appropriately +[[ -z "$RAISIN_PATH" ]] && RAISIN_PATH="$PWD/lib" + +# Then as many as the sub-libraries as you need +source ${RAISIN_PATH}/common-functions.sh +source ${RAISIN_PATH}/git-checkout.sh +source ${RAISIN_PATH}/commands.sh + +# Set up basic functionality +common_init + +# parameters check +export VERBOSE=0 +export YES="n" +export NO_DEPS=0 +while [[ $# -gt 1 ]] +do + if [[ "$1" = "-v" || "$1" = "--verbose" ]] + then + VERBOSE=1 + shift 1 + elif [[ "$1" = "-y" || "$1" = "--yes" ]] + then + YES="y" + shift 1 + else + _help + exit 1 + fi +done + +case "$1" in + "build" | "install" | "configure" | "unraise" ) + COMMAND=$1 + ;; + *) + _help + exit 1 + ;; +esac + +$COMMAND + diff --git a/raise.sh b/raise.sh deleted file mode 100755 index 422fbe4..0000000 --- a/raise.sh +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env bash - -set -e - -source config -source lib/common-functions.sh -source lib/git-checkout.sh - -_help() { - echo "Usage: ./build.sh " - echo "where options are:" - echo " -n | --no-deps Do no install build-time dependencies" - echo " -v | --verbose Verbose" - echo " -y | --yes Do not ask questions and continue" - echo "where commands are:" - echo " build Build the components enabled in config" - echo " install Install binaries under / (requires sudo)" - echo " configure Configure the system (requires sudo)" -} - -_build() { - if [[ $YES != "y" ]] - then - echo "Do you want Raisin to automatically install build time dependencies for you? (y/n)" - while read answer - do - if [[ "$answer" = "n" ]] - then - NO_DEPS=1 - break - elif [[ "$answer" = "y" ]] - then - break - else - echo "Reply y or n" - fi - done - fi - - mkdir -p "$INST_DIR" &>/dev/null - install_dependencies git - if [[ $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 -} - -_install() { - # need single braces for filename matching expansion - if [ ! -f xen-sytem*rpm ] && [ ! -f xen-system*deb ] - then - echo You need to raise.sh build first. - exit 1 - fi - install_package xen-system -} - -_configure() { - if [[ $YES != "y" ]] - then - echo "Proceeding we'll make changes to the running system," - echo "are you sure that you want to continue? (y/n)" - while read answer - do - if [[ "$answer" = "n" ]] - then - exit 0 - elif [[ "$answer" = "y" ]] - then - break - else - echo "Reply y or n" - fi - done - fi - - for_each_component configure -} - -# start execution -common_init - -# parameters check -export VERBOSE=0 -export YES="n" -export NO_DEPS=0 -while [[ $# -gt 1 ]] -do - if [[ "$1" = "-v" || "$1" = "--verbose" ]] - then - VERBOSE=1 - shift 1 - elif [[ "$1" = "-y" || "$1" = "--yes" ]] - then - YES="y" - shift 1 - else - _help - exit 1 - fi -done - -case "$1" in - "build" | "install" | "configure" ) - COMMAND=$1 - ;; - *) - _help - exit 1 - ;; -esac - -_$COMMAND - diff --git a/scripts/mkdeb b/scripts/mkdeb index 46ade07..44a4f7d 100755 --- a/scripts/mkdeb +++ b/scripts/mkdeb @@ -35,7 +35,8 @@ mkdir -p deb/opt/raisin cp -r data deb/opt/raisin cp -r components deb/opt/raisin cp -r scripts deb/opt/raisin -cp config raise.sh unraise.sh deb/opt/raisin +cp -r lib deb/opt/raisin +cp config raise deb/opt/raisin # Debian doesn't use /usr/lib64 for 64-bit libraries diff --git a/scripts/mkrpm b/scripts/mkrpm index c530466..8de4508 100755 --- a/scripts/mkrpm +++ b/scripts/mkrpm @@ -47,9 +47,9 @@ mkdir -p \$RPM_BUILD_ROOT/opt/raisin cp -r "$BASEDIR"/data \$RPM_BUILD_ROOT/opt/raisin cp -r "$BASEDIR"/components \$RPM_BUILD_ROOT/opt/raisin cp -r "$BASEDIR"/scripts \$RPM_BUILD_ROOT/opt/raisin +cp -r "$BASEDIR"/lib \$RPM_BUILD_ROOT/opt/raisin cp "$BASEDIR"/config \$RPM_BUILD_ROOT/opt/raisin -cp "$BASEDIR"/raise.sh \$RPM_BUILD_ROOT/opt/raisin -cp "$BASEDIR"/unraise.sh \$RPM_BUILD_ROOT/opt/raisin +cp "$BASEDIR"/raise \$RPM_BUILD_ROOT/opt/raisin %clean diff --git a/unraise.sh b/unraise.sh deleted file mode 100755 index 50ce310..0000000 --- a/unraise.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -set -e - -source config -source lib/common-functions.sh - - -# start execution -common_init - -for_each_component clean - -uninstall_package xen-system -for_each_component unconfigure - -rm -rf "$INST_DIR"