raisin: Refactor to be more like a library
Subsystems (2)
Update to the core.sh calling convention, which will parse var=value arguments.
Also tweak some Fedora dependencies and refactor the build dependency checking / installation code.
PATCH 1/8 Add core.sh and wrapper function
Add core functionality and an executable to run it
---
CC: Stefano Stabellini <[email protected]>
--- lib/core.sh | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ raise | 16 +++++++ 2 files changed, 163 insertions(+) create mode 100644 lib/core.sh create mode 100755 raise
lib/core.sh new file +147 -0
@@ -0,0 +1,147 @@ +#!/usr/bin/env bash + +RAISIN_HELP=() + +# Core calling convention functionality +# +# $arg_parse +# +# Parse $@. Begin with every element that a '=' in it being treated +# as a variable assignment: declare the LHS a local variable and set +# it to the RHS. Once you reach an element without a '=' in it, or +# a '--', put all further elements into the array args. +# +# $requireargs VARNAME1 [VARNAME2, ...] +# +# Check to see that VARNAME1 is defined, and throw an error if not. +# +# default VARNAME "VALUE" ; $default_post +# +# Check to see is VARNAME is defined; if not, declare it a local +# variable and set it to VALUE. +# +# Example usage: +# +# function log() +# { +# local i; +# +# $arg_parse +# +# default tmpdir "/tmp"; $default_post +# +# $requireargs filename +# +# for $i in ${args[@]} ; do +# echo "$i" > $tmpdir/$filename +# done +# +# [[ -n "$flower" ] && echo $flower +# } + +arg_parse_cmd=\ +"local -a args; +local _a; +local _vn; +local _m; + +_m=true; + +for _a in \"\$@\" ; do + false && echo \"Evaluating \${_a} [[ \"\${_a/=}\" = \"\${_a}\" ]]\"; + if \$_m && [[ \"\${_a/=}\" != \"\${_a}\" ]] ; then + false && echo Parameter; + _vn=\${_a%%=*}; + eval \"local \$_vn\"; + eval \"\$_a\"; + elif \$_m && [[ \"\${_a}\" == \"--\" ]] ; then + false && echo Separator; + _m=false; + else + false && echo Argument; + _m=false; + args+=(\"\$_a\"); + fi; +done" + +arg_parse="eval $arg_parse_cmd" + +# Pass in either the current function name, or the name of the script +requireargs="eval _func=\"\$FUNCNAME\" ; eval [[ -n \\\"\$_func\\\" ]] || _func=\$0 ; eval _require-args \$_func" + +function _require-args() +{ + local _arg + local _args + + _args=($@) + + for _arg in ${_args[@]:1} ; do + eval "[[ -n \"\${$_arg}\" ]] || fail \"${_args[0]}: Missing $_arg\"" + done +} + +function default() +{ + # l0: eval i="5" + # l1: default_post="eval $1=\"$2\"" + # l3: eval "if [[ -z \"\$$1\" ]] ; then default_post=\"eval \$1=\\\"$2\\\"\" ; fi" + eval "if [[ -z \"\$$1\" ]] ; then default_post=\"eval local \$1=\\\"$2\\\"\" ; else unset default_post ; fi" +} + +function fail() +{ + echo FATAL "$@" 1>&2 + [[ -n "$fail_cleanup" ]] && $fail_cleanup + exit 1 +} + +function info() +{ + echo INFO "$@" 1>&2 +} + +function error() +{ + echo ERROR "$@" 1>&2 +} + +RAISIN_HELP+=("help List available commands") +function help() +{ + echo "Usage: $0 command [arguments...]" + echo " Run '$0 help' for a list of commands, or '$0 command-help' for" + echo " help on a particular command." + echo + + for i in "${RAISIN_HELP[@]}" ; do + echo "$i" + done + + echo + + exit 0 +} + +function cmdline() +{ + local cmd; + + [[ "$#" -eq "0" ]] && help + + $arg_parse + + # If the command is not defined, then print help and exit + if ! type "${args[0]}" 2>/dev/null | grep -q 'function' ; then + echo "Unknown function: ${args[0]}" + echo + help + fi + + info Running "${args[0]}" + "${args[0]}" "${args[@]:1}" || exit 1 + + if ! [[ -z "$RET" ]] ; then + echo $RET + fi +}
raise new file +16 -0
@@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# 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 +. ${RAISIN_PATH}/core.sh + +# And do your own thing rather than running commands +# I suggest defining a "main" function of your own and running it like this. +cmdline "$@"
Signature · 1 line
1.9.1
Re: [PATCH 1/8] Add core.sh and wrapper function
Quoted 5 lines · George Dunlap
Add core functionality and an executable to run it
Signed-off-by George Dunlap <[email protected]>---
CC: Stefano Stabellini <[email protected]>
Hmm, not sure where the 0/8 for this patch went... anyway, you can also find this series here:
git://xenbits.xenproject.org/people/gdunlap/raisin.git out/librarify/v1
-George
Quoted 190 lines
--- lib/core.sh | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ raise | 16 +++++++ 2 files changed, 163 insertions(+) create mode 100644 lib/core.sh create mode 100755 raiselib/core.sh new file +147
-0@@ -0,0 +1,147 @@ +#!/usr/bin/env bash + +RAISIN_HELP=() + +# Core calling convention functionality +# +# $arg_parse +# +# Parse $@. Begin with every element that a '=' in it being treated +# as a variable assignment: declare the LHS a local variable and set +# it to the RHS. Once you reach an element without a '=' in it, or +# a '--', put all further elements into the array args. +# +# $requireargs VARNAME1 [VARNAME2, ...] +# +# Check to see that VARNAME1 is defined, and throw an error if not. +# +# default VARNAME "VALUE" ; $default_post +# +# Check to see is VARNAME is defined; if not, declare it a local +# variable and set it to VALUE. +# +# Example usage: +# +# function log() +# { +# local i; +# +# $arg_parse +# +# default tmpdir "/tmp"; $default_post +# +# $requireargs filename +# +# for $i in ${args[@]} ; do +# echo "$i" > $tmpdir/$filename +# done +# +# [[ -n "$flower" ] && echo $flower +# } + +arg_parse_cmd=\ +"local -a args; +local _a; +local _vn; +local _m; + +_m=true; + +for _a in \"\$@\" ; do + false && echo \"Evaluating \${_a} [[ \"\${_a/=}\" = \"\${_a}\" ]]\"; + if \$_m && [[ \"\${_a/=}\" != \"\${_a}\" ]] ; then + false && echo Parameter; + _vn=\${_a%%=*}; + eval \"local \$_vn\"; + eval \"\$_a\"; + elif \$_m && [[ \"\${_a}\" == \"--\" ]] ; then + false && echo Separator; + _m=false; + else + false && echo Argument; + _m=false; + args+=(\"\$_a\"); + fi; +done" + +arg_parse="eval $arg_parse_cmd" + +# Pass in either the current function name, or the name of the script +requireargs="eval _func=\"\$FUNCNAME\" ; eval [[ -n \\\"\$_func\\\" ]] || _func=\$0 ; eval _require-args \$_func" + +function _require-args() +{ + local _arg + local _args + + _args=($@) + + for _arg in ${_args[@]:1} ; do + eval "[[ -n \"\${$_arg}\" ]] || fail \"${_args[0]}: Missing $_arg\"" + done +} + +function default() +{ + # l0: eval i="5" + # l1: default_post="eval $1=\"$2\"" + # l3: eval "if [[ -z \"\$$1\" ]] ; then default_post=\"eval \$1=\\\"$2\\\"\" ; fi" + eval "if [[ -z \"\$$1\" ]] ; then default_post=\"eval local \$1=\\\"$2\\\"\" ; else unset default_post ; fi" +} + +function fail() +{ + echo FATAL "$@" 1>&2 + [[ -n "$fail_cleanup" ]] && $fail_cleanup + exit 1 +} + +function info() +{ + echo INFO "$@" 1>&2 +} + +function error() +{ + echo ERROR "$@" 1>&2 +} + +RAISIN_HELP+=("help List available commands") +function help() +{ + echo "Usage: $0 command [arguments...]" + echo " Run '$0 help' for a list of commands, or '$0 command-help' for" + echo " help on a particular command." + echo + + for i in "${RAISIN_HELP[@]}" ; do + echo "$i" + done + + echo + + exit 0 +} + +function cmdline() +{ + local cmd; + + [[ "$#" -eq "0" ]] && help + + $arg_parse + + # If the command is not defined, then print help and exit + if ! type "${args[0]}" 2>/dev/null | grep -q 'function' ; then + echo "Unknown function: ${args[0]}" + echo + help + fi + + info Running "${args[0]}" + "${args[0]}" "${args[@]:1}" || exit 1 + + if ! [[ -z "$RET" ]] ; then + echo $RET + fi +}raise new file +16
-1@@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# 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 +. ${RAISIN_PATH}/core.sh + +# And do your own thing rather than running commands +# I suggest defining a "main" function of your own and running it like this. +cmdline "$@" --1.9.1
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 1/8] Add core.sh and wrapper function
Quoted 4 lines · George Dunlap
Quoted 2 lines · George Dunlap
Add core functionality and an executable to run it
Quoted 9 lines
Quoted 3 lines
Signed-off-by George Dunlap <[email protected]>---
CC: Stefano Stabellini <[email protected]>Hmm, not sure where the 0/8 for this patch went... anyway, you can also find this series here:
git://xenbits.xenproject.org/people/gdunlap/raisin.gitout/librarify/v1
I have applied as is patches #2 #3 #6 and #7.
I dropped patch #1 and applied the others to the existing code base. I needed to make a few changes to do so, but they are mostly unmodified.
Quoted 196 lines
Quoted 186 lines
--- lib/core.sh | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ raise | 16 +++++++ 2 files changed, 163 insertions(+) create mode 100644 lib/core.sh create mode 100755 raiselib/core.sh new file +147
-0@@ -0,0 +1,147 @@ +#!/usr/bin/env bash + +RAISIN_HELP=() + +# Core calling convention functionality +# +# $arg_parse +# +# Parse $@. Begin with every element that a '=' in it being treated +# as a variable assignment: declare the LHS a local variable and set +# it to the RHS. Once you reach an element without a '=' in it, or +# a '--', put all further elements into the array args. +# +# $requireargs VARNAME1 [VARNAME2, ...] +# +# Check to see that VARNAME1 is defined, and throw an error if not. +# +# default VARNAME "VALUE" ; $default_post +# +# Check to see is VARNAME is defined; if not, declare it a local +# variable and set it to VALUE. +# +# Example usage: +# +# function log() +# { +# local i; +# +# $arg_parse +# +# default tmpdir "/tmp"; $default_post +# +# $requireargs filename +# +# for $i in ${args[@]} ; do +# echo "$i" > $tmpdir/$filename +# done +# +# [[ -n "$flower" ] && echo $flower +# } + +arg_parse_cmd=\ +"local -a args; +local _a; +local _vn; +local _m; + +_m=true; + +for _a in \"\$@\" ; do + false && echo \"Evaluating \${_a} [[ \"\${_a/=}\" = \"\${_a}\" ]]\"; + if \$_m && [[ \"\${_a/=}\" != \"\${_a}\" ]] ; then + false && echo Parameter; + _vn=\${_a%%=*}; + eval \"local \$_vn\"; + eval \"\$_a\"; + elif \$_m && [[ \"\${_a}\" == \"--\" ]] ; then + false && echo Separator; + _m=false; + else + false && echo Argument; + _m=false; + args+=(\"\$_a\"); + fi; +done" + +arg_parse="eval $arg_parse_cmd" + +# Pass in either the current function name, or the name of the script +requireargs="eval _func=\"\$FUNCNAME\" ; eval [[ -n \\\"\$_func\\\" ]] || _func=\$0 ; eval _require-args \$_func" + +function _require-args() +{ + local _arg + local _args + + _args=($@) + + for _arg in ${_args[@]:1} ; do + eval "[[ -n \"\${$_arg}\" ]] || fail \"${_args[0]}: Missing $_arg\"" + done +} + +function default() +{ + # l0: eval i="5" + # l1: default_post="eval $1=\"$2\"" + # l3: eval "if [[ -z \"\$$1\" ]] ; then default_post=\"eval \$1=\\\"$2\\\"\" ; fi" + eval "if [[ -z \"\$$1\" ]] ; then default_post=\"eval local \$1=\\\"$2\\\"\" ; else unset default_post ; fi" +} + +function fail() +{ + echo FATAL "$@" 1>&2 + [[ -n "$fail_cleanup" ]] && $fail_cleanup + exit 1 +} + +function info() +{ + echo INFO "$@" 1>&2 +} + +function error() +{ + echo ERROR "$@" 1>&2 +} + +RAISIN_HELP+=("help List available commands") +function help() +{ + echo "Usage: $0 command [arguments...]" + echo " Run '$0 help' for a list of commands, or '$0 command-help' for" + echo " help on a particular command." + echo + + for i in "${RAISIN_HELP[@]}" ; do + echo "$i" + done + + echo + + exit 0 +} + +function cmdline() +{ + local cmd; + + [[ "$#" -eq "0" ]] && help + + $arg_parse + + # If the command is not defined, then print help and exit + if ! type "${args[0]}" 2>/dev/null | grep -q 'function' ; then + echo "Unknown function: ${args[0]}" + echo + help + fi + + info Running "${args[0]}" + "${args[0]}" "${args[@]:1}" || exit 1 + + if ! [[ -z "$RET" ]] ; then + echo $RET + fi +}raise new file +16
-1@@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# 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 +. ${RAISIN_PATH}/core.sh + +# And do your own thing rather than running commands +# I suggest defining a "main" function of your own and running it like this. +cmdline "$@" --1.9.1
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 1/8] Add core.sh and wrapper function
In reply to George DunlapQuoted 73 lines · George Dunlap
Add core functionality and an executable to run it
Signed-off-by George Dunlap <[email protected]>---
CC: Stefano Stabellini <[email protected]>--- lib/core.sh | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ raise | 16 +++++++ 2 files changed, 163 insertions(+) create mode 100644 lib/core.sh create mode 100755 raiselib/core.sh new file +55
-0@@ -0,0 +1,147 @@ +#!/usr/bin/env bash + +RAISIN_HELP=() + +# Core calling convention functionality +# +# $arg_parse +# +# Parse $@. Begin with every element that a '=' in it being treated +# as a variable assignment: declare the LHS a local variable and set +# it to the RHS. Once you reach an element without a '=' in it, or +# a '--', put all further elements into the array args. +# +# $requireargs VARNAME1 [VARNAME2, ...] +# +# Check to see that VARNAME1 is defined, and throw an error if not. +# +# default VARNAME "VALUE" ; $default_post +# +# Check to see is VARNAME is defined; if not, declare it a local +# variable and set it to VALUE. +# +# Example usage: +# +# function log() +# { +# local i; +# +# $arg_parse +# +# default tmpdir "/tmp"; $default_post +# +# $requireargs filename +# +# for $i in ${args[@]} ; do +# echo "$i" > $tmpdir/$filename +# done +# +# [[ -n "$flower" ] && echo $flower +# } + +arg_parse_cmd=\ +"local -a args; +local _a; +local _vn; +local _m; + +_m=true; + +for _a in \"\$@\" ; do + false && echo \"Evaluating \${_a} [[ \"\${_a/=}\" = \"\${_a}\" ]]\"; + if \$_m && [[ \"\${_a/=}\" != \"\${_a}\" ]] ; then + false && echo Parameter; + _vn=\${_a%%=*}; + eval \"local \$_vn\";
lib/core.sh line 65
Quoted 10 lines
lib/core.sh new file +10
-0+ eval \"\$_a\"; + elif \$_m && [[ \"\${_a}\" == \"--\" ]] ; then + false && echo Separator; + _m=false; + else + false && echo Argument; + _m=false; + args+=(\"\$_a\"); + fi; +done"
I am sorry but I cannot bear myself to introduce so much complexity into the world. raisin is supposed to be easy to read. If we end up actually needing something so powerful and so complex in the future we can import it then, but I think that at the moment we can do nicely without it.
But I do like the idea of a single unified raise script executing commands.
Quoted 87 lines
lib/core.sh new file +81
-0+arg_parse="eval $arg_parse_cmd" + +# Pass in either the current function name, or the name of the script +requireargs="eval _func=\"\$FUNCNAME\" ; eval [[ -n \\\"\$_func\\\" ]] || _func=\$0 ; eval _require-args \$_func" + +function _require-args() +{ + local _arg + local _args + + _args=($@) + + for _arg in ${_args[@]:1} ; do + eval "[[ -n \"\${$_arg}\" ]] || fail \"${_args[0]}: Missing $_arg\"" + done +} + +function default() +{ + # l0: eval i="5" + # l1: default_post="eval $1=\"$2\"" + # l3: eval "if [[ -z \"\$$1\" ]] ; then default_post=\"eval \$1=\\\"$2\\\"\" ; fi" + eval "if [[ -z \"\$$1\" ]] ; then default_post=\"eval local \$1=\\\"$2\\\"\" ; else unset default_post ; fi" +} + +function fail() +{ + echo FATAL "$@" 1>&2 + [[ -n "$fail_cleanup" ]] && $fail_cleanup + exit 1 +} + +function info() +{ + echo INFO "$@" 1>&2 +} + +function error() +{ + echo ERROR "$@" 1>&2 +} + +RAISIN_HELP+=("help List available commands") +function help() +{ + echo "Usage: $0 command [arguments...]" + echo " Run '$0 help' for a list of commands, or '$0 command-help' for" + echo " help on a particular command." + echo + + for i in "${RAISIN_HELP[@]}" ; do + echo "$i" + done + + echo + + exit 0 +} + +function cmdline() +{ + local cmd; + + [[ "$#" -eq "0" ]] && help + + $arg_parse + + # If the command is not defined, then print help and exit + if ! type "${args[0]}" 2>/dev/null | grep -q 'function' ; then + echo "Unknown function: ${args[0]}" + echo + help + fi + + info Running "${args[0]}" + "${args[0]}" "${args[@]:1}" || exit 1 + + if ! [[ -z "$RET" ]] ; then + echo $RET + fi +}raise new file +0
-0
raise line 1
Quoted 1 line
raise new file +1
-0@@ -0,0 +1,16 @@ +#!/usr/bin/env bash
It is important to "set -e" immediately to catch all possible errors:
"-e Exit immediately if a command exits with a non-zero status."
Then you can drop set -e from raise.sh and unraise.sh when you turn them into libraries.
Quoted 17 lines
raise new file +14
-0+# 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 +. ${RAISIN_PATH}/core.sh + +# And do your own thing rather than running commands +# I suggest defining a "main" function of your own and running it like this. +cmdline "$@"Signature · 1 line
1.9.1
Re: [PATCH 1/8] Add core.sh and wrapper function
Quoted 10 lines · Stefano Stabellini
raise line 1
Quoted 7 lines
raise new file +1
-0@@ -0,0 +1,16 @@ +#!/usr/bin/env bashIt is important to "set -e" immediately to catch all possible errors:
Quoted 4 lines
"-e Exit immediately if a command exits with a non-zero status."
Then you can drop set -e from
raise.shandunraise.shwhen you turn them into libraries.
"set -e" gets tricky when you sometimes expect commands to fail; particularly if you may want to do some sort of clean-up. But let's cross that bridge when we come to it. :-)
-George
Re: [PATCH 1/8] Add core.sh and wrapper function
In reply to Stefano StabelliniQuoted 22 lines · Stefano Stabellini
Quoted 22 lines
lib/core.sh new file +22
-0+arg_parse_cmd=\ +"local -a args; +local _a; +local _vn; +local _m; + +_m=true; + +for _a in \"\$@\" ; do + false && echo \"Evaluating \${_a} [[ \"\${_a/=}\" = \"\${_a}\" ]]\"; + if \$_m && [[ \"\${_a/=}\" != \"\${_a}\" ]] ; then + false && echo Parameter; + _vn=\${_a%%=*}; + eval \"local \$_vn\"; + eval \"\$_a\"; + elif \$_m && [[ \"\${_a}\" == \"--\" ]] ; then + false && echo Separator; + _m=false; + else + false && echo Argument; + _m=false; + args+=(\"\$_a\");
Quoted 8 lines
lib/core.sh line 65
Quoted 2 lines
lib/core.sh new file +2
-0+ fi; +done"I am sorry but I cannot bear myself to introduce so much complexity into the world. raisin is supposed to be easy to read. If we end up actually needing something so powerful and so complex in the future we can import it then, but I think that at the moment we can do nicely without it.
I can certainly understand the sentiment, but the idea behind this calling convention is actually to make it *easier* both to read and debug most of the source file, at the cost of two very complex, but well-tested and generic macros ($arg_parse and $requireargs).
Consider some criteria:
- Difficulty of writing or reading code that calls a function
- Difficulty of writing a function which will be called
- Availability of sensible defaults
- Ability to make sure all necessary arguments have been specified
- Passing function arguments into sub-functions
- Global variables are nasty to debug
Consider alternate ways of passing arguments into functions:
1. Positional
i.e., "cp SRC DEST"
In this model, it's easy to make sure that all necessary arguments have been specified; and there are no nasty global variables to work with.
However is really hard to program and read because you have to remember what argument goes where. You also have to specify all possible arguments -- you can't have a default. And if you need to take an argument and pass it to another function you call, you have to repeat it again.
2. Option
i.e., "-v --components='a b'"
This is easier to read if you use long options (or common ones like -v or -y), and you can also have defaults. Additionally, you can have a certain amount of error checking -- if you get an argument you don't recognize you can throw an error.
But you have to write a lot of boilerplate option processing at the top of each function; and if you have anything a bit complex (line "--components= above"), it makes it a lot harder to read. And you have to write new code every time, giving you more opportunity for bugs.
Consider the argument parsing code you have in raise at the moment -- it assumes that you will run a command without any additional parameters. What if you wanted to do something like this:
"raise -v build xen"
The current code would have to be refactored.
And you have to write a lot of custom code to check to make sure that all the required arguments have been passed in.
And you have the same problem that if you need to pass an argument further down the call stack, you have to repeat it again.
3. Global variables
i.e.,
"VAR=foo
function"
This is a bit easier to read in the sense that you're using full variable names for options. It's easier to write, since you don't have any parsing code. Additionally, variables can be passed further down the calling stack automatically without having to be explicitly copied around. In theory you should be able to have sensible local defaults.
But you have all the problems with global variables being really hard to debug.
4. Prefix variable
i.e., "YES=y check-builddep"
This is a bit easier to read in the sense that you're using full variable names for options. It's easier to write, since you don't have any parsing code. Additionally, variables can be passed further down the calling stack automatically without having to be explicitly copied around. In theory you should be able to have sensible local defaults.
I hadn't thought about this as a calling convention. It certainly has the advantage that it's build into bash and fairly well-understood by experienced users.
But I do think it's a bit unnatural to have to prefix all the variables to the function.
5. VAR=VAL automatic parsing with inheritance
This allows you to have a rich, consistent way to pass in arguments that are descriptive. It's easy to write code to parse the arguments and check to make sure you have all the ones you need: Just add $arg_parse and $requireargs at the top of your function. They are automatically declared local, so there's no worry about polluting the global namespace. They are automatically inherited, so you don't have to keep passing information further down the stack. And you can have sensible defaults.
I think #5 is well worth the little bit of macro hackery confined to a handful of well-tested macros, particularly if raise becomes a fairly large and fully-functional script. I've been using this calling convention for several years now in my own scripts, so it's pretty well tested code-wise, feature-wise, and it hasn't become a cancer that spreads throughout the rest of the code. :-)
-George
Re: [PATCH 1/8] Add core.sh and wrapper function
Quoted 131 lines · George Dunlap
Quoted 22 lines · Stefano Stabellini
Quoted 22 lines
lib/core.sh new file +22
-0+arg_parse_cmd=\ +"local -a args; +local _a; +local _vn; +local _m; + +_m=true; + +for _a in \"\$@\" ; do + false && echo \"Evaluating \${_a} [[ \"\${_a/=}\" = \"\${_a}\" ]]\"; + if \$_m && [[ \"\${_a/=}\" != \"\${_a}\" ]] ; then + false && echo Parameter; + _vn=\${_a%%=*}; + eval \"local \$_vn\"; + eval \"\$_a\"; + elif \$_m && [[ \"\${_a}\" == \"--\" ]] ; then + false && echo Separator; + _m=false; + else + false && echo Argument; + _m=false; + args+=(\"\$_a\");Quoted 8 lines
lib/core.sh line 65
Quoted 2 lines
lib/core.sh new file +2
-0+ fi; +done"I am sorry but I cannot bear myself to introduce so much complexity into the world. raisin is supposed to be easy to read. If we end up actually needing something so powerful and so complex in the future we can import it then, but I think that at the moment we can do nicely without it.
I can certainly understand the sentiment, but the idea behind this calling convention is actually to make it *easier* both to read and debug most of the source file, at the cost of two very complex, but well-tested and generic macros ($arg_parse and $requireargs).
Consider some criteria:
- Difficulty of writing or reading code that calls a function
- Difficulty of writing a function which will be called
- Availability of sensible defaults
- Ability to make sure all necessary arguments have been specified
- Passing function arguments into sub-functions
- Global variables are nasty to debugConsider alternate ways of passing arguments into functions:
1. Positional
i.e., "cp SRC DEST"
In this model, it's easy to make sure that all necessary arguments have been specified; and there are no nasty global variables to work with.
However is really hard to program and read because you have to remember what argument goes where. You also have to specify all possible arguments -- you can't have a default. And if you need to take an argument and pass it to another function you call, you have to repeat it again.
2. Option
i.e., "-v --components='a b'"
This is easier to read if you use long options (or common ones like -v or -y), and you can also have defaults. Additionally, you can have a certain amount of error checking -- if you get an argument you don't recognize you can throw an error.
But you have to write a lot of boilerplate option processing at the top of each function; and if you have anything a bit complex (line "--components= above"), it makes it a lot harder to read. And you have to write new code every time, giving you more opportunity for bugs.
Consider the argument parsing code you have in raise at the moment -- it assumes that you will run a command without any additional parameters. What if you wanted to do something like this:
"raise -v build xen"
The current code would have to be refactored.
And you have to write a lot of custom code to check to make sure that all the required arguments have been passed in.
And you have the same problem that if you need to pass an argument further down the call stack, you have to repeat it again.
3. Global variables
i.e.,
"VAR=foo
function"This is a bit easier to read in the sense that you're using full variable names for options. It's easier to write, since you don't have any parsing code. Additionally, variables can be passed further down the calling stack automatically without having to be explicitly copied around. In theory you should be able to have sensible local defaults.
But you have all the problems with global variables being really hard to debug.
4. Prefix variable
i.e., "YES=y check-builddep"
This is a bit easier to read in the sense that you're using full variable names for options. It's easier to write, since you don't have any parsing code. Additionally, variables can be passed further down the calling stack automatically without having to be explicitly copied around. In theory you should be able to have sensible local defaults.
I hadn't thought about this as a calling convention. It certainly has the advantage that it's build into bash and fairly well-understood by experienced users.
But I do think it's a bit unnatural to have to prefix all the variables to the function.
5. VAR=VAL automatic parsing with inheritance
This allows you to have a rich, consistent way to pass in arguments that are descriptive. It's easy to write code to parse the arguments and check to make sure you have all the ones you need: Just add $arg_parse and $requireargs at the top of your function. They are automatically declared local, so there's no worry about polluting the global namespace. They are automatically inherited, so you don't have to keep passing information further down the stack. And you can have sensible defaults.
Quoted 6 lines
I think #5 is well worth the little bit of macro hackery confined to a handful of well-tested macros, particularly if raise becomes a fairly large and fully-functional script. I've been using this calling convention for several years now in my own scripts, so it's pretty well tested code-wise, feature-wise, and it hasn't become a cancer that spreads throughout the rest of the code. :-)
We have two different use cases:
- command line parsing in the main script, raise
- argument parsing in the other functions
I think it might be OK to have something like 5) just for the command line parsing in raise, for the sake of giving more flexibility to the user. Also it would be confined to one specific call site. But I am uncertain that the pros outweigh the cons in this case.
I would rather avoid it in all the other functions. The reason is that not only is very complex, but it makes the code quite different from most of the other bash code out there, including DevStack. For the principle of least astonishment, I would rather have something more common and easier to read and guess the meaning of it.
I would be content with requiring a simple comment on top of each new function that documents which are the arguments of the function. Otherwise option 4) would also work.
Re: [PATCH 1/8] Add core.sh and wrapper function
Quoted 4 lines · Stefano Stabellini
I think it might be OK to have something like 5) just for the command line parsing in raise, for the sake of giving more flexibility to the user. Also it would be confined to one specific call site. But I am uncertain that the pros outweigh the cons in this case.
I've only glanced at it, but isn't this largely replicating getopt(1)? Perhaps without requiring -- on the options, but having the -- is more conventional I think.
Ian.
Re: [PATCH 1/8] Add core.sh and wrapper function
Quoted 9 lines · Ian Campbell
Quoted 4 lines · Stefano Stabellini
I think it might be OK to have something like 5) just for the command line parsing in raise, for the sake of giving more flexibility to the user. Also it would be confined to one specific call site. But I am uncertain that the pros outweigh the cons in this case.
I've only glanced at it, but isn't this largely replicating getopt(1)? Perhaps without requiring -- on the options, but having the -- is more conventional I think.
For the top-level command-line parsing, yeah, I wouldn't think introducing that crazy macro would be worth it; doing getopt just the one time is probably worth it.
For the internal calling convention, setting up getopt at the top fo every single function would be a nightmare. I have been using the $arg_parse calling convention in my own script library for several years now, and believe me, it is a *lot* nicer.
-George
Re: [PATCH 1/8] Add core.sh and wrapper function
Quoted 11 lines · George Dunlap
Quoted 9 lines · Ian Campbell
Quoted 4 lines · Stefano Stabellini
I think it might be OK to have something like 5) just for the command line parsing in raise, for the sake of giving more flexibility to the user. Also it would be confined to one specific call site. But I am uncertain that the pros outweigh the cons in this case.
I've only glanced at it, but isn't this largely replicating getopt(1)? Perhaps without requiring -- on the options, but having the -- is more conventional I think.
Quoted 8 lines
For the top-level command-line parsing, yeah, I wouldn't think introducing that crazy macro would be worth it; doing getopt just the one time is probably worth it.
For the internal calling convention, setting up getopt at the top fo every single function would be a nightmare. I have been using the $arg_parse calling convention in my own script library for several years now, and believe me, it is a *lot* nicer.
Right, that's why I trimmed all but the bit where Stefano talked about the raise command line, sorry for not making it clearer why I'd done that in my comment.
I've no particular opinion on the internal calling convention used within the shell functions.
Ian.
PATCH 2/8 Remove redundant "source" from component definitions
In reply to George DunlapThese should be called from other places that have already done the appropriate "source"
---
CC: Stefano Stabellini <[email protected]>
--- components/grub | 4 ---- components/libvirt | 4 ---- components/xen | 4 ---- 3 files changed, 12 deletions(-)
components/grub +0 -4
@@ -1,9 +1,5 @@ #!/usr/bin/env bash -source "$BASEDIR"/config -source "$BASEDIR"/scripts/common-functions.sh - - function _grub_install_dependencies() { local DEP_Debian_common="build-essential tar autoconf bison flex" local DEP_Debian_x86_32="$DEP_Debian_common"
components/libvirt +0 -4
@@ -1,9 +1,5 @@ #!/usr/bin/env bash -source "$BASEDIR"/config -source "$BASEDIR"/scripts/common-functions.sh - - function _libvirt_install_dependencies() { local DEP_Debian_common="build-essential libtool autoconf autopoint \ xsltproc libxml2-utils pkg-config python-dev \
components/xen +0 -4
@@ -1,9 +1,5 @@ #!/usr/bin/env bash -source "$BASEDIR"/config -source "$BASEDIR"/scripts/common-functions.sh - - function _xen_install_dependencies() { local DEP_Debian_common="build-essential python-dev gettext uuid-dev \ libncurses5-dev libyajl-dev libaio-dev pkg-config libglib2.0-dev \
Signature · 1 line
1.9.1
Re: [PATCH 2/8] Remove redundant "source" from component definitions
Quoted 4 lines · George Dunlap
These should be called from other places that have already done the appropriate "source"
Signed-off-by George Dunlap <[email protected]>
Yes, you are right about that. I committed this.
Quoted 52 lines
CC Stefano Stabellini <[email protected]>--- components/grub | 4 ---- components/libvirt | 4 ---- components/xen | 4 ---- 3 files changed, 12 deletions(-)components/grub +0
-4@@ -1,9 +1,5 @@ #!/usr/bin/env bash -source "$BASEDIR"/config -source "$BASEDIR"/scripts/common-functions.sh - - function _grub_install_dependencies() { local DEP_Debian_common="build-essential tar autoconf bison flex" local DEP_Debian_x86_32="$DEP_Debian_common"components/libvirt +0
-4@@ -1,9 +1,5 @@ #!/usr/bin/env bash -source "$BASEDIR"/config -source "$BASEDIR"/scripts/common-functions.sh - - function _libvirt_install_dependencies() { local DEP_Debian_common="build-essential libtool autoconf autopoint \ xsltproc libxml2-utils pkg-config python-dev \components/xen +0
-4@@ -1,9 +1,5 @@ #!/usr/bin/env bash -source "$BASEDIR"/config -source "$BASEDIR"/scripts/common-functions.sh - - function _xen_install_dependencies() { local DEP_Debian_common="build-essential python-dev gettext uuid-dev \ libncurses5-dev libyajl-dev libaio-dev pkg-config libglib2.0-dev \Signature · 1 line
1.9.1
PATCH 3/8 Move common-functions.sh and git-checkout.sh into lib
In reply to George Dunlap"script" implies something which is designed to be run standalone.
"lib" implies that this is going to be sourced from another bash script.
Also change "git-checkout" to be a function rather than a script
---
CC: Stefano Stabellini <[email protected]>
---
components/grub | 2 +-
components/libvirt | 2 +-
components/xen | 2 +-
{scripts => lib}/common-functions.sh | 0
lib/git-checkout.sh | 32 ++++++++++++++++++++++++++++++++
raise.sh | 3 ++-
scripts/git-checkout.sh | 30 ------------------------------
unraise.sh | 2 +-
8 files changed, 38 insertions(+), 35 deletions(-)
rename {scripts => lib}/common-functions.sh (100%)
create mode 100755 lib/git-checkout.sh
delete mode 100755 scripts/git-checkout.shcomponents/grub +1 -1
@@ -29,7 +29,7 @@ function grub_build() { cd "$BASEDIR" rm -f memdisk.tar tar cf memdisk.tar -C data grub.cfg - ./scripts/git-checkout.sh $GRUB_UPSTREAM_URL $GRUB_UPSTREAM_REVISION grub-dir + git-checkout $GRUB_UPSTREAM_URL $GRUB_UPSTREAM_REVISION grub-dir cd grub-dir ./autogen.sh ## GRUB32
components/libvirt +1 -1
@@ -26,7 +26,7 @@ function libvirt_build() { _libvirt_install_dependencies cd "$BASEDIR" - ./scripts/git-checkout.sh $LIBVIRT_UPSTREAM_URL $LIBVIRT_UPSTREAM_REVISION libvirt-dir + git-checkout $LIBVIRT_UPSTREAM_URL $LIBVIRT_UPSTREAM_REVISION libvirt-dir cd libvirt-dir CFLAGS="-I$INST_DIR/$PREFIX/include" \ LDFLAGS="-L$INST_DIR/$PREFIX/lib -Wl,-rpath-link=$INST_DIR/$PREFIX/lib" \
components/xen +1 -1
@@ -23,7 +23,7 @@ function xen_build() { _xen_install_dependencies cd "$BASEDIR" - ./scripts/git-checkout.sh $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir + git-checkout $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir cd xen-dir ./configure --prefix=$PREFIX $MAKE
lib/common-functions.sh renamed from scripts/common-functions.sh +0 -0
lib/git-checkout.sh new file +32 -0
@@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +function git-checkout() { + if [[ $# -lt 3 ]] + then + echo "Usage: $0 <tree> <tag> <dir>" + exit 1 + fi + + TREE=$1 + TAG=$2 + DIR=$3 + + set -e + + if [[ ! -d $DIR-remote ]] + then + rm -rf $DIR-remote $DIR-remote.tmp + mkdir -p $DIR-remote.tmp; rmdir $DIR-remote.tmp + $GIT clone $TREE $DIR-remote.tmp + if [[ "$TAG" ]] + then + cd $DIR-remote.tmp + $GIT branch -D dummy >/dev/null 2>&1 ||: + $GIT checkout -b dummy $TAG + cd .. + fi + mv $DIR-remote.tmp $DIR-remote + fi + rm -f $DIR + ln -sf $DIR-remote $DIR +}
raise.sh +2 -1
@@ -3,7 +3,8 @@ set -e source config -source scripts/common-functions.sh +source lib/common-functions.sh +source lib/git-checkout.sh _help() { echo "Usage: ./build.sh <options> <command>"
scripts/git-checkout.sh deleted +0 -30
@@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -if [[ $# -lt 3 ]] -then - echo "Usage: $0 <tree> <tag> <dir>" - exit 1 -fi - -TREE=$1 -TAG=$2 -DIR=$3 - -set -e - -if [[ ! -d $DIR-remote ]] -then - rm -rf $DIR-remote $DIR-remote.tmp - mkdir -p $DIR-remote.tmp; rmdir $DIR-remote.tmp - $GIT clone $TREE $DIR-remote.tmp - if [[ "$TAG" ]] - then - cd $DIR-remote.tmp - $GIT branch -D dummy >/dev/null 2>&1 ||: - $GIT checkout -b dummy $TAG - cd .. - fi - mv $DIR-remote.tmp $DIR-remote -fi -rm -f $DIR -ln -sf $DIR-remote $DIR
unraise.sh +1 -1
@@ -3,7 +3,7 @@ set -e source config -source scripts/common-functions.sh +source lib/common-functions.sh # start execution
Signature · 1 line
1.9.1
Re: [PATCH 3/8] Move common-functions.sh and git-checkout.sh into lib
Quoted 9 lines · George Dunlap
"script" implies something which is designed to be run standalone.
"lib" implies that this is going to be sourced from another bash script.
Also change "git-checkout" to be a function rather than a script
Signed-off-by George Dunlap <[email protected]>---
CC: Stefano Stabellini <[email protected]>
It makes sense to separate library scripts from executables. I committed this too.
Quoted 160 lines
components/grub | 2 +- components/libvirt | 2 +- components/xen | 2 +- {scripts => lib}/common-functions.sh | 0 lib/git-checkout.sh | 32 ++++++++++++++++++++++++++++++++ raise.sh | 3 ++- scripts/git-checkout.sh | 30 ------------------------------ unraise.sh | 2 +- 8 files changed, 38 insertions(+), 35 deletions(-) rename {scripts => lib}/common-functions.sh (100%) create mode 100755 lib/git-checkout.sh delete mode 100755 scripts/git-checkout.shcomponents/grub +1
-1@@ -29,7 +29,7 @@ function grub_build() { cd "$BASEDIR" rm -f memdisk.tar tar cf memdisk.tar -C data grub.cfg - ./scripts/git-checkout.sh $GRUB_UPSTREAM_URL $GRUB_UPSTREAM_REVISION grub-dir + git-checkout $GRUB_UPSTREAM_URL $GRUB_UPSTREAM_REVISION grub-dir cd grub-dir ./autogen.sh ## GRUB32components/libvirt +1
-1@@ -26,7 +26,7 @@ function libvirt_build() { _libvirt_install_dependencies cd "$BASEDIR" - ./scripts/git-checkout.sh $LIBVIRT_UPSTREAM_URL $LIBVIRT_UPSTREAM_REVISION libvirt-dir + git-checkout $LIBVIRT_UPSTREAM_URL $LIBVIRT_UPSTREAM_REVISION libvirt-dir cd libvirt-dir CFLAGS="-I$INST_DIR/$PREFIX/include" \ LDFLAGS="-L$INST_DIR/$PREFIX/lib -Wl,-rpath-link=$INST_DIR/$PREFIX/lib" \components/xen +1
-1@@ -23,7 +23,7 @@ function xen_build() { _xen_install_dependencies cd "$BASEDIR" - ./scripts/git-checkout.sh $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir + git-checkout $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir cd xen-dir ./configure --prefix=$PREFIX $MAKElib/common-functions.sh renamed from scripts/common-functions.sh +0
-0lib/git-checkout.sh new file +32
-0@@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +function git-checkout() { + if [[ $# -lt 3 ]] + then + echo "Usage: $0 <tree> <tag> <dir>" + exit 1 + fi + + TREE=$1 + TAG=$2 + DIR=$3 + + set -e + + if [[ ! -d $DIR-remote ]] + then + rm -rf $DIR-remote $DIR-remote.tmp + mkdir -p $DIR-remote.tmp; rmdir $DIR-remote.tmp + $GIT clone $TREE $DIR-remote.tmp + if [[ "$TAG" ]] + then + cd $DIR-remote.tmp + $GIT branch -D dummy >/dev/null 2>&1 ||: + $GIT checkout -b dummy $TAG + cd .. + fi + mv $DIR-remote.tmp $DIR-remote + fi + rm -f $DIR + ln -sf $DIR-remote $DIR +}raise.sh +2
-1@@ -3,7 +3,8 @@ set -e source config -source scripts/common-functions.sh +source lib/common-functions.sh +source lib/git-checkout.sh _help() { echo "Usage: ./build.sh <options> <command>"scripts/git-checkout.sh deleted +0
-30@@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -if [[ $# -lt 3 ]] -then - echo "Usage: $0 <tree> <tag> <dir>" - exit 1 -fi - -TREE=$1 -TAG=$2 -DIR=$3 - -set -e - -if [[ ! -d $DIR-remote ]] -then - rm -rf $DIR-remote $DIR-remote.tmp - mkdir -p $DIR-remote.tmp; rmdir $DIR-remote.tmp - $GIT clone $TREE $DIR-remote.tmp - if [[ "$TAG" ]] - then - cd $DIR-remote.tmp - $GIT branch -D dummy >/dev/null 2>&1 ||: - $GIT checkout -b dummy $TAG - cd .. - fi - mv $DIR-remote.tmp $DIR-remote -fi -rm -f $DIR -ln -sf $DIR-remote $DIRunraise.sh +1
-1@@ -3,7 +3,7 @@ set -e source config -source scripts/common-functions.sh +source lib/common-functions.sh # start executionSignature · 1 line
1.9.1
PATCH 4/8 Import raise.sh and unraise.sh into library
In reply to George DunlapMake as few changes as possible to begin with, just to separate code motion from changes.
For now, remove raise.sh and unraise.sh from package creation, until we can figure out what to do instead.
---
CC: Stefano Stabellini <[email protected]>
--- raise.sh => lib/build.sh | 62 ++++++++++++++++-------------------------------- raise | 6 +++++ scripts/mkdeb | 3 ++- scripts/mkrpm | 5 ++-- unraise.sh | 17 ------------- 5 files changed, 31 insertions(+), 62 deletions(-) rename raise.sh => lib/build.sh (77%) delete mode 100755 unraise.sh
lib/build.sh renamed from raise.sh +20 -42
@@ -2,10 +2,6 @@ set -e -source config -source lib/common-functions.sh -source lib/git-checkout.sh - _help() { echo "Usage: ./build.sh <options> <command>" echo "where options are:"
@@ -18,7 +14,9 @@ _help() { echo " configure Configure the system (requires sudo)" } -_build() { +build() { + $arg_parse + if [[ $YES != "y" ]] then echo "Do you want Raisin to automatically install build time dependencies for you? (y/n)"
@@ -50,7 +48,20 @@ _build() { build_package xen-system } -_install() { +unraise() { + $arg_parse + + for_each_component clean + + uninstall_package xen-system + for_each_component unconfigure + + rm -rf "$INST_DIR" +} + +install() { + $arg_parse + # need single braces for filename matching expansion if [ ! -f xen-sytem*rpm ] && [ ! -f xen-system*deb ] then
@@ -60,7 +71,9 @@ _install() { install_package xen-system } -_configure() { +configure() { + $arg_parse + if [[ $YES != "y" ]] then echo "Proceeding we'll make changes to the running system,"
@@ -82,38 +95,3 @@ _configure() { 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 -
raise +6 -0
@@ -10,6 +10,12 @@ fi # Then as many as the sub-libraries as you need . ${RAISIN_PATH}/core.sh +. ${RAISIN_PATH}/common-functions.sh +. ${RAISIN_PATH}/git-checkout.sh +. ${RAISIN_PATH}/build.sh + +# Set up basic functionality +common_init # And do your own thing rather than running commands # I suggest defining a "main" function of your own and running it like this.
scripts/mkdeb +2 -1
@@ -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 +# FIXME +#cp config raise.sh unraise.sh deb/opt/raisin # Debian doesn't use /usr/lib64 for 64-bit libraries
scripts/mkrpm +3 -2
@@ -48,8 +48,9 @@ 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 "$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 +# FIXME +# cp "$BASEDIR"/raise.sh \$RPM_BUILD_ROOT/opt/raisin +# cp "$BASEDIR"/unraise.sh \$RPM_BUILD_ROOT/opt/raisin %clean
unraise.sh deleted +0 -17
@@ -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"
Signature · 1 line
1.9.1
Re: [PATCH 4/8] Import raise.sh and unraise.sh into library
Quoted 7 lines · George Dunlap
Make as few changes as possible to begin with, just to separate code motion from changes.
For now, remove
raise.shandunraise.shfrom package creation, until we can figure out what to do instead.Signed-off-by George Dunlap <[email protected]>
Good idea, I like it.
Quoted 99 lines
CC Stefano Stabellini <[email protected]>--- raise.sh => lib/build.sh | 62 ++++++++++++++++-------------------------------- raise | 6 +++++ scripts/mkdeb | 3 ++- scripts/mkrpm | 5 ++-- unraise.sh | 17 ------------- 5 files changed, 31 insertions(+), 62 deletions(-) rename raise.sh => lib/build.sh (77%) delete mode 100755 unraise.shlib/build.sh renamed from raise.sh +20
-29@@ -2,10 +2,6 @@ set -e -source config -source lib/common-functions.sh -source lib/git-checkout.sh - _help() { echo "Usage: ./build.sh <options> <command>" echo "where options are:"@@ -18,7 +14,9 @@ _help() { echo " configure Configure the system (requires sudo)" } -_build() { +build() { + $arg_parse + if [[ $YES != "y" ]] then echo "Do you want Raisin to automatically install build time dependencies for you? (y/n)"@@ -50,7 +48,20 @@ _build() { build_package xen-system } -_install() { +unraise() { + $arg_parse + + for_each_component clean + + uninstall_package xen-system + for_each_component unconfigure + + rm -rf "$INST_DIR" +} + +install() { + $arg_parse + # need single braces for filename matching expansion if [ ! -f xen-sytem*rpm ] && [ ! -f xen-system*deb ] then@@ -60,7 +71,9 @@ _install() { install_package xen-system } -_configure() { +configure() { + $arg_parse + if [[ $YES != "y" ]] then echo "Proceeding we'll make changes to the running system,"@@ -82,38 +95,3 @@ _configure() { 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
lib/build.sh _configure() { · line 116
Quoted 10 lines
lib/build.sh renamed from raise.sh +0
-10- -case "$1" in - "build" | "install" | "configure" ) - COMMAND=$1 - ;; - *) - _help - exit 1 - ;; -esac
I would move the command line parsing to raise so that it can work without core.sh.
Quoted 24 lines
lib/build.sh renamed from raise.sh +0
-2-_$COMMAND -raise +6
-0@@ -10,6 +10,12 @@ fi # Then as many as the sub-libraries as you need . ${RAISIN_PATH}/core.sh +. ${RAISIN_PATH}/common-functions.sh +. ${RAISIN_PATH}/git-checkout.sh +. ${RAISIN_PATH}/build.sh + +# Set up basic functionality +common_init # And do your own thing rather than running commands # I suggest defining a "main" function of your own and running it like this.scripts/mkdeb +0
-0
scripts/mkdeb mkdir -p deb/opt/raisin · line 39
Quoted 6 lines
scripts/mkdeb +2
-1@@ -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 +# FIXME +#cp config raise.sh unraise.sh deb/opt/raisin
This can be easily fixed by copying lib and raise.
Quoted 7 lines
scripts/mkdeb +0
-0# Debian doesn't use /usr/lib64 for 64-bit librariesscripts/mkrpm +0
-0
scripts/mkrpm cp -r "$BASEDIR"/data \$RPM_BUILD_ROOT/opt/raisin · line 53
Quoted 8 lines
scripts/mkrpm +3
-2@@ -48,8 +48,9 @@ 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 "$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 +# FIXME +# cp "$BASEDIR"/raise.sh \$RPM_BUILD_ROOT/opt/raisin +# cp "$BASEDIR"/unraise.sh \$RPM_BUILD_ROOT/opt/raisin
same
Quoted 28 lines
scripts/mkrpm +0
-0%cleanunraise.sh deleted +0
-17@@ -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"Signature · 1 line
1.9.1
PATCH 5/8 Allow the user's config to live outside of git
In reply to George DunlapMove the default config to "defconfig" and add config to .gitignore. If config doesn't exist, then copy defconfig to it in common_init.
---
CC: Stefano Stabellini <[email protected]>
--- .gitignore | 1 + config => defconfig | 0 raise | 13 ++++++++----- 3 files changed, 9 insertions(+), 5 deletions(-) rename config => defconfig (100%)
.gitignore +1 -0
@@ -28,6 +28,7 @@ cscope.in.out cscope.out cscope.po.out .config +config xen-dir xen-dir-remote
defconfig renamed from config +0 -0
raise +8 -5
@@ -1,10 +1,5 @@ #!/usr/bin/env bash -# 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"
@@ -14,6 +9,14 @@ fi . ${RAISIN_PATH}/git-checkout.sh . ${RAISIN_PATH}/build.sh +# Include your defaults +if [[ ! -e "./config" ]] ; then + echo "No config file found, copying default config" + cp defconfig config +fi + +. ./config + # Set up basic functionality common_init
Signature · 1 line
1.9.1
Re: [PATCH 5/8] Allow the user's config to live outside of git
Quoted 4 lines · George Dunlap
Move the default config to "defconfig" and add config to .gitignore. If config doesn't exist, then copy defconfig to it in
common_init.Signed-off-by George Dunlap <[email protected]>
but you also need to update the files copied by mkdeb and mkrpm
Quoted 57 lines
CC Stefano Stabellini <[email protected]>--- .gitignore | 1 + config => defconfig | 0 raise | 13 ++++++++----- 3 files changed, 9 insertions(+), 5 deletions(-) rename config => defconfig (100%).gitignore +1
-0@@ -28,6 +28,7 @@ cscope.in.out cscope.out cscope.po.out .config +config xen-dir xen-dir-remotedefconfig renamed from config +0
-0raise +8
-5@@ -1,10 +1,5 @@ #!/usr/bin/env bash -# 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"@@ -14,6 +9,14 @@ fi . ${RAISIN_PATH}/git-checkout.sh . ${RAISIN_PATH}/build.sh +# Include your defaults +if [[ ! -e "./config" ]] ; then + echo "No config file found, copying default config" + cp defconfig config +fi + +. ./config + # Set up basic functionality common_initSignature · 1 line
1.9.1
PATCH 6/8 xen: Replace iasl with acpica-tools
In reply to George Dunlapacpica-tools is the new package that replaces iasl.
---
CC: Stefano Stabellini <[email protected]>
--- components/xen | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
components/xen +1 -1
@@ -12,7 +12,7 @@ function _xen_install_dependencies() { local DEP_Fedora_common="make gcc python-devel gettext libuuid-devel \ ncurses-devel glib2-devel libaio-devel openssl-devel yajl-devel \ patch pixman-devel glibc-devel bridge-utils grub2" - local DEP_Fedora_x86_32="$DEP_Fedora_common dev86 iasl texinfo" + local DEP_Fedora_x86_32="$DEP_Fedora_common dev86 acpica-tools texinfo" local DEP_Fedora_x86_64="$DEP_Fedora_x86_32 glibc-devel.i686" echo installing Xen dependencies
Signature · 1 line
1.9.1
Re: [PATCH 6/8] xen: Replace iasl with acpica-tools
Quoted 3 lines · George Dunlap
acpica-tools is the new package that replaces iasl.
Signed-off-by George Dunlap <[email protected]>
Acked and committed
Quoted 21 lines
CC Stefano Stabellini <[email protected]>--- components/xen | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)components/xen +1
-1@@ -12,7 +12,7 @@ function _xen_install_dependencies() { local DEP_Fedora_common="make gcc python-devel gettext libuuid-devel \ ncurses-devel glib2-devel libaio-devel openssl-devel yajl-devel \ patch pixman-devel glibc-devel bridge-utils grub2" - local DEP_Fedora_x86_32="$DEP_Fedora_common dev86 iasl texinfo" + local DEP_Fedora_x86_32="$DEP_Fedora_common dev86 acpica-tools texinfo" local DEP_Fedora_x86_64="$DEP_Fedora_x86_32 glibc-devel.i686" echo installing Xen dependenciesSignature · 1 line
1.9.1
PATCH 7/8 xen: Require wget
In reply to George DunlapThe xen build requires eiter wget or ftp. Use wget.
---
CC: Stefano Stabellini <[email protected]>
--- components/xen | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
components/xen +2 -2
@@ -3,7 +3,7 @@ function _xen_install_dependencies() { local DEP_Debian_common="build-essential python-dev gettext uuid-dev \ libncurses5-dev libyajl-dev libaio-dev pkg-config libglib2.0-dev \ - libssl-dev libpixman-1-dev bridge-utils" + libssl-dev libpixman-1-dev bridge-utils wget" local DEP_Debian_x86_32="$DEP_Debian_common bcc iasl bin86 texinfo" local DEP_Debian_x86_64="$DEP_Debian_x86_32 libc6-dev-i386" local DEP_Debian_arm32="$DEP_Debian_common libfdt-dev"
@@ -11,7 +11,7 @@ function _xen_install_dependencies() { local DEP_Fedora_common="make gcc python-devel gettext libuuid-devel \ ncurses-devel glib2-devel libaio-devel openssl-devel yajl-devel \ - patch pixman-devel glibc-devel bridge-utils grub2" + patch pixman-devel glibc-devel bridge-utils grub2 wget" local DEP_Fedora_x86_32="$DEP_Fedora_common dev86 acpica-tools texinfo" local DEP_Fedora_x86_64="$DEP_Fedora_x86_32 glibc-devel.i686"
Signature · 1 line
1.9.1
Re: [PATCH 7/8] xen: Require wget
Quoted 3 lines · George Dunlap
The xen build requires eiter wget or ftp. Use wget.
Signed-off-by George Dunlap <[email protected]>
Acked and committed
Quoted 30 lines
CC Stefano Stabellini <[email protected]>--- components/xen | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)components/xen +2
-2@@ -3,7 +3,7 @@ function _xen_install_dependencies() { local DEP_Debian_common="build-essential python-dev gettext uuid-dev \ libncurses5-dev libyajl-dev libaio-dev pkg-config libglib2.0-dev \ - libssl-dev libpixman-1-dev bridge-utils" + libssl-dev libpixman-1-dev bridge-utils wget" local DEP_Debian_x86_32="$DEP_Debian_common bcc iasl bin86 texinfo" local DEP_Debian_x86_64="$DEP_Debian_x86_32 libc6-dev-i386" local DEP_Debian_arm32="$DEP_Debian_common libfdt-dev"@@ -11,7 +11,7 @@ function _xen_install_dependencies() { local DEP_Fedora_common="make gcc python-devel gettext libuuid-devel \ ncurses-devel glib2-devel libaio-devel openssl-devel yajl-devel \ - patch pixman-devel glibc-devel bridge-utils grub2" + patch pixman-devel glibc-devel bridge-utils grub2 wget" local DEP_Fedora_x86_32="$DEP_Fedora_common dev86 acpica-tools texinfo" local DEP_Fedora_x86_64="$DEP_Fedora_x86_32 glibc-devel.i686"Signature · 1 line
1.9.1
PATCH 8/8 Refactor package dependency checking and installation
In reply to George DunlapFirst, create a new global variable, PKGTYPE. At the moment support "deb" and "rpm".
Define _check-package-$PKGTYPE which returns true if the package is installed, false otherwise, and _install-package-$PKGTYPE which will install a list of packages.
Define check-package(), which will take a list of packages, and check to see if they're installed. Any missing packages will be added to an array called "missing".
Change _${COMPONENT}_install_dependencies to ${COMPONENT}_check_package. Have these call check-package.
Don't call _${COMPONENT}_install_dependencies from ${COMPONENT}_build.
Define check-builddeps(). Define an empty "missing" array. Call check-package for "raisin" dependincies (like git and rpmbuild). Then call for_each_component check_package.
At this point we have an array with all missing packages. If it's empty, be happy. If it's non-empty, and deps=true, try to install the packages; otherwise print the missing packages and exit.
Add install-builddeps(), which is basically check-builddeps() with deps=true by default.
Call check-builddeps from build() to close the loop.
---
CC: Stefano Stabellini <[email protected]>
--- components/grub | 6 ++-- components/libvirt | 6 ++-- components/xen | 10 +++--- lib/build.sh | 87 +++++++++++++++++++++++++++++++++++------------ lib/common-functions.sh | 89 +++++++++++++++++++++++++++++++++++++++---------- 5 files changed, 148 insertions(+), 50 deletions(-)
components/grub +3 -3
@@ -1,6 +1,6 @@ #!/usr/bin/env bash -function _grub_install_dependencies() { +function grub_check_package() { local DEP_Debian_common="build-essential tar autoconf bison flex" local DEP_Debian_x86_32="$DEP_Debian_common" local DEP_Debian_x86_64="$DEP_Debian_common libc6-dev-i386"
@@ -18,8 +18,8 @@ function _grub_install_dependencies() { echo grub is only supported on x86_32 and x86_64 return fi - echo installing Grub dependencies - eval install_dependencies \$DEP_"$DISTRO"_"$ARCH" + echo checking Grub dependencies + eval check-package \$DEP_"$DISTRO"_"$ARCH" }
components/libvirt +3 -3
@@ -1,6 +1,6 @@ #!/usr/bin/env bash -function _libvirt_install_dependencies() { +function libvirt_check_package() { local DEP_Debian_common="build-essential libtool autoconf autopoint \ xsltproc libxml2-utils pkg-config python-dev \ libxml-xpath-perl libyajl-dev libxml2-dev \
@@ -18,8 +18,8 @@ function _libvirt_install_dependencies() { local DEP_Fedora_x86_32="$DEP_Fedora_common" local DEP_Fedora_x86_64="$DEP_Fedora_common" - echo installing Libvirt dependencies - eval install_dependencies \$DEP_"$DISTRO"_"$ARCH" + echo checking Libvirt dependencies + eval check-package \$DEP_"$DISTRO"_"$ARCH" } function libvirt_build() {
components/xen +5 -5
@@ -1,6 +1,8 @@ #!/usr/bin/env bash -function _xen_install_dependencies() { +function xen_check_package() { + $requireargs DISTRO ARCH + local DEP_Debian_common="build-essential python-dev gettext uuid-dev \ libncurses5-dev libyajl-dev libaio-dev pkg-config libglib2.0-dev \ libssl-dev libpixman-1-dev bridge-utils wget"
@@ -15,13 +17,11 @@ function _xen_install_dependencies() { local DEP_Fedora_x86_32="$DEP_Fedora_common dev86 acpica-tools texinfo" local DEP_Fedora_x86_64="$DEP_Fedora_x86_32 glibc-devel.i686" - echo installing Xen dependencies - eval install_dependencies \$DEP_"$DISTRO"_"$ARCH" + echo Checking Xen dependencies + eval check-package \$DEP_"$DISTRO"_"$ARCH" } function xen_build() { - _xen_install_dependencies - cd "$BASEDIR" git-checkout $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir cd xen-dir
lib/build.sh +65 -22
133 lines not on this page · raw message
lib/common-functions.sh +72 -17
117 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH 8/8] Refactor package dependency checking and installation
Quoted 19 lines · George Dunlap
First, create a new global variable, PKGTYPE. At the moment support "deb" and "rpm".
Define _check-package-$PKGTYPE which returns true if the package is installed, false otherwise, and _install-package-$PKGTYPE which will install a list of packages.
Define check-package(), which will take a list of packages, and check to see if they're installed. Any missing packages will be added to an array called "missing".
Change _${COMPONENT}_install_dependencies to ${COMPONENT}_check_package. Have these call check-package.
Don't call _${COMPONENT}_install_dependencies from ${COMPONENT}_build.
Define check-builddeps(). Define an empty "missing" array. Call check-package for "raisin" dependincies (like git and rpmbuild). Then call
for_each_componentcheck_package.
Quoted 8 lines
At this point we have an array with all missing packages. If it's empty, be happy. If it's non-empty, and deps=true, try to install the packages; otherwise print the missing packages and exit.
Add install-builddeps(), which is basically check-builddeps() with deps=true by default.
Call check-builddeps from
build()to close the loop.
I think that this is a good idea. It is nice to be able to check whether the deps are already installed before going ahead and installing them. I also like the new command to install dependencies and do nothing else.
It needs to be changed a bit to work without core.sh but it is mostly OK.
Quoted 24 lines
Signed-off-by George Dunlap <[email protected]>---
CC: Stefano Stabellini <[email protected]>--- components/grub | 6 ++-- components/libvirt | 6 ++-- components/xen | 10 +++--- lib/build.sh | 87 +++++++++++++++++++++++++++++++++++------------ lib/common-functions.sh | 89 +++++++++++++++++++++++++++++++++++++++---------- 5 files changed, 148 insertions(+), 50 deletions(-)components/grub +1
-1@@ -1,6 +1,6 @@ #!/usr/bin/env bash -function _grub_install_dependencies() { +function grub_check_package() { local DEP_Debian_common="build-essential tar autoconf bison flex" local DEP_Debian_x86_32="$DEP_Debian_common" local DEP_Debian_x86_64="$DEP_Debian_common libc6-dev-i386"
components/grub function _grub_install_dependencies() { · line 24
Quoted 9 lines
components/grub +2
-2@@ -18,8 +18,8 @@ function _grub_install_dependencies() { echo grub is only supported on x86_32 and x86_64 return fi - echo installing Grub dependencies - eval install_dependencies \$DEP_"$DISTRO"_"$ARCH" + echo checking Grub dependencies + eval check-package \$DEP_"$DISTRO"_"$ARCH" }
Need to change build not to call _grub_install_dependencies
Quoted 13 lines
components/libvirt +1
-1@@ -1,6 +1,6 @@ #!/usr/bin/env bash -function _libvirt_install_dependencies() { +function libvirt_check_package() { local DEP_Debian_common="build-essential libtool autoconf autopoint \ xsltproc libxml2-utils pkg-config python-dev \ libxml-xpath-perl libyajl-dev libxml2-dev \
components/libvirt function _libvirt_install_dependencies() { · line 23
Quoted 8 lines
components/libvirt +2
-2@@ -18,8 +18,8 @@ function _libvirt_install_dependencies() { local DEP_Fedora_x86_32="$DEP_Fedora_common" local DEP_Fedora_x86_64="$DEP_Fedora_common" - echo installing Libvirt dependencies - eval install_dependencies \$DEP_"$DISTRO"_"$ARCH" + echo checking Libvirt dependencies + eval check-package \$DEP_"$DISTRO"_"$ARCH" }
Same here
Quoted 60 lines
components/libvirt +0
-0function libvirt_build() {components/xen +5
-5@@ -1,6 +1,8 @@ #!/usr/bin/env bash -function _xen_install_dependencies() { +function xen_check_package() { + $requireargs DISTRO ARCH + local DEP_Debian_common="build-essential python-dev gettext uuid-dev \ libncurses5-dev libyajl-dev libaio-dev pkg-config libglib2.0-dev \ libssl-dev libpixman-1-dev bridge-utils wget"@@ -15,13 +17,11 @@ function _xen_install_dependencies() { local DEP_Fedora_x86_32="$DEP_Fedora_common dev86 acpica-tools texinfo" local DEP_Fedora_x86_64="$DEP_Fedora_x86_32 glibc-devel.i686" - echo installing Xen dependencies - eval install_dependencies \$DEP_"$DISTRO"_"$ARCH" + echo Checking Xen dependencies + eval check-package \$DEP_"$DISTRO"_"$ARCH" } function xen_build() { - _xen_install_dependencies - cd "$BASEDIR" git-checkout $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir cd xen-dirlib/build.sh +19
-2@@ -2,32 +2,72 @@ set -e -_help() { - echo "Usage: ./build.sh <options> <command>" +RAISIN_HELP+=("check-builddep Check to make sure we have all dependencies installed") +function check-builddep() { + local -a missing + + $arg_parse + + default deps "false" ; $default_post + + $requireargs PKGTYPE DISTRO + + check-package git + + if [[ $DISTRO = "Fedora" ]] ; then + check-package rpm-build + fi + + for_each_component check_package + + if [[ -n "${missing[@]}" ]] ; then
lib/build.sh line 33
Quoted 10 lines
lib/build.sh +10
-0+ echo "Missing packages: ${missing[@]}" + if $deps ; then + echo "Installing..." + install-package "${missing[@]}" + else + echo "Please install, or run ./raise install-builddep" + exit 1 + fi + fi +}
indentation is wrong
Quoted 13 lines
lib/build.sh +11
-1+RAISIN_HELP+=("install-builddep Install all packages required for build. Uses sudo.") +function install-builddep() { + local pkgtype + + $arg_parse + + check-builddep deps=true +} + +build-help() { + echo "Usage: $0 build opt=val" echo "where options are:" - echo " -n | --no-deps Do no install build-time dependencies"
lib/build.sh line 50
Quoted 10 lines
lib/build.sh +3
-6- 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 " yes=(true|false) Don't ask before doing anything dangerous. Defaults to false." + echo " deps=(true|false) Attempt to install dependencies. Defaults to false." + echo " verbose=(true|false) Increased verbosity. Defaults to false." }
I would keep the old style help and options for simplicity. Removing the deps option entirely is OK I think.
Quoted 17 lines
lib/build.sh +8
-3+RAISIN_HELP+=("build Clone and build components enabled in config") build() { $arg_parse - if [[ $YES != "y" ]] - then - echo "Do you want Raisin to automatically install build time dependencies for you? (y/n)" + default deps "false" ; $default_post + default verbose "false" ; $default_post + default yes "false" ; $default_post + + if $deps && ! $yes ; then + echo "WARNING: You have chosen to automatically install software as root." + echo -n "Are you sure that you want to continue? (y/n)" while read answer do if [[ "$answer" = "n" ]]
lib/build.sh line 73
Quoted 10 lines
lib/build.sh +2
-2then - NO_DEPS=1 - break + exit 0 elif [[ "$answer" = "y" ]] then + yes="true" break else echo "Reply y or n"
I would keep the warning as it was before
Quoted 131 lines
lib/build.sh +11
-8@@ -35,12 +75,10 @@ build() { done fi + check-builddep + 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@@ -59,6 +97,7 @@ unraise() { rm -rf "$INST_DIR" } +RAISIN_HELP+=("install Install binaries under / (requires sudo)") install() { $arg_parse@@ -71,12 +110,15 @@ install() { install_package xen-system } +RAISIN_HELP+=("configure Configure the system (requires sudo)") configure() { $arg_parse - if [[ $YES != "y" ]] - then - echo "Proceeding we'll make changes to the running system," + default verbose "false" ; $default_post + default yes "false" ; $default_post + + if $deps && ! $yes ; then + echo "WARNING: Proceeding we'll make changes to the running system," echo "are you sure that you want to continue? (y/n)" while read answer do@@ -85,6 +127,7 @@ configure() { exit 0 elif [[ "$answer" = "y" ]] then + yes="true" break else echo "Reply y or n"lib/common-functions.sh +31
-17@@ -97,15 +97,23 @@ function get_distro() { case "$os_VENDOR" in "Debian"* | "Ubuntu"* | "LinuxMint"* ) DISTRO="Debian" + PKGTYPE="deb" + ;; + "Fedora" ) + DISTRO="Fedora" + PKGTYPE="rpm" ;; "SUSE"* ) DISTRO="SUSE" + PKGTYPE="rpm" ;; "OpenSUSE"* | "openSUSE"* ) DISTRO="openSUSE" + PKGTYPE="rpm" ;; "Red"* | "CentOS"* ) DISTRO="CentOS" + PKGTYPE="rpm" ;; *) DISTRO=$os_VENDOR@@ -114,6 +122,7 @@ function get_distro() { export os_VENDOR os_RELEASE os_UPDATE os_CODENAME export DISTRO + export PKGTYPE } function get_arch() {@@ -122,24 +131,70 @@ function get_arch() { -e s/aarch64/arm64/` } -function install_dependencies() { - if [[ "$NO_DEPS" && "$NO_DEPS" -eq 1 ]] - then - echo "Not installing any dependencies, as requested." - echo "Depency list: $*" - return 0 +function _check-package-deb() { + $arg_parse + + $verbose && echo "Checking for package ${args[0]}" + + if dpkg -s "${args[0]}" 2>/dev/null | grep -q "Status:.*installed" ; then + return 0 + else + return 1 fi - case $DISTRO in - "Debian" ) - $SUDO apt-get install -y $* - ;; - "Fedora" ) - $SUDO yum install -y $* - ;; - * ) - echo "I don't know how to install dependencies on $DISTRO" - ;; - esac +} + +function _install-package-deb() { + $arg_parse + + $requireargs SUDO + + $SUDO apt-get install -y "${args[@]}" +} + +function _check-package-rpm() { + local pstatus +
lib/common-functions.sh function get_arch() { · line 166
Quoted 10 lines
lib/common-functions.sh +10
-0+ $arg_parse + + $verbose && echo "Checking for package ${args[0]}" + + if rpm -q "${args[0]}" 2>&1 >/dev/null ; then + return 0 + else + return 1 + fi +}
Indentation and coding style
Quoted 11 lines
lib/common-functions.sh +11
-0+function _install-package-rpm() { + $arg_parse + + $requireargs SUDO + + $SUDO yum install -y "${args[@]}" +} + +# Modifies inherited variable "missing" +function check-package() { + local p
lib/common-functions.sh function get_arch() { · line 188
Quoted 10 lines
lib/common-functions.sh +10
-0+ + $arg_parse + + $requireargs PKGTYPE + + for p in "${args[@]}" ; do + if ! _check-package-${PKGTYPE} $p ; then + missing+=("$p") + fi + done
same here
Quoted 14 lines
lib/common-functions.sh +8
-0+} + +function install-package() { + $arg_parse + + $requireargs PKGTYPE + + _install-package-${PKGTYPE} "${args[@]}" } function start_initscripts() {Signature · 1 line
1.9.1